mirror of https://github.com/python/cpython.git
Patch # 1331 by Christian Heimes.
The patch fixes some of the problems on Windows. It doesn't introduce addition problems on Linux.
This commit is contained in:
parent
daa251ca09
commit
c12a813aa7
|
@ -26,9 +26,12 @@ def __init__(self, file=None):
|
||||||
file = os.path.join(os.environ['HOME'], ".netrc")
|
file = os.path.join(os.environ['HOME'], ".netrc")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise IOError("Could not find .netrc: $HOME is not set")
|
raise IOError("Could not find .netrc: $HOME is not set")
|
||||||
fp = open(file)
|
|
||||||
self.hosts = {}
|
self.hosts = {}
|
||||||
self.macros = {}
|
self.macros = {}
|
||||||
|
with open(file) as fp:
|
||||||
|
self._parse(file, fp)
|
||||||
|
|
||||||
|
def _parse(self, file, fp):
|
||||||
lexer = shlex.shlex(fp)
|
lexer = shlex.shlex(fp)
|
||||||
lexer.wordchars += r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
|
lexer.wordchars += r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
|
||||||
while 1:
|
while 1:
|
||||||
|
|
|
@ -809,6 +809,8 @@ def _communicate(self, input):
|
||||||
|
|
||||||
if self.stdin:
|
if self.stdin:
|
||||||
if input is not None:
|
if input is not None:
|
||||||
|
if isinstance(input, str):
|
||||||
|
input = input.encode()
|
||||||
self.stdin.write(input)
|
self.stdin.write(input)
|
||||||
self.stdin.close()
|
self.stdin.close()
|
||||||
|
|
||||||
|
|
|
@ -885,6 +885,7 @@ def printlist(x, width=70, indent=4):
|
||||||
test_pwd
|
test_pwd
|
||||||
test_resource
|
test_resource
|
||||||
test_signal
|
test_signal
|
||||||
|
test_syslog
|
||||||
test_threadsignals
|
test_threadsignals
|
||||||
test_wait3
|
test_wait3
|
||||||
test_wait4
|
test_wait4
|
||||||
|
|
|
@ -58,6 +58,7 @@ def setUp(self):
|
||||||
self._box = self._factory(self._path)
|
self._box = self._factory(self._path)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
self._box.close()
|
||||||
self._delete_recursively(self._path)
|
self._delete_recursively(self._path)
|
||||||
|
|
||||||
def test_add(self):
|
def test_add(self):
|
||||||
|
@ -390,12 +391,14 @@ def _test_flush_or_close(self, method):
|
||||||
self._box.add(contents[0])
|
self._box.add(contents[0])
|
||||||
self._box.add(contents[1])
|
self._box.add(contents[1])
|
||||||
self._box.add(contents[2])
|
self._box.add(contents[2])
|
||||||
|
oldbox = self._box
|
||||||
method()
|
method()
|
||||||
self._box = self._factory(self._path)
|
self._box = self._factory(self._path)
|
||||||
keys = self._box.keys()
|
keys = self._box.keys()
|
||||||
self.assertEqual(len(keys), 3)
|
self.assertEqual(len(keys), 3)
|
||||||
for key in keys:
|
for key in keys:
|
||||||
self.assert_(self._box.get_string(key) in contents)
|
self.assert_(self._box.get_string(key) in contents)
|
||||||
|
oldbox.close()
|
||||||
|
|
||||||
def test_dump_message(self):
|
def test_dump_message(self):
|
||||||
# Write message representations to disk
|
# Write message representations to disk
|
||||||
|
@ -403,7 +406,7 @@ def test_dump_message(self):
|
||||||
_sample_message, io.StringIO(_sample_message)):
|
_sample_message, io.StringIO(_sample_message)):
|
||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
self._box._dump_message(input, output)
|
self._box._dump_message(input, output)
|
||||||
self.assert_(output.getvalue() ==
|
self.assertEqual(output.getvalue(),
|
||||||
_sample_message.replace('\n', os.linesep))
|
_sample_message.replace('\n', os.linesep))
|
||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
self.assertRaises(TypeError,
|
self.assertRaises(TypeError,
|
||||||
|
@ -694,6 +697,7 @@ def test_directory_in_folder (self):
|
||||||
class _TestMboxMMDF(TestMailbox):
|
class _TestMboxMMDF(TestMailbox):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
self._box.close()
|
||||||
self._delete_recursively(self._path)
|
self._delete_recursively(self._path)
|
||||||
for lock_remnant in glob.glob(self._path + '.*'):
|
for lock_remnant in glob.glob(self._path + '.*'):
|
||||||
test_support.unlink(lock_remnant)
|
test_support.unlink(lock_remnant)
|
||||||
|
@ -916,6 +920,7 @@ class TestBabyl(TestMailbox):
|
||||||
_factory = lambda self, path, factory=None: mailbox.Babyl(path, factory)
|
_factory = lambda self, path, factory=None: mailbox.Babyl(path, factory)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
self._box.close()
|
||||||
self._delete_recursively(self._path)
|
self._delete_recursively(self._path)
|
||||||
for lock_remnant in glob.glob(self._path + '.*'):
|
for lock_remnant in glob.glob(self._path + '.*'):
|
||||||
test_support.unlink(lock_remnant)
|
test_support.unlink(lock_remnant)
|
||||||
|
|
|
@ -21,25 +21,24 @@
|
||||||
|
|
||||||
class NetrcTestCase(unittest.TestCase):
|
class NetrcTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp (self):
|
def setUp(self):
|
||||||
mode = 'w'
|
mode = 'w'
|
||||||
if sys.platform not in ['cygwin']:
|
if sys.platform not in ['cygwin']:
|
||||||
mode += 't'
|
mode += 't'
|
||||||
fp = open(temp_filename, mode)
|
fp = open(temp_filename, mode)
|
||||||
fp.write(TEST_NETRC)
|
fp.write(TEST_NETRC)
|
||||||
fp.close()
|
fp.close()
|
||||||
self.netrc = netrc.netrc(temp_filename)
|
|
||||||
|
|
||||||
def tearDown (self):
|
def tearDown(self):
|
||||||
del self.netrc
|
|
||||||
os.unlink(temp_filename)
|
os.unlink(temp_filename)
|
||||||
|
|
||||||
def test_case_1(self):
|
def test_case_1(self):
|
||||||
self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'],
|
nrc = netrc.netrc(temp_filename)
|
||||||
|
self.assert_(nrc.macros == {'macro1':['line1\n', 'line2\n'],
|
||||||
'macro2':['line3\n', 'line4\n']}
|
'macro2':['line3\n', 'line4\n']}
|
||||||
)
|
)
|
||||||
self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
|
self.assert_(nrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
|
||||||
self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2'))
|
self.assert_(nrc.hosts['default'] == ('log2', None, 'pass2'))
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(NetrcTestCase)
|
test_support.run_unittest(NetrcTestCase)
|
||||||
|
|
|
@ -36,7 +36,7 @@ def setUp(self):
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
for name in self.files:
|
for name in self.files:
|
||||||
f = open(name, 'w')
|
f = open(name, 'wb')
|
||||||
f.write((name+'\n').encode("utf-8"))
|
f.write((name+'\n').encode("utf-8"))
|
||||||
f.close()
|
f.close()
|
||||||
os.stat(name)
|
os.stat(name)
|
||||||
|
@ -71,7 +71,7 @@ def test_failures(self):
|
||||||
|
|
||||||
def test_open(self):
|
def test_open(self):
|
||||||
for name in self.files:
|
for name in self.files:
|
||||||
f = open(name, 'w')
|
f = open(name, 'wb')
|
||||||
f.write((name+'\n').encode("utf-8"))
|
f.write((name+'\n').encode("utf-8"))
|
||||||
f.close()
|
f.close()
|
||||||
os.stat(name)
|
os.stat(name)
|
||||||
|
@ -80,7 +80,7 @@ def test_listdir(self):
|
||||||
f1 = os.listdir(test_support.TESTFN)
|
f1 = os.listdir(test_support.TESTFN)
|
||||||
# Printing f1 is not appropriate, as specific filenames
|
# Printing f1 is not appropriate, as specific filenames
|
||||||
# returned depend on the local encoding
|
# returned depend on the local encoding
|
||||||
f2 = os.listdir(str(test_support.TESTFN,
|
f2 = os.listdir(str(test_support.TESTFN.encode("utf-8"),
|
||||||
sys.getfilesystemencoding()))
|
sys.getfilesystemencoding()))
|
||||||
f2.sort()
|
f2.sort()
|
||||||
print(f2)
|
print(f2)
|
||||||
|
@ -96,7 +96,7 @@ def test_directory(self):
|
||||||
oldwd = os.getcwd()
|
oldwd = os.getcwd()
|
||||||
os.mkdir(dirname)
|
os.mkdir(dirname)
|
||||||
os.chdir(dirname)
|
os.chdir(dirname)
|
||||||
f = open(filename, 'w')
|
f = open(filename, 'wb')
|
||||||
f.write((filename + '\n').encode("utf-8"))
|
f.write((filename + '\n').encode("utf-8"))
|
||||||
f.close()
|
f.close()
|
||||||
print(repr(filename))
|
print(repr(filename))
|
||||||
|
|
|
@ -630,7 +630,7 @@ def test_shell_sequence(self):
|
||||||
p = subprocess.Popen(["set"], shell=1,
|
p = subprocess.Popen(["set"], shell=1,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
env=newenv)
|
env=newenv)
|
||||||
self.assertNotEqual(p.stdout.read().find("physalis"), -1)
|
self.assertNotEqual(p.stdout.read().find(b"physalis"), -1)
|
||||||
|
|
||||||
def test_shell_string(self):
|
def test_shell_string(self):
|
||||||
# Run command through the shell (string)
|
# Run command through the shell (string)
|
||||||
|
@ -639,7 +639,7 @@ def test_shell_string(self):
|
||||||
p = subprocess.Popen("set", shell=1,
|
p = subprocess.Popen("set", shell=1,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
env=newenv)
|
env=newenv)
|
||||||
self.assertNotEqual(p.stdout.read().find("physalis"), -1)
|
self.assertNotEqual(p.stdout.read().find(b"physalis"), -1)
|
||||||
|
|
||||||
def test_call_string(self):
|
def test_call_string(self):
|
||||||
# call() function with string argument on Windows
|
# call() function with string argument on Windows
|
||||||
|
|
Loading…
Reference in New Issue