Exemplo n.º 1
0
def parse_setcookie(rawstr):
    kwargs = {"secure": False}
    parts = rawstr.split(";")
    name, value = parts[0].strip().split("=", 1)
    for otherpart in parts[1:]:
        subparts = otherpart.strip().split("=", 1)
        try:
            n, v = subparts
        except ValueError:
            if subparts[0].startswith("sec"):
                kwargs["secure"] = True
            else:
                raise
        else:
            n = n.strip().lower()
            v = v.strip()
            if n.startswith("exp"):
                try:
                    t = timelib.strptime(v, "%a, %d-%b-%Y %H:%M:%S %Z")
                except ValueError:  # might get 2 digit year, so try again.
                    t = timelib.strptime(v, "%a, %d-%b-%y %H:%M:%S %Z")
                kwargs[n] = calendar.timegm(t)
            else:
                kwargs[n] = v
    return RawCookie(name, value, **kwargs)
Exemplo n.º 2
0
def parse_setcookie(rawstr):
    kwargs = {"secure": False}
    parts = rawstr.split(";")
    name, value = parts[0].strip().split("=", 1)
    for otherpart in parts[1:]:
        subparts = otherpart.strip().split("=", 1)
        try:
            n, v = subparts
        except ValueError:
            if subparts[0] == "secure":
                kwargs["secure"] = True
            elif subparts[0] == "HttpOnly":
                kwargs["httponly"] = True
            else:
                raise
        else:
            n = n.strip().lower()
            v = v.strip()
            if n.startswith("exp"):
                try:
                    t = timelib.strptime(v, "%a, %d-%b-%Y %H:%M:%S %Z")
                except ValueError:  # might get 2 digit year, so try again.
                    t = timelib.strptime(v, "%a, %d-%b-%y %H:%M:%S %Z")
                kwargs[n] = calendar.timegm(t)
            else:
                kwargs[n] = v
    return RawCookie(name, value, **kwargs)
Exemplo n.º 3
0
 def parse(self, datestring):
     try:
         t = timelib.strptime(datestring, "%a, %d %b %Y %H:%M:%S GMT") # rfc1123 style
     except ValueError:
         try:
             t = timelib.strptime(datestring, "%A, %d-%b-%y %H:%M:%S GMT") # rfc850 style
         except ValueError:
             try:
                 t = timelib.strptime(datestring, "%a %b %d %H:%M:%S %Y") # asctime style
             except ValueError:
                 raise ValueInvalidError(datestring)
     self._value = t
Exemplo n.º 4
0
 def parse(self, datestring):
     try:
         t = timelib.strptime(datestring, "%a, %d %b %Y %H:%M:%S GMT")  # rfc1123 style
     except ValueError:
         try:
             t = timelib.strptime(datestring, "%A, %d-%b-%y %H:%M:%S GMT")  # rfc850 style
         except ValueError:
             try:
                 t = timelib.strptime(datestring, "%a %b %d %H:%M:%S %Y")  # asctime style
             except ValueError:
                 raise ValueInvalidError(datestring)
     self._value = t