Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
43ee1a5d
Commit
43ee1a5d
authored
Jun 10, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix regression in netrc comment handling (closes #12009)
parent
2231e1a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
44 deletions
+107
-44
Lib/netrc.py
Lib/netrc.py
+8
-4
Lib/test/test_netrc.py
Lib/test/test_netrc.py
+93
-40
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Lib/netrc.py
View file @
43ee1a5d
...
...
@@ -41,8 +41,12 @@ class netrc:
if not tt:
break
elif tt[0] == '#':
fp.readline();
continue;
# seek to beginning of comment, in case reading the token put
# us on a new line, and then skip the rest of the line.
pos = len(tt) + 1
lexer.instream.seek(-pos, 1)
lexer.instream.readline()
continue
elif tt == 'machine':
entryname = lexer.get_token()
elif tt == 'default':
...
...
@@ -68,8 +72,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)
...
...
Lib/test/test_netrc.py
View file @
43ee1a5d
import
netrc
,
os
,
unittest
,
sys
import
netrc
,
os
,
unittest
,
sys
,
textwrap
from
test
import
test_support
TEST_NETRC
=
"""
#this is a comment
#this is a comment
# this is a comment
machine foo login log1 password pass1 account acct1
machine bar login log1 password pass# account acct1
macdef macro1
line1
line2
macdef macro2
line3
line4
default login log2 password pass2
"""
temp_filename
=
test_support
.
TESTFN
class
NetrcTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
mode
=
'w'
if
sys
.
platform
not
in
[
'cygwin'
]:
mode
+=
't'
fp
=
open
(
temp_filename
,
mode
)
fp
.
write
(
TEST_NETRC
)
fp
.
close
()
self
.
nrc
=
netrc
.
netrc
(
temp_filename
)
def
tearDown
(
self
):
def
tearDown
(
self
):
os
.
unlink
(
temp_filename
)
def
test_case_1
(
self
):
self
.
assertEqual
(
self
.
nrc
.
hosts
[
'foo'
],
(
'log1'
,
'acct1'
,
'pass1'
))
self
.
assertEqual
(
self
.
nrc
.
hosts
[
'default'
],
(
'log2'
,
None
,
'pass2'
))
def
make_nrc
(
self
,
test_data
):
test_data
=
textwrap
.
dedent
(
test_data
)
mode
=
'w'
if
sys
.
platform
!=
'cygwin'
:
mode
+=
't'
with
open
(
temp_filename
,
mode
)
as
fp
:
fp
.
write
(
test_data
)
return
netrc
.
netrc
(
temp_filename
)
def
test_default
(
self
):
nrc
=
self
.
make_nrc
(
"""
\
machine host1.domain.com login log1 password pass1 account acct1
default login log2 password pass2
"""
)
self
.
assertEqual
(
nrc
.
hosts
[
'host1.domain.com'
],
(
'log1'
,
'acct1'
,
'pass1'
))
self
.
assertEqual
(
nrc
.
hosts
[
'default'
],
(
'log2'
,
None
,
'pass2'
))
def
test_macros
(
self
):
self
.
assertEqual
(
self
.
nrc
.
macros
,
{
'macro1'
:[
'line1
\
n
'
,
'line2
\
n
'
],
'macro2'
:[
'line3
\
n
'
,
'line4
\
n
'
]})
nrc
=
self
.
make_nrc
(
"""
\
macdef macro1
line1
line2
macdef macro2
line3
line4
"""
)
self
.
assertEqual
(
nrc
.
macros
,
{
'macro1'
:
[
'line1
\
n
'
,
'line2
\
n
'
],
'macro2'
:
[
'line3
\
n
'
,
'line4
\
n
'
]})
def
_test_passwords
(
self
,
nrc
,
passwd
):
nrc
=
self
.
make_nrc
(
nrc
)
self
.
assertEqual
(
nrc
.
hosts
[
'host.domain.com'
],
(
'log'
,
'acct'
,
passwd
))
def
test_password_with_leading_hash
(
self
):
self
.
_test_passwords
(
"""
\
machine host.domain.com login log password #pass account acct
"""
,
'#pass'
)
def
test_password_with_trailing_hash
(
self
):
self
.
_test_passwords
(
"""
\
machine host.domain.com login log password pass# account acct
"""
,
'pass#'
)
def
test_password_with_internal_hash
(
self
):
self
.
_test_passwords
(
"""
\
machine host.domain.com login log password pa#ss account acct
"""
,
'pa#ss'
)
def
_test_comment
(
self
,
nrc
,
passwd
=
'pass'
):
nrc
=
self
.
make_nrc
(
nrc
)
self
.
assertEqual
(
nrc
.
hosts
[
'foo.domain.com'
],
(
'bar'
,
None
,
passwd
))
self
.
assertEqual
(
nrc
.
hosts
[
'bar.domain.com'
],
(
'foo'
,
None
,
'pass'
))
def
test_comment_before_machine_line
(
self
):
self
.
_test_comment
(
"""
\
# comment
machine foo.domain.com login bar password pass
machine bar.domain.com login foo password pass
"""
)
def
test_comment_before_machine_line_no_space
(
self
):
self
.
_test_comment
(
"""
\
#comment
machine foo.domain.com login bar password pass
machine bar.domain.com login foo password pass
"""
)
def
test_comment_before_machine_line_hash_only
(
self
):
self
.
_test_comment
(
"""
\
#
machine foo.domain.com login bar password pass
machine bar.domain.com login foo password pass
"""
)
def
test_comment_at_end_of_machine_line
(
self
):
self
.
_test_comment
(
"""
\
machine foo.domain.com login bar password pass # comment
machine bar.domain.com login foo password pass
"""
)
def
test_comment_at_end_of_machine_line_no_space
(
self
):
self
.
_test_comment
(
"""
\
machine foo.domain.com login bar password pass #comment
machine bar.domain.com login foo password pass
"""
)
def
test_comment_at_end_of_machine_line_pass_has_hash
(
self
):
self
.
_test_comment
(
"""
\
machine foo.domain.com login bar password #pass #comment
machine bar.domain.com login foo password pass
"""
,
'#pass'
)
def
test_parses_passwords_with_hash_character
(
self
):
self
.
assertEqual
(
self
.
nrc
.
hosts
[
'bar'
],
(
'log1'
,
'acct1'
,
'pass#'
))
def
test_main
():
test_support
.
run_unittest
(
NetrcTestCase
)
...
...
Misc/ACKS
View file @
43ee1a5d
...
...
@@ -566,6 +566,7 @@ Paul Moore
Derek Morr
James A Morrison
Pablo Mouzo
Ruslan Mstoi
Sjoerd Mullender
Sape Mullender
Michael Muller
...
...
Misc/NEWS
View file @
43ee1a5d
...
...
@@ -7,6 +7,11 @@ What's New in Python 2.7.2?
*Release date: 2011-06-XX*
Library
-------
- Issue #12009: Fixed regression in netrc file comment handling.
Extension Modules
-----------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment