Inverse operation of urllib.urlencode. Returns a dictionary of (name, value)-items from a URL query string.
(query)
| 185 | return os.path.splitext(filename)[1] |
| 186 | |
| 187 | def urldecode(query): |
| 188 | """ Inverse operation of urllib.urlencode. |
| 189 | Returns a dictionary of (name, value)-items from a URL query string. |
| 190 | """ |
| 191 | def _format(s): |
| 192 | if s == "" or s == "None": |
| 193 | return None |
| 194 | if s.lstrip("-").isdigit(): |
| 195 | return int(s) |
| 196 | try: return float(s) |
| 197 | except: |
| 198 | return s |
| 199 | if query: |
| 200 | query = query.lstrip("?").split("&") |
| 201 | query = ((kv.split("=") + [None])[:2] for kv in query) |
| 202 | query = ((u(urllib.unquote_plus(bytestring(k))), |
| 203 | _format(u(urllib.unquote_plus(bytestring(v))))) for k, v in query if k != "") |
| 204 | return dict(query) |
| 205 | return {} |
| 206 | |
| 207 | url_decode = urldecode |
| 208 |