[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[bridgedb/master] Move bridgedb.Util → bridgedb.util.
commit d8088ca7a6955dc0c528092faaf135817fa28dc2
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Wed Apr 2 14:36:39 2014 +0000
Move bridgedb.Util â?? bridgedb.util.
---
doc/sphinx/source/bridgedb.Util.rst | 6 +++---
doc/sphinx/source/bridgedb.rst | 3 ++-
doc/sphinx/source/conf.py | 2 +-
lib/bridgedb/Bridges.py | 10 +++++-----
lib/bridgedb/Dist.py | 16 ++++++++--------
lib/bridgedb/EmailServer.py | 22 +++++++++++-----------
lib/bridgedb/HTTPServer.py | 12 ++++++------
lib/bridgedb/Main.py | 4 ++--
lib/bridgedb/Util.py | 24 ------------------------
lib/bridgedb/util.py | 24 ++++++++++++++++++++++++
10 files changed, 62 insertions(+), 61 deletions(-)
diff --git a/doc/sphinx/source/bridgedb.Util.rst b/doc/sphinx/source/bridgedb.Util.rst
index 70b8713..63db16d 100644
--- a/doc/sphinx/source/bridgedb.Util.rst
+++ b/doc/sphinx/source/bridgedb.Util.rst
@@ -1,9 +1,9 @@
-.. _Util:
+.. _util:
-bridgedb.Util
+bridgedb.util
-------------
-.. automodule:: bridgedb.Util
+.. automodule:: bridgedb.util
:members:
:undoc-members:
:show-inheritance:
diff --git a/doc/sphinx/source/bridgedb.rst b/doc/sphinx/source/bridgedb.rst
index 38dc9a2..40e0151 100644
--- a/doc/sphinx/source/bridgedb.rst
+++ b/doc/sphinx/source/bridgedb.rst
@@ -21,5 +21,6 @@ bridgedb
bridgedb.Stability
bridgedb.Storage
bridgedb.Tests
- bridgedb.Util
+ bridgedb.txrecaptcha
+ bridgedb.util
gen_bridge_descriptors
diff --git a/doc/sphinx/source/conf.py b/doc/sphinx/source/conf.py
index de44db4..4caac64 100644
--- a/doc/sphinx/source/conf.py
+++ b/doc/sphinx/source/conf.py
@@ -43,7 +43,7 @@ import bridgedb.Stability
import bridgedb.Storage
import bridgedb.test
import bridgedb.Tests
-import bridgedb.Util
+import bridgedb.util
import gen_bridge_descriptors
diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index 5c406f6..a60ff85 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -22,8 +22,8 @@ import random
import bridgedb.Storage
import bridgedb.Bucket
-import bridgedb.Util as Util
+from bridgedb import util
from bridgedb.crypto import getHMACFunc
from bridgedb.parse import addr
from bridgedb.parse import networkstatus
@@ -1035,7 +1035,7 @@ class BridgeRing(BridgeHolder):
else:
logging.debug(
"Got duplicate bridge %r in main hashring for position %r."
- % (Util.logSafely(k.encode('hex')), pos.encode('hex')))
+ % (util.logSafely(k.encode('hex')), pos.encode('hex')))
keys = keys[:N]
keys.sort()
@@ -1280,12 +1280,12 @@ class FilteredBridgeSplitter(BridgeHolder):
if not bridge.running:
logging.warn(
"Skipping hashring insertion for non-running bridge: '%s'"
- % Util.logSafely(bridge.fingerprint))
+ % util.logSafely(bridge.fingerprint))
return
index = 0
logging.debug("Inserting %s into splitter"
- % (Util.logSafely(bridge.fingerprint)))
+ % (util.logSafely(bridge.fingerprint)))
for old_bridge in self.bridges[:]:
if bridge.fingerprint == old_bridge.fingerprint:
self.bridges[index] = bridge
@@ -1297,7 +1297,7 @@ class FilteredBridgeSplitter(BridgeHolder):
if filterFn(bridge):
subring.insert(bridge)
logging.debug("Inserted bridge '%s' into '%s' sub hashring"
- % (Util.logSafely(bridge.fingerprint), ringname))
+ % (util.logSafely(bridge.fingerprint), ringname))
def extractFilterNames(self, ringname):
"""Get the names of the filters applied to a particular sub hashring.
diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py
index 7107867..e7bc443 100644
--- a/lib/bridgedb/Dist.py
+++ b/lib/bridgedb/Dist.py
@@ -14,7 +14,7 @@
import bridgedb.Bridges
import bridgedb.Storage
-import bridgedb.Util as Util
+import bridgedb.util as util
import logging
import re
@@ -235,7 +235,7 @@ class IPBasedDistributor(Distributor):
for an example of how this is used.
"""
logging.info("Attempting to return %d bridges to client %s..."
- % (N, Util.logSafely(ip)))
+ % (N, util.logSafely(ip)))
if not bridgeFilterRules:
bridgeFilterRules=[]
@@ -251,7 +251,7 @@ class IPBasedDistributor(Distributor):
area = self.areaMapper(ip)
logging.debug("IP mapped to area:\t%s"
- % Util.logSafely("{0}.0/24".format(area)))
+ % util.logSafely("{0}.0/24".format(area)))
key1 = ''
pos = 0
@@ -267,7 +267,7 @@ class IPBasedDistributor(Distributor):
len(self.categories),
n)
bridgeFilterRules.append(g)
- logging.info("category<%s>%s", epoch, Util.logSafely(area))
+ logging.info("category<%s>%s", epoch, util.logSafely(area))
pos = self.areaOrderHmac("category<%s>%s" % (epoch, area))
key1 = getHMAC(self.splitter.key,
"Order-Bridges-In-Ring-%d" % n)
@@ -485,19 +485,19 @@ class EmailBasedDistributor(Distributor):
lastSaw = db.getEmailTime(emailaddress)
logging.info("Attempting to return for %d bridges for %s..."
- % (N, Util.logSafely(emailaddress)))
+ % (N, util.logSafely(emailaddress)))
if lastSaw is not None and lastSaw + MAX_EMAIL_RATE >= now:
logging.info("Client %s sent duplicate request within %d seconds."
- % (Util.logSafely(emailaddress), MAX_EMAIL_RATE))
+ % (util.logSafely(emailaddress), MAX_EMAIL_RATE))
if wasWarned:
logging.info(
"Client was already warned about duplicate requests.")
raise IgnoreEmail("Client was warned",
- Util.logSafely(emailaddress))
+ util.logSafely(emailaddress))
else:
logging.info("Sending duplicate request warning to %s..."
- % Util.logSafely(emailaddress))
+ % util.logSafely(emailaddress))
db.setWarnedEmail(emailaddress, True, now)
db.commit()
diff --git a/lib/bridgedb/EmailServer.py b/lib/bridgedb/EmailServer.py
index 90b22af..0242103 100644
--- a/lib/bridgedb/EmailServer.py
+++ b/lib/bridgedb/EmailServer.py
@@ -29,7 +29,7 @@ from twisted.internet.error import ConnectionRefusedError
from zope.interface import implements
import bridgedb.Dist
-import bridgedb.Util as Util
+import bridgedb.util as util
from bridgedb.Dist import BadEmail, TooSoonEmail, IgnoreEmail
from bridgedb.Filters import filterBridgesByIP6, filterBridgesByIP4
from bridgedb.Filters import filterBridgesByTransport
@@ -104,11 +104,11 @@ def getMailResponse(lines, ctx):
logging.info("Ignoring bad address on incoming email.")
return None,None
if not addrdomain:
- logging.info("Couldn't parse domain from %r", Util.logSafely(clientAddr))
+ logging.info("Couldn't parse domain from %r", util.logSafely(clientAddr))
if addrdomain and ctx.cfg.EMAIL_DOMAIN_MAP:
addrdomain = ctx.cfg.EMAIL_DOMAIN_MAP.get(addrdomain, addrdomain)
if addrdomain not in ctx.cfg.EMAIL_DOMAINS:
- logging.info("Unrecognized email domain %r", Util.logSafely(addrdomain))
+ logging.info("Unrecognized email domain %r", util.logSafely(addrdomain))
return None,None
rules = ctx.cfg.EMAIL_DOMAIN_RULES.get(addrdomain, [])
if 'dkim' in rules:
@@ -181,7 +181,7 @@ def getMailResponse(lines, ctx):
# Handle rate limited email
except TooSoonEmail, e:
logging.info("Got a mail too frequently; warning %r: %s.",
- Util.logSafely(clientAddr), e)
+ util.logSafely(clientAddr), e)
# Compose a warning email
# MAX_EMAIL_RATE is in seconds, convert to hours
@@ -191,12 +191,12 @@ def getMailResponse(lines, ctx):
except IgnoreEmail, e:
logging.info("Got a mail too frequently; ignoring %r: %s.",
- Util.logSafely(clientAddr), e)
+ util.logSafely(clientAddr), e)
return None, None
except BadEmail, e:
logging.info("Got a mail from a bad email address %r: %s.",
- Util.logSafely(clientAddr), e)
+ util.logSafely(clientAddr), e)
return None, None
if bridges:
@@ -269,18 +269,18 @@ def replyToMail(lines, ctx):
if response is None:
logging.debug("getMailResponse() said not to reply to %s, so I won't."
- % Util.logSafely(sendToUser))
+ % util.logSafely(sendToUser))
return
response.seek(0)
- logging.info("Sending reply to %r", Util.logSafely(sendToUser))
+ logging.info("Sending reply to %r", util.logSafely(sendToUser))
d = Deferred()
factory = twisted.mail.smtp.SMTPSenderFactory(ctx.smtpFromAddr, sendToUser,
response, d, retries=0,
timeout=30)
d.addErrback(_ebReplyToMailFailure)
- logging.info("Sending reply to %r", Util.logSafely(sendToUser))
+ logging.info("Sending reply to %r", util.logSafely(sendToUser))
reactor.connectTCP(ctx.smtpServer, ctx.smtpPort, factory)
return d
@@ -461,11 +461,11 @@ def composeEmail(fromAddr, clientAddr, subject, body, msgID=False,
# Only log the email text (including all headers) if SAFE_LOGGING is
# disabled:
- if not Util.safe_logging:
+ if not util.safe_logging:
mail.seek(0)
logging.debug("Email contents:\n%s" % mail.read())
else:
- logging.debug("Email text for %r created." % Util.logSafely(clientAddr))
+ logging.debug("Email text for %r created." % util.logSafely(clientAddr))
mail.seek(0)
return clientAddr, mail
diff --git a/lib/bridgedb/HTTPServer.py b/lib/bridgedb/HTTPServer.py
index 3809f2d..c0e5b66 100644
--- a/lib/bridgedb/HTTPServer.py
+++ b/lib/bridgedb/HTTPServer.py
@@ -24,11 +24,11 @@ from twisted.web.util import redirectTo
import bridgedb.Dist
import bridgedb.I18n as I18n
-import bridgedb.Util as Util
from bridgedb import captcha
from bridgedb import crypto
from bridgedb import txrecaptcha
+from bridgedb import util
from bridgedb.Filters import filterBridgesByIP4
from bridgedb.Filters import filterBridgesByIP6
from bridgedb.Filters import filterBridgesByTransport
@@ -287,7 +287,7 @@ class GimpCaptchaProtectedResource(CaptchaProtectedResource):
valid = captcha.GimpCaptcha.check(challenge, solution,
self.secretKey, clientHMACKey)
logging.debug("%sorrect captcha from %r: %r." % (
- "C" if valid else "Inc", Util.logSafely(clientIP), solution))
+ "C" if valid else "Inc", util.logSafely(clientIP), solution))
return valid
@@ -463,7 +463,7 @@ class ReCaptchaProtectedResource(CaptchaProtectedResource):
remoteIP = self.getRemoteIP()
logging.debug("Captcha from %r. Parameters: %r"
- % (Util.logSafely(clientIP), request.args))
+ % (util.logSafely(clientIP), request.args))
def checkResponse(solution, request):
"""Check the :class:`txrecaptcha.RecaptchaResponse`.
@@ -479,11 +479,11 @@ class ReCaptchaProtectedResource(CaptchaProtectedResource):
# breaking). Hence, the 'no cover' pragma.
if solution.is_valid: # pragma: no cover
logging.info("Valid CAPTCHA solution from %r."
- % Util.logSafely(clientIP))
+ % util.logSafely(clientIP))
return (True, request)
else:
logging.info("Invalid CAPTCHA solution from %r: %r"
- % (Util.logSafely(clientIP), solution.error_code))
+ % (util.logSafely(clientIP), solution.error_code))
return (False, request)
d = txrecaptcha.submit(challenge, response, self.recaptchaPrivKey,
@@ -669,7 +669,7 @@ class WebResourceBridges(resource.Resource):
unblocked = False
logging.info("Replying to web request from %s. Parameters were %r"
- % (Util.logSafely(ip), request.args))
+ % (util.logSafely(ip), request.args))
rules = []
bridgeLines = None
diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py
index d21239c..c2c69c9 100644
--- a/lib/bridgedb/Main.py
+++ b/lib/bridgedb/Main.py
@@ -26,7 +26,7 @@ import bridgedb.Bridges as Bridges
import bridgedb.Dist as Dist
import bridgedb.Time as Time
import bridgedb.Storage
-import bridgedb.Util as Util
+from bridgedb import util
def configureLogging(cfg):
@@ -41,7 +41,7 @@ def configureLogging(cfg):
logfile = getattr(cfg, 'LOGFILE', "")
logfile_count = getattr(cfg, 'LOGFILE_COUNT', 5)
logfile_rotate_size = getattr(cfg, 'LOGFILE_ROTATE_SIZE', 10000000)
- Util.set_safe_logging(safelogging)
+ util.set_safe_logging(safelogging)
logging.getLogger().setLevel(level)
if logfile:
diff --git a/lib/bridgedb/Util.py b/lib/bridgedb/Util.py
deleted file mode 100644
index de512d5..0000000
--- a/lib/bridgedb/Util.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- coding: utf-8 ; test-case-name: bridgedb.test.test_Util -*-
-#
-# This file is part of BridgeDB, a Tor bridge distribution system.
-#
-# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis@xxxxxxxxxxxxxx>
-# Matthew Finkel 0x017DD169EA793BE2 <sysrqb@xxxxxxxxxxxxxx>
-# :copyright: (c) 2013-2014, Isis Lovecruft
-# (c) 2013-2014, Matthew Finkel
-# (c) 2007-2014, The Tor Project, Inc.
-# :license: 3-Clause BSD, see LICENSE for licensing information
-
-"""Common utilities for BridgeDB."""
-
-safe_logging = True
-
-def set_safe_logging(safe):
- global safe_logging
- safe_logging = safe
-
-def logSafely(val):
- if safe_logging:
- return "[scrubbed]"
- else:
- return val
diff --git a/lib/bridgedb/util.py b/lib/bridgedb/util.py
new file mode 100644
index 0000000..723ed8e
--- /dev/null
+++ b/lib/bridgedb/util.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 ; test-case-name: bridgedb.test.test_util -*-
+#
+# This file is part of BridgeDB, a Tor bridge distribution system.
+#
+# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis@xxxxxxxxxxxxxx>
+# Matthew Finkel 0x017DD169EA793BE2 <sysrqb@xxxxxxxxxxxxxx>
+# :copyright: (c) 2013-2014, Isis Lovecruft
+# (c) 2013-2014, Matthew Finkel
+# (c) 2007-2014, The Tor Project, Inc.
+# :license: 3-Clause BSD, see LICENSE for licensing information
+
+"""Common utilities for BridgeDB."""
+
+safe_logging = True
+
+def set_safe_logging(safe):
+ global safe_logging
+ safe_logging = safe
+
+def logSafely(val):
+ if safe_logging:
+ return "[scrubbed]"
+ else:
+ return val
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits