Skip to content

Commit

Permalink
Merge pull request #398 from meejah/396-deps
Browse files Browse the repository at this point in the history
Remove usage of "six" (thanks @a-detiste)
  • Loading branch information
meejah committed Mar 13, 2024
2 parents 705def3 + 1f73222 commit bc917b9
Show file tree
Hide file tree
Showing 62 changed files with 65 additions and 238 deletions.
1 change: 0 additions & 1 deletion 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
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
2 changes: 0 additions & 2 deletions 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
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
2 changes: 0 additions & 2 deletions examples/launch_tor.py
@@ -1,5 +1,3 @@
from __future__ import print_function

"""
Launch a private Tor instance.
"""
Expand Down
2 changes: 0 additions & 2 deletions examples/launch_tor2web.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 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
Expand Down
2 changes: 0 additions & 2 deletions examples/launch_tor_endpoint2.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 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'
Expand Down
2 changes: 0 additions & 2 deletions examples/launch_tor_with_simplehttpd.py
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
2 changes: 0 additions & 2 deletions examples/monitor.py
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion examples/stem_relay_descriptor.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions examples/stream_circuit_logger.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions examples/tor_info.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 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
Expand Down
2 changes: 0 additions & 2 deletions 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
Expand Down
2 changes: 0 additions & 2 deletions examples/web_client_custom_circuit.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 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
Expand Down
1 change: 0 additions & 1 deletion examples/web_onion_service_endpoints.py
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion examples/web_onion_service_ephemeral_auth.py
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion examples/web_onion_service_ephemeral_nonanon.py
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion examples/web_onion_service_ephemeral_unix.py
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
1 change: 0 additions & 1 deletion examples/web_onion_service_prop224.py
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion examples/web_onion_service_prop224_endpoints_file.py
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions 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
Expand Down
12 changes: 6 additions & 6 deletions integration/hidden_service_listen_ports/container_run
Expand Up @@ -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
Expand All @@ -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)
19 changes: 10 additions & 9 deletions integration/hidden_service_listen_ports/host_run
Expand Up @@ -15,18 +15,19 @@ 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))

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:
Expand All @@ -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,
Expand All @@ -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)
2 changes: 0 additions & 2 deletions integration/run.py
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions integration/timeout_tor_launch/container_run
Expand Up @@ -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)
17 changes: 8 additions & 9 deletions integration/timeout_tor_launch/host_run
Expand Up @@ -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)
3 changes: 0 additions & 3 deletions 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
Expand Down
7 changes: 0 additions & 7 deletions 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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit bc917b9

Please sign in to comment.