Let Python's cookie.py module support the colon-key approach _python

Source: Internet
Author: User
For compatibility, you can only select a compatible: colon.

It's easy to change the Cookie.morsel
Copy Code code as follows:

#!/usr/bin/python
#-*-Coding:utf-8-*-
"" "Morselhook, fix Cookie.CookieError:Illegal key value:ys-tab:entrance:e
"""

Import Cookie
Import string

_morsel = Cookie.morsel

Class Morselhook (_morsel):
"""
>>> Import Inspect
>>> (Inspect.getargspec (Morselhook.set) [3]) [0]
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!#$%& ' *+-.^_ ' |~:"
>>> cookies = Cookie.simplecookie ()
>>> cookie.load ("YS-TAB:ENTRANCE:E=ABC; Webpy_session_id=75eb60dcc83e2d902146af0bb7f47afe61fbd2b2 ")
>>> Print Cookies
SET-COOKIE:WEBPY_SESSION_ID=75EB60DCC83E2D902146AF0BB7F47AFE61FBD2B2;
SET-COOKIE:YS-TAB:ENTRANCE:E=ABC;
"""
def set (self, key, Val, Coded_val, legalchars=cookie._legalchars+ ': ', Idmap=string._idmap, translate=string.translate ):
Return super (Morselhook, self). Set (Key, Val, Coded_val, Legalchars, Idmap, translate)

Cookie.morsel = Morselhook

# Let the above code execute once where you need to use cookies


if __name__ = = ' __main__ ':
Import Doctest
Doctest.testmod ()
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.