mirror of
https://github.com/magic-wormhole/magic-wormhole.git
synced 2024-08-18 02:24:35 +03:00
Merge pull request #516 from a-detiste/master
remove python2 compatibility
This commit is contained in:
@@ -38,9 +38,7 @@ and the
|
||||
Magic-Wormhole is released under the MIT license, see the `LICENSE` file for details.
|
||||
|
||||
This library is compatible with Python 3.8 and higher (tested against
|
||||
3.8, and 3.9). It also still works with Python 2.7 although that is no
|
||||
longer supported by upstream libraries like Cryptography, so it may
|
||||
stop working at any time.
|
||||
versions up to 3.12).
|
||||
|
||||
## Packaging, Installation
|
||||
|
||||
|
||||
1
setup.py
1
setup.py
@@ -45,7 +45,6 @@ setup(name="magic-wormhole",
|
||||
},
|
||||
install_requires=[
|
||||
"spake2==0.8", "pynacl",
|
||||
"six",
|
||||
"attrs >= 19.2.0", # 19.2.0 replaces cmp parameter with eq/order
|
||||
"twisted[tls] >= 17.5.0", # 17.5.0 adds failAfterFailures=
|
||||
"autobahn[twisted] >= 0.14.1",
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
import six
|
||||
from attr import attrib, attrs
|
||||
from attr.validators import instance_of, optional, provides
|
||||
from automat import MethodicalMachine
|
||||
@@ -366,7 +363,7 @@ class Boss(object):
|
||||
|
||||
@m.output()
|
||||
def W_received(self, phase, plaintext):
|
||||
assert isinstance(phase, six.integer_types), type(phase)
|
||||
assert isinstance(phase, int), type(phase)
|
||||
# we call Wormhole.received() in strict phase order, with no gaps
|
||||
self._rx_phases[phase] = plaintext
|
||||
while self._next_rx_phase in self._rx_phases:
|
||||
@@ -375,7 +372,7 @@ class Boss(object):
|
||||
|
||||
@m.output()
|
||||
def D_received_dilate(self, seqnum, plaintext):
|
||||
assert isinstance(seqnum, six.integer_types), type(seqnum)
|
||||
assert isinstance(seqnum, int), type(seqnum)
|
||||
# strict phase order, no gaps
|
||||
self._rx_dilate_seqnums[seqnum] = plaintext
|
||||
while self._next_rx_dilate_seqnum in self._rx_dilate_seqnums:
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from __future__ import print_function, unicode_literals
|
||||
from collections import namedtuple
|
||||
import six
|
||||
from attr import attrs, attrib
|
||||
from attr.validators import instance_of, provides
|
||||
from automat import MethodicalMachine
|
||||
@@ -306,19 +304,19 @@ def encode_record(r):
|
||||
if isinstance(r, Pong):
|
||||
return b"\x02" + r.ping_id
|
||||
if isinstance(r, Open):
|
||||
assert isinstance(r.scid, six.integer_types)
|
||||
assert isinstance(r.seqnum, six.integer_types)
|
||||
assert isinstance(r.scid, int)
|
||||
assert isinstance(r.seqnum, int)
|
||||
return b"\x03" + to_be4(r.scid) + to_be4(r.seqnum)
|
||||
if isinstance(r, Data):
|
||||
assert isinstance(r.scid, six.integer_types)
|
||||
assert isinstance(r.seqnum, six.integer_types)
|
||||
assert isinstance(r.scid, int)
|
||||
assert isinstance(r.seqnum, int)
|
||||
return b"\x04" + to_be4(r.scid) + to_be4(r.seqnum) + r.data
|
||||
if isinstance(r, Close):
|
||||
assert isinstance(r.scid, six.integer_types)
|
||||
assert isinstance(r.seqnum, six.integer_types)
|
||||
assert isinstance(r.scid, int)
|
||||
assert isinstance(r.seqnum, int)
|
||||
return b"\x05" + to_be4(r.scid) + to_be4(r.seqnum)
|
||||
if isinstance(r, Ack):
|
||||
assert isinstance(r.resp_seqnum, six.integer_types)
|
||||
assert isinstance(r.resp_seqnum, int)
|
||||
return b"\x06" + to_be4(r.resp_seqnum)
|
||||
raise TypeError(r)
|
||||
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
from __future__ import print_function, unicode_literals
|
||||
import six
|
||||
import os
|
||||
from collections import deque
|
||||
try:
|
||||
# py >= 3.3
|
||||
from collections.abc import Sequence
|
||||
except ImportError:
|
||||
# py 2 and py3 < 3.3
|
||||
from collections import Sequence
|
||||
from collections.abc import Sequence
|
||||
from attr import attrs, attrib
|
||||
from attr.validators import provides, instance_of, optional
|
||||
from automat import MethodicalMachine
|
||||
@@ -256,15 +249,15 @@ class Manager(object):
|
||||
self._outbound.subchannel_unregisterProducer(sc)
|
||||
|
||||
def send_open(self, scid):
|
||||
assert isinstance(scid, six.integer_types)
|
||||
assert isinstance(scid, int)
|
||||
self._queue_and_send(Open, scid)
|
||||
|
||||
def send_data(self, scid, data):
|
||||
assert isinstance(scid, six.integer_types)
|
||||
assert isinstance(scid, int)
|
||||
self._queue_and_send(Data, scid, data)
|
||||
|
||||
def send_close(self, scid):
|
||||
assert isinstance(scid, six.integer_types)
|
||||
assert isinstance(scid, int)
|
||||
self._queue_and_send(Close, scid)
|
||||
|
||||
def _queue_and_send(self, record_type, *args):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import six
|
||||
from collections import deque
|
||||
from attr import attrs, attrib
|
||||
from attr.validators import instance_of, provides
|
||||
@@ -74,7 +73,7 @@ class _WormholeAddress(object):
|
||||
@implementer(IAddress)
|
||||
@attrs
|
||||
class _SubchannelAddress(object):
|
||||
_scid = attrib(validator=instance_of(six.integer_types))
|
||||
_scid = attrib(validator=instance_of(int))
|
||||
|
||||
|
||||
@attrs(eq=False)
|
||||
@@ -83,7 +82,7 @@ class _SubchannelAddress(object):
|
||||
@implementer(IConsumer)
|
||||
@implementer(ISubChannel)
|
||||
class SubChannel(object):
|
||||
_scid = attrib(validator=instance_of(six.integer_types))
|
||||
_scid = attrib(validator=instance_of(int))
|
||||
_manager = attrib(validator=provides(IDilationManager))
|
||||
_host_addr = attrib(validator=instance_of(_WormholeAddress))
|
||||
_peer_addr = attrib(validator=instance_of(_SubchannelAddress))
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from __future__ import print_function, unicode_literals
|
||||
import sys
|
||||
import re
|
||||
import six
|
||||
from collections import namedtuple
|
||||
from twisted.internet.endpoints import TCP4ClientEndpoint, TCP6ClientEndpoint, HostnameEndpoint
|
||||
from twisted.internet.abstract import isIPAddress, isIPv6Address
|
||||
@@ -121,7 +119,7 @@ def parse_tcp_v1_hint(hint): # hint_struct -> hint_obj
|
||||
log.msg("invalid hostname in hint: %r" % (hint, ))
|
||||
return None
|
||||
if not ("port" in hint and
|
||||
isinstance(hint["port"], six.integer_types)):
|
||||
isinstance(hint["port"], int)):
|
||||
log.msg("invalid port in hint: %r" % (hint, ))
|
||||
return None
|
||||
priority = hint.get("priority", 0.0)
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
from hashlib import sha256
|
||||
|
||||
import six
|
||||
from attr import attrib, attrs
|
||||
from attr.validators import instance_of, provides
|
||||
from automat import MethodicalMachine
|
||||
@@ -25,7 +22,7 @@ def derive_key(key, purpose, length=SecretBox.KEY_SIZE):
|
||||
raise TypeError(type(key))
|
||||
if not isinstance(purpose, type(b"")):
|
||||
raise TypeError(type(purpose))
|
||||
if not isinstance(length, six.integer_types):
|
||||
if not isinstance(length, int):
|
||||
raise TypeError(type(length))
|
||||
return HKDF(key, length, CTXinfo=purpose)
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import print_function, absolute_import, unicode_literals
|
||||
import os
|
||||
from six.moves.urllib_parse import urlparse
|
||||
from urllib.parse import urlparse
|
||||
from attr import attrs, attrib
|
||||
from attr.validators import provides, instance_of, optional
|
||||
from zope.interface import implementer
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import traceback
|
||||
from sys import stderr
|
||||
|
||||
from attr import attrib, attrs
|
||||
from six.moves import input
|
||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||
from twisted.internet.threads import blockingCallFromThread, deferToThread
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import time
|
||||
start = time.time()
|
||||
@@ -8,7 +6,6 @@ from sys import stderr, stdout # noqa: E402
|
||||
from textwrap import dedent, fill # noqa: E402
|
||||
|
||||
import click # noqa: E402
|
||||
import six # noqa: E402
|
||||
from twisted.internet.defer import inlineCallbacks, maybeDeferred # noqa: E402
|
||||
from twisted.internet.task import react # noqa: E402
|
||||
from twisted.python.failure import Failure # noqa: E402
|
||||
@@ -151,16 +148,16 @@ def _dispatch_command(reactor, cfg, command):
|
||||
except (WelcomeError, UnsendableFileError, KeyFormatError) as e:
|
||||
msg = fill("ERROR: " + dedent(e.__doc__))
|
||||
print(msg, file=cfg.stderr)
|
||||
print(six.u(""), file=cfg.stderr)
|
||||
print(six.text_type(e), file=cfg.stderr)
|
||||
print("", file=cfg.stderr)
|
||||
print(str(e), file=cfg.stderr)
|
||||
raise SystemExit(1)
|
||||
except TransferError as e:
|
||||
print(u"TransferError: %s" % six.text_type(e), file=cfg.stderr)
|
||||
print(u"TransferError: %s" % str(e), file=cfg.stderr)
|
||||
raise SystemExit(1)
|
||||
except ServerConnectionError as e:
|
||||
msg = fill("ERROR: " + dedent(e.__doc__)) + "\n"
|
||||
msg += "(relay URL was %s)\n" % e.url
|
||||
msg += six.text_type(e)
|
||||
msg += str(e)
|
||||
print(msg, file=cfg.stderr)
|
||||
raise SystemExit(1)
|
||||
except Exception as e:
|
||||
@@ -168,7 +165,7 @@ def _dispatch_command(reactor, cfg, command):
|
||||
# traceback.print_exc() just prints a TB to the "yield"
|
||||
# line above ...
|
||||
Failure().printTraceback(file=cfg.stderr)
|
||||
print(u"ERROR:", six.text_type(e), file=cfg.stderr)
|
||||
print(u"ERROR:", str(e), file=cfg.stderr)
|
||||
raise SystemExit(1)
|
||||
|
||||
cfg.timing.add("exit")
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
@@ -7,7 +5,6 @@ import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
import six
|
||||
from humanize import naturalsize
|
||||
from tqdm import tqdm
|
||||
from twisted.internet import reactor
|
||||
@@ -390,7 +387,7 @@ class Receiver:
|
||||
def _ask_permission(self):
|
||||
with self.args.timing.add("permission", waiting="user") as t:
|
||||
while True and not self.args.accept_file:
|
||||
ok = six.moves.input("ok? (Y/n): ")
|
||||
ok = input("ok? (Y/n): ")
|
||||
if ok.lower().startswith("y") or len(ok) == 0:
|
||||
if os.path.exists(self.abs_destname):
|
||||
self._remove_existing(self.abs_destname)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import errno
|
||||
import hashlib
|
||||
import os
|
||||
@@ -7,7 +5,6 @@ import sys
|
||||
|
||||
import stat
|
||||
|
||||
import six
|
||||
from humanize import naturalsize
|
||||
from tqdm import tqdm
|
||||
from twisted.internet import reactor
|
||||
@@ -240,7 +237,7 @@ class Sender:
|
||||
def _check_verifier(self, w, verifier_bytes):
|
||||
verifier = bytes_to_hexstr(verifier_bytes)
|
||||
while True:
|
||||
ok = six.moves.input("Verifier %s. ok? (yes/no): " % verifier)
|
||||
ok = input("Verifier %s. ok? (yes/no): " % verifier)
|
||||
if ok.lower() == "yes":
|
||||
break
|
||||
if ok.lower() == "no":
|
||||
@@ -262,7 +259,7 @@ class Sender:
|
||||
print(u"Reading text message from stdin..", file=args.stderr)
|
||||
text = sys.stdin.read()
|
||||
if not text and not args.what:
|
||||
text = six.moves.input("Text to send: ")
|
||||
text = input("Text to send: ")
|
||||
|
||||
if text is not None:
|
||||
print(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import builtins
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
@@ -8,7 +7,6 @@ import sys
|
||||
import zipfile
|
||||
from textwrap import dedent, fill
|
||||
|
||||
import six
|
||||
from click import UsageError
|
||||
from click.testing import CliRunner
|
||||
from humanize import naturalsize
|
||||
@@ -147,7 +145,7 @@ class OfferData(unittest.TestCase):
|
||||
self.assertEqual(d["directory"]["mode"], "zipfile/deflated")
|
||||
self.assertEqual(d["directory"]["numfiles"], 5)
|
||||
self.assertIn("numbytes", d["directory"])
|
||||
self.assertIsInstance(d["directory"]["numbytes"], six.integer_types)
|
||||
self.assertIsInstance(d["directory"]["numbytes"], int)
|
||||
|
||||
zdata = b"".join(fd_to_send)
|
||||
self.assertEqual(len(zdata), d["directory"]["zipsize"])
|
||||
@@ -607,8 +605,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
|
||||
with mock.patch.object(cmd_receive, "VERIFY_TIMER", VERIFY_TIMER):
|
||||
with mock.patch.object(cmd_send, "VERIFY_TIMER", VERIFY_TIMER):
|
||||
if mock_accept or verify:
|
||||
with mock.patch.object(
|
||||
cmd_receive.six.moves, 'input',
|
||||
with mock.patch.object(builtins, 'input',
|
||||
return_value='yes') as i:
|
||||
yield gatherResults([send_d, receive_d], True)
|
||||
if verify:
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import gc
|
||||
import io
|
||||
from binascii import hexlify, unhexlify
|
||||
|
||||
import six
|
||||
from nacl.exceptions import CryptoError
|
||||
from nacl.secret import SecretBox
|
||||
from twisted.internet import address, defer, endpoints, error, protocol, task
|
||||
@@ -141,14 +138,8 @@ class Misc(unittest.TestCase):
|
||||
self.assertIsInstance(portno, int)
|
||||
|
||||
|
||||
# ipaddrs.py currently uses native strings: bytes on py2, unicode on
|
||||
# py3
|
||||
if six.PY2:
|
||||
LOOPADDR = b"127.0.0.1"
|
||||
OTHERADDR = b"1.2.3.4"
|
||||
else:
|
||||
LOOPADDR = "127.0.0.1" # unicode_literals
|
||||
OTHERADDR = "1.2.3.4"
|
||||
LOOPADDR = "127.0.0.1"
|
||||
OTHERADDR = "1.2.3.4"
|
||||
|
||||
|
||||
class Basic(unittest.TestCase):
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unicodedata
|
||||
|
||||
import six
|
||||
from twisted.trial import unittest
|
||||
|
||||
from unittest import mock
|
||||
@@ -51,7 +48,7 @@ class Space(unittest.TestCase):
|
||||
def test_free_space(self):
|
||||
free = util.estimate_free_space(".")
|
||||
self.assert_(
|
||||
isinstance(free, six.integer_types + (type(None), )), repr(free))
|
||||
isinstance(free, (int, type(None))), repr(free))
|
||||
# some platforms (I think the VMs used by travis are in this
|
||||
# category) return 0, and windows will return None, so don't assert
|
||||
# anything more specific about the return value
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
# no unicode_literals, revisit after twisted patch
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
@@ -8,7 +5,6 @@ import time
|
||||
from binascii import hexlify, unhexlify
|
||||
from collections import deque
|
||||
|
||||
import six
|
||||
from nacl.secret import SecretBox
|
||||
from twisted.internet import (address, defer, endpoints, error, interfaces,
|
||||
protocol, task)
|
||||
@@ -595,7 +591,7 @@ class Common:
|
||||
# 127.0.0.1, and the tests will hang badly if we remove it.
|
||||
addresses = non_loopback_addresses
|
||||
direct_hints = [
|
||||
DirectTCPV1Hint(six.u(addr), portnum, 0.0) for addr in addresses
|
||||
DirectTCPV1Hint(str(addr), portnum, 0.0) for addr in addresses
|
||||
]
|
||||
ep = endpoints.serverFromString(self._reactor, "tcp:%d" % portnum)
|
||||
return direct_hints, ep
|
||||
|
||||
Reference in New Issue
Block a user