FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[2.7] bpo-30806: Fix netrc.__repr__() format (GH-2491) by sloria · Pull Request #4276 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
12 changes: 6 additions & 6 deletions Lib/netrc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ def __repr__(self):
rep = ""
for host in self.hosts.keys():
attrs = self.hosts[host]
rep = rep + "machine "+ host + "\n\tlogin " + repr(attrs[0]) + "\n"
rep += "machine {host}\n\tlogin {attrs[0]}\n".format(host=host, attrs=attrs)
if attrs[1]:
rep = rep + "account " + repr(attrs[1])
rep = rep + "\tpassword " + repr(attrs[2]) + "\n"
rep += "\taccount {attrs[1]}\n".format(attrs=attrs)
rep += "\tpassword {attrs[2]}\n".format(attrs=attrs)
for macro in self.macros.keys():
rep = rep + "macdef " + macro + "\n"
rep += "macdef {macro}\n".format(macro=macro)
for line in self.macros[macro]:
rep = rep + line
rep = rep + "\n"
rep += line
rep += "\n"
return rep

if __name__ == '__main__':
Expand Down
10 changes: 7 additions & 3 deletions Lib/test/test_netrc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@

class NetrcTestCase(unittest.TestCase):

def make_nrc(self, test_data):
def make_nrc(self, test_data, cleanup=True):
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)
self.addCleanup(os.unlink, temp_filename)
if cleanup:
self.addCleanup(os.unlink, temp_filename)
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
""")
""", cleanup=False)
self.assertEqual(nrc.hosts['host1.domain.com'],
('log1', 'acct1', 'pass1'))
self.assertEqual(nrc.hosts['default'], ('log2', None, 'pass2'))

nrc2 = self.make_nrc(nrc.__repr__(), cleanup=True)
self.assertEqual(nrc.hosts, nrc2.hosts)

def test_macros(self):
nrc = self.make_nrc("""\
macdef macro1
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the string representation of a netrc object.

Back | FazBrowse Home | New Git URL