[or-cvs] r20802: {projects} More cleanups (in projects/gettor: . gettor)
kaner at seul.org
kaner at seul.org
Sun Oct 18 12:18:45 UTC 2009
Author: kaner
Date: 2009-10-18 08:18:44 -0400 (Sun, 18 Oct 2009)
New Revision: 20802
Modified:
projects/gettor/GetTor.py
projects/gettor/gettor/blacklist.py
projects/gettor/gettor/constants.py
projects/gettor/gettor/requests.py
projects/gettor/gettor/responses.py
Log:
More cleanups
Modified: projects/gettor/GetTor.py
===================================================================
--- projects/gettor/GetTor.py 2009-10-18 11:32:44 UTC (rev 20801)
+++ projects/gettor/GetTor.py 2009-10-18 12:18:44 UTC (rev 20802)
@@ -34,23 +34,28 @@
log.info("Processing mail..")
# Retrieve request from stdin
- request = gettor.requests.requestMail(conf)
- replyTo, lang, pack, split, sig = request.parseMail()
- log.info("Request from %s package %s, lang %s, split %s" \
- % (replyTo, pack, lang, split))
- log.info("Signature is %s" % sig)
+ try:
+ request = gettor.requests.requestMail(conf)
+ replyTo, lang, pack, split, sig = request.parseMail()
+ log.info("Request from %s package %s, lang %s, split %s" \
+ % (replyTo, pack, lang, split))
+ log.info("Signature is %s" % sig)
+ except Exception, e:
+ log.error("Parsing the request failed.")
+ log.error("Here is the exception I saw: %s" % sys.exc_info()[0])
+ log.error("Detail: %s" % e)
+ return False
# Ok, information aquired. Initiate reply sequence
try:
reply = gettor.responses.Response(conf, replyTo, lang, pack, split, sig)
- except:
- log.error("Parsing the request failed.")
- log.error("Here is the exception I saw: %s" % sys.exc_info()[0])
- try:
reply.sendReply()
- except:
+ return True
+ except Exception, e:
log.error("Sending the reply failed.")
log.error("Here is the exception I saw: %s" % sys.exc_info()[0])
+ log.error("Detail: %s" %e)
+ return False
def processOptions(options, conf):
"""Do everything that's not part of parsing a mail. Prepare GetTor usage,
@@ -88,7 +93,10 @@
processOptions(options, config)
else:
# We've got mail
- processMail(config)
+ if processMail(config):
+ log.info("Processing mail finished")
+ else:
+ log.error("Processing mail failed")
log.info("Done.")
Modified: projects/gettor/gettor/blacklist.py
===================================================================
--- projects/gettor/gettor/blacklist.py 2009-10-18 11:32:44 UTC (rev 20801)
+++ projects/gettor/gettor/blacklist.py 2009-10-18 12:18:44 UTC (rev 20802)
@@ -36,6 +36,9 @@
def lookupListEntry(self, address):
"""Check to see if we have a list entry for the given address."""
+ if address is None:
+ log.error("Argument 'address' is None")
+ return False
emailonly = self.stripEmail(address)
entry = self.listDir + "/" + str(hashlib.sha1(emailonly).hexdigest())
try:
@@ -45,6 +48,10 @@
return True
def createListEntry(self, address):
+ """ Create a black- or whitelist entry """
+ if address is None:
+ log.error("Argument 'address' is None")
+ return False
emailonly = self.stripEmail(address)
entry = self.listDir + "/" + str(hashlib.sha1(emailonly).hexdigest())
if self.lookupListEntry(address) == False:
@@ -53,23 +60,27 @@
fd.close
return True
except:
- log.error(_("Creating list entry %s failed.") % entry)
+ log.error("Creating list entry %s failed." % entry)
return False
else:
# List entry already exists
return False
def removeListEntry(self, address):
+ """ Remove an entry from the black- or whitelist """
+ if address is None:
+ log.error("Argument 'address' is None")
+ return False
emailonly = self.stripEmail(address)
entry = self.listDir + "/" + str(hashlib.sha1(emailonly).hexdigest())
if (self.lookupListEntry(address) == True):
try:
os.unlink(entry)
except OSError:
- log.error(_("Could not unlink entry %s") % entry)
+ log.error("Could not unlink entry %s" % entry)
return False
else:
- log.info(_("Requested removal of non-existing entry %s. Abord.")
+ log.info("Requested removal of non-existing entry %s. Abord."
% entry)
return False
@@ -81,7 +92,7 @@
rmfile = os.path.join(root, file)
os.remove(rmfile)
except:
- log.error(_("Could not remove %s." % rmfile))
+ log.error("Could not remove %s." % rmfile)
return False
return True
@@ -91,36 +102,3 @@
if match is not None:
return match.group()
return address
-
-def blackListtests(address):
- """ This is a basic evaluation of our blacklist functionality """
- bwlist = BWList("/tmp/")
- print bwlist.createListEntry(address)
- print bwlist.lookupListEntry(address)
- #prepBLStateDir()
- #privateAddress = makeAddressPrivate(address)
- #print "We have a private address of: " + privateAddress
- #print "Testing creation of blacklist entry: "
- #blackListEntry = createBlackListEntry(privateAddress)
- #print blackListEntry
- #print "We're testing a lookup of a known positive blacklist entry: "
- #blackListEntry = lookupBlackListEntry(privateAddress)
- #print blackListEntry
- #print "We're testing removal of a known blacklist entry: "
- #blackListEntry = removeBlackListEntry(privateAddress)
- #print blackListEntry
- #print "We're testing a lookup of a known false blacklist entry: "
- #blackListEntry = lookupBlackListEntry(privateAddress)
- #print blackListEntry
- #print "Now we'll test the higher level blacklist functionality..."
- #print "This should not find an entry in the blacklist: "
- #print blackList(address)
- #print "This should add an entry to the blacklist: "
- #print blackList(address, True)
- #print "This should find the previous addition to the blacklist: "
- #print blackList(address)
- #print "Please ensure the tests match what you would expect for your environment."
-
-if __name__ == "__main__" :
- print "Running some tests.."
- blackListtests("requestingUser at example.com")
Modified: projects/gettor/gettor/constants.py
===================================================================
--- projects/gettor/gettor/constants.py 2009-10-18 11:32:44 UTC (rev 20801)
+++ projects/gettor/gettor/constants.py 2009-10-18 12:18:44 UTC (rev 20802)
@@ -8,7 +8,6 @@
This is Free Software. See LICENSE for license information.
- This library implements all of the email replying features needed for gettor.
"""
import gettext
Modified: projects/gettor/gettor/requests.py
===================================================================
--- projects/gettor/gettor/requests.py 2009-10-18 11:32:44 UTC (rev 20801)
+++ projects/gettor/gettor/requests.py 2009-10-18 12:18:44 UTC (rev 20802)
@@ -49,6 +49,7 @@
# TODO XXX:
# Scrub this data
self.replytoAddress = self.parsedMessage["from"]
+ assert self.replytoAddress is not None, "Replyto address is None"
# If no package name could be recognized, use 'None'
self.returnPackage = None
self.splitDelivery = False
Modified: projects/gettor/gettor/responses.py
===================================================================
--- projects/gettor/gettor/responses.py 2009-10-18 11:32:44 UTC (rev 20801)
+++ projects/gettor/gettor/responses.py 2009-10-18 12:18:44 UTC (rev 20802)
@@ -33,11 +33,16 @@
self.config = config
self.srcEmail = "GetTor <gettor at torproject.org>"
self.replyTo = replyto
+ if self.replyTo is None:
+ log.error("Empty replyto address.")
+ # XXX Raise something self-defined
+ raise Exception("Empty reply to address")
self.mailLang = lang
self.package = package
self.splitsend = split
self.signature = signature
self.whiteList = gettor.blacklist.BWList(config.getWlStateDir())
+ self.blackList = gettor.blacklist.BWList(config.getBlStateDir())
try:
trans = gettext.translation("gettor", config.getLocaleDir(), [lang])
trans.install()
@@ -53,13 +58,13 @@
and not re.compile(".*@yahoo.com.cn").match(self.replyTo) \
and not re.compile(".*@yahoo.cn").match(self.replyTo) \
and not re.compile(".*@gmail.com").match(self.replyTo):
- blackListed = blackList.lookupListEntry(self.replyTo)
+ blackListed = self.blackList.lookupListEntry(self.replyTo)
if blackListed:
log.info("Unsigned messaged to gettor by blacklisted user dropped.")
return False
else:
# Reply with some help and bail out
- blackList.createListEntry(self.replyTo)
+ self.blackList.createListEntry(self.replyTo)
log.info("Unsigned messaged to gettor. We will issue help.")
return self.sendHelp()
else:
More information about the tor-commits
mailing list