Extract parameters and return them as a list of 2-tuples. Will successfully extract parameters from urlencoded query strings, dicts, or lists of 2-tuples. Empty strings/dicts/lists will return an empty list of parameters. Any other input will result in a return value of None.
(raw)
| 111 | |
| 112 | |
| 113 | def extract_params(raw): |
| 114 | """Extract parameters and return them as a list of 2-tuples. |
| 115 | |
| 116 | Will successfully extract parameters from urlencoded query strings, |
| 117 | dicts, or lists of 2-tuples. Empty strings/dicts/lists will return an |
| 118 | empty list of parameters. Any other input will result in a return |
| 119 | value of None. |
| 120 | """ |
| 121 | if isinstance(raw, (list, tuple)): |
| 122 | try: |
| 123 | raw = dict(raw) |
| 124 | except (TypeError, ValueError): |
| 125 | return None |
| 126 | |
| 127 | if isinstance(raw, dict): |
| 128 | params = [] |
| 129 | for k, v in raw.items(): |
| 130 | params.append((to_unicode(k), to_unicode(v))) |
| 131 | return params |
| 132 | |
| 133 | if not raw: |
| 134 | return None |
| 135 | |
| 136 | try: |
| 137 | return url_decode(raw) |
| 138 | except ValueError: |
| 139 | return None |
| 140 | |
| 141 | |
| 142 | def is_valid_url(url: str, fragments_allowed=True): |
no test coverage detected
searching dependent graphs…