Skip to content
Browse files

Major code cleanup and dead code removal

  • Loading branch information...
1 parent b21e1a1 commit 04fbaf655d753cdcb36e5450f1cedcef1f1d0807 @hellais hellais committed
Showing with 25 additions and 69 deletions.
  1. +17 −29 run.py
  2. +0 −7 tor2web.py
  3. +8 −33 utils.py
View
46 run.py
@@ -1,39 +1,29 @@
-# Tor2web calamity edition.
-# Arturo Filasto' <art@globaleaks.org>
-#
-# a re-implementation of Tor2web in Python over Tornado
-
-import os
-import sys
-from pprint import pprint
-import urllib
-import urllib2
+# -*- coding: utf-8 -*-
+"""
+ Tor2web calamity edition.
+ ========================
+ Arturo Filasto' <art@globaleaks.org>
+
+ a re-implementation of Tor2web in Python over T̶o̶r̶n̶a̶d̶o̶ Twisted
+
+ run.py
+ ------
+
+ use this script to start tor2web. To run you need
+ twisted and you should do:
+ $ twistd -y run.py
+
+"""
import urlparse
-import ssl
import re
import gzip
-import socket
-
-import tornado.web
from StringIO import StringIO
-from twisted.application import service, internet
-from twisted.internet import reactor, endpoints
-from twisted.python import log
-from twisted.web import proxy, http, client, server, static
-from twisted.web.http import Request
-from twisted.web.resource import Resource
-
from socksclient import SOCKSv4ClientProtocol, SOCKSWrapper
-try:
- import socks
-except:
- print "Error! Unable to import socks: SocksiPy not installed!"
-
from tor2web import Tor2web, Config
-from utils import SocksiPyConnection, SocksiPyHandler, Storage
+from utils import Storage
debug_mode = True
@@ -218,10 +208,8 @@ class ProxyFactory(http.HTTPFactory):
protocol = Tor2webProxy
def startTor2web():
-
return internet.TCPServer(int(config.listen_port), ProxyFactory())
application = service.Application("Tor2web")
service = startTor2web()
service.setServiceParent(application)
-
View
7 tor2web.py
@@ -25,13 +25,6 @@
import ConfigParser
-# import gevent
-# from gevent import monkey
-
-import tornado.ioloop
-import tornado.web
-from tornado import httpclient
-
from utils import Storage
http_client = httpclient.HTTPClient()
View
41 utils.py
@@ -1,12 +1,15 @@
-import httplib
-import urllib2
-import socks
+"""
+ util.py
+ -------
+ This class contains utility functions
+ and objects that don't fit anywhere else.
+"""
class Storage(dict):
"""
A Storage object is like a dictionary except `obj.foo` can be used
in addition to `obj['foo']`.
-
+
>>> o = Storage(a=1)
>>> o.a
1
@@ -18,7 +21,7 @@ class Storage(dict):
>>> del o.a
>>> o.a
None
-
+
"""
def __getattr__(self, key):
@@ -45,31 +48,3 @@ def __getstate__(self):
def __setstate__(self, value):
for (k, v) in value.items():
self[k] = v
-
-class SocksiPyConnection(httplib.HTTPConnection):
- def __init__(self, proxytype, proxyaddr, proxyport = None,
- rdns = True, username = None, password = None, *args, **kwargs):
- self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
- httplib.HTTPConnection.__init__(self, *args, **kwargs)
-
- def connect(self):
- self.sock = socks.socksocket()
- self.sock.setproxy(*self.proxyargs)
- if isinstance(self.timeout, float):
- self.sock.settimeout(self.timeout)
- self.sock.connect((self.host, self.port))
-
-class SocksiPyHandler(urllib2.HTTPHandler):
- def __init__(self, *args, **kwargs):
- self.args = args
- self.kw = kwargs
- urllib2.HTTPHandler.__init__(self)
-
- def http_open(self, req):
- def build(host, port=None, strict=None, timeout=0):
- conn = SocksiPyConnection(*self.args, host=host,
- port=port, strict=strict,
- timeout=timeout, **self.kw)
- return conn
- return self.do_open(build, req)
-

0 comments on commit 04fbaf6

Please sign in to comment.
Something went wrong with that request. Please try again.