netrc
— netrc 文件处理
¶
源代码: Lib/netrc.py
The
netrc
类剖析和封装的 netrc 文件格式用于 Unix
ftp
程序和其它 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 – as determined byos.path.expanduser()– will be read. Otherwise, aFileNotFoundErrorexception will be raised. 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.3.4 版改变: 添加 POSIX (便携式操作系统接口) 权限校验。
3.7 版改变:
os.path.expanduser()用于查找位置对于.netrc文件当 file 未作为自变量传递。3.10 版改变:
netrctry 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.