def _from_string(self, header_string, value_re=HEADER_VALUE_REGEXP): # Match header value and remove from string m = value_re.match(header_string) if not m: raise HttpHeaderError('%s: invalid header' % header_string) value = m.groups()[0] attr_string = header_string[m.end():] # Split and parse string of header attributes attributes = [] for s in split_quoted(attr_string, delimiter=';'): if not s: continue try: k, v = split_quoted(s.strip(), delimiter='=', remove_quotes=True) except ValueError: raise HttpHeaderError("'%s': failed to parse header attribute" % s) attributes.append((k, v)) return (value, attributes)
def _from_string(self, s): try: k, v = split_quoted(s, delimiter='=', remove_quotes=True) except ValueError: raise HttpHeaderError return (k, v)
def parse(self, header_value): self._headers = [self._from_string(value.strip()) for value in split_quoted(header_value)] return self._headers