mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
merge master (I think properly)
This commit is contained in:
commit
6140b5ff52
@ -13,10 +13,7 @@ from ..util.assertutil import precondition
|
||||
from allmydata.util.encodingutil import (unicode_platform, get_filesystem_encoding,
|
||||
|
||||
get_io_encoding)
|
||||
|
||||
if PY2: # XXX this is a hack that makes some tests pass on Python3, remove
|
||||
# in the future
|
||||
from ..scripts import runner
|
||||
from ..scripts import runner
|
||||
|
||||
def skip_if_cannot_represent_filename(u):
|
||||
precondition(isinstance(u, unicode))
|
||||
|
@ -1,11 +1,5 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from builtins import zip, str, range, object
|
||||
import binascii
|
||||
import six
|
||||
import hashlib
|
||||
@ -244,10 +238,10 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
|
||||
basedir = "util/FileUtil/test_write_atomically"
|
||||
fileutil.make_dirs(basedir)
|
||||
fn = os.path.join(basedir, "here")
|
||||
fileutil.write_atomically(fn, b"one")
|
||||
self.failUnlessEqual(fileutil.read(fn), b"one")
|
||||
fileutil.write_atomically(fn, u"two", mode="") # non-binary
|
||||
self.failUnlessEqual(fileutil.read(fn), b"two")
|
||||
fileutil.write_atomically(fn, "one")
|
||||
self.failUnlessEqual(fileutil.read(fn), "one")
|
||||
fileutil.write_atomically(fn, "two", mode="") # non-binary
|
||||
self.failUnlessEqual(fileutil.read(fn), "two")
|
||||
|
||||
def test_rename(self):
|
||||
basedir = "util/FileUtil/test_rename"
|
||||
@ -329,15 +323,13 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
|
||||
self.failUnlessEqual(10+11+12+13, used)
|
||||
|
||||
def test_abspath_expanduser_unicode(self):
|
||||
self.failUnlessRaises(AssertionError, fileutil.abspath_expanduser_unicode, b"bytestring")
|
||||
self.failUnlessRaises(AssertionError, fileutil.abspath_expanduser_unicode, "bytestring")
|
||||
|
||||
saved_cwd = os.path.normpath(os.getcwd())
|
||||
if PY2:
|
||||
saved_cwd = saved_cwd.decode("utf8")
|
||||
saved_cwd = os.path.normpath(os.getcwdu())
|
||||
abspath_cwd = fileutil.abspath_expanduser_unicode(u".")
|
||||
abspath_cwd_notlong = fileutil.abspath_expanduser_unicode(u".", long_path=False)
|
||||
self.failUnless(isinstance(saved_cwd, str), saved_cwd)
|
||||
self.failUnless(isinstance(abspath_cwd, str), abspath_cwd)
|
||||
self.failUnless(isinstance(saved_cwd, unicode), saved_cwd)
|
||||
self.failUnless(isinstance(abspath_cwd, unicode), abspath_cwd)
|
||||
if sys.platform == "win32":
|
||||
self.failUnlessReallyEqual(abspath_cwd, fileutil.to_windows_long_path(saved_cwd))
|
||||
else:
|
||||
@ -398,10 +390,10 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
|
||||
os.chdir(cwd)
|
||||
for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\', u'~'):
|
||||
uabspath = fileutil.abspath_expanduser_unicode(upath)
|
||||
self.failUnless(isinstance(uabspath, str), uabspath)
|
||||
self.failUnless(isinstance(uabspath, unicode), uabspath)
|
||||
|
||||
uabspath_notlong = fileutil.abspath_expanduser_unicode(upath, long_path=False)
|
||||
self.failUnless(isinstance(uabspath_notlong, str), uabspath_notlong)
|
||||
self.failUnless(isinstance(uabspath_notlong, unicode), uabspath_notlong)
|
||||
finally:
|
||||
os.chdir(saved_cwd)
|
||||
|
||||
@ -555,7 +547,7 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
def test_encrypted_tempfile(self):
|
||||
f = EncryptedTemporaryFile()
|
||||
f.write(b"foobar")
|
||||
f.write("foobar")
|
||||
f.close()
|
||||
|
||||
|
||||
@ -715,7 +707,7 @@ class DictUtil(unittest.TestCase):
|
||||
# we put the serialized form in the auxdata
|
||||
d.set_with_aux("key", ("filecap", "metadata"), "serialized")
|
||||
|
||||
self.failUnlessEqual(list(d.keys()), ["key"])
|
||||
self.failUnlessEqual(d.keys(), ["key"])
|
||||
self.failUnlessEqual(d["key"], ("filecap", "metadata"))
|
||||
self.failUnlessEqual(d.get_aux("key"), "serialized")
|
||||
def _get_missing(key):
|
||||
@ -733,7 +725,7 @@ class DictUtil(unittest.TestCase):
|
||||
d.set_with_aux("key2", "value2", "aux2")
|
||||
self.failUnlessEqual(sorted(d.keys()), ["key", "key2"])
|
||||
del d["key2"]
|
||||
self.failUnlessEqual(list(d.keys()), ["key"])
|
||||
self.failUnlessEqual(d.keys(), ["key"])
|
||||
self.failIf("key2" in d)
|
||||
self.failUnlessRaises(KeyError, _get_missing, "key2")
|
||||
self.failUnlessEqual(d.get("key2"), None)
|
||||
@ -867,7 +859,7 @@ class ByteSpans(unittest.TestCase):
|
||||
s1 = Spans(3, 4) # 3,4,5,6
|
||||
self._check1(s1)
|
||||
|
||||
s1 = Spans(int(3), int(4)) # 3,4,5,6
|
||||
s1 = Spans(long(3), long(4)) # 3,4,5,6
|
||||
self._check1(s1)
|
||||
|
||||
s2 = Spans(s1)
|
||||
@ -1110,6 +1102,7 @@ class SimpleDataSpans(object):
|
||||
|
||||
def __bool__(self): # this gets us bool()
|
||||
return bool(self.len())
|
||||
|
||||
def len(self):
|
||||
return len(self.missing.replace("1", ""))
|
||||
def _dump(self):
|
||||
@ -1194,9 +1187,9 @@ class StringSpans(unittest.TestCase):
|
||||
self.failUnlessEqual(ds.get(2, 4), "fear")
|
||||
|
||||
ds = klass()
|
||||
ds.add(int(2), "four")
|
||||
ds.add(int(3), "ea")
|
||||
self.failUnlessEqual(ds.get(int(2), int(4)), "fear")
|
||||
ds.add(long(2), "four")
|
||||
ds.add(long(3), "ea")
|
||||
self.failUnlessEqual(ds.get(long(2), long(4)), "fear")
|
||||
|
||||
|
||||
def do_scan(self, klass):
|
||||
@ -1359,7 +1352,6 @@ class YAML(unittest.TestCase):
|
||||
def test_convert(self):
|
||||
data = yaml.safe_dump(["str", u"unicode", u"\u1234nicode"])
|
||||
back = yamlutil.safe_load(data)
|
||||
str_type = type("x") # workaround for future.builtins.str
|
||||
self.failUnlessEqual(type(back[0]), str_type)
|
||||
self.failUnlessEqual(type(back[1]), str_type)
|
||||
self.failUnlessEqual(type(back[2]), str_type)
|
||||
self.failUnlessEqual(type(back[0]), unicode)
|
||||
self.failUnlessEqual(type(back[1]), unicode)
|
||||
self.failUnlessEqual(type(back[2]), unicode)
|
||||
|
@ -4,6 +4,7 @@ unicode and back.
|
||||
"""
|
||||
|
||||
import sys, os, re, locale
|
||||
from types import NoneType
|
||||
|
||||
from allmydata.util.assertutil import precondition, _assert
|
||||
from twisted.python import usage
|
||||
@ -138,7 +139,7 @@ def to_str(s):
|
||||
return s.encode('utf-8')
|
||||
|
||||
def from_utf8_or_none(s):
|
||||
precondition(isinstance(s, str) or s is None, s)
|
||||
precondition(isinstance(s, (NoneType, str)), s)
|
||||
if s is None:
|
||||
return s
|
||||
return s.decode('utf-8')
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
@ -11,7 +11,7 @@ if PY2:
|
||||
Futz with files like a pro.
|
||||
"""
|
||||
|
||||
import sys, os, stat, tempfile, time, binascii
|
||||
import sys, exceptions, os, stat, tempfile, time, binascii
|
||||
import six
|
||||
from collections import namedtuple
|
||||
from errno import ENOENT
|
||||
@ -197,7 +197,7 @@ def make_dirs(dirname, mode=0o777):
|
||||
if not os.path.isdir(dirname):
|
||||
if tx:
|
||||
raise tx
|
||||
raise IOError("unknown error prevented creation of directory, or deleted the directory immediately after creation: %s" % dirname) # careful not to construct an IOError with a 2-tuple, as that has a special meaning...
|
||||
raise exceptions.IOError("unknown error prevented creation of directory, or deleted the directory immediately after creation: %s" % dirname) # careful not to construct an IOError with a 2-tuple, as that has a special meaning...
|
||||
|
||||
def rm_dir(dirname):
|
||||
"""
|
||||
@ -284,7 +284,7 @@ def put_file(path, inf):
|
||||
outf.write(data)
|
||||
|
||||
def precondition_abspath(path):
|
||||
if not isinstance(path, str):
|
||||
if not isinstance(path, unicode):
|
||||
raise AssertionError("an abspath must be a Unicode string")
|
||||
|
||||
if sys.platform == "win32":
|
||||
@ -316,7 +316,7 @@ def abspath_expanduser_unicode(path, base=None, long_path=True):
|
||||
abspath_expanduser_unicode.
|
||||
On Windows, the result will be a long path unless long_path is given as False.
|
||||
"""
|
||||
if not isinstance(path, str):
|
||||
if not isinstance(path, unicode):
|
||||
raise AssertionError("paths must be Unicode strings")
|
||||
if base is not None and long_path:
|
||||
precondition_abspath(base)
|
||||
@ -337,10 +337,7 @@ def abspath_expanduser_unicode(path, base=None, long_path=True):
|
||||
|
||||
if not os.path.isabs(path):
|
||||
if base is None:
|
||||
cwd = os.getcwd()
|
||||
if PY2:
|
||||
cwd = cwd.decode('utf8')
|
||||
path = os.path.join(cwd, path)
|
||||
path = os.path.join(os.getcwdu(), path)
|
||||
else:
|
||||
path = os.path.join(base, path)
|
||||
|
||||
@ -425,7 +422,7 @@ ERROR_ENVVAR_NOT_FOUND = 203
|
||||
def windows_getenv(name):
|
||||
# Based on <http://stackoverflow.com/questions/2608200/problems-with-umlauts-in-python-appdata-environvent-variable/2608368#2608368>,
|
||||
# with improved error handling. Returns None if there is no enivronment variable of the given name.
|
||||
if not isinstance(name, str):
|
||||
if not isinstance(name, unicode):
|
||||
raise AssertionError("name must be Unicode")
|
||||
|
||||
n = GetEnvironmentVariableW(name, None, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user