Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c12a813

Browse files
committed
Patch # 1331 by Christian Heimes.
The patch fixes some of the problems on Windows. It doesn't introduce addition problems on Linux.
1 parent daa251c commit c12a813

7 files changed

Lines changed: 25 additions & 15 deletions

File tree

Lib/netrc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ def __init__(self, file=None):
2626
file = os.path.join(os.environ['HOME'], ".netrc")
2727
except KeyError:
2828
raise IOError("Could not find .netrc: $HOME is not set")
29-
fp = open(file)
3029
self.hosts = {}
3130
self.macros = {}
31+
with open(file) as fp:
32+
self._parse(file, fp)
33+
34+
def _parse(self, file, fp):
3235
lexer = shlex.shlex(fp)
3336
lexer.wordchars += r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
3437
while 1:

Lib/subprocess.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,8 @@ def _communicate(self, input):
809809

810810
if self.stdin:
811811
if input is not None:
812+
if isinstance(input, str):
813+
input = input.encode()
812814
self.stdin.write(input)
813815
self.stdin.close()
814816

Lib/test/regrtest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ def printlist(x, width=70, indent=4):
885885
test_pwd
886886
test_resource
887887
test_signal
888+
test_syslog
888889
test_threadsignals
889890
test_wait3
890891
test_wait4

Lib/test/test_mailbox.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def setUp(self):
5858
self._box = self._factory(self._path)
5959

6060
def tearDown(self):
61+
self._box.close()
6162
self._delete_recursively(self._path)
6263

6364
def test_add(self):
@@ -390,20 +391,22 @@ def _test_flush_or_close(self, method):
390391
self._box.add(contents[0])
391392
self._box.add(contents[1])
392393
self._box.add(contents[2])
394+
oldbox = self._box
393395
method()
394396
self._box = self._factory(self._path)
395397
keys = self._box.keys()
396398
self.assertEqual(len(keys), 3)
397399
for key in keys:
398400
self.assert_(self._box.get_string(key) in contents)
401+
oldbox.close()
399402

400403
def test_dump_message(self):
401404
# Write message representations to disk
402405
for input in (email.message_from_string(_sample_message),
403406
_sample_message, io.StringIO(_sample_message)):
404407
output = io.StringIO()
405408
self._box._dump_message(input, output)
406-
self.assert_(output.getvalue() ==
409+
self.assertEqual(output.getvalue(),
407410
_sample_message.replace('\n', os.linesep))
408411
output = io.StringIO()
409412
self.assertRaises(TypeError,
@@ -694,6 +697,7 @@ def test_directory_in_folder (self):
694697
class _TestMboxMMDF(TestMailbox):
695698

696699
def tearDown(self):
700+
self._box.close()
697701
self._delete_recursively(self._path)
698702
for lock_remnant in glob.glob(self._path + '.*'):
699703
test_support.unlink(lock_remnant)
@@ -916,6 +920,7 @@ class TestBabyl(TestMailbox):
916920
_factory = lambda self, path, factory=None: mailbox.Babyl(path, factory)
917921

918922
def tearDown(self):
923+
self._box.close()
919924
self._delete_recursively(self._path)
920925
for lock_remnant in glob.glob(self._path + '.*'):
921926
test_support.unlink(lock_remnant)

Lib/test/test_netrc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,24 @@
2121

2222
class NetrcTestCase(unittest.TestCase):
2323

24-
def setUp (self):
24+
def setUp(self):
2525
mode = 'w'
2626
if sys.platform not in ['cygwin']:
2727
mode += 't'
2828
fp = open(temp_filename, mode)
2929
fp.write(TEST_NETRC)
3030
fp.close()
31-
self.netrc = netrc.netrc(temp_filename)
3231

33-
def tearDown (self):
34-
del self.netrc
32+
def tearDown(self):
3533
os.unlink(temp_filename)
3634

3735
def test_case_1(self):
38-
self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'],
36+
nrc = netrc.netrc(temp_filename)
37+
self.assert_(nrc.macros == {'macro1':['line1\n', 'line2\n'],
3938
'macro2':['line3\n', 'line4\n']}
4039
)
41-
self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
42-
self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2'))
40+
self.assert_(nrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
41+
self.assert_(nrc.hosts['default'] == ('log2', None, 'pass2'))
4342

4443
def test_main():
4544
test_support.run_unittest(NetrcTestCase)

Lib/test/test_pep277.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def setUp(self):
3636
except OSError:
3737
pass
3838
for name in self.files:
39-
f = open(name, 'w')
39+
f = open(name, 'wb')
4040
f.write((name+'\n').encode("utf-8"))
4141
f.close()
4242
os.stat(name)
@@ -71,7 +71,7 @@ def test_failures(self):
7171

7272
def test_open(self):
7373
for name in self.files:
74-
f = open(name, 'w')
74+
f = open(name, 'wb')
7575
f.write((name+'\n').encode("utf-8"))
7676
f.close()
7777
os.stat(name)
@@ -80,7 +80,7 @@ def test_listdir(self):
8080
f1 = os.listdir(test_support.TESTFN)
8181
# Printing f1 is not appropriate, as specific filenames
8282
# returned depend on the local encoding
83-
f2 = os.listdir(str(test_support.TESTFN,
83+
f2 = os.listdir(str(test_support.TESTFN.encode("utf-8"),
8484
sys.getfilesystemencoding()))
8585
f2.sort()
8686
print(f2)
@@ -96,7 +96,7 @@ def test_directory(self):
9696
oldwd = os.getcwd()
9797
os.mkdir(dirname)
9898
os.chdir(dirname)
99-
f = open(filename, 'w')
99+
f = open(filename, 'wb')
100100
f.write((filename + '\n').encode("utf-8"))
101101
f.close()
102102
print(repr(filename))

Lib/test/test_subprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ def test_shell_sequence(self):
630630
p = subprocess.Popen(["set"], shell=1,
631631
stdout=subprocess.PIPE,
632632
env=newenv)
633-
self.assertNotEqual(p.stdout.read().find("physalis"), -1)
633+
self.assertNotEqual(p.stdout.read().find(b"physalis"), -1)
634634

635635
def test_shell_string(self):
636636
# Run command through the shell (string)
@@ -639,7 +639,7 @@ def test_shell_string(self):
639639
p = subprocess.Popen("set", shell=1,
640640
stdout=subprocess.PIPE,
641641
env=newenv)
642-
self.assertNotEqual(p.stdout.read().find("physalis"), -1)
642+
self.assertNotEqual(p.stdout.read().find(b"physalis"), -1)
643643

644644
def test_call_string(self):
645645
# call() function with string argument on Windows

0 commit comments

Comments
 (0)