Ejemplo n.º 1
0
    def __init__(self, iterable, status, headers):
        self._text = None

        self._content = b''.join(iterable)
        if hasattr(iterable, 'close'):
            iterable.close()

        self._status = status
        self._status_code = int(status[:3])
        self._headers = CaseInsensitiveDict(headers)

        self._encoding = get_encoding_from_headers(self._headers)
Ejemplo n.º 2
0
    def __init__(self, iterable, status, headers):
        self._text = None

        self._content = b''.join(iterable)
        if hasattr(iterable, 'close'):
            iterable.close()

        self._status = status
        self._status_code = int(status[:3])
        self._headers = CaseInsensitiveDict(headers)

        self._encoding = helpers.get_encoding_from_headers(self._headers)
Ejemplo n.º 3
0
    def __init__(self, iterable, status, headers):
        self._text = None

        self._content = b''.join(iterable)
        if hasattr(iterable, 'close'):
            iterable.close()

        self._status = status
        self._status_code = int(status[:3])
        self._headers = CaseInsensitiveDict(headers)

        cookies = http_cookies.SimpleCookie()
        for name, value in headers:
            if name.lower() == 'set-cookie':
                cookies.load(value)

                if _PY26 or (_PY27 and _JYTHON):
                    match = re.match(r'\s*([^=;,]+)=', value)
                    assert match

                    cookie_name = match.group(1)

                    # NOTE(kgriffs): py26/Jython has a bug that causes
                    # SimpleCookie to incorrectly parse the "expires"
                    # attribute, so we have to do it ourselves. This
                    # algorithm is obviously very naive, but it should
                    # work well enough until we stop supporting
                    # 2.6, at which time we can remove this code.
                    match = re.search('expires=([^;]+)', value)
                    if match:
                        cookies[cookie_name]['expires'] = match.group(1)

                    # NOTE(kgriffs): py26/Jython's SimpleCookie won't
                    # parse the "httponly" and "secure" attributes, so
                    # we have to do it ourselves.
                    if 'httponly' in value:
                        cookies[cookie_name]['httponly'] = True

                    if 'secure' in value:
                        cookies[cookie_name]['secure'] = True

        self._cookies = dict(
            (morsel.key, Cookie(morsel))
            for morsel in cookies.values()
        )

        self._encoding = helpers.get_encoding_from_headers(self._headers)
Ejemplo n.º 4
0
    def __init__(self, iterable, status, headers):
        self._text = None

        self._content = b''.join(iterable)
        if hasattr(iterable, 'close'):
            iterable.close()

        self._status = status
        self._status_code = int(status[:3])
        self._headers = CaseInsensitiveDict(headers)

        cookies = http_cookies.SimpleCookie()
        for name, value in headers:
            if name.lower() == 'set-cookie':
                cookies.load(value)

                if _PY26 or (_PY27 and _JYTHON):
                    match = re.match(r'\s*([^=;,]+)=', value)
                    assert match

                    cookie_name = match.group(1)

                    # NOTE(kgriffs): py26/Jython has a bug that causes
                    # SimpleCookie to incorrectly parse the "expires"
                    # attribute, so we have to do it ourselves. This
                    # algorithm is obviously very naive, but it should
                    # work well enough until we stop supporting
                    # 2.6, at which time we can remove this code.
                    match = re.search('expires=([^;]+)', value)
                    if match:
                        cookies[cookie_name]['expires'] = match.group(1)

                    # NOTE(kgriffs): py26/Jython's SimpleCookie won't
                    # parse the "httponly" and "secure" attributes, so
                    # we have to do it ourselves.
                    if 'httponly' in value:
                        cookies[cookie_name]['httponly'] = True

                    if 'secure' in value:
                        cookies[cookie_name]['secure'] = True

        self._cookies = dict(
            (morsel.key, Cookie(morsel))
            for morsel in cookies.values()
        )

        self._encoding = helpers.get_encoding_from_headers(self._headers)
Ejemplo n.º 5
0
    def __init__(self, iterable, status, headers):
        self._text = None

        self._content = b''.join(iterable)

        self._status = status
        self._status_code = int(status[:3])
        self._headers = CaseInsensitiveDict(headers)

        cookies = http_cookies.SimpleCookie()
        for name, value in headers:
            if name.lower() == 'set-cookie':
                cookies.load(value)

        self._cookies = dict(
            (morsel.key, Cookie(morsel)) for morsel in cookies.values())

        self._encoding = helpers.get_encoding_from_headers(self._headers)
Ejemplo n.º 6
0
    def __init__(self, iterable, status, headers):
        self._text = None

        self._content = b''.join(iterable)

        self._status = status
        self._status_code = int(status[:3])
        self._headers = CaseInsensitiveDict(headers)

        cookies = http_cookies.SimpleCookie()
        for name, value in headers:
            if name.lower() == 'set-cookie':
                cookies.load(value)

        self._cookies = dict(
            (morsel.key, Cookie(morsel))
            for morsel in cookies.values()
        )

        self._encoding = helpers.get_encoding_from_headers(self._headers)