Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
python-percentcoding/percentcoding/__init__.py /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (25 sloc)
790 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import string | |
| from percentcoding.cext import Codec | |
| URI_UNRESERVED = string.ascii_uppercase + string.ascii_lowercase + string.digits + "-_.~" | |
| URI_RESERVED = "!*'();:@&=+$,/?#[]" | |
| URI_SAFE = ''.join( set([c for c in URI_UNRESERVED]) - set([c for c in URI_RESERVED]) ) | |
| URI_SAFE_FORM = URI_SAFE+'+' | |
| urlcoding = Codec(URI_SAFE) | |
| urlpluscoding = Codec(URI_SAFE_FORM) | |
| def quote(s): | |
| global urlcoding | |
| return urlcoding.encode(s) | |
| def quote_default(s, default='-'): | |
| if s is None: | |
| return default | |
| return quote(s) | |
| def unquote(s): | |
| global urlcoding | |
| return urlcoding.decode(s) | |
| def quote_plus(s): | |
| global urlpluscoding | |
| return urlpluscoding.encode(s.replace(" ","+")) | |
| def unquote_plus(s): | |
| global urlpluscoding | |
| return urlpluscoding.decode(s.replace("+"," ")) |