Changes in / [ec7185a:99e37df] in trunk
- Location:
- src/allmydata
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/dirnode.py ¶
rec7185a r99e37df 3 3 Ported to Python 3. 4 4 """ 5 6 from past.builtins import unicode7 5 8 6 import time … … 40 38 41 39 NAME = 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.", 47 43 ) 48 44 49 45 METADATA = Field.for_types( 50 u"metadata",46 "metadata", 51 47 [dict], 52 u"Data about a node.",48 "Data about a node.", 53 49 ) 54 50 55 51 OVERWRITE = Field.for_types( 56 u"overwrite",52 "overwrite", 57 53 [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.", 60 56 ) 61 57 62 58 ADD_FILE = ActionType( 63 u"dirnode:add-file",59 "dirnode:add-file", 64 60 [NAME, METADATA, OVERWRITE], 65 61 [], 66 u"Add a new file as a child of a directory.",62 "Add a new file as a child of a directory.", 67 63 ) 68 64 -
TabularUnified src/allmydata/mutable/layout.py ¶
rec7185a r99e37df 2 2 Ported to Python 3. 3 3 """ 4 5 from past.utils import old_div6 4 7 5 import struct … … 261 259 assert expected_segment_size == segment_size 262 260 263 self._block_size = old_div(self._segment_size, self._required_shares)261 self._block_size = self._segment_size // self._required_shares 264 262 265 263 # This is meant to mimic how SDMF files were built before MDMF … … 794 792 self._num_segments = mathutil.div_ceil(self._data_length, 795 793 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 797 795 # We also calculate the share size, to help us with block 798 796 # constraints later. … … 803 801 self._tail_block_size = mathutil.next_multiple(tail_size, 804 802 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 806 804 807 805 # We already know where the sharedata starts; right after the end … … 1325 1323 self._data_length = datalen 1326 1324 1327 self._block_size = old_div(self._segment_size, self._required_shares)1325 self._block_size = self._segment_size // self._required_shares 1328 1326 # We can upload empty files, and need to account for this fact 1329 1327 # so as to avoid zero-division and zero-modulo errors. … … 1337 1335 self._tail_block_size = mathutil.next_multiple(tail_size, 1338 1336 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 1340 1338 1341 1339 return encoding_parameters -
TabularUnified src/allmydata/storage/immutable.py ¶
rec7185a r99e37df 2 2 Ported to Python 3. 3 3 """ 4 5 6 from future.utils import bytes_to_native_str7 4 8 5 import os, stat, struct, time … … 535 532 def __repr__(self): 536 533 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(), 540 535 self.shnum) 541 536 -
TabularUnified src/allmydata/storage/server.py ¶
rec7185a r99e37df 4 4 from __future__ import annotations 5 5 6 from future.utils import bytes_to_native_str7 6 from typing import Iterable, Any 8 7 … … 906 905 """ 907 906 908 def render_corruption_report(share_type, si_s, shnum, reason): 907 def render_corruption_report( 908 share_type: bytes, 909 si_s: bytes, 910 shnum: int, 911 reason: bytes 912 ) -> str: 909 913 """ 910 914 Create a string that explains a corruption report using freeform text. … … 921 925 """ 922 926 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(), 925 929 share_number=shnum, 926 reason= bytes_to_native_str(reason),930 reason=reason.decode(), 927 931 ) 928 932 929 def get_corruption_report_path(base_dir, now, si_s, shnum): 933 def get_corruption_report_path( 934 base_dir: str, 935 now: str, 936 si_s: str, 937 shnum: int 938 ) -> str: 930 939 """ 931 940 Determine the path to which a certain corruption report should be written. -
TabularUnified src/allmydata/test/test_encode.py ¶
rec7185a r99e37df 3 3 """ 4 4 5 from past.builtins import chr as byteschr , long5 from past.builtins import chr as byteschr 6 6 7 7 from zope.interface import implementer … … 100 100 d = self._start() 101 101 def _try(unused=None): 102 assert isinstance(blocknum, (int, long))102 assert isinstance(blocknum, int) 103 103 if self.mode == "bad block": 104 104 return flip_bit(self.blocks[blocknum]) -
TabularUnified src/allmydata/test/test_encodingutil.py ¶
rec7185a r99e37df 344 344 for fp in (nosep_fp, sep_fp): 345 345 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) 348 347 349 348 if sys.platform == "win32": … … 361 360 fp = extend_filepath(foo_fp, [u'bar', u'baz']) 362 361 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) 365 363 366 364 def test_unicode_from_filepath(self): -
TabularUnified src/allmydata/test/test_log.py ¶
rec7185a r99e37df 4 4 Ported to Python 3. 5 5 """ 6 7 8 from future.utils import native_str9 6 10 7 from twisted.trial import unittest … … 162 159 for message in self.messages: 163 160 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 6 6 7 7 from __future__ import annotations 8 from future.utils import native_str, bytes_to_native_str,bchr8 from future.utils import bchr 9 9 from six import ensure_str 10 10 … … 110 110 parts = os.path.split(path) 111 111 self.assertThat(parts[0], Equals(parts[1][:2])) 112 self.assertThat(path, IsInstance( native_str))112 self.assertThat(path, IsInstance(str)) 113 113 114 114 def test_get_share_file_mutable(self): … … 1243 1243 reports = os.listdir(reportdir) 1244 1244 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] 1246 1246 f = open(os.path.join(reportdir, report_si1), "rb") 1247 1247 report = f.read() … … 1810 1810 Equals({})) 1811 1811 # and the bucket directory should now be gone 1812 si = base32.b2a(b"si1") 1812 si = base32.b2a(b"si1").decode() 1813 1813 # note: this is a detail of the storage server implementation, and 1814 1814 # may change in the future 1815 si = bytes_to_native_str(si)# filesystem paths are native strings1815 # filesystem paths are native strings 1816 1816 prefix = si[:2] 1817 1817 prefixdir = os.path.join(self.workdir("test_remove"), "shares", prefix) -
TabularUnified src/allmydata/test/test_system.py ¶
rec7185a r99e37df 4 4 from __future__ import annotations 5 5 6 from past.builtins import chr as byteschr , long6 from past.builtins import chr as byteschr 7 7 from six import ensure_text 8 8 … … 396 396 # convenient and basically measures the same thing 397 397 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) 399 399 400 400 # We currently don't support resumption of upload if the data is -
TabularUnified src/allmydata/util/encodingutil.py ¶
rec7185a r99e37df 9 9 """ 10 10 11 from past.builtins import unicode12 11 from six import ensure_str 13 12 … … 54 53 55 54 filesystem_encoding = None 56 is_unicode_platform = True57 use_unicode_filepath = True58 55 59 56 def _reload(): … … 83 80 This is the inverse of ``unicode_to_argv``. 84 81 """ 85 if isinstance(s, unicode):82 if isinstance(s, str): 86 83 return s 87 84 … … 89 86 90 87 try: 91 return unicode(s, io_encoding)88 return str(s, io_encoding) 92 89 except UnicodeDecodeError: 93 90 raise usage.UsageError("Argument %s cannot be decoded as %s." % … … 113 110 Windows, this returns the input unmodified. 114 111 """ 115 precondition(isinstance(s, unicode), s)112 precondition(isinstance(s, str), s) 116 113 warnings.warn("This is unnecessary.", DeprecationWarning) 117 114 if sys.platform == "win32": … … 167 164 the responsibility of stdout/stderr, they expect Unicode by default. 168 165 """ 169 precondition(isinstance(s, unicode), s)166 precondition(isinstance(s, str), s) 170 167 warnings.warn("This is unnecessary.", DeprecationWarning) 171 168 return s … … 215 212 """ 216 213 result = quote_output(*args, **kwargs) 217 if isinstance(result, unicode):214 if isinstance(result, str): 218 215 return result 219 216 # Since we're quoting, the assumption is this will be read by a human, and … … 240 237 On Python 3, returns Unicode strings. 241 238 """ 242 precondition(isinstance(s, (bytes, unicode)), s)239 precondition(isinstance(s, (bytes, str)), s) 243 240 # Since we're quoting, the assumption is this will be read by a human, and 244 241 # therefore printed, so stdout's encoding is the plausible one. io_encoding … … 279 276 280 277 def quote_local_unicode_path(path, quotemarks=True): 281 precondition(isinstance(path, unicode), path)278 precondition(isinstance(path, str), path) 282 279 283 280 if sys.platform == "win32" and path.startswith(u"\\\\?\\"): … … 299 296 fp = fp.child(segment) 300 297 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 305 299 306 300 def 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) 312 302 313 303 if sys.platform == "win32": 314 _assert(isinstance(path, unicode), path=path)304 _assert(isinstance(path, str), path=path) 315 305 if path.startswith(u"\\\\?\\") and len(path) > 4: 316 306 # FilePath normally strips trailing path separators, but not in this case. … … 320 310 321 311 def _decode(s): 322 precondition(isinstance(s, (bytes, unicode)), s=s)312 precondition(isinstance(s, (bytes, str)), s=s) 323 313 324 314 if isinstance(s, bytes): … … 341 331 Does the current platform handle Unicode filenames natively? 342 332 """ 343 return is_unicode_platform333 return True 344 334 345 335 class FilenameEncodingError(Exception): … … 350 340 pass 351 341 352 def listdir_unicode_fallback(path):353 """354 This function emulates a fallback Unicode API similar to one available355 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 371 342 def listdir_unicode(path): 372 343 """ … … 374 345 Unicode API even under platforms that don't provide one natively. 375 346 """ 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) 385 349 386 350 def listdir_filepath(fp): -
TabularUnified src/allmydata/util/iputil.py ¶
rec7185a r99e37df 2 2 Utilities for getting IP addresses. 3 3 """ 4 5 from future.utils import native_str6 4 7 5 from typing import Callable … … 105 103 """ 106 104 return list( 107 native_str(address["addr"])105 str(address["addr"]) 108 106 for iface_name 109 107 in interfaces() -
TabularUnified src/allmydata/util/time_format.py ¶
rec7185a r99e37df 6 6 """ 7 7 8 from future.utils import native_str 8 import calendar, datetime, re, time 9 9 10 import calendar, datetime, re, time 10 from typing import Optional 11 11 12 12 def format_time(t): 13 13 return time.strftime("%Y-%m-%d %H:%M:%S", t) 14 14 15 def iso_utc_date(now=None, t=time.time): 15 def iso_utc_date( 16 now: Optional[float] = None, 17 t=time.time 18 ) -> str: 16 19 if now is None: 17 20 now = t() 18 21 return datetime.datetime.utcfromtimestamp(now).isoformat()[:10] 19 22 20 def iso_utc(now=None, sep='_', t=time.time): 23 def iso_utc( 24 now: Optional[float] = None, 25 sep: str = '_', 26 t=time.time 27 ) -> str: 21 28 if now is None: 22 29 now = t() 23 sep = native_str(sep) # Python 2 doesn't allow unicode input to isoformat30 sep = str(sep) # should already be a str 24 31 return datetime.datetime.utcfromtimestamp(now).isoformat(sep) 25 32
Note: See TracChangeset
for help on using the changeset viewer.