Some progress towards running crawler on Python 3.
This commit is contained in:
parent
e971ccf58e
commit
ff582c5129
|
@ -1,3 +1,4 @@
|
|||
from future.utils import PY3
|
||||
|
||||
import os.path
|
||||
from allmydata.util import base32
|
||||
|
@ -17,5 +18,12 @@ def si_a2b(ascii_storageindex):
|
|||
return base32.a2b(ascii_storageindex)
|
||||
|
||||
def storage_index_to_dir(storageindex):
|
||||
"""Convert storage index to directory path.
|
||||
|
||||
Returns native string.
|
||||
"""
|
||||
sia = si_b2a(storageindex)
|
||||
if PY3:
|
||||
# On Python 3 we expect paths to be unicode.
|
||||
sia = sia.decode("ascii")
|
||||
return os.path.join(sia[:2], sia)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from future.utils import native_str, PY3
|
||||
|
||||
import os, time, struct
|
||||
try:
|
||||
|
@ -77,6 +78,9 @@ class ShareCrawler(service.MultiService):
|
|||
self.statefile = statefile
|
||||
self.prefixes = [si_b2a(struct.pack(">H", i << (16-10)))[:2]
|
||||
for i in range(2**10)]
|
||||
if PY3:
|
||||
# On Python 3 we expect the paths to be unicode, not bytes.
|
||||
self.prefixes = [p.decode("ascii") for p in self.prefixes]
|
||||
self.prefixes.sort()
|
||||
self.timer = None
|
||||
self.bucket_cache = (None, [])
|
||||
|
@ -314,7 +318,8 @@ class ShareCrawler(service.MultiService):
|
|||
try:
|
||||
buckets = os.listdir(prefixdir)
|
||||
buckets.sort()
|
||||
except EnvironmentError:
|
||||
except EnvironmentError as e:
|
||||
print(e)
|
||||
buckets = []
|
||||
self.bucket_cache = (i, buckets)
|
||||
self.process_prefixdir(cycle, prefix, prefixdir,
|
||||
|
|
|
@ -8,7 +8,7 @@ class LeaseInfo(object):
|
|||
self.cancel_secret = cancel_secret
|
||||
self.expiration_time = expiration_time
|
||||
if nodeid is not None:
|
||||
assert isinstance(nodeid, str)
|
||||
assert isinstance(nodeid, bytes)
|
||||
assert len(nodeid) == 20
|
||||
self.nodeid = nodeid
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class StorageServer(service.MultiService, Referenceable):
|
|||
expiration_cutoff_date=None,
|
||||
expiration_sharetypes=("mutable", "immutable")):
|
||||
service.MultiService.__init__(self)
|
||||
assert isinstance(nodeid, str)
|
||||
assert isinstance(nodeid, bytes)
|
||||
assert len(nodeid) == 20
|
||||
self.my_nodeid = nodeid
|
||||
self.storedir = storedir
|
||||
|
|
|
@ -100,11 +100,11 @@ class Basic(unittest.TestCase, StallMixin, pollmixin.PollMixin):
|
|||
return self.s.stopService()
|
||||
|
||||
def si(self, i):
|
||||
return hashutil.storage_index_hash(bytes(i))
|
||||
return hashutil.storage_index_hash(b"%d" % (i,))
|
||||
def rs(self, i, serverid):
|
||||
return hashutil.bucket_renewal_secret_hash(bytes(i), serverid)
|
||||
return hashutil.bucket_renewal_secret_hash(b"%d" % (i,), serverid)
|
||||
def cs(self, i, serverid):
|
||||
return hashutil.bucket_cancel_secret_hash(bytes(i), serverid)
|
||||
return hashutil.bucket_cancel_secret_hash(b"%d" % (i,), serverid)
|
||||
|
||||
def write(self, i, ss, serverid, tail=0):
|
||||
si = self.si(i)
|
||||
|
|
Loading…
Reference in New Issue