Lynn Rees  committed 3706474


  • Participants
  • Parent commits 58c556d
  • Branches wsgiakismet

Comments (0)

Files changed (1)

File trunk/

 This is a web service for blocking SPAM comments to blogs - or other online
 services. Based on akismet 0.1.3.
-You will need a Wordpress API key, from
+You will need a Wordpress API key, from
 You should pass in the keyword argument 'agent' to the name of your program,
 when you create an Akismet instance. This sets the ``user-agent`` to a useful
 __all__ = ['__version__', 'WsgiAkismet', 'akismet']
 __version__ = '0.1'
 __author__ = 'L.C. Rees <'
-__docformat__ = 'restructuredtext en'
 user_agent = '%s |'
 DEFAULTAGENT = 'Python Interface by Fuzzyman/%s'
     @param strict Stops on errors (default: False)
     winput = env['wsgi.input']
+    # Non-destructively retrieve string
     if hasattr(winput, 'getvalue'):
         tinput = winput.getvalue()
+    # Recreate wsgi.input as fallback
         tinput =
         env['wsgi.input'] = StringIO(tinput)
+    # Parse form submission
     qdict = cgi.parse(fp=StringIO(tinput), environ=env)
     # Remove invididual entries from list and store as naked string
     for key, value in qdict.iteritems():
     return ['Comment was spam.']
 def akismet(key, blog_url, **kw):
+    '''Decorator for Akismet.'''
     def decorator(application):
         return WsgiAkismet(application, key, blog_url, **kw)
     return decorator
         self.handler = kw.get('handler', _handler)        
     def __call__(self, environ, start_response):
-        # Parse form
         formdata = formparse(environ)
         # Get comment
         comment = formdata[self.comment_key]
         data = {'key':self.key, 'blog':self.blog_url}
         # this function *doesn't* use the key as part of the URL
         url = 'http://%sverify-key' % self.baseurl
-        headers = {'User-Agent' : self.user_agent}        
+        headers = {'User-Agent':self.user_agent}        
         req = urllib2.Request(url, urlencode(data), headers)
             if urllib2.urlopen(req).read().lower() == 'valid': return True