Changes in / [ec7185a:99e37df] in trunk


Ignore:
Location:
src/allmydata
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/dirnode.py

    rec7185a r99e37df  
    33Ported to Python 3.
    44"""
    5 
    6 from past.builtins import unicode
    75
    86import time
     
    4038
    4139NAME = Field.for_types(
    42     u"name",
    43     # Make sure this works on Python 2; with str, it gets Future str which
    44     # breaks Eliot.
    45     [unicode],
    46     u"The name linking the parent to this node.",
     40    "name",
     41    [str],
     42    "The name linking the parent to this node.",
    4743)
    4844
    4945METADATA = Field.for_types(
    50     u"metadata",
     46    "metadata",
    5147    [dict],
    52     u"Data about a node.",
     48    "Data about a node.",
    5349)
    5450
    5551OVERWRITE = Field.for_types(
    56     u"overwrite",
     52    "overwrite",
    5753    [bool],
    58     u"True to replace an existing file of the same name, "
    59     u"false to fail with a collision error.",
     54    "True to replace an existing file of the same name, "
     55    "false to fail with a collision error.",
    6056)
    6157
    6258ADD_FILE = ActionType(
    63     u"dirnode:add-file",
     59    "dirnode:add-file",
    6460    [NAME, METADATA, OVERWRITE],
    6561    [],
    66     u"Add a new file as a child of a directory.",
     62    "Add a new file as a child of a directory.",
    6763)
    6864
  • TabularUnified src/allmydata/mutable/layout.py

    rec7185a r99e37df  
    22Ported to Python 3.
    33"""
    4 
    5 from past.utils import old_div
    64
    75import struct
     
    261259        assert expected_segment_size == segment_size
    262260
    263         self._block_size = old_div(self._segment_size, self._required_shares)
     261        self._block_size = self._segment_size // self._required_shares
    264262
    265263        # This is meant to mimic how SDMF files were built before MDMF
     
    794792        self._num_segments = mathutil.div_ceil(self._data_length,
    795793                                               self._segment_size)
    796         self._block_size = old_div(self._segment_size, self._required_shares)
     794        self._block_size = self._segment_size // self._required_shares
    797795        # We also calculate the share size, to help us with block
    798796        # constraints later.
     
    803801            self._tail_block_size = mathutil.next_multiple(tail_size,
    804802                                                           self._required_shares)
    805             self._tail_block_size = old_div(self._tail_block_size, self._required_shares)
     803            self._tail_block_size = self._tail_block_size // self._required_shares
    806804
    807805        # We already know where the sharedata starts; right after the end
     
    13251323        self._data_length = datalen
    13261324
    1327         self._block_size = old_div(self._segment_size, self._required_shares)
     1325        self._block_size = self._segment_size // self._required_shares
    13281326        # We can upload empty files, and need to account for this fact
    13291327        # so as to avoid zero-division and zero-modulo errors.
     
    13371335            self._tail_block_size = mathutil.next_multiple(tail_size,
    13381336                                                    self._required_shares)
    1339             self._tail_block_size = old_div(self._tail_block_size, self._required_shares)
     1337            self._tail_block_size = self._tail_block_size // self._required_shares
    13401338
    13411339        return encoding_parameters
  • TabularUnified src/allmydata/storage/immutable.py

    rec7185a r99e37df  
    22Ported to Python 3.
    33"""
    4 
    5 
    6 from future.utils import bytes_to_native_str
    74
    85import os, stat, struct, time
     
    535532    def __repr__(self):
    536533        return "<%s %s %s>" % (self.__class__.__name__,
    537                                bytes_to_native_str(
    538                                    base32.b2a(self.storage_index[:8])[:12]
    539                                ),
     534                               base32.b2a(self.storage_index[:8])[:12].decode(),
    540535                               self.shnum)
    541536
  • TabularUnified src/allmydata/storage/server.py

    rec7185a r99e37df  
    44from __future__ import annotations
    55
    6 from future.utils import bytes_to_native_str
    76from typing import Iterable, Any
    87
     
    906905"""
    907906
    908 def render_corruption_report(share_type, si_s, shnum, reason):
     907def render_corruption_report(
     908    share_type: bytes,
     909    si_s: bytes,
     910    shnum: int,
     911    reason: bytes
     912) -> str:
    909913    """
    910914    Create a string that explains a corruption report using freeform text.
     
    921925    """
    922926    return CORRUPTION_REPORT_FORMAT.format(
    923         type=bytes_to_native_str(share_type),
    924         storage_index=bytes_to_native_str(si_s),
     927        type=share_type.decode(),
     928        storage_index=si_s.decode(),
    925929        share_number=shnum,
    926         reason=bytes_to_native_str(reason),
     930        reason=reason.decode(),
    927931    )
    928932
    929 def get_corruption_report_path(base_dir, now, si_s, shnum):
     933def get_corruption_report_path(
     934    base_dir: str,
     935    now: str,
     936    si_s: str,
     937    shnum: int
     938) -> str:
    930939    """
    931940    Determine the path to which a certain corruption report should be written.
  • TabularUnified src/allmydata/test/test_encode.py

    rec7185a r99e37df  
    33"""
    44
    5 from past.builtins import chr as byteschr, long
     5from past.builtins import chr as byteschr
    66
    77from zope.interface import implementer
     
    100100        d = self._start()
    101101        def _try(unused=None):
    102             assert isinstance(blocknum, (int, long))
     102            assert isinstance(blocknum, int)
    103103            if self.mode == "bad block":
    104104                return flip_bit(self.blocks[blocknum])
  • TabularUnified src/allmydata/test/test_encodingutil.py

    rec7185a r99e37df  
    344344        for fp in (nosep_fp, sep_fp):
    345345            self.failUnlessReallyEqual(fp, FilePath(foo_u))
    346             if encodingutil.use_unicode_filepath:
    347                 self.failUnlessReallyEqual(fp.path, foo_u)
     346            self.failUnlessReallyEqual(fp.path, foo_u)
    348347
    349348        if sys.platform == "win32":
     
    361360            fp = extend_filepath(foo_fp, [u'bar', u'baz'])
    362361            self.failUnlessReallyEqual(fp, FilePath(foo_bar_baz_u))
    363             if encodingutil.use_unicode_filepath:
    364                 self.failUnlessReallyEqual(fp.path, foo_bar_baz_u)
     362            self.failUnlessReallyEqual(fp.path, foo_bar_baz_u)
    365363
    366364    def test_unicode_from_filepath(self):
  • TabularUnified src/allmydata/test/test_log.py

    rec7185a r99e37df  
    44Ported to Python 3.
    55"""
    6 
    7 
    8 from future.utils import native_str
    96
    107from twisted.trial import unittest
     
    162159        for message in self.messages:
    163160            for k in message[-1].keys():
    164                 self.assertIsInstance(k, native_str)
     161                self.assertIsInstance(k, str)
  • TabularUnified src/allmydata/test/test_storage.py

    rec7185a r99e37df  
    66
    77from __future__ import annotations
    8 from future.utils import native_str, bytes_to_native_str, bchr
     8from future.utils import bchr
    99from six import ensure_str
    1010
     
    110110        parts = os.path.split(path)
    111111        self.assertThat(parts[0], Equals(parts[1][:2]))
    112         self.assertThat(path, IsInstance(native_str))
     112        self.assertThat(path, IsInstance(str))
    113113
    114114    def test_get_share_file_mutable(self):
     
    12431243        reports = os.listdir(reportdir)
    12441244        self.assertThat(reports, HasLength(2))
    1245         report_si1 = [r for r in reports if bytes_to_native_str(si1_s) in r][0]
     1245        report_si1 = [r for r in reports if si1_s.decode() in r][0]
    12461246        f = open(os.path.join(reportdir, report_si1), "rb")
    12471247        report = f.read()
     
    18101810                             Equals({}))
    18111811        # and the bucket directory should now be gone
    1812         si = base32.b2a(b"si1")
     1812        si = base32.b2a(b"si1").decode()
    18131813        # note: this is a detail of the storage server implementation, and
    18141814        # may change in the future
    1815         si = bytes_to_native_str(si)  # filesystem paths are native strings
     1815        # filesystem paths are native strings
    18161816        prefix = si[:2]
    18171817        prefixdir = os.path.join(self.workdir("test_remove"), "shares", prefix)
  • TabularUnified src/allmydata/test/test_system.py

    rec7185a r99e37df  
    44from __future__ import annotations
    55
    6 from past.builtins import chr as byteschr, long
     6from past.builtins import chr as byteschr
    77from six import ensure_text
    88
     
    396396                # convenient and basically measures the same thing
    397397                bytes_sent = results.get_ciphertext_fetched()
    398                 self.failUnless(isinstance(bytes_sent, (int, long)), bytes_sent)
     398                self.failUnless(isinstance(bytes_sent, int), bytes_sent)
    399399
    400400                # We currently don't support resumption of upload if the data is
  • TabularUnified src/allmydata/util/encodingutil.py

    rec7185a r99e37df  
    99"""
    1010
    11 from past.builtins import unicode
    1211from six import ensure_str
    1312
     
    5453
    5554filesystem_encoding = None
    56 is_unicode_platform = True
    57 use_unicode_filepath = True
    5855
    5956def _reload():
     
    8380    This is the inverse of ``unicode_to_argv``.
    8481    """
    85     if isinstance(s, unicode):
     82    if isinstance(s, str):
    8683        return s
    8784
     
    8986
    9087    try:
    91         return unicode(s, io_encoding)
     88        return str(s, io_encoding)
    9289    except UnicodeDecodeError:
    9390        raise usage.UsageError("Argument %s cannot be decoded as %s." %
     
    113110    Windows, this returns the input unmodified.
    114111    """
    115     precondition(isinstance(s, unicode), s)
     112    precondition(isinstance(s, str), s)
    116113    warnings.warn("This is unnecessary.", DeprecationWarning)
    117114    if sys.platform == "win32":
     
    167164    the responsibility of stdout/stderr, they expect Unicode by default.
    168165    """
    169     precondition(isinstance(s, unicode), s)
     166    precondition(isinstance(s, str), s)
    170167    warnings.warn("This is unnecessary.", DeprecationWarning)
    171168    return s
     
    215212    """
    216213    result = quote_output(*args, **kwargs)
    217     if isinstance(result, unicode):
     214    if isinstance(result, str):
    218215        return result
    219216    # Since we're quoting, the assumption is this will be read by a human, and
     
    240237    On Python 3, returns Unicode strings.
    241238    """
    242     precondition(isinstance(s, (bytes, unicode)), s)
     239    precondition(isinstance(s, (bytes, str)), s)
    243240    # Since we're quoting, the assumption is this will be read by a human, and
    244241    # therefore printed, so stdout's encoding is the plausible one. io_encoding
     
    279276
    280277def quote_local_unicode_path(path, quotemarks=True):
    281     precondition(isinstance(path, unicode), path)
     278    precondition(isinstance(path, str), path)
    282279
    283280    if sys.platform == "win32" and path.startswith(u"\\\\?\\"):
     
    299296        fp = fp.child(segment)
    300297
    301     if isinstance(fp.path, unicode) and not use_unicode_filepath:
    302         return FilePath(fp.path.encode(filesystem_encoding))
    303     else:
    304         return fp
     298    return fp
    305299
    306300def to_filepath(path):
    307     precondition(isinstance(path, unicode if use_unicode_filepath else (bytes, unicode)),
    308                  path=path)
    309 
    310     if isinstance(path, unicode) and not use_unicode_filepath:
    311         path = path.encode(filesystem_encoding)
     301    precondition(isinstance(path, str), path=path)
    312302
    313303    if sys.platform == "win32":
    314         _assert(isinstance(path, unicode), path=path)
     304        _assert(isinstance(path, str), path=path)
    315305        if path.startswith(u"\\\\?\\") and len(path) > 4:
    316306            # FilePath normally strips trailing path separators, but not in this case.
     
    320310
    321311def _decode(s):
    322     precondition(isinstance(s, (bytes, unicode)), s=s)
     312    precondition(isinstance(s, (bytes, str)), s=s)
    323313
    324314    if isinstance(s, bytes):
     
    341331    Does the current platform handle Unicode filenames natively?
    342332    """
    343     return is_unicode_platform
     333    return True
    344334
    345335class FilenameEncodingError(Exception):
     
    350340    pass
    351341
    352 def listdir_unicode_fallback(path):
    353     """
    354     This function emulates a fallback Unicode API similar to one available
    355     under Windows or MacOS X.
    356 
    357     If badly encoded filenames are encountered, an exception is raised.
    358     """
    359     precondition(isinstance(path, unicode), path)
    360 
    361     try:
    362         byte_path = path.encode(filesystem_encoding)
    363     except (UnicodeEncodeError, UnicodeDecodeError):
    364         raise FilenameEncodingError(path)
    365 
    366     try:
    367         return [unicode(fn, filesystem_encoding) for fn in os.listdir(byte_path)]
    368     except UnicodeDecodeError as e:
    369         raise FilenameEncodingError(e.object)
    370 
    371342def listdir_unicode(path):
    372343    """
     
    374345    Unicode API even under platforms that don't provide one natively.
    375346    """
    376     precondition(isinstance(path, unicode), path)
    377 
    378     # On Windows and MacOS X, the Unicode API is used
    379     # On other platforms (ie. Unix systems), the byte-level API is used
    380 
    381     if is_unicode_platform:
    382         return os.listdir(path)
    383     else:
    384         return listdir_unicode_fallback(path)
     347    precondition(isinstance(path, str), path)
     348    return os.listdir(path)
    385349
    386350def listdir_filepath(fp):
  • TabularUnified src/allmydata/util/iputil.py

    rec7185a r99e37df  
    22Utilities for getting IP addresses.
    33"""
    4 
    5 from future.utils import native_str
    64
    75from typing import Callable
     
    105103    """
    106104    return list(
    107         native_str(address["addr"])
     105        str(address["addr"])
    108106        for iface_name
    109107        in interfaces()
  • TabularUnified src/allmydata/util/time_format.py

    rec7185a r99e37df  
    66"""
    77
    8 from future.utils import native_str
     8import calendar, datetime, re, time
    99
    10 import calendar, datetime, re, time
     10from typing import Optional
    1111
    1212def format_time(t):
    1313    return time.strftime("%Y-%m-%d %H:%M:%S", t)
    1414
    15 def iso_utc_date(now=None, t=time.time):
     15def iso_utc_date(
     16    now: Optional[float] = None,
     17    t=time.time
     18) -> str:
    1619    if now is None:
    1720        now = t()
    1821    return datetime.datetime.utcfromtimestamp(now).isoformat()[:10]
    1922
    20 def iso_utc(now=None, sep='_', t=time.time):
     23def iso_utc(
     24    now: Optional[float] = None,
     25    sep: str = '_',
     26    t=time.time
     27) -> str:
    2128    if now is None:
    2229        now = t()
    23     sep = native_str(sep)  # Python 2 doesn't allow unicode input to isoformat
     30    sep = str(sep)  # should already be a str
    2431    return datetime.datetime.utcfromtimestamp(now).isoformat(sep)
    2532
Note: See TracChangeset for help on using the changeset viewer.