Read application/x-www-form-urlencoded data into entity.params.
(entity)
| 141 | # ------------------------------- Processors -------------------------------- # |
| 142 | |
| 143 | def process_urlencoded(entity): |
| 144 | """Read application/x-www-form-urlencoded data into entity.params.""" |
| 145 | qs = entity.fp.read() |
| 146 | for charset in entity.attempt_charsets: |
| 147 | try: |
| 148 | params = {} |
| 149 | for aparam in qs.split(b'&'): |
| 150 | for pair in aparam.split(b';'): |
| 151 | if not pair: |
| 152 | continue |
| 153 | |
| 154 | atoms = pair.split(b'=', 1) |
| 155 | if len(atoms) == 1: |
| 156 | atoms.append(b'') |
| 157 | |
| 158 | key = unquote_plus(atoms[0]).decode(charset) |
| 159 | value = unquote_plus(atoms[1]).decode(charset) |
| 160 | |
| 161 | if key in params: |
| 162 | if not isinstance(params[key], list): |
| 163 | params[key] = [params[key]] |
| 164 | params[key].append(value) |
| 165 | else: |
| 166 | params[key] = value |
| 167 | except UnicodeDecodeError: |
| 168 | pass |
| 169 | else: |
| 170 | entity.charset = charset |
| 171 | break |
| 172 | else: |
| 173 | raise cherrypy.HTTPError( |
| 174 | 400, 'The request entity could not be decoded. The following ' |
| 175 | 'charsets were attempted: %s' % repr(entity.attempt_charsets)) |
| 176 | |
| 177 | # Now that all values have been successfully parsed and decoded, |
| 178 | # apply them to the entity.params dict. |
| 179 | for key, value in params.items(): |
| 180 | if key in entity.params: |
| 181 | if not isinstance(entity.params[key], list): |
| 182 | entity.params[key] = [entity.params[key]] |
| 183 | entity.params[key].append(value) |
| 184 | else: |
| 185 | entity.params[key] = value |
| 186 | |
| 187 | |
| 188 | def process_multipart(entity): |
nothing calls this directly
no test coverage detected
searching dependent graphs…