13.4. netrc — Arquivo de processamento netrc¶
Novo na versão 1.5.2.
Código-fonte: Lib/netrc.py
A classe netrc analisa e encapsula o formato do arquivo netrc usado pelo programa Unix ftp e outros clientes FTP.
-
class
netrc.netrc([file])¶ A
netrcinstance 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.netrcin the user’s home directory will be read. Parse errors will raiseNetrcParseErrorwith 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.netrcfile will raise aNetrcParseErrorif 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.Alterado na versão 2.7.6: Added the POSIX permissions check.
-
exception
netrc.NetrcParseError¶ Exceção levantada pela classe
netrcquando erros sintáticos são encontrados no texto de origem. As instâncias desta exceção fornecem três atributos interessantes:msgé uma explicação textual do erro,filenameé o nome do arquivo-fonte elinenofornece o número da linha na qual o erro foi encontrado.
13.4.1. Objetos netrc¶
Uma instância da classe netrc tem os seguintes métodos:
-
netrc.authenticators(host)¶ Retorna uma tupla de 3 elementos
(login, conta, senha)dos autenticadores do host. Se o arquivo netrc não contém uma entrada para o host dado, retorna a tupla associada com a entrada padrão. Se não houver nenhum host correspondente nem uma entrada padrão estiver disponível, retornaNone.
-
netrc.__repr__()¶ Despeja os dados da classe como uma string no formato de um arquivo netrc. (Isso descarta os comentários e pode reordenar as entradas.)
Instâncias de netrc possuem variáveis de instância públicas:
-
netrc.hosts¶ Dicionário mapeando nomes de host para tuplas
(login, conta, senha). A entrada default, se houver, é representada como um pseudo-host por esse nome.
-
netrc.macros¶ Dicionário mapeando nomes de macros para listas de strings.
Nota
Passwords are limited to a subset of the ASCII character set. Versions of this module prior to 2.3 were extremely limited. Starting with 2.3, all ASCII punctuation is allowed in passwords. However, note that whitespace and non-printable characters are not allowed in passwords. This is a limitation of the way the .netrc file is parsed and may be removed in the future.
