From 0e1a4dd51305759901b208fee03b0489d163e471 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 24 May 2016 16:22:37 -0700 Subject: [PATCH 1/5] move wormhole.twisted.transit up to wormhole.transit --- src/wormhole/cli/cmd_receive.py | 2 +- src/wormhole/cli/cmd_send.py | 2 +- src/wormhole/test/common.py | 2 +- src/wormhole/test/test_transit_twisted.py | 2 +- src/wormhole/{twisted => }/transit.py | 8 ++++---- src/wormhole/twisted/tor_manager.py | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/wormhole/{twisted => }/transit.py (99%) diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index 2e0447a..f4c19f9 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -4,7 +4,7 @@ from tqdm import tqdm from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, returnValue from ..wormhole import wormhole -from ..twisted.transit import TransitReceiver +from ..transit import TransitReceiver from ..errors import TransferError APPID = u"lothar.com/wormhole/text-or-file-xfer" diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index dba5ee0..ff32ed0 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -6,7 +6,7 @@ from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, returnValue from ..errors import TransferError from ..wormhole import wormhole -from ..twisted.transit import TransitSender +from ..transit import TransitSender APPID = u"lothar.com/wormhole/text-or-file-xfer" diff --git a/src/wormhole/test/common.py b/src/wormhole/test/common.py index 48c0685..b50f776 100644 --- a/src/wormhole/test/common.py +++ b/src/wormhole/test/common.py @@ -1,7 +1,7 @@ from twisted.application import service from twisted.internet import reactor, defer from twisted.python import log -from ..twisted.transit import allocate_tcp_port +from ..transit import allocate_tcp_port from ..server.server import RelayServer from .. import __version__ diff --git a/src/wormhole/test/test_transit_twisted.py b/src/wormhole/test/test_transit_twisted.py index 4d87816..bbc33a8 100644 --- a/src/wormhole/test/test_transit_twisted.py +++ b/src/wormhole/test/test_transit_twisted.py @@ -6,7 +6,7 @@ from twisted.internet import defer, task, endpoints, protocol, address, error from twisted.internet.defer import gatherResults, inlineCallbacks from twisted.python import log, failure from twisted.test import proto_helpers -from ..twisted import transit +from .. import transit from ..errors import UsageError from nacl.secret import SecretBox from nacl.exceptions import CryptoError diff --git a/src/wormhole/twisted/transit.py b/src/wormhole/transit.py similarity index 99% rename from src/wormhole/twisted/transit.py rename to src/wormhole/transit.py index cbc8724..b48ae5d 100644 --- a/src/wormhole/twisted/transit.py +++ b/src/wormhole/transit.py @@ -1,4 +1,4 @@ -from __future__ import print_function +from __future__ import print_function, absolute_import import re, sys, time, socket, collections from binascii import hexlify, unhexlify from zope.interface import implementer @@ -9,9 +9,9 @@ from twisted.internet.defer import inlineCallbacks, returnValue from twisted.protocols import policies from nacl.secret import SecretBox from hkdf import Hkdf -from ..errors import UsageError -from ..timing import DebugTiming -from . import ipaddrs +from .errors import UsageError +from .timing import DebugTiming +from .twisted import ipaddrs def HKDF(skm, outlen, salt=None, CTXinfo=b""): return Hkdf(salt, skm).expand(CTXinfo, outlen) diff --git a/src/wormhole/twisted/tor_manager.py b/src/wormhole/twisted/tor_manager.py index 80a72c1..e6cc3de 100644 --- a/src/wormhole/twisted/tor_manager.py +++ b/src/wormhole/twisted/tor_manager.py @@ -5,7 +5,7 @@ from twisted.internet.error import ConnectError import txtorcon import ipaddr from ..timing import DebugTiming -from .transit import allocate_tcp_port +from ..transit import allocate_tcp_port class TorManager: def __init__(self, reactor, tor_socks_port=None, tor_control_port=9051, From 7140565b992539be945c19d9c5d43ae300e9de43 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 24 May 2016 16:23:52 -0700 Subject: [PATCH 2/5] move wormhole.twisted.ipaddrs up to wormhole/ --- src/wormhole/{twisted => }/ipaddrs.py | 0 src/wormhole/transit.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/wormhole/{twisted => }/ipaddrs.py (100%) diff --git a/src/wormhole/twisted/ipaddrs.py b/src/wormhole/ipaddrs.py similarity index 100% rename from src/wormhole/twisted/ipaddrs.py rename to src/wormhole/ipaddrs.py diff --git a/src/wormhole/transit.py b/src/wormhole/transit.py index b48ae5d..c94e919 100644 --- a/src/wormhole/transit.py +++ b/src/wormhole/transit.py @@ -11,7 +11,7 @@ from nacl.secret import SecretBox from hkdf import Hkdf from .errors import UsageError from .timing import DebugTiming -from .twisted import ipaddrs +from . import ipaddrs def HKDF(skm, outlen, salt=None, CTXinfo=b""): return Hkdf(salt, skm).expand(CTXinfo, outlen) From c218b939c08752a5e9d82ab8a9a86b4b3e23a487 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 24 May 2016 16:25:12 -0700 Subject: [PATCH 3/5] move wormhole.twisted.tor_manager up to wormhole/ --- src/wormhole/cli/cmd_receive.py | 2 +- src/wormhole/cli/cmd_send.py | 2 +- src/wormhole/{twisted => }/tor_manager.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/wormhole/{twisted => }/tor_manager.py (98%) diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index f4c19f9..e7fa2ab 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -38,7 +38,7 @@ class TwistedReceiver: tor_manager = None if self.args.tor: with self.args.timing.add("import", which="tor_manager"): - from ..twisted.tor_manager import TorManager + from ..tor_manager import TorManager tor_manager = TorManager(self._reactor, timing=self.args.timing) # For now, block everything until Tor has started. Soon: launch # tor in parallel with everything else, make sure the TorManager diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index ff32ed0..e393a0d 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -41,7 +41,7 @@ def send(args, reactor=reactor): tor_manager = None if args.tor: with args.timing.add("import", which="tor_manager"): - from ..twisted.tor_manager import TorManager + from ..tor_manager import TorManager tor_manager = TorManager(reactor, timing=args.timing) # For now, block everything until Tor has started. Soon: launch tor # in parallel with everything else, make sure the TorManager can diff --git a/src/wormhole/twisted/tor_manager.py b/src/wormhole/tor_manager.py similarity index 98% rename from src/wormhole/twisted/tor_manager.py rename to src/wormhole/tor_manager.py index e6cc3de..4e96284 100644 --- a/src/wormhole/twisted/tor_manager.py +++ b/src/wormhole/tor_manager.py @@ -4,8 +4,8 @@ from twisted.internet.defer import inlineCallbacks, returnValue from twisted.internet.error import ConnectError import txtorcon import ipaddr -from ..timing import DebugTiming -from ..transit import allocate_tcp_port +from .timing import DebugTiming +from .transit import allocate_tcp_port class TorManager: def __init__(self, reactor, tor_socks_port=None, tor_control_port=9051, From c06bc83d3feb566abda97b11a2ea4a98de4db699 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 24 May 2016 16:25:37 -0700 Subject: [PATCH 4/5] remove unused twisted/eventual.py --- src/wormhole/twisted/eventual.py | 76 -------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/wormhole/twisted/eventual.py diff --git a/src/wormhole/twisted/eventual.py b/src/wormhole/twisted/eventual.py deleted file mode 100644 index 02fbdd5..0000000 --- a/src/wormhole/twisted/eventual.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- test-case-name: foolscap.test.test_eventual -*- - -from twisted.internet import reactor, defer -from twisted.python import log - -class _SimpleCallQueue(object): - # XXX TODO: merge epsilon.cooperator in, and make this more complete. - def __init__(self): - self._events = [] - self._flushObservers = [] - self._timer = None - - def append(self, cb, args, kwargs): - self._events.append((cb, args, kwargs)) - if not self._timer: - self._timer = reactor.callLater(0, self._turn) - - def _turn(self): - self._timer = None - # flush all the messages that are currently in the queue. If anything - # gets added to the queue while we're doing this, those events will - # be put off until the next turn. - events, self._events = self._events, [] - for cb, args, kwargs in events: - try: - cb(*args, **kwargs) - except: - log.err() - if not self._events: - observers, self._flushObservers = self._flushObservers, [] - for o in observers: - o.callback(None) - - def flush(self): - """Return a Deferred that will fire (with None) when the call queue - is completely empty.""" - if not self._events: - return defer.succeed(None) - d = defer.Deferred() - self._flushObservers.append(d) - return d - - -_theSimpleQueue = _SimpleCallQueue() - -def eventually(cb, *args, **kwargs): - """This is the eventual-send operation, used as a plan-coordination - primitive. The callable will be invoked (with args and kwargs) in a later - reactor turn. Doing 'eventually(a); eventually(b)' guarantees that a will - be called before b. - - Any exceptions that occur in the callable will be logged with log.err(). - If you really want to ignore them, be sure to provide a callable that - catches those exceptions. - - This function returns None. If you care to know when the callable was - run, be sure to provide a callable that notifies somebody. - """ - _theSimpleQueue.append(cb, args, kwargs) - - -def fireEventually(value=None): - """This returns a Deferred which will fire in a later reactor turn, after - the current call stack has been completed, and after all other deferreds - previously scheduled with callEventually(). - """ - d = defer.Deferred() - eventually(d.callback, value) - return d - -def flushEventualQueue(_ignored=None): - """This returns a Deferred which fires when the eventual-send queue is - finally empty. This is useful to wait upon as the last step of a Trial - test method. - """ - return _theSimpleQueue.flush() From 0414051df2ad1c32cbaeca82ebe10d26778e2e36 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 24 May 2016 16:26:17 -0700 Subject: [PATCH 5/5] remove wormhole/twisted/ --- setup.py | 1 - src/wormhole/twisted/__init__.py | 0 2 files changed, 1 deletion(-) delete mode 100644 src/wormhole/twisted/__init__.py diff --git a/setup.py b/setup.py index d1c239a..f652859 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ setup(name="magic-wormhole", "wormhole.cli", "wormhole.server", "wormhole.test", - "wormhole.twisted", ], package_data={"wormhole.server": ["db-schemas/*.sql"]}, entry_points={"console_scripts": diff --git a/src/wormhole/twisted/__init__.py b/src/wormhole/twisted/__init__.py deleted file mode 100644 index e69de29..0000000