[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r17052: {weather} safeRelease should not exist! (weather/trunk)



Author: pde
Date: 2008-10-09 02:03:26 -0400 (Thu, 09 Oct 2008)
New Revision: 17052

Modified:
   weather/trunk/weather.py
Log:
safeRelease should not exist!



Modified: weather/trunk/weather.py
===================================================================
--- weather/trunk/weather.py	2008-10-09 03:56:29 UTC (rev 17051)
+++ weather/trunk/weather.py	2008-10-09 06:03:26 UTC (rev 17052)
@@ -26,12 +26,6 @@
 )
 
 
-def safeRelease(gdbm_lock):
-    try:
-        gdbm_lock.release()
-    except AssertionError:
-        pass
-
 if apache_fcgi:
   web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
 
@@ -165,23 +159,24 @@
   def allowed_to_subscribe(self,ip):
     "An antispam measure!"
     antispam_lock.acquire()
-    if antispam.has_key(ip):
-      if antispam[ip] == 0:
-        antispam_lock.release()
-        return False
+    try:
+      if antispam.has_key(ip):
+        if antispam[ip] == 0:
+          antispam_lock.release()
+          return False
+        else:
+          antispam[ip] -= 1
+          return True
       else:
-        antispam[ip] -= 1
-        antispam_lock.release()
+        # okay this is silly but leaks very slightly less information
+        antispam[ip] = random.randrange(antispam_min,antispam_max)
         return True
-    else:
-      # okay this is silly but leaks very slightly less information
-      antispam[ip] = random.randrange(antispam_min,antispam_max)
+    finally:
       antispam_lock.release()
-      return True
 
   def already_subscribed(self, address, node):
+    gdbm_lock.acquire()
     try:
-        gdbm_lock.acquire()
 
         try:
           words = subscriptions[node].split()
@@ -194,15 +189,14 @@
 
     finally:
         gdbm_lock.release()
-        return already
+    return already
     
   def send_confirmation_email(self, address, node):
     authstring = randstring()
 
+    gdbm_lock.acquire()
     try:
-        gdbm_lock.acquire()
         requests[authstring] = address + " " + node
-
     finally:
         gdbm_lock.release()
 
@@ -296,12 +290,11 @@
     print "<html>"
     if debug: print "checking confirmation..."
 
+    gdbm_lock.acquire()
     try:
-        gdbm_lock.acquire()
 
         if not requests.has_key(authstring):
           print "Error in subscription request!"
-          gdbm_lock.release()
           return 0
 
         email, node = requests[authstring].split()
@@ -328,26 +321,27 @@
         subscriptions.sync()
 
     finally:
-        safeRelease(gdbm_lock)
+        gdbm_lock.release()
 
     # okay now slacken antispam watch
     antispam_lock.acquire()
-    if antispam.has_key(web.ctx.ip):
-      antispam[web.ctx.ip] += 1
-      if antispam[web.ctx.ip] >= antispam_max:
-        del antispam[web.ctx.ip]
-    antispam_lock.release()
+    try:
+      if antispam.has_key(web.ctx.ip):
+        antispam[web.ctx.ip] += 1
+        if antispam[web.ctx.ip] >= antispam_max:
+          del antispam[web.ctx.ip]
+    finally:
+      antispam_lock.release()
     
 class unsubscribe:
   def GET(self,authstring):
 
     web.header('content-type', 'text/html')
+    gdbm_lock.acquire()
     try:
-        gdbm_lock.acquire()
         if not unsubscriptions.has_key(authstring):
           print "Invalid unsubscription request!"
           print unsubscriptions
-          gdbm_lock.release()
           return 0
 
         email, node, _ = unsubscriptions[authstring].split()
@@ -359,7 +353,7 @@
         del (unsubscriptions[authstring])
 
     finally:
-        safeRelease(gdbm_lock)
+        gdbm_lock.release()
 
 class AntispamRelaxer(threading.Thread):
   "Prevent long term accretion of antispam counts."
@@ -368,11 +362,13 @@
     while True:
       time.sleep(random.randrange(0,self.timescale))
       antispam_lock.acquire()
-      for ip in antispam.keys():
-        antispam[ip] += 1
-        if antispam[ip] == antispam_max:
-          del antispam[ip]
-      antispam_lock.release()
+      try:
+        for ip in antispam.keys():
+          antispam[ip] += 1
+          if antispam[ip] == antispam_max:
+            del antispam[ip]
+      finally:
+        antispam_lock.release()
 
 def main():
   from poll import WeatherPoller