Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Last active December 17, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markrwilliams/5617598 to your computer and use it in GitHub Desktop.
Save markrwilliams/5617598 to your computer and use it in GitHub Desktop.
import re
urldecoder = re.compile('%([0-9a-fA-F]{2})')
def urldecode(s):
bs = bytearray(s)
offset = 0
for encoded in urldecoder.finditer(s):
start, end = encoded.span()
bs[start + offset:end + offset] = chr(int(encoded.group(1), 16))
offset += (start - end + 1)
return str(bs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment