netrc --- netrc file processing

Code source : Lib/netrc.py


La classe netrc analyse et encapsule le format de fichier netrc utilisé par le programme Unix ftp et d'autres clients FTP.

class netrc.netrc([file])

A netrc instance or subclass instance encapsulates data from a netrc file. The initialization argument, if present, specifies the file to parse. If no argument is given, the file .netrc in the user's home directory -- as determined by os.path.expanduser() -- will be read. Otherwise, a FileNotFoundError exception will be raised. Parse errors will raise NetrcParseError with diagnostic information including the file name, line number, and terminating token.

If no argument is specified on a POSIX system, the presence of passwords in the .netrc file will raise a NetrcParseError if the file ownership or permissions are insecure (owned by a user other than the user running the process, or accessible for read or write by any other user). This implements security behavior equivalent to that of ftp and other programs that use .netrc. Such security checks are not available on platforms that do not support os.getuid().

Modifié dans la version 3.4: Ajout de la vérification d'autorisations POSIX.

Modifié dans la version 3.7: os.path.expanduser() est utilisée pour trouver l'emplacement du fichier netrc lorsque file n'est pas passé en tant qu'argument.

Modifié dans la version 3.10: netrc try UTF-8 encoding before using locale specific encoding. The entry in the netrc file no longer needs to contain all tokens. The missing tokens' value default to an empty string. All the tokens and their values now can contain arbitrary characters, like whitespace and non-ASCII characters. If the login name is anonymous, it won't trigger the security check.

exception netrc.NetrcParseError

Exception raised by the netrc class when syntactical errors are encountered in source text. Instances of this exception provide three interesting attributes:

msg

Textual explanation of the error.

filename

The name of the source file.

lineno

The line number on which the error was found.

Objets netrc

Une instance netrc a les méthodes suivantes :

netrc.authenticators(host)

Renvoie un triplet (login, account, password) pour s'authentifier auprès de l'hôte host. Si le fichier netrc ne contient pas d'entrée pour l'hôte donné, renvoie le triplet associé à l'entrée par défaut. Si aucun hôte correspondant ni aucune entrée par défaut n'est disponible, renvoie None.

netrc.__repr__()

Déverse les données de la classe sous forme de chaîne dans le format d'un fichier netrc. (Ceci ignore les commentaires et peut réorganiser les entrées).

Les instances de netrc ont des variables d'instance publiques :

netrc.hosts

Dictionnaire faisant correspondre les noms d'hôtes dans des triplets (login, account, password). L'entrée par défaut, le cas échéant, est représentée en tant que pseudo-hôte par ce nom.

netrc.macros

Dictionnaire faisant correspondre les noms de macro en listes de chaînes.