Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| #!/usr/bin/python3 | |
| import cherrypy | |
| import urllib.request | |
| class NoRed(urllib.request.HTTPErrorProcessor): | |
| def http_response(self, request, response): | |
| return response | |
| https_response = http_response | |
| class Controller(object): | |
| def pool(self, debfile=None): | |
| opener = urllib.request.build_opener(NoRed) | |
| response = opener.open( | |
| 'https://launchpad.net/ubuntu/+archive/primary/+files/' + debfile) | |
| url = response.getheader('Location').replace('https://', 'http://') | |
| raise cherrypy.HTTPRedirect(url) | |
| d = cherrypy.dispatch.RoutesDispatcher() | |
| c = Controller() | |
| d.connect('pool', | |
| '{debfile:.*?}', | |
| c, | |
| action='pool') | |
| conf = { | |
| '/': {'request.dispatch': d}, | |
| } | |
| def application(environ, start_response): | |
| cherrypy.tree.mount(None, config=conf) | |
| return cherrypy.tree(environ, start_response) | |
| if __name__ == '__main__': | |
| print(c.pool("hello_2.8-4_amd64.deb")) |