Merge pull request #1075 from tahoe-lafs/3729.scripts-python-3-part-4

Finish porting allmydata.scripts to Python 3

Fixes ticket:3729
This commit is contained in:
Itamar Turner-Trauring 2021-06-03 16:49:42 -04:00 committed by GitHub
commit e2831ee8b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 86 additions and 18 deletions

0
newsfragments/3729.minor Normal file
View File

View File

@ -1,6 +1,14 @@
"""
Ported to Python 3.
"""
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division
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 urllib.parse import quote as url_quote
from allmydata.scripts.common_http import do_http, check_http_error
@ -37,7 +45,7 @@ def mkdir(options):
return 0
# create a new directory at the given location
path = unicode(path, "utf-8")
path = str(path, "utf-8")
if path.endswith("/"):
path = path[:-1]
# path must be "/".join([s.encode("utf-8") for s in segments])

View File

@ -1,6 +1,14 @@
"""
Ported to Python 3.
"""
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division
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
import re
from urllib.parse import quote as url_quote
@ -27,7 +35,7 @@ def mv(options, mode="move"):
except UnknownAliasError as e:
e.display(stderr)
return 1
from_path = unicode(from_path, "utf-8")
from_path = str(from_path, "utf-8")
from_url = nodeurl + "uri/%s" % url_quote(rootcap)
if from_path:
from_url += "/" + escape_path(from_path)
@ -47,7 +55,7 @@ def mv(options, mode="move"):
e.display(stderr)
return 1
to_url = nodeurl + "uri/%s" % url_quote(rootcap)
path = unicode(path, "utf-8")
path = str(path, "utf-8")
if path:
to_url += "/" + escape_path(path)

View File

@ -1,7 +1,14 @@
"""
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.utils import PY2
from past.builtins import unicode
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 io import BytesIO
from urllib.parse import quote as url_quote
@ -56,7 +63,7 @@ def put(options):
except UnknownAliasError as e:
e.display(stderr)
return 1
path = unicode(path, "utf-8")
path = str(path, "utf-8")
if path.startswith("/"):
suggestion = to_file.replace(u"/", u"", 1)
print("Error: The remote filename must not start with a slash", file=stderr)

View File

@ -1,5 +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.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
__all__ = [
"RunOptions",
"run",

View File

@ -1,6 +1,14 @@
"""
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.builtins import chr
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
import os
from urllib.parse import urlencode, quote as url_quote
@ -53,7 +61,7 @@ def _get_json_for_cap(options, cap):
'uri/%s?t=json' % url_quote(cap),
)
def pretty_progress(percent, size=10, ascii=False):
def pretty_progress(percent, size=10, output_ascii=False):
"""
Displays a unicode or ascii based progress bar of a certain
length. Should we just depend on a library instead?
@ -64,7 +72,7 @@ def pretty_progress(percent, size=10, ascii=False):
curr = int(percent / 100.0 * size)
part = (percent / (100.0 / size)) - curr
if ascii:
if output_ascii:
part = int(part * 4)
part = '.oO%'[part]
block_chr = '#'

View File

@ -1,5 +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.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 urllib.parse import quote as url_quote
from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \

View File

@ -1,4 +1,14 @@
from past.builtins import unicode
"""
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.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 urllib.parse import quote as url_quote
@ -18,7 +28,7 @@ def webopen(options, opener=None):
except UnknownAliasError as e:
e.display(stderr)
return 1
path = unicode(path, "utf-8")
path = str(path, "utf-8")
if path == '/':
path = ''
url = nodeurl + "uri/%s" % url_quote(rootcap)

View File

@ -60,30 +60,30 @@ class FakeStatus(object):
class ProgressBar(unittest.TestCase):
def test_ascii0(self):
prog = pretty_progress(80.0, size=10, ascii=True)
prog = pretty_progress(80.0, size=10, output_ascii=True)
self.assertEqual('########. ', prog)
def test_ascii1(self):
prog = pretty_progress(10.0, size=10, ascii=True)
prog = pretty_progress(10.0, size=10, output_ascii=True)
self.assertEqual('#. ', prog)
def test_ascii2(self):
prog = pretty_progress(13.0, size=10, ascii=True)
prog = pretty_progress(13.0, size=10, output_ascii=True)
self.assertEqual('#o ', prog)
def test_ascii3(self):
prog = pretty_progress(90.0, size=10, ascii=True)
prog = pretty_progress(90.0, size=10, output_ascii=True)
self.assertEqual('#########.', prog)
def test_unicode0(self):
self.assertEqual(
pretty_progress(82.0, size=10, ascii=False),
pretty_progress(82.0, size=10, output_ascii=False),
u'\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258e ',
)
def test_unicode1(self):
self.assertEqual(
pretty_progress(100.0, size=10, ascii=False),
pretty_progress(100.0, size=10, output_ascii=False),
u'\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588',
)

View File

@ -110,6 +110,13 @@ PORTED_MODULES = [
"allmydata.scripts.tahoe_invite",
"allmydata.scripts.tahoe_ls",
"allmydata.scripts.tahoe_manifest",
"allmydata.scripts.tahoe_mkdir",
"allmydata.scripts.tahoe_mv",
"allmydata.scripts.tahoe_put",
"allmydata.scripts.tahoe_run",
"allmydata.scripts.tahoe_status",
"allmydata.scripts.tahoe_unlink",
"allmydata.scripts.tahoe_webopen",
"allmydata.scripts.types_",
"allmydata.stats",
"allmydata.storage_client",