Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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