Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Optimized alternative to urllib.quote #134
Things are especially slow in python 3, but are reasonably snappy under pypy. The first thing that comes to mind here is calling out to cffi using a C module for quoting and unquoting URLs.
I found python-percentcoding on PyPI, but it doesn't work on Python 3 and it might not work on pypy, either.
I remember looking at the urllib.quote function a long time ago, because I hit the unicode bug in it.
Check out the implementation: https://gist.github.com/syllog1sm/6656171
It's easy to see that this could be made more efficient, just by reimplementing it in a more straight-forward way.
Looking at the falcon source, it seems this is only used in utils.percent_escape, right? So the set of reserved characters is fixed. That makes things much simpler.
If the simple Python way isn't good enough, a Cython array would be very efficient.
Oh, also, it seems you want urllib.parse.quote_from_bytes for Python 3?