def url_encoded_data(self): if self.headers.content_type == \ media.application_x_www_form_urlencoded and \ okay(self.decoded_body) and self.content_is_full: for char in iterbytes(self.decoded_body): if not URL_ENCODED_GOOD_CHARS[ord(char)]: self.complain(1040, char=format_chars([char])) return Unavailable(self.decoded_body) # pylint: disable=no-member return parse_qs(self.decoded_body.decode('ascii')) return None
def _check_protocol_id(complain, encoded_id): # Since there is only one correct way to encode # an ALPN protocol ID into an RFC 7838 ``protocol-id``, # we just compute it and compare to what's in the message. decoded_id = pct_decode(force_bytes(encoded_id)) correct_encoded_id = u'' for c in iterbytes(decoded_id): if (tchar - '%').match(c): correct_encoded_id += force_unicode(c) else: correct_encoded_id += pct_encode(c, safe='').upper() if encoded_id != correct_encoded_id: complain(1256, actual=encoded_id, correct=correct_encoded_id) return decoded_id
def _check_basic_auth(req, hdr, credentials): if isinstance(credentials, str): # ``token68`` form try: credentials = base64.b64decode(credentials) except Exception as e: req.complain(1210, header=hdr, error=e) else: # RFC 7617 section 2 requires that, # whatever the encoding of the credentials, # it must be ASCII-compatible, so we don't need to know it. if b':' not in credentials: req.complain(1211, header=hdr) for c in iterbytes(credentials): if CTL.match(c): req.complain(1212, header=hdr, char=hex(ord(c))) else: req.complain(1209, header=hdr)