Ver a proveniência

Take advantage of quoting/unquoting.

pull/24/head
Ben Kurtovic há 12 anos
ascendente
cometimento
409412ddcd
1 ficheiros alterados com 9 adições e 6 eliminações
  1. +9
    -6
      toolserver/cookies.py

+ 9
- 6
toolserver/cookies.py Ver ficheiro

@@ -1,26 +1,29 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-


import base64 import base64
from Cookie import BaseCookie
from Cookie import CookieError, SimpleCookie
from datetime import datetime, timedelta from datetime import datetime, timedelta
from os import path from os import path


class _CookieManager(BaseCookie):
class _CookieManager(SimpleCookie):
def __init__(self, environ): def __init__(self, environ):
self._path = path.split(environ["PATH_INFO"])[0] self._path = path.split(environ["PATH_INFO"])[0]
try: try:
super(_CookieManager, self).__init__(environ["HTTP_COOKIE"]) super(_CookieManager, self).__init__(environ["HTTP_COOKIE"])
except AttributeError:
except (CookieError, AttributeError):
super(_CookieManager, self).__init__() super(_CookieManager, self).__init__()


def value_decode(self, value): def value_decode(self, value):
unquoted = super(_CookieManager, self).value_decode(value)[0]
try: try:
return base64.b64decode(value).decode("utf8")
return base64.b64decode(unquoted).decode("utf8"), value
except (TypeError, UnicodeDecodeError): except (TypeError, UnicodeDecodeError):
return u"False"
return u"False", "False"


def value_encode(self, value): def value_encode(self, value):
return base64.b64encode(value.encode("utf8"))
encoded = base64.b64encode(value.encode("utf8"))
quoted = super(_CookieManager, self).value_encode(encoded)[1]
return value, encoded


@property @property
def path(self): def path(self):


Carregando…
Cancelar
Guardar