Skip to content

Instantly share code, notes, and snippets.

@tbreeds
Last active May 12, 2016 00:00
Show Gist options
  • Save tbreeds/7f09e506fafbfbde0ffe83e8c61b2741 to your computer and use it in GitHub Desktop.
Save tbreeds/7f09e506fafbfbde0ffe83e8c61b2741 to your computer and use it in GitHub Desktop.
Grovel around in the pypi simple API and generate Apache rewrite rules to get to the non-std. packagenames
#!/usr/bin/env python
from __future__ import print_function
import contextlib
import HTMLParser
from packaging.utils import canonicalize_name
import urllib
class SimpleParser(HTMLParser.HTMLParser):
def handle_data(self, data):
name = data.rstrip().lstrip()
pep_name = canonicalize_name(name)
if name and name != pep_name:
print("RewriteRule %s %s" % (pep_name, name))
SimpleParser().feed(urllib.urlopen('http://pypi.python.org/simple').read())
@tbreeds
Copy link
Author

tbreeds commented May 12, 2016

@r1chardj0n3s laughed at me.

It didn't handle errors very well anyway ;P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment