Skip to content

Instantly share code, notes, and snippets.

@dcolish
Created February 22, 2011 03:51
Show Gist options
  • Select an option

  • Save dcolish/838189 to your computer and use it in GitHub Desktop.

Select an option

Save dcolish/838189 to your computer and use it in GitHub Desktop.
Url bouncer for redirecting svn urls to bitbucket
from urlparse import urljoin
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util, WSGIApplication
class Bouncer(webapp.RequestHandler):
def __init__(self, mapping=()):
super(Bouncer, self).__init__(self)
self.mapping = mapping
@classmethod
def from_mapping(self, mapping):
return lambda: Bouncer(mapping)
def get(self, path):
newloc, oldbasepath, newbasepath = self.mapping
newpath = path.replace(oldbasepath, newbasepath)
newurl = urljoin(newloc, newpath)
#: Uncomment this line and comment the one below for testing
# self.response.out.write(newurl)
self.redirect(newurl, permanent=True)
def handle_exception(self, exception, debug_mode):
self.response.out.write(exception)
def main():
mapping = ("https://bitbucket.org",
"svn/pypy/trunk",
"pypy/pypy/src/default")
application = WSGIApplication(
[(r'/(.*)', Bouncer.from_mapping(mapping))],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment