mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-14 22:26:39 +00:00
Some progress towards passing Python 3 tests.
This commit is contained in:
parent
d6406d5edb
commit
06c4ed13b7
@ -1,7 +1,7 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import print_function
|
||||
from six import ensure_binary
|
||||
from six import ensure_str
|
||||
|
||||
import os, sys, textwrap
|
||||
import codecs
|
||||
@ -276,17 +276,27 @@ def get_alias(aliases, path_unicode, default):
|
||||
return uri.from_string_dirnode(aliases[alias]).to_string(), path[colon+1:]
|
||||
|
||||
def escape_path(path):
|
||||
# type: (Union[str,bytes]) -> bytes
|
||||
# type: (Union[str,bytes]) -> str
|
||||
u"""
|
||||
Return path quoted to US-ASCII, valid URL characters.
|
||||
|
||||
>>> path = u'/føö/bar/☃'
|
||||
>>> escaped = escape_path(path)
|
||||
>>> escaped
|
||||
b'/f%C3%B8%C3%B6/bar/%E2%98%83'
|
||||
u'/f%C3%B8%C3%B6/bar/%E2%98%83'
|
||||
"""
|
||||
if isinstance(path, str):
|
||||
path = path.encode("utf-8")
|
||||
segments = path.split(b"/")
|
||||
return b"/".join([urllib.parse.quote(s).encode("ascii") for s in segments])
|
||||
|
||||
result = str(
|
||||
b"/".join([
|
||||
urllib.parse.quote(s).encode("ascii") for s in segments
|
||||
]),
|
||||
"ascii"
|
||||
)
|
||||
# Eventually (i.e. as part of Python 3 port) we want this to always return
|
||||
# Unicode strings. However, to reduce diff sizes in the short term it'll
|
||||
# return native string (i.e. bytes) on Python 2.
|
||||
if PY2:
|
||||
result = result.encode("ascii").__native__()
|
||||
return result
|
||||
|
@ -1,5 +1,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from past.builtins import unicode
|
||||
|
||||
import os.path
|
||||
import time
|
||||
from urllib.parse import quote as url_quote
|
||||
@ -345,7 +347,7 @@ class FileTarget(object):
|
||||
target = PermissionDeniedTarget(self._path, isdir=False)
|
||||
return target.backup(progress, upload_file, upload_directory)
|
||||
else:
|
||||
assert isinstance(childcap, str)
|
||||
assert isinstance(childcap, bytes)
|
||||
if created:
|
||||
return progress.created_file(self._path, childcap, metadata)
|
||||
return progress.reused_file(self._path, childcap, metadata)
|
||||
@ -525,12 +527,12 @@ class BackupProgress(object):
|
||||
return self, {
|
||||
os.path.basename(create_path): create_value
|
||||
for (create_path, create_value)
|
||||
in self._create_contents.iteritems()
|
||||
in self._create_contents.items()
|
||||
if os.path.dirname(create_path) == dirpath
|
||||
}, {
|
||||
os.path.basename(compare_path): compare_value
|
||||
for (compare_path, compare_value)
|
||||
in self._compare_contents.iteritems()
|
||||
in self._compare_contents.items()
|
||||
if os.path.dirname(compare_path) == dirpath
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user