Lynn Rees avatar Lynn Rees committed 3706474

[svn]

Comments (0)

Files changed (1)

trunk/wsgiakismet.py

 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 http://wordpress.com.
+You will need a Wordpress API key, from http://wordpress.com/.
 
 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 <lcrees@gmail.com?'
-__docformat__ = 'restructuredtext en'
 user_agent = '%s | wsgiakismet.py/%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
     else:
         tinput = winput.read()
         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)
         try:
             if urllib2.urlopen(req).read().lower() == 'valid': return True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.