netrc
— netrc 파일 처리¶
소스 코드: Lib/netrc.py
netrc
클래스는 유닉스 ftp 프로그램과 다른 FTP 클라이언트가 사용하는 netrc 파일 형식을 구문 분석하고 캡슐화합니다.
- 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 byos.path.expanduser()
– will be read. Otherwise, aFileNotFoundError
exception will be raised. Parse errors will raiseNetrcParseError
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 aNetrcParseError
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 supportos.getuid()
.버전 3.4에서 변경: POSIX 권한 검사를 추가했습니다.
버전 3.7에서 변경: file이 인자로 전달되지 않으면
os.path.expanduser()
가.netrc
파일의 위치를 찾는 데 사용됩니다.버전 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¶
소스 텍스트에 문법적인 에러가 있을 때
netrc
클래스에서 발생하는 예외. 이 예외 인스턴스는 세 가지 흥미로운 어트리뷰트를 제공합니다.- msg¶
에러의 텍스트 설명.
- filename¶
소스 파일의 이름.
- lineno¶
에러가 발견된 줄 번호.
netrc 객체¶
netrc
인스턴스에는 다음과 같은 메서드가 있습니다:
- netrc.authenticators(host)¶
host에 대한 인증 자의 3-tuple
(login, account, password)
를 반환합니다. netrc 파일에 주어진 호스트에 대한 항목이 없으면 ‘default’ 항목과 연관된 튜플을 반환합니다. 일치하는 호스트도 기본 항목도 사용할 수 없으면None
을 반환합니다.
- netrc.__repr__()¶
클래스 데이터를 netrc 파일의 형식의 문자열로 덤프합니다. (이것은 주석을 버리고 엔트리를 재정렬할 수 있습니다.)
netrc
의 인스턴스에는 공개 인스턴스 변수가 있습니다:
- netrc.hosts¶
호스트 이름을
(login, account, password)
튜플에 매핑하는 딕셔너리. ‘default’ 항목이 있으면 그 이름의 의사 호스트로 표시됩니다.
- netrc.macros¶
매크로 이름을 문자열 리스트에 매핑하는 딕셔너리.