[or-cvs] [torflow/master 68/92] Made soat_tester easier to extend
mikeperry at torproject.org
mikeperry at torproject.org
Sat Aug 21 05:14:00 UTC 2010
Author: John M. Schanck <john at anomos.info>
Date: Wed, 11 Aug 2010 10:18:20 -0400
Subject: Made soat_tester easier to extend
Commit: 0972dd3a85bb25f391b9bb05382239a237585252
---
NetworkScanners/ExitAuthority/test/soat_tester.py | 29 ++++++++------------
1 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/NetworkScanners/ExitAuthority/test/soat_tester.py b/NetworkScanners/ExitAuthority/test/soat_tester.py
index a827b32..d4fa6ab 100644
--- a/NetworkScanners/ExitAuthority/test/soat_tester.py
+++ b/NetworkScanners/ExitAuthority/test/soat_tester.py
@@ -44,6 +44,8 @@ class Tester:
exit_ip = None # By default
class HTTPTester(BaseHTTPRequestHandler, Tester):
+ server=HTTPServer
+ port=80
def do_GET(self):
if self.client_address[0] == self.direct_ip:
self.direct_GET()
@@ -72,22 +74,13 @@ class HTTPTester(BaseHTTPRequestHandler, Tester):
class HTTPSTester(HTTPTester):
-
+ server=SSLServer
+ port=443
def setup(self):
self.connection = self.request
self.rfile = socket._fileobject(self.connection, "rb", self.rbufsize)
self.wfile = socket._fileobject(self.connection, "wb", self.wbufsize)
-def run_HTTPTester():
- serv = HTTPServer(('', 80), HTTPTester)
- print "Serving HTTP on port 80"
- serv.serve_forever()
-
-def run_HTTPSTester():
- serv = SSLServer(('', 443), HTTPSTester)
- print "Serving HTTP on port 443"
- serv.serve_forever()
-
def usage(argv):
print "Usage: %s --exit=<exit ip> [options]" % argv[0]
@@ -100,19 +93,21 @@ if __name__ == '__main__':
print err
usage(sys.argv)
- run = run_HTTPTester
+ test = "HTTP"
for flag, val in flags:
if flag == "--exit":
Tester.exit_ip = val
elif flag == "--direct":
Tester.direct_ip = val
elif flag == "--test":
- if val.lower() == "http":
- run = run_HTTPTester
- elif val.lower() == "https":
- run = run_HTTPSTester
+ test = val
+ tester = globals().get(test+"Tester")
+ if not tester:
+ print "No such test, " + test
+ sys.exit(1)
+ print "Serving %s on %d" % (test, tester.port)
try:
- run()
+ tester.server(('', tester.port), tester).serve_forever()
except KeyboardInterrupt:
print "Done"
--
1.7.1
More information about the tor-commits
mailing list