Changeset 9ed0cd42 in trunk


Ignore:
Timestamp:
2021-06-03T13:08:13Z (4 years ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
aef8705, e2831ee
Parents:
336ca45c (diff), a910ebcc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Itamar Turner-Trauring <itamar@…> (2021-06-03 13:08:13)
git-committer:
GitHub <noreply@…> (2021-06-03 13:08:13)
Message:

Merge pull request #1074 from tahoe-lafs/3728.scripts-python-3-part-3

Port allmydata.scripts to Python 3, part 3

Fixes ticket:3728

Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/scripts/cli.py

    r336ca45c r9ed0cd42  
    516516def list_(options):
    517517    from allmydata.scripts import tahoe_ls
    518     rc = tahoe_ls.list(options)
     518    rc = tahoe_ls.ls(options)
    519519    return rc
    520520
  • TabularUnified src/allmydata/scripts/tahoe_cp.py

    r336ca45c r9ed0cd42  
     1"""
     2Ported to Python 3.
     3"""
     4from __future__ import unicode_literals
     5from __future__ import absolute_import
     6from __future__ import division
    17from __future__ import print_function
    28
    3 from past.builtins import unicode
     9from future.utils import PY2
     10if PY2:
     11    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
    412
    513import os.path
     
    163171
    164172    def get_child_target(self, name):
    165         precondition(isinstance(name, unicode), name)
     173        precondition(isinstance(name, str), name)
    166174        precondition(len(name), name) # don't want ""
    167175        if self.children is None:
     
    176184
    177185    def put_file(self, name, inf):
    178         precondition(isinstance(name, unicode), name)
     186        precondition(isinstance(name, str), name)
    179187        pathname = os.path.join(self.pathname, name)
    180188        fileutil.put_file(pathname, inf)
     
    259267        assert nodetype == "dirnode"
    260268        self.mutable = d.get("mutable", False) # older nodes don't provide it
    261         self.children_d = dict( [(unicode(name),value)
     269        self.children_d = dict( [(str(name),value)
    262270                                 for (name,value)
    263271                                 in d["children"].items()] )
     
    269277        self.readcap = to_bytes(d.get("ro_uri"))
    270278        self.mutable = d.get("mutable", False) # older nodes don't provide it
    271         self.children_d = dict( [(unicode(name),value)
     279        self.children_d = dict( [(str(name),value)
    272280                                 for (name,value)
    273281                                 in d["children"].items()] )
     
    339347        self.readcap = to_bytes(d.get("ro_uri"))
    340348        self.mutable = d.get("mutable", False) # older nodes don't provide it
    341         self.children_d = dict( [(unicode(name),value)
     349        self.children_d = dict( [(str(name),value)
    342350                                 for (name,value)
    343351                                 in d["children"].items()] )
     
    356364        assert nodetype == "dirnode"
    357365        self.mutable = d.get("mutable", False) # older nodes don't provide it
    358         self.children_d = dict( [(unicode(name),value)
     366        self.children_d = dict( [(str(name),value)
    359367                                 for (name,value)
    360368                                 in d["children"].items()] )
     
    412420    def get_child_target(self, name):
    413421        # return a new target for a named subdirectory of this dir
    414         precondition(isinstance(name, unicode), name)
     422        precondition(isinstance(name, str), name)
    415423        if self.children is None:
    416424            self.populate(recurse=False)
     
    425433
    426434    def put_file(self, name, inf):
    427         precondition(isinstance(name, unicode), name)
     435        precondition(isinstance(name, str), name)
    428436        url = self.nodeurl + "uri"
    429437        if not seekable(inf):
     
    445453
    446454    def put_uri(self, name, filecap):
    447         precondition(isinstance(name, unicode), name)
     455        precondition(isinstance(name, str), name)
    448456        self.new_children[name] = filecap
    449457
     
    454462               + "?t=set_children")
    455463        set_data = {}
    456         for (name, filecap) in self.new_children.items():
     464        for (name, filecap) in list(self.new_children.items()):
    457465            # it just so happens that ?t=set_children will accept both file
    458466            # read-caps and write-caps as ['rw_uri'], and will handle either
     
    598606
    599607    def get_target_info(self, destination_spec):
    600         precondition(isinstance(destination_spec, unicode), destination_spec)
     608        precondition(isinstance(destination_spec, str), destination_spec)
    601609        rootcap, path_utf8 = get_alias(self.aliases, destination_spec, None)
    602610        path = path_utf8.decode("utf-8")
     
    645653        This turns an argv string into a (Local|Tahoe)(File|Directory)Source.
    646654        """
    647         precondition(isinstance(source_spec, unicode), source_spec)
     655        precondition(isinstance(source_spec, str), source_spec)
    648656        rootcap, path_utf8 = get_alias(self.aliases, source_spec, None)
    649657        path = path_utf8.decode("utf-8")
     
    753761        # target name collisions are an error
    754762        collisions = []
    755         for target, sources in targetmap.items():
     763        for target, sources in list(targetmap.items()):
    756764            target_names = {}
    757765            for source in sources:
     
    822830        # copy everything in the source into the target
    823831        precondition(isinstance(source, DirectorySources), source)
    824         for name, child in source.children.items():
     832        for name, child in list(source.children.items()):
    825833            if isinstance(child, DirectorySources):
    826834                # we will need a target directory for this one
     
    838846        targets_finished = 0
    839847
    840         for target, sources in targetmap.items():
     848        for target, sources in list(targetmap.items()):
    841849            _assert(isinstance(target, DirectoryTargets), target)
    842850            for source in sources:
     
    858866        precondition(isinstance(source, FileSources), source)
    859867        precondition(isinstance(target, DirectoryTargets), target)
    860         precondition(isinstance(name, unicode), name)
     868        precondition(isinstance(name, str), name)
    861869        if self.need_to_copy_bytes(source, target):
    862870            # if the target is a local directory, this will just write the
  • TabularUnified src/allmydata/scripts/tahoe_get.py

    r336ca45c r9ed0cd42  
     1"""
     2Ported to Python 3.
     3"""
     4from __future__ import unicode_literals
     5from __future__ import absolute_import
     6from __future__ import division
    17from __future__ import print_function
    28
    3 from future.utils import PY3
     9from future.utils import PY2, PY3
     10if PY2:
     11    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
    412
    513from urllib.parse import quote as url_quote
  • TabularUnified src/allmydata/scripts/tahoe_invite.py

    r336ca45c r9ed0cd42  
     1"""
     2Ported to Python 3.
     3"""
     4from __future__ import unicode_literals
     5from __future__ import absolute_import
     6from __future__ import division
    17from __future__ import print_function
     8
     9from future.utils import PY2
     10if PY2:
     11    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
    212
    313try:
  • TabularUnified src/allmydata/scripts/tahoe_ls.py

    r336ca45c r9ed0cd42  
     1"""
     2Ported to Python 3.
     3"""
     4from __future__ import unicode_literals
     5from __future__ import absolute_import
     6from __future__ import division
    17from __future__ import print_function
    28
    3 from past.builtins import unicode
    4 from six import ensure_text, ensure_str
     9from future.utils import PY2
     10if PY2:
     11    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
     12
     13from six import ensure_text
    514
    615import time
     
    1221from allmydata.util.encodingutil import unicode_to_output, quote_output, is_printable_ascii, to_bytes
    1322
    14 def list(options):
     23def ls(options):
    1524    nodeurl = options['node-url']
    1625    aliases = options.aliases
     
    2938        return 1
    3039
    31     path = unicode(path, "utf-8")
     40    path = str(path, "utf-8")
    3241    url = nodeurl + "uri/%s" % url_quote(rootcap)
    3342    if path:
     
    5160        # The webapi server should always output printable ASCII.
    5261        if is_printable_ascii(data):
    53             data = unicode(data, "ascii")
     62            data = str(data, "ascii")
    5463            print(data, file=stdout)
    5564            return 0
     
    8897    for name in childnames:
    8998        child = children[name]
    90         name = unicode(name)
     99        name = str(name)
    91100        childtype = child[0]
    92101
     
    148157            classify = ""
    149158
    150         encoding_error = False
    151         try:
    152             line.append(unicode_to_output(name) + classify)
    153         except UnicodeEncodeError:
    154             encoding_error = True
    155             line.append(quote_output(name) + classify)
     159        line.append(name + classify)
    156160
    157161        if options["uri"]:
    158             line.append(ensure_str(uri))
     162            line.append(ensure_text(uri))
    159163        if options["readonly-uri"]:
    160             line.append(quote_output(ensure_str(ro_uri) or "-", quotemarks=False))
    161 
    162         rows.append((encoding_error, line))
     164            line.append(quote_output(ensure_text(ro_uri) or "-", quotemarks=False))
     165
     166        rows.append(line)
    163167
    164168    max_widths = []
    165169    left_justifys = []
    166     for (encoding_error, row) in rows:
     170    for row in rows:
    167171        for i,cell in enumerate(row):
    168172            while len(max_widths) <= i:
     
    186190
    187191    rc = 0
    188     for (encoding_error, row) in rows:
     192    for row in rows:
     193        row = (fmt % tuple(row)).rstrip()
     194        encoding_error = False
     195        try:
     196            row = unicode_to_output(row)
     197        except UnicodeEncodeError:
     198            encoding_error = True
     199            row = quote_output(row)
    189200        if encoding_error:
    190             print((fmt % tuple(row)).rstrip(), file=stderr)
     201            print(row, file=stderr)
    191202            rc = 1
    192203        else:
    193             print((fmt % tuple(row)).rstrip(), file=stdout)
     204            print(row, file=stdout)
    194205
    195206    if rc == 1:
  • TabularUnified src/allmydata/scripts/tahoe_manifest.py

    r336ca45c r9ed0cd42  
     1"""
     2Ported to Python 3.
     3"""
     4from __future__ import unicode_literals
     5from __future__ import absolute_import
     6from __future__ import division
    17from __future__ import print_function
    28
    3 from future.utils import PY3
    4 from past.builtins import unicode
     9from future.utils import PY2, PY3
     10if PY2:
     11    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
     12
     13from six import ensure_str
    514
    615from urllib.parse import quote as url_quote
     
    3847            e.display(stderr)
    3948            return 1
    40         path = unicode(path, "utf-8")
     49        path = str(path, "utf-8")
    4150        if path == '/':
    4251            path = ''
     
    97106                        print(quote_output(vc, quotemarks=False), file=stdout)
    98107                else:
    99                     print("%s %s" % (quote_output(d["cap"], quotemarks=False),
    100                                                quote_path(d["path"], quotemarks=False)), file=stdout)
     108                    # ensure_str() only necessary for Python 2.
     109                    print(ensure_str("%s %s") % (
     110                        quote_output(d["cap"], quotemarks=False),
     111                        quote_path(d["path"], quotemarks=False)), file=stdout)
    101112
    102113def manifest(options):
  • TabularUnified src/allmydata/util/_python3.py

    r336ca45c r9ed0cd42  
    106106    "allmydata.scripts.tahoe_backup",
    107107    "allmydata.scripts.tahoe_check",
     108    "allmydata.scripts.tahoe_cp",
     109    "allmydata.scripts.tahoe_get",
     110    "allmydata.scripts.tahoe_invite",
     111    "allmydata.scripts.tahoe_ls",
     112    "allmydata.scripts.tahoe_manifest",
    108113    "allmydata.scripts.types_",
    109114    "allmydata.stats",
Note: See TracChangeset for help on using the changeset viewer.