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

[3.6] bpo-30806: Fix netrc.__repr__() format (GH-2491) by miss-islington · Pull Request #4244 · 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 @@ -127,15 +127,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 += f"machine {host}\n\tlogin {attrs[0]}\n"
if attrs[1]:
rep = rep + "account " + repr(attrs[1])
rep = rep + "\tpassword " + repr(attrs[2]) + "\n"
rep += f"\taccount {attrs[1]}\n"
rep += f"\tpassword {attrs[2]}\n"
for macro in self.macros.keys():
rep = rep + "macdef " + macro + "\n"
rep += f"macdef {macro}\n"
for line in self.macros[macro]:
rep = rep + line
rep = rep + "\n"
rep += line
rep += "\n"
return rep

if __name__ == '__main__':
Expand Down
9 changes: 6 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
@@ -1,7 +1,6 @@
import netrc, os, unittest, sys, textwrap
import netrc, os, unittest, sys, tempfile, textwrap
from test import support

temp_filename = support.TESTFN

class NetrcTestCase(unittest.TestCase):

Expand All @@ -10,7 +9,8 @@ def make_nrc(self, test_data):
mode = 'w'
if sys.platform != 'cygwin':
mode += 't'
with open(temp_filename, mode) as fp:
temp_fd, temp_filename = tempfile.mkstemp()
with os.fdopen(temp_fd, mode=mode) as fp:
fp.write(test_data)
self.addCleanup(os.unlink, temp_filename)
return netrc.netrc(temp_filename)
Expand All @@ -24,6 +24,9 @@ def test_default(self):
('log1', 'acct1', 'pass1'))
self.assertEqual(nrc.hosts['default'], ('log2', None, 'pass2'))

nrc2 = self.make_nrc(nrc.__repr__())
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