[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r9564: Cleanup some pychecker+pylint messages. (torflow/trunk)
Author: mikeperry
Date: 2007-02-11 02:37:34 -0500 (Sun, 11 Feb 2007)
New Revision: 9564
Modified:
torflow/trunk/TorCtl.py
torflow/trunk/TorUtil.py
torflow/trunk/metatroller.py
torflow/trunk/nodemon.py
Log:
Cleanup some pychecker+pylint messages.
Modified: torflow/trunk/TorCtl.py
===================================================================
--- torflow/trunk/TorCtl.py 2007-02-11 05:43:41 UTC (rev 9563)
+++ torflow/trunk/TorCtl.py 2007-02-11 07:37:34 UTC (rev 9564)
@@ -18,6 +18,7 @@
import socket
import binascii
import types
+import time
from TorUtil import *
# Types of "EVENT" message.
@@ -50,6 +51,10 @@
"Raised when Tor controller returns an error"
pass
+class NotImplemented(TorCtlError):
+ "Raised when user doesn't implement EventHandler event"
+ pass
+
class NetworkStatus:
"Filled in during NS events"
pass
@@ -61,13 +66,13 @@
self.to_port = target_port
def entry_chooser(self, path):
- raise NotImplemented
+ raise NotImplemented()
def middle_chooser(self, path):
- raise NotImplemented
+ raise NotImplemented()
def exit_chooser(self, path):
- raise NotImplemented
+ raise NotImplemented()
class ExitPolicyLine:
def __init__(self, match, ip_mask, port_low, port_high):
@@ -251,6 +256,7 @@
# Here's where the result goes...
result = []
+ plog("DEBUG", "Sending: "+msg)
if self._closedEx is not None:
raise self._closedEx
elif self._closed:
@@ -682,7 +688,7 @@
elif evtype == "NEWDESC":
args = (body.split(" "),)
elif evtype == "ADDRMAP":
- m = re.match(r'(\S+)\s+(\S+)\s+(\"[^"]+\"|\w+)')
+ m = re.match(r'(\S+)\s+(\S+)\s+(\"[^"]+\"|\w+)', body)
if not m:
raise ProtocolError("BANDWIDTH event misformatted.")
fromaddr, toaddr, when = m.groups()
@@ -703,7 +709,7 @@
"""Called when we get an event type we don't recognize. This
is almost alwyas an error.
"""
- raise NotImplemented
+ raise NotImplemented()
def circ_status(self, eventtype, circID, status, path, reason, remote):
"""Called when a circuit status changes if listening to CIRCSTATUS
@@ -711,14 +717,14 @@
circuit ID, and 'path' is the circuit's path so far as a list of
names.
"""
- raise NotImplemented
+ raise NotImplemented()
def stream_status(self, eventtype, streamID, status, circID, target_host, target_port, reason, remote):
"""Called when a stream status changes if listening to STREAMSTATUS
events. 'status' is a member of STREAM_STATUS; streamID is a
numeric stream ID, and 'target' is the destination of the stream.
"""
- raise NotImplemented
+ raise NotImplemented()
def or_conn_status(self, eventtype, status, target, age, read, wrote,
reason, ncircs):
@@ -726,33 +732,33 @@
ORCONNSTATUS events. 'status' is a member of OR_CONN_STATUS; target
is the OR in question.
"""
- raise NotImplemented
+ raise NotImplemented()
def bandwidth(self, eventtype, read, written):
"""Called once a second if listening to BANDWIDTH events. 'read' is
the number of bytes read; 'written' is the number of bytes written.
"""
- raise NotImplemented
+ raise NotImplemented()
def new_desc(self, eventtype, identities):
"""Called when Tor learns a new server descriptor if listenting to
NEWDESC events.
"""
- raise NotImplemented
+ raise NotImplemented()
def msg(self, eventtype, severity, message):
"""Called when a log message of a given severity arrives if listening
to INFO_MSG, NOTICE_MSG, WARN_MSG, or ERR_MSG events."""
- raise NotImplemented
+ raise NotImplemented()
def ns(self, eventtype, nslist):
- raise NotImplemented
+ raise NotImplemented()
def address_mapped(self, eventtype, fromAddr, toAddr, expiry=None):
"""Called when Tor adds a mapping for an address if listening
to ADDRESSMAPPED events.
"""
- raise NotImplemented
+ raise NotImplemented()
class DebugEventHandler(EventHandler):
Modified: torflow/trunk/TorUtil.py
===================================================================
--- torflow/trunk/TorUtil.py 2007-02-11 05:43:41 UTC (rev 9563)
+++ torflow/trunk/TorUtil.py 2007-02-11 07:37:34 UTC (rev 9564)
@@ -18,6 +18,7 @@
import socket
import binascii
import types
+import sha
__all__ = ["Enum", "Enum2", "quote", "escape_dots", "unescape_dots",
"BufSock", "secret_to_key", "urandom_rng", "s2k_gen", "s2k_check",
Modified: torflow/trunk/metatroller.py
===================================================================
--- torflow/trunk/metatroller.py 2007-02-11 05:43:41 UTC (rev 9563)
+++ torflow/trunk/metatroller.py 2007-02-11 07:37:34 UTC (rev 9564)
@@ -9,7 +9,6 @@
import atexit
import sys
import socket
-import struct
import traceback
import re
import random
@@ -95,9 +94,10 @@
# - VersionRange (Less than, greater than, in-range)
# - OSSelector (ex Yes: Linux, *BSD; No: Windows, Solaris)
# - OceanPhobicRestrictor (avoids Pacific Ocean or two atlantic crossings)
-# - Mathematical proof of predecessor expectation
+# or ContinentRestrictor (avoids doing more than N continent crossings)
+# - Mathematical/empirical study of predecessor expectation
# - If middle node is on the same continent as exit, exit learns nothing
-# - else, exit knows the continent of origin of user
+# - else, exit has a bias on the continent of origin of user
# - Language and browser accept string determine this anyway
# - ExitCountry
# - AllCountry
@@ -157,7 +157,7 @@
# FIXME: This should apply to ORDEREXITS (for speedracer?)
if self.all_exits:
- min_bw = self.min_bw
+ minbw = self.min_bw
pct_fast = self.pct_fast
pct_skip = self.pct_skip
self.min_bw = self.pct_skip = 0
@@ -172,7 +172,7 @@
r = self.pick_r(allowed)
if self.all_exits:
- self.min_bw = min_bw
+ self.min_bw = minbw
self.pct_fast = pct_fast
self.pct_skip = pct_skip
@@ -332,21 +332,21 @@
plog("WARN", "Remap id "+str(streamID)+" not found")
else:
if not re.match(r"\d+.\d+.\d+.\d+", target_host):
- target_host = "255.255.255.255"
- plog("NOTICE", "Non-IP remap for "+str(streamID)+" to "
+ target_host = "255.255.255.255"
+ plog("NOTICE", "Non-IP remap for "+str(streamID)+" to "
+ target_host)
streams[streamID].host = target_host
streams[streamID].port = target_port
def ns(self, eventtype, nslist):
read_routers(self.c, nslist)
- plog("DEBUG", "Read " + str(len(nslist)) + " NS dox => "
+ plog("DEBUG", "Read " + str(len(nslist)) + eventtype + " => "
+ str(len(sorted_r)) + " routers")
def new_desc(self, eventtype, identities):
for i in identities: # Is this too slow?
read_routers(self.c, self.c.get_network_status("id/"+i))
- plog("DEBUG", "Read " + str(len(identities)) + " desc => "
+ plog("DEBUG", "Read " + str(len(identities)) + eventtype + " => "
+ str(len(sorted_r)) + " routers")
@@ -471,7 +471,7 @@
s.connect((control_host,control_port))
c = TorCtl.get_connection(s)
c.set_event_handler(SnakeHandler(c))
- th = c.launch_thread()
+ c.launch_thread()
c.authenticate()
c.set_events([TorCtl.EVENT_TYPE.STREAM,
TorCtl.EVENT_TYPE.NS,
@@ -479,4 +479,5 @@
TorCtl.EVENT_TYPE.NEWDESC], True)
listenloop(c)
-main(sys.argv)
+if __name__ == '__main__':
+ main(sys.argv)
Modified: torflow/trunk/nodemon.py
===================================================================
--- torflow/trunk/nodemon.py 2007-02-11 05:43:41 UTC (rev 9563)
+++ torflow/trunk/nodemon.py 2007-02-11 07:37:34 UTC (rev 9564)
@@ -6,17 +6,13 @@
"""
import TorCtl
-import atexit
import sys
import socket
-import struct
import traceback
import re
-import random
from TorUtil import *
import sched, time
import thread
-import copy
class Reason:
def __init__(self, reason): self.reason = reason
@@ -26,7 +22,7 @@
class RouterStats(TorCtl.Router):
# Behold, a "Promotion Constructor"!
# Also allows null superclasses! Python is awesome
- def __init__(self, r=None):
+ def __init__(self, r=None):
if r:
self.__dict__ = r.__dict__
else:
@@ -186,7 +182,7 @@
def notlambda(x, y):
if y.tot_ncircs or x.tot_ncircs:
return cmp(y.tot_ncircs, x.tot_ncircs)
- else:
+ else:
return cmp(y.tot_count, x.tot_count)
routers.sort(notlambda)
@@ -217,11 +213,13 @@
s.connect((control_host,control_port))
c = TorCtl.get_connection(s)
c.set_event_handler(NodeHandler(c))
- th = c.launch_thread()
+ c.launch_thread()
c.authenticate()
c.set_events([TorCtl.EVENT_TYPE.ORCONN,
TorCtl.EVENT_TYPE.NS,
TorCtl.EVENT_TYPE.NEWDESC], True)
startmon(c)
-main(sys.argv)
+
+if __name__ == '__main__':
+ main(sys.argv)