Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 5056462126
Fetching contributors…

Cannot retrieve contributors at this time

28 lines (21 sloc) 0.901 kb
import logging
from google.appengine.dist import use_library
use_library('django', '1.2')
appstats_RECORD_FRACTION = .1
class BlockingMiddleware(object):
def __init__(self, app):
self._wrapped_app = app
def __call__(self, environ, start_response):
user_agent = environ.get('HTTP_USER_AGENT', None)
# Scraper running on EC2 (IP addresses and
# that's requesting lots of Tweet Digest pages.
if user_agent == 'Python-urllib/2.7':'Blocked request')
start_response('403 Forbidden', [('Content-type','text/plain')])
return ['']
return self._wrapped_app(environ, start_response)
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats import recording
app = recording.appstats_wsgi_middleware(app)
app = BlockingMiddleware(app)
return app
Jump to Line
Something went wrong with that request. Please try again.