Changeset 06c4ed1 in trunk


Ignore:
Timestamp:
2021-04-12T13:28:51Z (4 years ago)
Author:
Itamar Turner-Trauring <itamar@…>
Branches:
master
Children:
069fcb9
Parents:
d6406d5
Message:

Some progress towards passing Python 3 tests.

Location:
src/allmydata/scripts
Files:
2 edited

Legend:

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

    rd6406d5 r06c4ed1  
    22
    33from __future__ import print_function
    4 from six import ensure_binary
     4from six import ensure_str
    55
    66import os, sys, textwrap
     
    277277
    278278def escape_path(path):
    279     # type: (Union[str,bytes]) -> bytes
     279    # type: (Union[str,bytes]) -> str
    280280    u"""
    281281    Return path quoted to US-ASCII, valid URL characters.
     
    284284    >>> escaped = escape_path(path)
    285285    >>> escaped
    286     b'/f%C3%B8%C3%B6/bar/%E2%98%83'
     286    u'/f%C3%B8%C3%B6/bar/%E2%98%83'
    287287    """
    288288    if isinstance(path, str):
    289289        path = path.encode("utf-8")
    290290    segments = path.split(b"/")
    291     return b"/".join([urllib.parse.quote(s).encode("ascii") for s in segments])
    292 
     291    result = str(
     292        b"/".join([
     293            urllib.parse.quote(s).encode("ascii") for s in segments
     294        ]),
     295        "ascii"
     296    )
     297    # Eventually (i.e. as part of Python 3 port) we want this to always return
     298    # Unicode strings. However, to reduce diff sizes in the short term it'll
     299    # return native string (i.e. bytes) on Python 2.
     300    if PY2:
     301        result = result.encode("ascii").__native__()
     302    return result
  • TabularUnified src/allmydata/scripts/tahoe_backup.py

    rd6406d5 r06c4ed1  
    11from __future__ import print_function
     2
     3from past.builtins import unicode
    24
    35import os.path
     
    346348            return target.backup(progress, upload_file, upload_directory)
    347349        else:
    348             assert isinstance(childcap, str)
     350            assert isinstance(childcap, bytes)
    349351            if created:
    350352                return progress.created_file(self._path, childcap, metadata)
     
    526528            os.path.basename(create_path): create_value
    527529            for (create_path, create_value)
    528             in self._create_contents.iteritems()
     530            in self._create_contents.items()
    529531            if os.path.dirname(create_path) == dirpath
    530532        }, {
    531533            os.path.basename(compare_path): compare_value
    532534            for (compare_path, compare_value)
    533             in self._compare_contents.iteritems()
     535            in self._compare_contents.items()
    534536            if os.path.dirname(compare_path) == dirpath
    535537        }
Note: See TracChangeset for help on using the changeset viewer.