Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-135788: Support NETRC environment variable in netrc and update documentation #135802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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