def decodeCookies(url, server, headers, cookies):
    # the path of the request URL up to, but not including, the right-most /
    request_path = urlparse.urlparse(url)[2]
    if len(request_path) > 1 and request_path[-1] == '/':
        request_path = request_path[:-1]

    hdrcookies = Cookie.SimpleCookie("\n".join(map(lambda x: x.strip(), 
        headers.getallmatchingheaders('set-cookie'))))
    for cookie in hdrcookies.values():
        # XXX: there doesn't seem to be a way to determine if the
        # cookie was set or defaulted to an empty string :(
        if cookie['domain']:
            domain = cookie['domain']

            # reject if The value for the Domain attribute contains no
            # embedded dots or does not start with a dot.
            if '.' not in domain:
                raise Error, 'Cookie domain "%s" has no "."'%domain
            if domain[0] != '.':
                raise Error, 'Cookie domain "%s" doesn\'t start '\
                    'with "."'%domain
            # reject if The value for the request-host does not
            # domain-match the Domain attribute.
            if not server.endswith(domain):
                raise Error, 'Cookie domain "%s" doesn\'t match '\
                    'request host "%s"'%(domain, server)
            # reject if The request-host is a FQDN (not IP address) and
            # has the form HD, where D is the value of the Domain
            # attribute, and H is a string that contains one or more dots.
            if re.search(r'[a-zA-Z]', server):
                H = server[:-len(domain)]
                if '.' in H:
                    raise Error, 'Cookie domain "%s" too short '\
                    'for request host "%s"'%(domain, server)
        else:
            domain = server

        # path check
        path = cookie['path'] or request_path
        # reject if Path attribute is not a prefix of the request-URI
        # (noting that empty request path and '/' are often synonymous, yay)
        if not (request_path.startswith(path) or (request_path == '' and
                cookie['path'] == '/')):
            raise Error, 'Cookie path "%s" doesn\'t match '\
                'request url "%s"'%(path, request_path)

        bydom = cookies.setdefault(domain, {})
        bypath = bydom.setdefault(path, {})
        bypath[cookie.key] = cookie
Decode cookies into the supplied cookies dictionary
dataset/ETHPy150Open wesabe/fixofx/3rdparty/wsgi_intercept/webunit_intercept/cookie.py/decodeCookies