From 562efe11d140a7b15d0d1255422e018d408c1613 Mon Sep 17 00:00:00 2001 From: James Sexton Date: Thu, 29 Jun 2017 14:08:11 -0500 Subject: [PATCH 1/4] Fix bug in netrc.__repr__() --- Lib/netrc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/netrc.py b/Lib/netrc.py index aa8eea3c4ddecae..148204dda302ebe 100644 --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -127,10 +127,10 @@ 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 = rep + "machine "+ host + "\n\tlogin " + str(attrs[0]) + "\n" if attrs[1]: - rep = rep + "account " + repr(attrs[1]) - rep = rep + "\tpassword " + repr(attrs[2]) + "\n" + rep = rep + "\taccount " + str(attrs[1]) + "\n" + rep = rep + "\tpassword " + str(attrs[2]) + "\n" for macro in self.macros.keys(): rep = rep + "macdef " + macro + "\n" for line in self.macros[macro]: From 21741d1f285892590a46953d2163956297d4898b Mon Sep 17 00:00:00 2001 From: James Sexton Date: Thu, 3 Aug 2017 07:35:00 -0500 Subject: [PATCH 2/4] Use f-strings --- Lib/netrc.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/netrc.py b/Lib/netrc.py index 148204dda302ebe..baf8f1d99d9d305 100644 --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -127,15 +127,15 @@ def __repr__(self): rep = "" for host in self.hosts.keys(): attrs = self.hosts[host] - rep = rep + "machine "+ host + "\n\tlogin " + str(attrs[0]) + "\n" + rep += f"machine {host}\n\tlogin {attrs[0]}\n" if attrs[1]: - rep = rep + "\taccount " + str(attrs[1]) + "\n" - rep = rep + "\tpassword " + str(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__': From eef4b34750b0e772b3064913d47130aa24d113bd Mon Sep 17 00:00:00 2001 From: James Sexton Date: Fri, 29 Sep 2017 12:25:05 -0500 Subject: [PATCH 3/4] Create 2017-09-29.bpo-30806.lP5GrH.rst --- Misc/NEWS.d/next/Library/2017-09-29.bpo-30806.lP5GrH.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2017-09-29.bpo-30806.lP5GrH.rst diff --git a/Misc/NEWS.d/next/Library/2017-09-29.bpo-30806.lP5GrH.rst b/Misc/NEWS.d/next/Library/2017-09-29.bpo-30806.lP5GrH.rst new file mode 100644 index 000000000000000..afad1b2fb266faa --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-09-29.bpo-30806.lP5GrH.rst @@ -0,0 +1 @@ +Fix the string representation of a netrc object. From 5ec9b1fe0029294eb43241a562f1c4b3c2e72512 Mon Sep 17 00:00:00 2001 From: James Sexton Date: Fri, 29 Sep 2017 14:47:16 -0500 Subject: [PATCH 4/4] Update test_netrc.py --- Lib/test/test_netrc.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_netrc.py b/Lib/test/test_netrc.py index 60a3ec9565b4cf7..ca6f27d03c3afd2 100644 --- a/Lib/test/test_netrc.py +++ b/Lib/test/test_netrc.py @@ -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): @@ -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) @@ -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