def parse_line(cls, line): """Parse a header line, returns a (name, content) tuple.""" assert isinstance(line, bytes) match = HEADER_FIELD_REGEX.match(line) if not match: raise HeaderParseError(line) name, content = (s.decode("ascii").strip() for s in match.groups(b"")) name = name.lower() if name != "set-cookie" or is_rfc1123_datetime(content): content = cls.split_field_content(content) return (name, content)
def split_field_content(cls, string): """Returns the string splitted at the commas.""" if "," in string and not is_rfc1123_datetime(string): return [s.strip() for s in string.split(",")] else: return string