+13
-9
lines changedFilter options
+13
-9
lines changed Original file line number Diff line number Diff line change
@@ -127,15 +127,15 @@ def __repr__(self):
127
127
rep = ""
128
128
for host in self.hosts.keys():
129
129
attrs = self.hosts[host]
130
-
rep = rep + "machine "+ host + "\n\tlogin " + repr(attrs[0]) + "\n"
130
+
rep += f"machine {host}\n\tlogin {attrs[0]}\n"
131
131
if attrs[1]:
132
-
rep = rep + "account " + repr(attrs[1])
133
-
rep = rep + "\tpassword " + repr(attrs[2]) + "\n"
132
+
rep += f"\taccount {attrs[1]}\n"
133
+
rep += f"\tpassword {attrs[2]}\n"
134
134
for macro in self.macros.keys():
135
-
rep = rep + "macdef " + macro + "\n"
135
+
rep += f"macdef {macro}\n"
136
136
for line in self.macros[macro]:
137
-
rep = rep + line
138
-
rep = rep + "\n"
137
+
rep += line
138
+
rep += "\n"
139
139
return rep
140
140
141
141
if __name__ == '__main__':
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
1
-
import netrc, os, unittest, sys, textwrap
1
+
import netrc, os, unittest, sys, tempfile, textwrap
2
2
from test import support
3
3
4
-
temp_filename = support.TESTFN
5
4
6
5
class NetrcTestCase(unittest.TestCase):
7
6
@@ -10,7 +9,8 @@ def make_nrc(self, test_data):
10
9
mode = 'w'
11
10
if sys.platform != 'cygwin':
12
11
mode += 't'
13
-
with open(temp_filename, mode) as fp:
12
+
temp_fd, temp_filename = tempfile.mkstemp()
13
+
with os.fdopen(temp_fd, mode=mode) as fp:
14
14
fp.write(test_data)
15
15
self.addCleanup(os.unlink, temp_filename)
16
16
return netrc.netrc(temp_filename)
@@ -24,6 +24,9 @@ def test_default(self):
24
24
('log1', 'acct1', 'pass1'))
25
25
self.assertEqual(nrc.hosts['default'], ('log2', None, 'pass2'))
26
26
27
+
nrc2 = self.make_nrc(nrc.__repr__())
28
+
self.assertEqual(nrc.hosts, nrc2.hosts)
29
+
27
30
def test_macros(self):
28
31
nrc = self.make_nrc("""\
29
32
macdef macro1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
+
Fix the string representation of a netrc object.
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4