mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
Port to Python 3.
This commit is contained in:
parent
61fdea9043
commit
9804a44c50
@ -1,6 +1,15 @@
|
|||||||
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from past.builtins import unicode
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
from six import ensure_text, ensure_str
|
from six import ensure_text, ensure_str
|
||||||
|
|
||||||
import time
|
import time
|
||||||
@ -28,7 +37,7 @@ def list(options):
|
|||||||
e.display(stderr)
|
e.display(stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
path = unicode(path, "utf-8")
|
path = str(path, "utf-8")
|
||||||
url = nodeurl + "uri/%s" % url_quote(rootcap)
|
url = nodeurl + "uri/%s" % url_quote(rootcap)
|
||||||
if path:
|
if path:
|
||||||
# move where.endswith check here?
|
# move where.endswith check here?
|
||||||
@ -50,7 +59,7 @@ def list(options):
|
|||||||
if options['json']:
|
if options['json']:
|
||||||
# The webapi server should always output printable ASCII.
|
# The webapi server should always output printable ASCII.
|
||||||
if is_printable_ascii(data):
|
if is_printable_ascii(data):
|
||||||
data = unicode(data, "ascii")
|
data = str(data, "ascii")
|
||||||
print(data, file=stdout)
|
print(data, file=stdout)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
@ -87,7 +96,7 @@ def list(options):
|
|||||||
|
|
||||||
for name in childnames:
|
for name in childnames:
|
||||||
child = children[name]
|
child = children[name]
|
||||||
name = unicode(name)
|
name = str(name)
|
||||||
childtype = child[0]
|
childtype = child[0]
|
||||||
|
|
||||||
# See webapi.txt for a discussion of the meanings of unix local
|
# See webapi.txt for a discussion of the meanings of unix local
|
||||||
@ -147,23 +156,18 @@ def list(options):
|
|||||||
if not options["classify"]:
|
if not options["classify"]:
|
||||||
classify = ""
|
classify = ""
|
||||||
|
|
||||||
encoding_error = False
|
line.append(name + classify)
|
||||||
try:
|
|
||||||
line.append(unicode_to_output(name) + classify)
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
encoding_error = True
|
|
||||||
line.append(quote_output(name) + classify)
|
|
||||||
|
|
||||||
if options["uri"]:
|
if options["uri"]:
|
||||||
line.append(ensure_str(uri))
|
line.append(ensure_text(uri))
|
||||||
if options["readonly-uri"]:
|
if options["readonly-uri"]:
|
||||||
line.append(quote_output(ensure_str(ro_uri) or "-", quotemarks=False))
|
line.append(quote_output(ensure_text(ro_uri) or "-", quotemarks=False))
|
||||||
|
|
||||||
rows.append((encoding_error, line))
|
rows.append(line)
|
||||||
|
|
||||||
max_widths = []
|
max_widths = []
|
||||||
left_justifys = []
|
left_justifys = []
|
||||||
for (encoding_error, row) in rows:
|
for row in rows:
|
||||||
for i,cell in enumerate(row):
|
for i,cell in enumerate(row):
|
||||||
while len(max_widths) <= i:
|
while len(max_widths) <= i:
|
||||||
max_widths.append(0)
|
max_widths.append(0)
|
||||||
@ -185,12 +189,19 @@ def list(options):
|
|||||||
fmt = " ".join(fmt_pieces)
|
fmt = " ".join(fmt_pieces)
|
||||||
|
|
||||||
rc = 0
|
rc = 0
|
||||||
for (encoding_error, row) in rows:
|
for row in rows:
|
||||||
|
row = (fmt % tuple(row)).rstrip()
|
||||||
|
encoding_error = False
|
||||||
|
try:
|
||||||
|
row = unicode_to_output(row)
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
encoding_error = True
|
||||||
|
row = quote_output(row)
|
||||||
if encoding_error:
|
if encoding_error:
|
||||||
print((fmt % tuple(row)).rstrip(), file=stderr)
|
print(row, file=stderr)
|
||||||
rc = 1
|
rc = 1
|
||||||
else:
|
else:
|
||||||
print((fmt % tuple(row)).rstrip(), file=stdout)
|
print(row, file=stdout)
|
||||||
|
|
||||||
if rc == 1:
|
if rc == 1:
|
||||||
print("\nThis listing included files whose names could not be converted to the terminal" \
|
print("\nThis listing included files whose names could not be converted to the terminal" \
|
||||||
|
@ -108,6 +108,7 @@ PORTED_MODULES = [
|
|||||||
"allmydata.scripts.tahoe_cp",
|
"allmydata.scripts.tahoe_cp",
|
||||||
"allmydata.scripts.tahoe_get",
|
"allmydata.scripts.tahoe_get",
|
||||||
"allmydata.scripts.tahoe_invite",
|
"allmydata.scripts.tahoe_invite",
|
||||||
|
"allmydata.scripts.tahoe_ls",
|
||||||
"allmydata.scripts.types_",
|
"allmydata.scripts.types_",
|
||||||
"allmydata.stats",
|
"allmydata.stats",
|
||||||
"allmydata.storage_client",
|
"allmydata.storage_client",
|
||||||
|
Loading…
Reference in New Issue
Block a user