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)
| 130 | |
| 131 | |
| 132 | def extract_params(raw): |
| 133 | """Extract parameters and return them as a list of 2-tuples. |
| 134 | |
| 135 | Will successfully extract parameters from urlencoded query strings, |
| 136 | dicts, or lists of 2-tuples. Empty strings/dicts/lists will return an |
| 137 | empty list of parameters. Any other input will result in a return |
| 138 | value of None. |
| 139 | """ |
| 140 | if isinstance(raw, (bytes, str)): |
| 141 | try: |
| 142 | params = urldecode(raw) |
| 143 | except ValueError: |
| 144 | params = None |
| 145 | elif hasattr(raw, '__iter__'): |
| 146 | try: |
| 147 | dict(raw) |
| 148 | except ValueError: |
| 149 | params = None |
| 150 | except TypeError: |
| 151 | params = None |
| 152 | else: |
| 153 | params = list(raw.items() if isinstance(raw, dict) else raw) |
| 154 | params = decode_params_utf8(params) |
| 155 | else: |
| 156 | params = None |
| 157 | |
| 158 | return params |
| 159 | |
| 160 | |
| 161 | def generate_nonce(): |
searching dependent graphs…