mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-30 01:38:55 +00:00
Merge pull request #916 from tahoe-lafs/3456.introducer-python3
Port allmydata.introducer to Python 3 Fixes ticket:3546
This commit is contained in:
commit
489b369218
0
newsfragments/3546.minor
Normal file
0
newsfragments/3546.minor
Normal file
@ -1,4 +1,16 @@
|
||||
from past.builtins import unicode, long
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
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
|
||||
from past.builtins import long
|
||||
|
||||
from six import ensure_text
|
||||
|
||||
import time
|
||||
@ -27,11 +39,11 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
nickname, my_version, oldest_supported,
|
||||
sequencer, cache_filepath):
|
||||
self._tub = tub
|
||||
if isinstance(introducer_furl, unicode):
|
||||
if isinstance(introducer_furl, str):
|
||||
introducer_furl = introducer_furl.encode("utf-8")
|
||||
self.introducer_furl = introducer_furl
|
||||
|
||||
assert type(nickname) is unicode
|
||||
assert isinstance(nickname, str)
|
||||
self._nickname = nickname
|
||||
self._my_version = my_version
|
||||
self._oldest_supported = oldest_supported
|
||||
@ -114,7 +126,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
|
||||
def _save_announcements(self):
|
||||
announcements = []
|
||||
for _, value in self._inbound_announcements.items():
|
||||
for value in self._inbound_announcements.values():
|
||||
ann, key_s, time_stamp = value
|
||||
# On Python 2, bytes strings are encoded into YAML Unicode strings.
|
||||
# On Python 3, bytes are encoded as YAML bytes. To minimize
|
||||
@ -125,7 +137,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
}
|
||||
announcements.append(server_params)
|
||||
announcement_cache_yaml = yamlutil.safe_dump(announcements)
|
||||
if isinstance(announcement_cache_yaml, unicode):
|
||||
if isinstance(announcement_cache_yaml, str):
|
||||
announcement_cache_yaml = announcement_cache_yaml.encode("utf-8")
|
||||
self._cache_filepath.setContent(announcement_cache_yaml)
|
||||
|
||||
@ -170,7 +182,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
self._local_subscribers.append( (service_name,cb,args,kwargs) )
|
||||
self._subscribed_service_names.add(service_name)
|
||||
self._maybe_subscribe()
|
||||
for index,(ann,key_s,when) in self._inbound_announcements.items():
|
||||
for index,(ann,key_s,when) in list(self._inbound_announcements.items()):
|
||||
precondition(isinstance(key_s, bytes), key_s)
|
||||
servicename = index[0]
|
||||
if servicename == service_name:
|
||||
@ -215,7 +227,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
self._outbound_announcements[service_name] = ann_d
|
||||
|
||||
# publish all announcements with the new seqnum and nonce
|
||||
for service_name,ann_d in self._outbound_announcements.items():
|
||||
for service_name,ann_d in list(self._outbound_announcements.items()):
|
||||
ann_d["seqnum"] = current_seqnum
|
||||
ann_d["nonce"] = current_nonce
|
||||
ann_t = sign_to_foolscap(ann_d, signing_key)
|
||||
@ -227,7 +239,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
self.log("want to publish, but no introducer yet", level=log.NOISY)
|
||||
return
|
||||
# this re-publishes everything. The Introducer ignores duplicates
|
||||
for ann_t in self._published_announcements.values():
|
||||
for ann_t in list(self._published_announcements.values()):
|
||||
self._debug_counts["outbound_message"] += 1
|
||||
self._debug_outstanding += 1
|
||||
d = self._publisher.callRemote("publish_v2", ann_t, self._canary)
|
||||
@ -267,7 +279,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
return
|
||||
# for ASCII values, simplejson might give us unicode *or* bytes
|
||||
if "nickname" in ann and isinstance(ann["nickname"], bytes):
|
||||
ann["nickname"] = unicode(ann["nickname"])
|
||||
ann["nickname"] = str(ann["nickname"])
|
||||
nick_s = ann.get("nickname",u"").encode("utf-8")
|
||||
lp2 = self.log(format="announcement for nickname '%(nick)s', service=%(svc)s: %(ann)s",
|
||||
nick=nick_s, svc=service_name, ann=ann, umid="BoKEag")
|
||||
|
@ -1,3 +1,15 @@
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
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
|
||||
|
||||
import re
|
||||
from allmydata.crypto.util import remove_prefix
|
||||
from allmydata.crypto import ed25519
|
||||
|
@ -1,5 +1,18 @@
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
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
|
||||
from past.builtins import long
|
||||
from six import ensure_str, ensure_text
|
||||
from six import ensure_text
|
||||
|
||||
import time, os.path, textwrap
|
||||
from zope.interface import implementer
|
||||
@ -157,7 +170,7 @@ class IntroducerService(service.MultiService, Referenceable):
|
||||
# 'subscriber_info' is a dict, provided directly by v2 clients. The
|
||||
# expected keys are: version, nickname, app-versions, my-version,
|
||||
# oldest-supported
|
||||
self._subscribers = {}
|
||||
self._subscribers = dictutil.UnicodeKeyDict({})
|
||||
|
||||
self._debug_counts = {"inbound_message": 0,
|
||||
"inbound_duplicate": 0,
|
||||
@ -181,7 +194,7 @@ class IntroducerService(service.MultiService, Referenceable):
|
||||
def get_announcements(self):
|
||||
"""Return a list of AnnouncementDescriptor for all announcements"""
|
||||
announcements = []
|
||||
for (index, (_, canary, ann, when)) in self._announcements.items():
|
||||
for (index, (_, canary, ann, when)) in list(self._announcements.items()):
|
||||
ad = AnnouncementDescriptor(when, index, canary, ann)
|
||||
announcements.append(ad)
|
||||
return announcements
|
||||
@ -189,8 +202,8 @@ class IntroducerService(service.MultiService, Referenceable):
|
||||
def get_subscribers(self):
|
||||
"""Return a list of SubscriberDescriptor objects for all subscribers"""
|
||||
s = []
|
||||
for service_name, subscriptions in self._subscribers.items():
|
||||
for rref,(subscriber_info,when) in subscriptions.items():
|
||||
for service_name, subscriptions in list(self._subscribers.items()):
|
||||
for rref,(subscriber_info,when) in list(subscriptions.items()):
|
||||
# note that if the subscriber didn't do Tub.setLocation,
|
||||
# tubid will be None. Also, subscribers do not tell us which
|
||||
# pubkey they use; only publishers do that.
|
||||
@ -281,7 +294,7 @@ class IntroducerService(service.MultiService, Referenceable):
|
||||
def remote_subscribe_v2(self, subscriber, service_name, subscriber_info):
|
||||
self.log("introducer: subscription[%s] request at %s"
|
||||
% (service_name, subscriber), umid="U3uzLg")
|
||||
service_name = ensure_str(service_name)
|
||||
service_name = ensure_text(service_name)
|
||||
subscriber_info = dictutil.UnicodeKeyDict({
|
||||
ensure_text(k): v for (k, v) in subscriber_info.items()
|
||||
})
|
||||
@ -307,11 +320,11 @@ class IntroducerService(service.MultiService, Referenceable):
|
||||
subscribers.pop(subscriber, None)
|
||||
subscriber.notifyOnDisconnect(_remove)
|
||||
|
||||
# Make sure types are correct:
|
||||
for k in self._announcements:
|
||||
assert isinstance(k[0], type(service_name))
|
||||
|
||||
# now tell them about any announcements they're interested in
|
||||
assert {type(service_name)}.issuperset(
|
||||
set(type(k[0]) for k in self._announcements)), (
|
||||
service_name, self._announcements.keys()
|
||||
)
|
||||
announcements = set( [ ann_t
|
||||
for idx,(ann_t,canary,ann,when)
|
||||
in self._announcements.items()
|
||||
|
@ -561,6 +561,9 @@ class _FoolscapStorage(object):
|
||||
}
|
||||
|
||||
*nickname* is optional.
|
||||
|
||||
The furl will be a Unicode string on Python 3; on Python 2 it will be
|
||||
either a native (bytes) string or a Unicode string.
|
||||
"""
|
||||
furl = furl.encode("utf-8")
|
||||
m = re.match(br'pb://(\w+)@', furl)
|
||||
|
@ -51,7 +51,10 @@ PORTED_MODULES = [
|
||||
"allmydata.immutable.offloaded",
|
||||
"allmydata.immutable.upload",
|
||||
"allmydata.interfaces",
|
||||
"allmydata.introducer.client",
|
||||
"allmydata.introducer.common",
|
||||
"allmydata.introducer.interfaces",
|
||||
"allmydata.introducer.server",
|
||||
"allmydata.monitor",
|
||||
"allmydata.mutable.checker",
|
||||
"allmydata.mutable.common",
|
||||
|
Loading…
Reference in New Issue
Block a user