Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Doc/library/netrc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ the Unix :program:`ftp` program and other FTP clients.
.. class:: netrc([file])

A :class:`~netrc.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 :file:`.netrc` in the user's home directory --
as determined by :func:`os.path.expanduser` -- will be read. Otherwise,
file. The initialization argument, if present, specifies the file to parse. If no
argument is given, it will look for the file path in the :envvar:`!NETRC` environment variable.
If that is not set, it defaults to reading the file :file:`.netrc` in the user's home
directory -- as determined by :func:`os.path.expanduser`. If the file cannot be found,
a :exc:`FileNotFoundError` exception will be raised.
Parse errors will raise :exc:`NetrcParseError` with diagnostic
information including the file name, line number, and terminating token.
Expand Down
5 changes: 3 additions & 2 deletions Lib/netrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def push_token(self, token):

class netrc:
def __init__(self, file=None):
default_netrc = file is None
netrc_envvar = os.environ.get("NETRC", "")
default_netrc = file is None and not bool(netrc_envvar)
if file is None:
file = os.path.join(os.path.expanduser("~"), ".netrc")
file = netrc_envvar or os.path.join(os.path.expanduser("~"), ".netrc")
self.hosts = {}
self.macros = {}
try:
Expand Down
Loading
Loading