summaryrefslogtreecommitdiffstats
path: root/Lib/netrc.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-06-10 16:32:52 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-06-10 16:32:52 (GMT)
commit1df0f214a9fdb4dde7506576b144cf6a7fd01b65 (patch)
tree5e2be8076884a09ef53577d9053c73d0e7570c62 /Lib/netrc.py
parente6eafa2ade22dc687eee78374fa93d4b9ab7a2c1 (diff)
downloadcpython-1df0f214a9fdb4dde7506576b144cf6a7fd01b65.zip
cpython-1df0f214a9fdb4dde7506576b144cf6a7fd01b65.tar.gz
cpython-1df0f214a9fdb4dde7506576b144cf6a7fd01b65.tar.bz2
fix regression in netrc comment handling (closes #12009)
Diffstat (limited to 'Lib/netrc.py')
-rw-r--r--Lib/netrc.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/netrc.py b/Lib/netrc.py
index a60b8b7..c96db6f 100644
--- a/Lib/netrc.py
+++ b/Lib/netrc.py
@@ -2,7 +2,7 @@
# Module and documentation by Eric S. Raymond, 21 Dec 1998
-import os, shlex
+import io, os, shlex
__all__ = ["netrc", "NetrcParseError"]
@@ -37,12 +37,14 @@ class netrc:
lexer.commenters = lexer.commenters.replace('#', '')
while 1:
# Look for a machine, default, or macdef top-level keyword
+ saved_lineno = lexer.lineno
toplevel = tt = lexer.get_token()
if not tt:
break
elif tt[0] == '#':
- fp.readline();
- continue;
+ if lexer.lineno == saved_lineno and len(tt) == 1:
+ lexer.instream.readline()
+ continue
elif tt == 'machine':
entryname = lexer.get_token()
elif tt == 'default':
@@ -68,8 +70,8 @@ class netrc:
self.hosts[entryname] = {}
while 1:
tt = lexer.get_token()
- if (tt=='' or tt == 'machine' or
- tt == 'default' or tt =='macdef'):
+ if (tt.startswith('#') or
+ tt in {'', 'machine', 'default', 'macdef'}):
if password:
self.hosts[entryname] = (login, account, password)
lexer.push_token(tt)