Python Cookie 模块,Cookie() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用Cookie.Cookie()

项目:w4py    作者:Cito    | 项目源码 | 文件源码
def delCookie(self, name, path='/', secure=False):
        """Delete a cookie at the browser.

        To do so, one has to create and send to the browser a cookie with
        parameters that will cause the browser to delete it.
        """
        if name in self._cookies:
            self._cookies[name].delete()
        else:
            cookie = Cookie(name, None)
            if path:
                cookie.setPath(path)
            if secure:
                cookie.setSecure(secure)
            cookie.delete()
            self.addCookie(cookie)
项目:w4py    作者:Cito    | 项目源码 | 文件源码
def writeHeaders(self):
        """Write headers to the response stream. Used internally."""
        if self._committed:
            print "response.writeHeaders called when already committed"
            return
        # make sure the status header comes first
        if 'Status' in self._headers:
            # store and temporarily delete status
            status = self._headers['Status']
            del self._headers['Status']
        else:
            # invent meaningful status
            status = '302 Found' if 'Location' in self._headers else '200 OK'
        head = ['Status: %s' % status]
        head.extend(map(lambda h: '%s: %s' % h, self._headers.items()))
        self._headers['Status'] = status  # restore status
        head.extend(map(lambda c: 'Set-Cookie: %s' % c.headerValue(),
            self._cookies.values()))
        head.extend(['']*2)  # this adds one empty line
        head = '\r\n'.join(head)
        self._strmOut.prepend(head)
项目:w4py    作者:Cito    | 项目源码 | 文件源码
def rawResponse(self):
        """Return the final contents of the response.

        Don't invoke this method until after deliver().

        Returns a dictionary representing the response containing only
        strings, numbers, lists, tuples, etc. with no backreferences.
        That means you don't need any special imports to examine the contents
        and you can marshal it. Currently there are two keys. 'headers' is
        list of tuples each of which contains two strings: the header and
        it's value. 'contents' is a string (that may be binary, for example,
        if an image were being returned).
        """
        headers = []
        for key, value in self._headers.items():
            headers.append((key, value))
        for cookie in self._cookies.values():
            headers.append(('Set-Cookie', cookie.headerValue()))
        return dict(headers=headers, contents=self._strmOut.buffer())
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def value_encode(self, val):
        if type(val) == type(""):
            return val, _quote(val)
        else:
            return val, _quote( dumps(val) )
# end SmartCookie


###########################################################
# Backwards Compatibility:  Don't break any existing code!

# We provide Cookie() as an alias for SmartCookie()
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:PyS60-Projects    作者:gauravssnl    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:PyS60-Projects    作者:gauravssnl    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output
项目:PyS60-Projects    作者:gauravssnl    | 项目源码 | 文件源码
def load(self, rawdata):
        """Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        """
        if type(rawdata) == type(""):
            self.__ParseString(rawdata)
        else:
            # self.update() wouldn't call our custom __setitem__
            for k, v in rawdata.items():
                self[k] = v
        return
    # end load()
项目:PyS60-Projects    作者:gauravssnl    | 项目源码 | 文件源码
def __init__(self, input=None):
        warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
                      DeprecationWarning)
        BaseCookie.__init__(self, input)
    # end __init__
项目:PyS60-Projects    作者:gauravssnl    | 项目源码 | 文件源码
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def output(self, attrs=None, header = "Set-Cookie:"):
        return "%s %s" % ( header, self.OutputString(attrs) )
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
        """Return a string suitable for HTTP."""
        result = []
        items = self.items()
        items.sort()
        for K,V in items:
            result.append( V.output(attrs, header) )
        return sep.join(result)
    # end output