diff --git a/examples/connect.py b/examples/connect.py index ac7d3ed1..f7917dc8 100644 --- a/examples/connect.py +++ b/examples/connect.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function from twisted.internet.task import react from twisted.internet.defer import inlineCallbacks from twisted.internet.endpoints import TCP4ClientEndpoint diff --git a/examples/disallow_streams_by_port.py b/examples/disallow_streams_by_port.py index 1fe744fe..b9e32712 100755 --- a/examples/disallow_streams_by_port.py +++ b/examples/disallow_streams_by_port.py @@ -1,4 +1,3 @@ -from __future__ import print_function # # This uses a very simple custom txtorcon.IStreamAttacher to disallow # certain streams based solely on their port; by default it closes diff --git a/examples/dns_lookups.py b/examples/dns_lookups.py index f49dc32d..727a8b38 100644 --- a/examples/dns_lookups.py +++ b/examples/dns_lookups.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from twisted.internet.task import react from twisted.internet.defer import inlineCallbacks from twisted.internet.endpoints import clientFromString diff --git a/examples/hidden_echo.py b/examples/hidden_echo.py index 3f527bb5..593a148c 100644 --- a/examples/hidden_echo.py +++ b/examples/hidden_echo.py @@ -1,4 +1,3 @@ -from __future__ import print_function from twisted.internet import protocol, reactor, endpoints # like the echo-server example on the front page of diff --git a/examples/launch_tor.py b/examples/launch_tor.py index 367cd899..5bb5feb2 100755 --- a/examples/launch_tor.py +++ b/examples/launch_tor.py @@ -1,5 +1,3 @@ -from __future__ import print_function - """ Launch a private Tor instance. """ diff --git a/examples/launch_tor2web.py b/examples/launch_tor2web.py index f83e2c34..fdf8136c 100644 --- a/examples/launch_tor2web.py +++ b/examples/launch_tor2web.py @@ -5,8 +5,6 @@ # running tor supports, *without* resorting to looking at version # numbers. -from __future__ import print_function - import sys from twisted.internet.task import react from twisted.internet.defer import inlineCallbacks, Deferred diff --git a/examples/launch_tor_endpoint.py b/examples/launch_tor_endpoint.py index 7346242a..ce3d89ec 100755 --- a/examples/launch_tor_endpoint.py +++ b/examples/launch_tor_endpoint.py @@ -1,5 +1,3 @@ -from __future__ import print_function - # Here we set up a Twisted Web server and then launch our own tor with # a configured hidden service directed at the Web server we set # up. This uses serverFromString to translate the "onion" endpoint diff --git a/examples/launch_tor_endpoint2.py b/examples/launch_tor_endpoint2.py index 510490d8..72a24c4c 100755 --- a/examples/launch_tor_endpoint2.py +++ b/examples/launch_tor_endpoint2.py @@ -5,8 +5,6 @@ # up. This uses serverFromString to translate the "onion" endpoint descriptor # into a TCPHiddenServiceEndpoint object... -from __future__ import print_function - from twisted.internet import reactor from twisted.web import server, resource from twisted.internet.endpoints import serverFromString diff --git a/examples/launch_tor_unix_sockets.py b/examples/launch_tor_unix_sockets.py index 54768bb1..750cfeb3 100644 --- a/examples/launch_tor_unix_sockets.py +++ b/examples/launch_tor_unix_sockets.py @@ -1,5 +1,3 @@ -from __future__ import print_function - """ Use the 'global_tor' instance from txtorcon; this is a Tor instance that either doesn't exist or is unique to this process' diff --git a/examples/launch_tor_with_simplehttpd.py b/examples/launch_tor_with_simplehttpd.py index 0bbc9519..6c799c75 100755 --- a/examples/launch_tor_with_simplehttpd.py +++ b/examples/launch_tor_with_simplehttpd.py @@ -11,8 +11,6 @@ ./launch_tor_with_simplehttpd.py -p 8080 -d /opt/files/ ''' -from __future__ import print_function - import SimpleHTTPServer import SocketServer import functools diff --git a/examples/minimal_endpoint.py b/examples/minimal_endpoint.py index 8a037bff..fc8115da 100755 --- a/examples/minimal_endpoint.py +++ b/examples/minimal_endpoint.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function from twisted.internet import reactor from twisted.internet.endpoints import serverFromString from twisted.web import server, static diff --git a/examples/monitor.py b/examples/monitor.py index 8907aa9a..1f4237c6 100755 --- a/examples/monitor.py +++ b/examples/monitor.py @@ -3,8 +3,6 @@ # Just listens for a few EVENTs from Tor (INFO NOTICE WARN ERR) and # prints out the contents, so functions like a log monitor. -from __future__ import print_function - from twisted.internet import task, defer from twisted.internet.endpoints import UNIXClientEndpoint import txtorcon diff --git a/examples/stem_relay_descriptor.py b/examples/stem_relay_descriptor.py index 855c56a5..2c9d1cf8 100755 --- a/examples/stem_relay_descriptor.py +++ b/examples/stem_relay_descriptor.py @@ -13,7 +13,6 @@ # descriptors -- by default Tor only downloads "microdescriptors" # (whose information is already available live via txtorcon.Router # instances). Set "UseMicrodescriptors 0" to download "full" descriptors -from __future__ import print_function from twisted.internet.task import react from twisted.internet.defer import inlineCallbacks diff --git a/examples/stream_circuit_logger.py b/examples/stream_circuit_logger.py index 53e7fc5e..50a98a1b 100755 --- a/examples/stream_circuit_logger.py +++ b/examples/stream_circuit_logger.py @@ -3,8 +3,6 @@ # This uses an IStreamListener and an ICircuitListener to log all # built circuits and all streams that succeed. -from __future__ import print_function - import sys from twisted.python import log from twisted.internet.task import react diff --git a/examples/tor_info.py b/examples/tor_info.py index 30188358..e1cc8fae 100755 --- a/examples/tor_info.py +++ b/examples/tor_info.py @@ -15,8 +15,6 @@ # transaction, you'll have to use TorControlProtocol's get_info # instead. -from __future__ import print_function - import sys from twisted.internet import reactor, defer from txtorcon import TorInfo, build_local_tor_connection diff --git a/examples/web_client.py b/examples/web_client.py index a9a95b21..3d7ff094 100644 --- a/examples/web_client.py +++ b/examples/web_client.py @@ -1,8 +1,6 @@ # this example shows how to use Twisted's web client with Tor via # txtorcon -from __future__ import print_function - from twisted.internet.defer import inlineCallbacks from twisted.internet.task import react from twisted.internet.endpoints import TCP4ClientEndpoint diff --git a/examples/web_client_authenticated.py b/examples/web_client_authenticated.py index 3bcf12d2..3eb1589a 100644 --- a/examples/web_client_authenticated.py +++ b/examples/web_client_authenticated.py @@ -1,8 +1,6 @@ # this example shows how to use Twisted's web client with Tor via # txtorcon -from __future__ import print_function - from twisted.internet.defer import inlineCallbacks from twisted.internet.task import react from twisted.internet.endpoints import TCP4ClientEndpoint diff --git a/examples/web_client_custom_circuit.py b/examples/web_client_custom_circuit.py index 8290f704..3ea29d87 100644 --- a/examples/web_client_custom_circuit.py +++ b/examples/web_client_custom_circuit.py @@ -5,8 +5,6 @@ # do anything "special" to select your circuit hops you risk making it # easy to de-anonymize this (and all other) Tor circuits. -from __future__ import print_function - from twisted.internet.protocol import Protocol, Factory from twisted.internet.defer import inlineCallbacks, Deferred from twisted.internet.task import react diff --git a/examples/web_client_treq.py b/examples/web_client_treq.py index 99d1a44b..a03de4a8 100644 --- a/examples/web_client_treq.py +++ b/examples/web_client_treq.py @@ -1,8 +1,6 @@ # just copying over most of "carml checkpypi" because it's a good # example of "I want a stream over *this* circuit". -from __future__ import print_function - from twisted.internet.defer import inlineCallbacks from twisted.internet.task import react from twisted.internet.endpoints import TCP4ClientEndpoint diff --git a/examples/web_onion_service_endpoints.py b/examples/web_onion_service_endpoints.py index 4a8df9a3..e845bb41 100644 --- a/examples/web_onion_service_endpoints.py +++ b/examples/web_onion_service_endpoints.py @@ -11,7 +11,6 @@ # parser plugin but code without knowledge of txtorcon can still # launch a Tor instance using it. cool! -from __future__ import print_function from twisted.internet import defer, task, endpoints, error from twisted.web import server, resource diff --git a/examples/web_onion_service_ephemeral_auth.py b/examples/web_onion_service_ephemeral_auth.py index daea3f02..d4051073 100644 --- a/examples/web_onion_service_ephemeral_auth.py +++ b/examples/web_onion_service_ephemeral_auth.py @@ -11,7 +11,6 @@ # parser plugin but code without knowledge of txtorcon can still # launch a Tor instance using it. cool! -from __future__ import print_function from twisted.internet import defer, task, endpoints from twisted.web import server, resource diff --git a/examples/web_onion_service_ephemeral_nonanon.py b/examples/web_onion_service_ephemeral_nonanon.py index d6e414ae..525e372f 100644 --- a/examples/web_onion_service_ephemeral_nonanon.py +++ b/examples/web_onion_service_ephemeral_nonanon.py @@ -6,7 +6,6 @@ # services. Once you publish a service like this, there's no going # back to location-hidden. -from __future__ import print_function from twisted.internet import defer, task, endpoints from twisted.web import server, resource diff --git a/examples/web_onion_service_ephemeral_unix.py b/examples/web_onion_service_ephemeral_unix.py index a735003b..487bd0ab 100644 --- a/examples/web_onion_service_ephemeral_unix.py +++ b/examples/web_onion_service_ephemeral_unix.py @@ -11,7 +11,6 @@ # parser plugin but code without knowledge of txtorcon can still # launch a Tor instance using it. cool! -from __future__ import print_function from os.path import abspath from twisted.internet import defer, task, endpoints diff --git a/examples/web_onion_service_filesystem.py b/examples/web_onion_service_filesystem.py index 4068b8b0..6fe038ac 100644 --- a/examples/web_onion_service_filesystem.py +++ b/examples/web_onion_service_filesystem.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function import os from twisted.internet import defer, task, endpoints diff --git a/examples/web_onion_service_prop224.py b/examples/web_onion_service_prop224.py index 04dd7bfa..3034b5e7 100644 --- a/examples/web_onion_service_prop224.py +++ b/examples/web_onion_service_prop224.py @@ -11,7 +11,6 @@ # parser plugin but code without knowledge of txtorcon can still # launch a Tor instance using it. cool! -from __future__ import print_function from twisted.internet import defer, task, endpoints from twisted.web import server, resource diff --git a/examples/web_onion_service_prop224_endpoints_file.py b/examples/web_onion_service_prop224_endpoints_file.py index 31099753..835a8174 100644 --- a/examples/web_onion_service_prop224_endpoints_file.py +++ b/examples/web_onion_service_prop224_endpoints_file.py @@ -11,7 +11,6 @@ # parser plugin but code without knowledge of txtorcon can still # launch a Tor instance using it. cool! -from __future__ import print_function from twisted.internet import defer, task, endpoints from twisted.web import server, resource diff --git a/examples/webui_server.py b/examples/webui_server.py index a17c4b1f..28d03676 100755 --- a/examples/webui_server.py +++ b/examples/webui_server.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function - from twisted.internet import reactor from nevow.appserver import NevowSite from nevow import loaders, tags, livepage diff --git a/integration/hidden_service_listen_ports/container_run b/integration/hidden_service_listen_ports/container_run index 0b0b031d..325e4c30 100755 --- a/integration/hidden_service_listen_ports/container_run +++ b/integration/hidden_service_listen_ports/container_run @@ -16,7 +16,7 @@ from twisted.python import log log.startLogging(sys.stdout) -print sys.argv[0] +print(sys.argv[0]) sys.path.insert(0, '/txtorcon') import txtorcon @@ -31,22 +31,22 @@ class Simple(resource.Resource): def updates(prog, tag, summary): p = ('#' * int(10*(prog/100.0))) + ('.'*(10 - int(10*(prog/100.0)))) - print "%s %s" % (p, summary) + print("%s %s" % (p, summary)) @defer.inlineCallbacks def main(reactor): - print "Launching Tor" + print("Launching Tor") tor = yield txtorcon.launch(reactor, socks_port=0, progress_updates=updates) hs_endpoint = tor.create_onion_endpoint(80) - print "Starting site" + print("Starting site") site = server.Site(Simple()) port = yield hs_endpoint.listen(site) - print port.getHost().onion_uri, port.getHost().onion_port, port.local_address - print "liftoff" + print(port.getHost().onion_uri, port.getHost().onion_port, port.local_address) + print("liftoff") os.system("netstat -pltn") task.react(main) diff --git a/integration/hidden_service_listen_ports/host_run b/integration/hidden_service_listen_ports/host_run index b0a039a0..0e9cf11b 100755 --- a/integration/hidden_service_listen_ports/host_run +++ b/integration/hidden_service_listen_ports/host_run @@ -15,10 +15,11 @@ from xml.dom import minidom d = os.path.realpath(os.path.curdir) container = subprocess.check_output(['docker', 'run', '-v', d+':/txtorcon:ro', '-d', - 'txtorcon-tester', '/txtorcon/integration/hidden_service_listen_ports/container_run']).strip() -print 'container:', container + 'txtorcon-tester', '/txtorcon/integration/hidden_service_listen_ports/container_run'], + text=True).strip() +print('container:', container) def kill_container(container): - print "killing", container + print("killing", container) subprocess.check_output(['docker', 'kill', container]) atexit.register(functools.partial(kill_container, container)) @@ -26,7 +27,7 @@ data = subprocess.check_output(['docker', 'inspect', container]) data = json.loads(data)[0] ip = data['NetworkSettings']['IPAddress'] -print "ip address", ip +print("ip address", ip) logs_printed = 0 while True: @@ -40,7 +41,7 @@ while True: time.sleep(1) continue -print "running nmap (scanning all 65535 TCP ports)..." +print("running nmap (scanning all 65535 TCP ports)...") fname = 'txtorcon-nmap' #print subprocess.check_output(['nmap', '-T5', '-PN', ip]) nmap = subprocess.check_output(['nmap', '-T5', '-p', '1-65535', '-oX', fname, @@ -50,17 +51,17 @@ dom = minidom.parse(open(fname, 'r')) ports = dom.getElementsByTagName('port') is_error = None if len(ports): - print "Open ports found:" + print("Open ports found:") for e in ports: state = e.getElementsByTagName('state')[0].getAttribute('state') port = e.getAttribute('portid') - print port, state + print(port, state) is_error = '%d open ports found' % len(ports) if is_error: - print "FAILED", is_error + print("FAILED", is_error) sys.exit(1) else: - print "OK." + print("OK.") sys.exit(0) diff --git a/integration/run.py b/integration/run.py index 55690da6..498e68d0 100644 --- a/integration/run.py +++ b/integration/run.py @@ -4,8 +4,6 @@ ## if any one does. ## FIXME can't I [ab]use trial or unittest for this?? -from __future__ import print_function - import os import sys import subprocess diff --git a/integration/timeout_tor_launch/container_run b/integration/timeout_tor_launch/container_run index 8916d5f6..2d529ff3 100755 --- a/integration/timeout_tor_launch/container_run +++ b/integration/timeout_tor_launch/container_run @@ -23,14 +23,14 @@ log.startLogging(sys.stdout) def updates(prog, tag, summary): p = ('#' * int(10*(prog/100.0))) + ('.'*(10 - int(10*(prog/100.0)))) - print "%s %s" % (p, summary) + print("%s %s" % (p, summary)) @defer.inlineCallbacks def main(reactor): - print "Launching Tor" + print("Launching Tor") tor = yield txtorcon.launch(reactor, progress_updates=updates) - print "launch over:", proto - print 'Running "ps afxu":' + print("launch over:", proto) + print('Running "ps afxu":') os.system("ps afxu") task.react(main) diff --git a/integration/timeout_tor_launch/host_run b/integration/timeout_tor_launch/host_run index fb4a8975..aea8fccb 100755 --- a/integration/timeout_tor_launch/host_run +++ b/integration/timeout_tor_launch/host_run @@ -8,27 +8,26 @@ import os import atexit import functools import subprocess -import json import time import sys -from xml.dom import minidom d = os.path.realpath(os.path.curdir) container = subprocess.check_output(['docker', 'run', '-v', d+':/txtorcon:ro', - '-d', 'txtorcon-tester', '/txtorcon/integration/timeout_tor_launch/container_run']).strip() -print 'container:', container + '-d', 'txtorcon-tester', '/txtorcon/integration/timeout_tor_launch/container_run'], + text=True).strip() +print('container:', container) def kill_container(container): - print "killing", container + print("killing", container) subprocess.check_output(['docker', 'kill', container]) atexit.register(functools.partial(kill_container, container)) -print "waiting 15 seconds" +print("waiting 15 seconds") time.sleep(15) -print "gathering logs" -logs = subprocess.check_output(['docker', 'logs', container]) +print("gathering logs") +logs = subprocess.check_output(['docker', 'logs', container], text=True) -print logs +print(logs) if '/usr/sbin/tor' in logs: sys.exit(1) sys.exit(0) diff --git a/setup.py b/setup.py index 8a588be1..7de741fa 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function - from os.path import join from os import listdir from setuptools import setup diff --git a/test/test_controller.py b/test/test_controller.py index 90ccc811..92a6e713 100644 --- a/test/test_controller.py +++ b/test/test_controller.py @@ -1,5 +1,4 @@ import os -import six import functools from os.path import join from unittest.mock import Mock, patch @@ -1504,12 +1503,6 @@ def test_remove_unfound(self): yield self.tor.remove_onion_authentication("non_existing.onion") self.assertEqual(0, len(self.cfg.HidServAuth)) - def test_context_manager_py2(self): - if not six.PY2: - return - with self.assertRaises(RuntimeError): - self.tor.onion_authentication("foo.onion", "token") - @defer.inlineCallbacks def test_add_and_remove(self): yield self.tor.add_onion_authentication("foo.onion", "a_token") diff --git a/test/test_endpoints.py b/test/test_endpoints.py index 500dda7c..5902fd0a 100644 --- a/test/test_endpoints.py +++ b/test/test_endpoints.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import os import sys from unittest.mock import patch @@ -1331,7 +1329,6 @@ def getHost(self): def port_generator(): - # XXX six has xrange/range stuff? for x in range(65535, 0, -1): yield x diff --git a/test/test_fsm.py b/test/test_fsm.py index 3bbc6a14..a0518d19 100644 --- a/test/test_fsm.py +++ b/test/test_fsm.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import txtorcon.spaghetti from txtorcon.spaghetti import State from txtorcon.spaghetti import Transition diff --git a/test/test_onion.py b/test/test_onion.py index 63960079..62471d05 100644 --- a/test/test_onion.py +++ b/test/test_onion.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import os import sys from unittest.mock import Mock diff --git a/test/test_socks.py b/test/test_socks.py index a017a40f..6342babc 100644 --- a/test/test_socks.py +++ b/test/test_socks.py @@ -1,4 +1,4 @@ -from six import BytesIO, text_type +from io import BytesIO from unittest.mock import Mock, patch from twisted.trial import unittest @@ -768,7 +768,7 @@ def test_resolve_ptr_str(self, fac): d = socks.resolve_ptr(socks_ep, 'meejah.ca') self.assertEqual(1, len(fac.mock_calls)) self.assertTrue( - isinstance(fac.mock_calls[0][1][0], text_type) + isinstance(fac.mock_calls[0][1][0], str) ) return d @@ -778,7 +778,7 @@ def test_resolve_str(self, fac): d = socks.resolve(socks_ep, 'meejah.ca') self.assertEqual(1, len(fac.mock_calls)) self.assertTrue( - isinstance(fac.mock_calls[0][1][0], text_type) + isinstance(fac.mock_calls[0][1][0], str) ) return d @@ -788,7 +788,7 @@ def test_resolve_ptr_bytes(self, fac): d = socks.resolve_ptr(socks_ep, b'meejah.ca') self.assertEqual(1, len(fac.mock_calls)) self.assertTrue( - isinstance(fac.mock_calls[0][1][0], text_type) + isinstance(fac.mock_calls[0][1][0], str) ) return d @@ -798,7 +798,7 @@ def test_resolve_bytes(self, fac): d = socks.resolve(socks_ep, b'meejah.ca') self.assertEqual(1, len(fac.mock_calls)) self.assertTrue( - isinstance(fac.mock_calls[0][1][0], text_type) + isinstance(fac.mock_calls[0][1][0], str) ) return d diff --git a/test/test_stream.py b/test/test_stream.py index 357f9e40..4d076095 100644 --- a/test/test_stream.py +++ b/test/test_stream.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from txtorcon.util import maybe_ip_addr from twisted.trial import unittest from twisted.internet import defer diff --git a/test/test_torconfig.py b/test/test_torconfig.py index fb0f6715..6f8a4aa6 100644 --- a/test/test_torconfig.py +++ b/test/test_torconfig.py @@ -1,11 +1,9 @@ -from __future__ import print_function - import os import shutil import tempfile import functools import warnings -from six import StringIO +from io import StringIO from unittest.mock import Mock, patch from os.path import join diff --git a/test/test_torcontrolprotocol.py b/test/test_torcontrolprotocol.py index e15bdf03..f74b4b3e 100644 --- a/test/test_torcontrolprotocol.py +++ b/test/test_torcontrolprotocol.py @@ -1,6 +1,3 @@ -from __future__ import print_function -from __future__ import with_statement - from os.path import exists from twisted.python import log, failure diff --git a/test/test_torstate.py b/test/test_torstate.py index ceab1315..ecc4e15d 100644 --- a/test/test_torstate.py +++ b/test/test_torstate.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from zope.interface import implementer, directlyProvides from zope.interface.verify import verifyClass from twisted.trial import unittest diff --git a/test/test_util_imports.py b/test/test_util_imports.py index b2285c96..64be5289 100644 --- a/test/test_util_imports.py +++ b/test/test_util_imports.py @@ -3,7 +3,6 @@ import sys import functools from unittest import skipUnless -import six def fake_import(orig, name, *args, **kw): @@ -14,7 +13,7 @@ def fake_import(orig, name, *args, **kw): class TestImports(unittest.TestCase): - @skipUnless(six.PY2 and 'pypy' not in sys.version.lower(), "Doesn't work in PYPY, Py3") + @skipUnless(False and 'pypy' not in sys.version.lower(), "Doesn't work in PYPY, Py3") def test_no_GeoIP(self): """ Make sure we don't explode if there's no GeoIP module diff --git a/test3/test_controller.py b/test3/test_controller.py index 5c6ceb79..8304d8c7 100644 --- a/test3/test_controller.py +++ b/test3/test_controller.py @@ -1,6 +1,5 @@ # this is for python3-only tests -import six import unittest from unittest.mock import Mock, patch @@ -12,9 +11,6 @@ import txtorcon -if six.PY2: - raise unittest.skip() - class Python3ControllerTests(unittest.TestCase): def setUp(self): diff --git a/txtorcon/__init__.py b/txtorcon/__init__.py index 7e6ea3cd..0f64e5dd 100644 --- a/txtorcon/__init__.py +++ b/txtorcon/__init__.py @@ -1,10 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - from txtorcon._metadata import __version__, __author__, __contact__ from txtorcon._metadata import __license__, __copyright__, __url__ diff --git a/txtorcon/addrmap.py b/txtorcon/addrmap.py index fea42939..1b53503e 100644 --- a/txtorcon/addrmap.py +++ b/txtorcon/addrmap.py @@ -1,10 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - from txtorcon.interface import IAddrListener from txtorcon.util import maybe_ip_addr @@ -15,7 +10,7 @@ import shlex -class Addr(object): +class Addr: """ One address mapping (e.g. example.com -> 127.0.0.1) """ diff --git a/txtorcon/circuit.py b/txtorcon/circuit.py index d9ce0917..d43b1565 100644 --- a/txtorcon/circuit.py +++ b/txtorcon/circuit.py @@ -1,11 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - -import six import time from datetime import datetime @@ -69,7 +63,7 @@ def add_endpoint(self, target_ep, circuit): def _add_real_target(self, real_addr, circuit, d): # joy oh joy, ipaddress wants unicode, Twisted gives us bytes... - real_host = maybe_ip_addr(six.text_type(real_addr.host)) + real_host = maybe_ip_addr(str(real_addr.host)) real_port = real_addr.port self._circuit_targets[(real_host, real_port)] = (circuit, d) diff --git a/txtorcon/controller.py b/txtorcon/controller.py index 4e7f4877..2e5c1792 100644 --- a/txtorcon/controller.py +++ b/txtorcon/controller.py @@ -1,12 +1,7 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - import os import sys -import six import shlex import tempfile import functools @@ -1039,7 +1034,7 @@ def create_onion_service(self, ports, private_key=None, version=3, raise ValueError( "The only valid Onion service versions are 2 or 3" ) - if not isinstance(ports, Sequence) or isinstance(ports, six.string_types): + if not isinstance(ports, Sequence) or isinstance(ports, str): raise ValueError("'ports' must be a sequence (list, tuple, ..)") processed_ports = yield _validate_ports(self._reactor, ports) @@ -1097,7 +1092,7 @@ def create_filesystem_onion_service(self, ports, onion_service_dir, been made. """ - if not isinstance(ports, Sequence) or isinstance(ports, six.string_types): + if not isinstance(ports, Sequence) or isinstance(ports, str): raise ValueError("'ports' must be a sequence (list, tuple, ..)") processed_ports = yield _validate_ports(self._reactor, ports) diff --git a/txtorcon/endpoints.py b/txtorcon/endpoints.py index 33535125..2ec6e0a5 100644 --- a/txtorcon/endpoints.py +++ b/txtorcon/endpoints.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - import os import shutil import weakref diff --git a/txtorcon/interface.py b/txtorcon/interface.py index 888efe80..84fd0c1d 100644 --- a/txtorcon/interface.py +++ b/txtorcon/interface.py @@ -1,10 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - from zope.interface import implementer from zope.interface import Interface, Attribute diff --git a/txtorcon/log.py b/txtorcon/log.py index 2292449f..c2443409 100644 --- a/txtorcon/log.py +++ b/txtorcon/log.py @@ -4,11 +4,6 @@ This module handles txtorcon debug messages. """ -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - from twisted.python import log as twlog __all__ = ['txtorlog'] diff --git a/txtorcon/onion.py b/txtorcon/onion.py index 4a3c207c..0daae4db 100644 --- a/txtorcon/onion.py +++ b/txtorcon/onion.py @@ -1,6 +1,5 @@ import os import re -import six import base64 import hashlib import functools @@ -20,7 +19,7 @@ from cryptography.hazmat.primitives import serialization -class HiddenServiceClientAuth(object): +class HiddenServiceClientAuth: """ Encapsulates a single client-authorization, as parsed from a HiddenServiceDir's "client_keys" file if you have stealth or basic @@ -1375,7 +1374,7 @@ def _validate_ports(reactor, ports): "{} 127.0.0.1:{}".format(remote, local) ) - elif isinstance(port, (six.text_type, str)): + elif isinstance(port, str): _validate_single_port_string(port) processed_ports.append(port) @@ -1407,7 +1406,7 @@ def _validate_ports_low_level(ports): """ if not isinstance(ports, (list, tuple)): raise ValueError("'ports' must be a list of strings") - if any([not isinstance(x, (six.text_type, str)) for x in ports]): + if any([not isinstance(x, str) for x in ports]): raise ValueError("'ports' must be a list of strings") for port in ports: _validate_single_port_string(port) diff --git a/txtorcon/router.py b/txtorcon/router.py index c1e648b9..a14505b3 100644 --- a/txtorcon/router.py +++ b/txtorcon/router.py @@ -1,15 +1,9 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - import json from datetime import datetime from .util import NetLocation from .util import _Version -import six from base64 import b64encode, b64decode from binascii import b2a_hex, a2b_hex @@ -38,7 +32,7 @@ def hashFromHexId(hexid): return b64encode(a2b_hex(hexid))[:-1].decode('ascii') -class PortRange(object): +class PortRange: """ Represents a range of ports for Router policies. """ @@ -53,7 +47,7 @@ def __str__(self): return "%d-%d" % (self.min, self.max) -class Router(object): +class Router: """ Represents a Tor Router, including location. @@ -179,7 +173,7 @@ def flags(self, flags): There is some current work in Twisted for open-ended constants (enums) support however, it seems. """ - if isinstance(flags, (six.text_type, bytes)): + if isinstance(flags, (str, bytes)): flags = flags.split() self._flags = [x.lower() for x in flags] self.name_is_unique = 'named' in self._flags diff --git a/txtorcon/socks.py b/txtorcon/socks.py index 46b41baf..a3e1dee5 100644 --- a/txtorcon/socks.py +++ b/txtorcon/socks.py @@ -4,9 +4,6 @@ # Python3. Also, Tor's SOCKS5 implementation is especially simple, # since it doesn't do BIND or UDP ASSOCIATE. -from __future__ import print_function - -import six import struct from socket import inet_pton, inet_ntoa, inet_aton, AF_INET6, AF_INET @@ -41,9 +38,9 @@ def _create_ip_address(host, port): - if not isinstance(host, six.text_type): + if not isinstance(host, str): raise ValueError( - "'host' must be {}, not {}".format(six.text_type, type(host)) + "'host' must be str, not {}".format(type(host)) ) try: a = ipaddress.ip_address(host) @@ -87,13 +84,13 @@ def __init__(self, req_type, host, req_type ) ) - if not isinstance(host, (bytes, str, six.text_type)): + if not isinstance(host, (bytes, str)): raise ValueError( "'host' must be text (not {})".format(type(host)) ) # XXX what if addr is None? self._req_type = req_type - self._addr = _create_ip_address(six.text_type(host), port) + self._addr = _create_ip_address(str(host), port) self._data = b'' self._on_disconnect = on_disconnect self._create_connection = create_connection @@ -646,9 +643,7 @@ def resolve(tor_endpoint, hostname): :param hostname: the hostname to look up. """ - if six.PY2 and isinstance(hostname, str): - hostname = unicode(hostname) # noqa - elif six.PY3 and isinstance(hostname, bytes): + if isinstance(hostname, bytes): hostname = hostname.decode('ascii') factory = _TorSocksFactory( hostname, 0, 'RESOLVE', None, @@ -667,9 +662,7 @@ def resolve_ptr(tor_endpoint, ip): :param ip: the IP address to look up. """ - if six.PY2 and isinstance(ip, str): - ip = unicode(ip) # noqa - elif six.PY3 and isinstance(ip, bytes): + if isinstance(ip, bytes): ip = ip.decode('ascii') factory = _TorSocksFactory( ip, 0, 'RESOLVE_PTR', None, @@ -692,9 +685,7 @@ class TorSocksEndpoint(object): def __init__(self, socks_endpoint, host, port, tls=False): self._proxy_ep = socks_endpoint # can be Deferred assert self._proxy_ep is not None - if six.PY2 and isinstance(host, str): - host = unicode(host) # noqa - if six.PY3 and isinstance(host, bytes): + if isinstance(host, bytes): host = host.decode('ascii') self._host = host self._port = port diff --git a/txtorcon/spaghetti.py b/txtorcon/spaghetti.py index 361dc915..b622fa08 100644 --- a/txtorcon/spaghetti.py +++ b/txtorcon/spaghetti.py @@ -1,13 +1,9 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - import warnings -class FSM(object): +class FSM: """ Pass callables for matcher and handler to add_handler to create transitions between states. A "matcher" is a predicate, and if a diff --git a/txtorcon/stream.py b/txtorcon/stream.py index 6ad98b81..bb49579f 100644 --- a/txtorcon/stream.py +++ b/txtorcon/stream.py @@ -11,18 +11,13 @@ """ -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - from twisted.python import log from twisted.internet import defer from txtorcon.interface import ICircuitContainer, IStreamListener from txtorcon.util import find_keywords, maybe_ip_addr -class Stream(object): +class Stream: """ Represents an active stream in Tor's state (:class:`txtorcon.TorState`). diff --git a/txtorcon/torconfig.py b/txtorcon/torconfig.py index 6c364259..3a1a6619 100644 --- a/txtorcon/torconfig.py +++ b/txtorcon/torconfig.py @@ -1,12 +1,7 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - import os import re -import six import functools import warnings from io import StringIO @@ -67,7 +62,7 @@ def launch_tor(config, reactor, defer.returnValue(tor.process) -class TorConfigType(object): +class TorConfigType: """ Base class for all configuration types, which function as parsers and un-parsers. @@ -253,11 +248,7 @@ def __repr__(self): return '_ListWrapper' + super(_ListWrapper, self).__repr__() -if six.PY2: - setattr(_ListWrapper, '__setslice__', _wrapture(list.__setslice__)) - - -class HiddenService(object): +class HiddenService: """ Because hidden service configuration is handled specially by Tor, we wrap the config in this class. This corresponds to the @@ -424,7 +415,7 @@ def _is_valid_keyblob(key_blob_or_type): # resulting class in isinstance() things and the like, because Twisted # makes it into a function instead :( so we @deprecate __init__ for now # @deprecated(_Version("txtorcon", 18, 0, 0)) -class EphemeralHiddenService(object): +class EphemeralHiddenService: ''' Deprecated as of 18.0.0. Please instead use :class:`txtorcon.EphemeralOnionService` @@ -448,7 +439,7 @@ def __init__(self, ports, key_blob_or_type='NEW:BEST', auth=[], ver=2): raise ValueError( 'key_blob_or_type must be a string in the formats ' '"NEW:" or ":"') - if isinstance(ports, (six.text_type, str)): + if isinstance(ports, str): ports = [ports] self._ports = [x.replace(' ', ',') for x in ports] self._keyblob = key_blob_or_type @@ -523,7 +514,7 @@ def _endpoint_from_socksport_line(reactor, socks_config): return TCP4ClientEndpoint(reactor, host, port) -class TorConfig(object): +class TorConfig: """This class abstracts out Tor's config, and can be used both to create torrc files from nothing and track live configuration of a Tor instance. diff --git a/txtorcon/torcontrolprotocol.py b/txtorcon/torcontrolprotocol.py index e882160a..a23a50d9 100644 --- a/txtorcon/torcontrolprotocol.py +++ b/txtorcon/torcontrolprotocol.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - import os import re import base64 diff --git a/txtorcon/torinfo.py b/txtorcon/torinfo.py index fb9f7917..44cdcace 100644 --- a/txtorcon/torinfo.py +++ b/txtorcon/torinfo.py @@ -1,17 +1,12 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import with_statement - import functools from twisted.internet import defer from txtorcon.interface import ITorControlProtocol -class MagicContainer(object): +class MagicContainer: """ This merely contains 1 or more methods or further MagicContainer instances; see _do_setup in TorInfo. diff --git a/txtorcon/torstate.py b/txtorcon/torstate.py index e3defdd6..64d46673 100644 --- a/txtorcon/torstate.py +++ b/txtorcon/torstate.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - import os import stat import warnings diff --git a/txtorcon/util.py b/txtorcon/util.py index 406a0f59..4800ac23 100644 --- a/txtorcon/util.py +++ b/txtorcon/util.py @@ -1,9 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - +import asyncio import glob import os import hmac @@ -12,7 +9,6 @@ import subprocess import ipaddress import re -import six from twisted.internet import defer from twisted.internet.interfaces import IProtocolFactory @@ -22,9 +18,6 @@ from zope.interface import implementer from zope.interface import Interface -if six.PY3: - import asyncio - try: import GeoIP as _GeoIP GeoIP = _GeoIP @@ -148,8 +141,6 @@ def maybe_ip_addr(addr): TODO consider explicitly checking for .exit or .onion at the end? """ - if six.PY2 and isinstance(addr, str): - addr = unicode(addr) # noqa try: return ipaddress.ip_address(addr) except ValueError: @@ -337,10 +328,7 @@ def unescape_quoted_string(string): # handeled as escape codes by string.decode('string-escape'). # This is needed so e.g. '\x00' is not unescaped as '\0' string = re.sub(r'((?:^|[^\\])(?:\\\\)*)\\([^ntr0-7\\])', r'\1\2', string) - if six.PY3: - # XXX hmmm? - return bytes(string, 'ascii').decode('unicode-escape') - return string.decode('string-escape') + return bytes(string, 'ascii').decode('unicode-escape') def default_control_port(): @@ -385,7 +373,7 @@ def maybe_coroutine(obj): (This is to insert in all callback chains from user code, in case that user code is Python3 and used 'async def') """ - if six.PY3 and asyncio.iscoroutine(obj): + if asyncio.iscoroutine(obj): return defer.ensureDeferred(obj) return obj @@ -532,7 +520,7 @@ def _is_non_public_numeric_address(host): # for numeric hostnames, skip RFC1918 addresses, since no Tor exit # node will be able to reach those. Likewise ignore IPv6 addresses. try: - a = ipaddress.ip_address(six.text_type(host)) + a = ipaddress.ip_address(str(host)) except ValueError: return False # non-numeric, let Tor try it if a.is_loopback or a.is_multicast or a.is_private or a.is_reserved \ diff --git a/txtorcon/web.py b/txtorcon/web.py index d42b0b32..f3485849 100644 --- a/txtorcon/web.py +++ b/txtorcon/web.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import with_statement - from twisted.web.iweb import IAgentEndpointFactory from twisted.web.client import Agent, BrowserLikePolicyForHTTPS from twisted.internet.defer import inlineCallbacks, returnValue, Deferred @@ -17,7 +13,7 @@ @implementer(IAgentEndpointFactory) -class _AgentEndpointFactoryUsingTor(object): +class _AgentEndpointFactoryUsingTor: def __init__(self, reactor, tor_socks_endpoint, tls_context_factory): self._reactor = reactor self._proxy_ep = SingleObserver()