Beispiel #1
0
else:  # pragma: no cover
    from urllib import (quote as _default_quote, unquote as _default_unquote)


def _total_seconds(td):
    """Wrapper to work around lack of .total_seconds() method in Python 3.1.
    """
    if hasattr(td, "total_seconds"):
        return td.total_seconds()
    return td.days * 3600 * 24 + td.seconds + td.microseconds / 100000.0


# see test_encoding_assumptions for how these magical safe= parms were figured
# out. the differences are because of what cookie-octet may contain
# vs the more liberal spec for extension-av
default_cookie_quote = lambda item: _default_quote(
    item, safe='!#$%&\'()*+/:<=>?@[]^`{|}~')

default_extension_quote = lambda item: _default_quote(
    item, safe=' !"#$%&\'()*+,/:<=>?@[\\]^`{|}~')

default_unquote = _default_unquote


def _report_invalid_cookie(data):
    "How this module logs a bad cookie when exception suppressed"
    logging.error("invalid Cookie: %r", data)


def _report_unknown_attribute(name):
    "How this module logs an unknown attribute when exception suppressed"
    logging.error("unknown Cookie attribute: %r", name)
Beispiel #2
0
else:  # pragma: no cover
    from urllib import (
        quote as _default_quote, unquote as _default_unquote)


def _total_seconds(td):
    """Wrapper to work around lack of .total_seconds() method in Python 3.1.
    """
    if hasattr(td, "total_seconds"):
        return td.total_seconds()
    return td.days * 3600 * 24 + td.seconds + td.microseconds / 100000.0

# see test_encoding_assumptions for how these magical safe= parms were figured
# out. the differences are because of what cookie-octet may contain
# vs the more liberal spec for extension-av
default_cookie_quote = lambda item: _default_quote(
    item, safe='!#$%&\'()*+/:<=>?@[]^`{|}~')

default_extension_quote = lambda item: _default_quote(
    item, safe=' !"#$%&\'()*+,/:<=>?@[\\]^`{|}~')

default_unquote = _default_unquote


def _report_invalid_cookie(data):
    "How this module logs a bad cookie when exception suppressed"
    logging.error("invalid Cookie: %r", data)


def _report_unknown_attribute(name):
    "How this module logs an unknown attribute when exception suppressed"
    logging.error("unknown Cookie attribute: %r", name)