mò mã¸Ec@s÷dZdkZdkZdkZdkZdkZdkZeidjo dkZndk l Z l Z l Z l Z lZdklZeidƒiZd„ZdZd„Zd „Zd „Zd fd „ƒYZd ee fd„ƒYZdS(spMicrosoft Internet Explorer cookie loading on Windows. Copyright 2002-2003 Johnny Lee (MSIE Perl code) Copyright 2002-2006 John J Lee (The Python port) This code is free software; you can redistribute it and/or modify it under the terms of the BSD or ZPL 2.1 licenses (see the file COPYING.txt included with the distribution). Ntnt(s FileCookieJars CookieJarsCookiesMISSING_FILENAME_TEXTs LoadError(s startswitht mechanizecCsXtiti|dtiƒ}yti||ƒd}Wnt j o d}nX|S(Ni( t_winregtOpenKeytHKEY_CURRENT_USERtpathtKEY_ALL_ACCESStkeyt QueryValueExtleaftvaluet WindowsErrortNone(RR R R((t7/data/zmath/zope/lib/python/mechanize/_msiecookiejar.pytregloads  l}*{Gí cCs<|tjotd|tfƒ‚nt|tdƒdS(s#Convert from win32 filetime to seconds-since-epoch value. MSIE stores create and expire times as Win32 FILETIME, which is 64 bits of 100 nanosecond intervals since Jan 01 1601. mechanize expects time in 32-bit value expressed in seconds since the epoch (Jan 01 1970). s"filetime (%d) is before epoch (%d)l€1iN(tfiletimet WIN32_EPOCHt ValueErrortdivmod(R((R t%epoch_time_offset_from_win32_filetime$s  cCsdt|ƒS(Ns%02X(tordtc(R((R tbinary_to_char4scCstittt|ƒƒdƒS(Nt(tstringtjointmapRtlisttd(R((R t binary_to_str5stMSIEBasecBsŒtZeidƒZdZeidƒZeidƒZdZdZ d„Z d„Z d „Z e e d „Ze e dd „Zd „ZRS( Ns Client UrlCache MMF Ver \d\.\d.*s ð­ s^([^/]+)(/.*)$s(Cookie\:.+\@([!-ÿ]+).*?(.+\@[!-ÿ]+\.txt)s@software\microsoft\windows\currentversion\explorer\shell folderstCookiescCs h|_dS(N(tselft_delayload_domains(R ((R t__init__DscCs€|ii|ƒ}|dj o]|\}}}y|i |||ƒWn&t t fj ot d|ƒq|X|i|=ndS(Ns'error reading cookie file, skipping: %s( R R!tgettdomaintdelayload_infoR t cookie_filetignore_discardtignore_expirestload_cookie_datat LoadErrortIOErrortdebug(R R$R'R&R%R(((R t_delayload_domainGs  c Cs£td|ƒg}t|ƒ}zrxk|iƒ}|djoPn|i} | d„}| d„}|i ƒ}|ƒ} |ƒ} |ƒ} |ƒ}|ƒ}|ƒ} |ƒ}|ƒ}d|| | | |||| |f jp |djoPn|ii| ƒ}|o€|idƒ}|idƒ}|ihd|<d | <d |<d |<d | <d |<d|<d|<d| <ƒq%q%WWd|iƒX|S(NsLoading MSIE cookies file: %siRcCst|ƒiƒƒS(N(tlongtrltrstrip(R/((R tgetlong`scCs |ƒiƒS(N(R/R0(R/((R tgetstrast*itKEYtVALUEtDOMAINtPATHtFLAGStHIXPtLOXPtHICREATEtLOCREATE(R,tfilenametcookiestopent cookies_fhtreadlineRR/R1R2R0R t domain_pathtflagst lo_expiret hi_expiret lo_createt hi_createtsepR tmsie_domain_retsearchtmtgroupR$Rtappendtclose(R R=R@R>RDRHRER1RKRBR R/RFRCRRRGR2R$((R t_load_cookies_from_fileTs>                5k cCsUttiƒƒ} |i|ƒ}x-|D]%} | d} | d@dj}| dd>| d}t |ƒ}|| jo t }nt}| d}t|dƒ} | o t }nt}td| d | d d t||| | d t|||d d hd | <ƒ} | o| ioq(n| o| i| ƒoq(nti|| ƒq(Wd S(sµLoad cookies from file containing actual cookie data. Old cookies are kept unless overwritten by newly loaded ones. You should not call this method if the delayload attribute is set. I think each of these files contain all cookies for one user, domain, and path. filename: file containing cookies -- usually found in a file like C:\WINNT\Profiles\joe\Cookies\joe@blah[1].txt R8i iR9i R:R6t.R4R5R7RCN(tintttimetnowR ROR=t cookie_datatcookieRCtsecureRRtexpirestTruetdiscardtFalseR$t startswitht initial_dottdomain_specifiedtCookieR RR'R(t is_expiredt CookieJart set_cookie(R R=R'R(R$RVRRWR]RURSRR\RCRYRT((R R)sB        cCsPt|i|iƒ}tiitii|dƒƒ}|i ||||ƒdS(s3 username: only required on win9x s INDEX.DATN(RR treg_pathtreg_keyt cookies_dirtosRtnormpathRR=tloadR'R(tusername(R R'R(RhRdR=((R tload_from_registry½s!cCs“ttiƒƒ}|djotitidƒ}nti i |ƒ}|idƒ}t|ƒdjotd|ƒ‚n|d |dd!|d} } }tid| ƒd} |ii| ƒ p | djo#td t|ƒ| | fƒ‚n|i| dƒd }xxd }d |} |i| ƒ}t|ƒ| joPn||}|d |dd!|d} } }tid| ƒd} | d |} | djo¬| dd|idfjdt| ƒfpt ‚| djoPn| |ijoqn| djpt ‚| d jo(| djpt ‚|i| d ƒqqn| d jo5|i| ƒ} t| ƒ| joPn|| }nd|d|} t#i$| |t#i%ƒ}|o¿ti i'||i(d ƒƒ}|i*pDy|i+|||ƒWq†tt.fj ot/d|ƒq†XqŠ|i(d ƒ}|i1dƒ}|djo|| }n|||f|i3| t MSIECookieJarcBsVtZdZeeed„Zd„Zd„Zd„Zd„Z eeed„Z RS(skFileCookieJar that reads from the Windows MSIE cookies database. MSIECookieJar can read the cookie files of Microsoft Internet Explorer (MSIE) for Windows version 5 on Windows NT and version 6 on Windows XP and Windows 98. Other configurations may also work, but are untested. Saving cookies in MSIE format is NOT supported. If you save cookies, they'll be in the usual Set-Cookie3 format, which you can read back in using an instance of the plain old CookieJar class. Don't save using the same filename that you loaded cookies from, because you may succeed in clobbering your MSIE cookies index file! You should be able to have LWP share Internet Explorer's cookies like this (note you need to supply a username to load_from_registry if you're on Windows 9x or Windows ME): cj = MSIECookieJar(delayload=1) # find cookies index file in registry and load cookies from it cj.load_from_registry() opener = mechanize.build_opener(mechanize.HTTPCookieProcessor(cj)) response = opener.open("http://example.com/") Iterating over a delayloaded MSIECookieJar instance will not cause any cookies to be read from disk. To force reading of all cookies from disk, call read_all_cookies. Note that the following methods iterate over self: clear_temporary_cookies, clear_expired_cookies, __len__, __repr__, __str__ and as_string. Additional methods: load_from_registry(ignore_discard=False, ignore_expires=False, username=None) load_cookie_data(filename, ignore_discard=False, ignore_expires=False) read_all_cookies() cCs'ti|ƒti||||ƒdS(N(RR"R t FileCookieJarR=R‡tpolicy(R R=R‡R((R R"Ps cCs2|io|i|iƒnti||ƒdS(N(R R‡R-RUR$R`Ra(R RU((R RaTs cCs_|iiƒ}|i|iƒ|iƒ}g}x'|D]}|i |i ||ƒƒq8W|S(s2Return a list of cookies to be returned to server.N( R t_cookiestcopytdomainstupdateR!tkeysR>R$textendt_cookies_for_domaintrequest(R R˜R“R>R$((R t_cookies_for_requestYs cCsY|ii||ƒpgSntd|ƒ|io|i|ƒnti |||ƒS(Ns!Checking %s for cookies to return( R t_policytdomain_return_okR$R˜R,R‡R-R`R—(R R$R˜((R R—ds   cCs9|io+x(|iiƒD]}|i|ƒqWndS(sEagerly read in all cookies.N(R R‡R!R•R$R-(R R$((R tread_all_cookiesls  cCsx|djo-|idj o |i}q:ttƒ‚nt|dƒ}z|i|||||ƒWd|i ƒXdS(sžLoad cookies from an MSIE 'index.dat' cookies index file. filename: full path to cookie index file username: only required on win9x trbN( R=R R RtMISSING_FILENAME_TEXTR?RsRŠR'R(RhRN(R R=R'R(RhRs((R Rgrs   ( R‹RŒt__doc__R RZR"RaR™R—RœRg(((R RŽ,s #   (RŸReR…RRRRytloggingtnameRt _clientcookieRR`R^RžR*t_utilR[t getLoggerR,RRRRRRRŽ(R[RR RyRRžRR^R*RRŽRR…RRRRR,R`ReRR((R t? s6 %     õ