zfc@sdZddlZddlZddlmZmZmZmZmZm Z m Z m Z m Z dZ defdYZdS(sLoad / save to libwww-perl (LWP) format files. Actually, the format is slightly extended from that used by LWP's (libwww-perl's) HTTP::Cookies, to avoid losing some RFC 2965 information not recorded by LWP. It uses the version string "2.0", though really there isn't an LWP Cookies 2.0 format. This indicates that there is extra information in here (domain_dot and # port_spec) while still being compatible with libwww-perl, I hope. iN( t_warn_unhandled_exceptiont FileCookieJart LoadErrortCookietMISSING_FILENAME_TEXTtjoin_header_wordstsplit_header_wordstiso2timet time2isozcCs|j|jfd|jfd|jfg}|jd k rU|jd|jfn|jrn|jdn|jr|jdn|j r|jdn|j r|jdn|j r|jdt t |j fn|jr|jdn|jr"|jd |jfn|jrD|jd |jfn|jj}|jx.|D]&}|j|t|j|fqdW|jd t|jft|gS(sReturn string representation of Cookie in the LWP cookie file format. Actually, the format is extended a bit -- see module docstring. tpathtdomaintportt path_spect port_spect domain_dottsecuretexpirestdiscardtcommentt commenturltversionN(R N(R N(RN(RN(RN(tnametvalueR R R tNonetappendtpath_specifiedtport_specifiedtdomain_initial_dotRRRtfloatRRt comment_urlt_resttkeystsorttstrRR(tcookiethRtk((s%/usr/lib64/python2.7/_LWPCookieJar.pytlwp_cookie_strs8           $t LWPCookieJarcBs8eZdZeedZdeedZdZRS(s[ The LWPCookieJar saves a sequence of "Set-Cookie3" lines. "Set-Cookie3" is the format used by the libwww-perl library, not known to be compatible with any browser, but which is easy to read and doesn't lose information about RFC 2965 cookies. Additional methods as_lwp_str(ignore_discard=True, ignore_expired=True) cCstj}g}xW|D]O}| r5|jr5qn| rQ|j|rQqn|jdt|qWdj|dgS(sReturn cookies as a string of "\n"-separated "Set-Cookie3" headers. ignore_discard and ignore_expires: see docstring for FileCookieJar.save sSet-Cookie3: %ss t(ttimeRt is_expiredRR%tjoin(tselftignore_discardtignore_expirestnowtrR"((s%/usr/lib64/python2.7/_LWPCookieJar.pyt as_lwp_str>s  cCs|dkr6|jdk r'|j}q6ttnt|d}z*|jd|j|j||Wd|jXdS(Ntws#LWP-Cookies-2.0 (Rtfilenamet ValueErrorRtopentwriteR0tclose(R+R2R,R-tf((s%/usr/lib64/python2.7/_LWPCookieJar.pytsaveNs   cCs |j}tj|j|s:d|}t|ntj}d}d} d} ykxd|j} | dkrzPn| j|sq^n| t|j} xt | gD]} | d\} }i}i}x| D]}t || s@