™N L•;cshdZdZ kZkZkZ kZ kZ kZkZdfd„ƒYZ dS(su Copyright (C) 2000-2001 Brandon Long VirtualBrowser - a controllable/scriptable web agent s0.10sVirtualBrowsercsƒed„Z&d„Z-d„ZBedeed„Zdd„Z d„Z©d „Z±d „Z¾d „Z RS( Ncs¤dt|_t|_d|_t|_h|_h|_dg|_ ddddg|_ t i ƒ|_ !d|_$||_dS( NsVirtualBrowser/%ss localhostsens text/htmls text/plains image/jpegs image/gifix(sVERSIONsselfs _user_agentsNones _current_urls_hosts _last_urls_cookiess _auth_caches _languagess_typessurllibs URLopeners_fallback_openers_timeouts auth_callbacks_auth_callback(sselfs auth_callbacks./VirtualBrowser.pys__init__s      csC&'y(t|ƒ|_Wn)tj o *nX+|SdS(N(sintsosselfs_timeouts ValueError(sselfsos./VirtualBrowser.pystimeout_&s c s0-.|io/ti|i|ƒ}n0||_1ti|ƒ\}}2| o 3d}n4ti |ƒ\}}5| o6|i }n 8||_ 9ti |ƒ\}};|djoJ<|i|||ƒ\}}} } =|i|_>||| | fSn@|ii|ƒSdS(Nshttp(sselfs _last_urlsurllibsbasejoinsurls _current_urls splittypestypesrests splithostshostspaths_hosts splitportsports fetch_httpserrcodeserrmsgspagesheaderss_fallback_openersretrieve( sselfsurlstypesrestshostspathsportserrcodeserrmsgspagesheaderss./VirtualBrowser.pys fetchpage-s       $csIBC| o Dd}n9FyGt|ƒ}WnHtj oId}nXK|i||ƒ}Mti ||ƒ} N| i i |i ƒO|oP| i||ƒnR| id|ƒS| id|ƒT| id|iƒU| idti|idƒƒV| idti|idƒƒW|ioX| id|iƒnY|oZ| id |ƒn[|o0\|i||ƒ} ]| id d | ƒn^|o|o6_| id |ƒ`| id tt|ƒƒƒnb| iƒd|oe| i|ƒng| i ƒ\} } } h| i$ƒ}i|i&ƒ}j|i(ƒl| d jom| | || fSno| i)dƒorsxh| i*dƒdsrR}tti,|ddƒ\}}ut/i0ti1|ƒƒ}v|i3||ƒq»Wnx| djo0y|i4|_z| d}{|i6|ƒSn}| djoÊ~| i)dƒo³| d}€t8i9d|ƒ}|oƒ‚|i:ƒ\}}ƒ|| d<„|| d<…ti<|ƒdjo7‡|i||ƒoˆ|i=||||ƒSnnnnn‹| | || fSdS(NiPsGETsHosts User-AgentsAccepts, sAccept-LanguagesReferersCookies AuthorizationsBasic %ss Content-TypesContent-Lengthis set-cookieis:i.slocationi‘swww-authenticates![ ]*([^ ]+)[ ]+realm="([^"]*)"svirtualbrowser-auth-schemesvirtualbrowser-auth-realmsbasic(>sportsints ValueErrorsselfs getCookieshostspathscookieshttplibsHTTPshssocks set_timeouts_timeoutsmethods putrequests putheaders _user_agentsstringsjoins_typess _languagess _last_urlsrealmsgetAuthsauthsbodysctypesstrslens endheadersssendsgetreplyserrcodeserrmsgsheaderssgetfilesfsreadspagescloseshas_keysgetallmatchingheadersslinessplitsheadersvaluesCookiesMorselsstripsms addCookies _current_urlsnewurls fetchpages auth_headersresmatchsgroupssschemeslowers fetch_http(sselfshostsportspathsrealmsmethodsbodysctypescookieshsauthserrcodeserrmsgsheaderssfspageslinesheadersvaluesmsnewurls auth_headersmatchsschemes./VirtualBrowser.pys fetch_httpBsr   ""   #         -sGETc s-Ž|ioti|i|ƒ}n||_‘ti|ƒ\}}’| o “d}n”ti |ƒ\}}•| o–|i }n ˜||_ ™ti |ƒ\}}›ti|ƒ} œ|i|||ddd| d|ƒ\} } } } |i|_ž| | | | fSdS(NshttpsmethodsPOSTsbodysctype(sselfs _last_urlsurllibsbasejoinsurls _current_urls splittypestypesrests splithostshostspaths_hosts splitportsports urlencodes post_dictsdatas fetch_httpsctypeserrcodeserrmsgspagesheaders(sselfsurls post_dictsctypestypesrestshostspathsportsdataserrcodeserrmsgspagesheaderss./VirtualBrowser.pysdo_posts      6s!application/x-www-form-urlencodedcsŒ ¡|dti|ƒ}¢|ii|ƒo£|i|Sn¤|io/¥|i\}}¦|i ||||ƒSn§t SdS(Ns@( srealmsstringslowershostskeysselfs _auth_cacheshas_keys_auth_callbacksuserspasswordsaddAuthsNone(sselfshostsrealmskeysuserspasswords./VirtualBrowser.pysgetAuth s c so©ªk}«|dti|ƒ}¬d||f}­ti |i |ƒƒ}®||i |<¯|SdS(Ns@s%s:%s(sbase64srealmsstringslowershostskeysuserspasswordsupsstrips encodestringsauthsselfs _auth_cache( sselfshostsrealmsuserspasswordsbase64skeysupsauths./VirtualBrowser.pysaddAuth©s  c sý±²g}³t|ƒ}´xª|iiƒd´r”\}}µt|ƒ}¶||||jo|t|ƒ |joJ·x@|i||fd·r&}¸|i d|i |ifƒq–Wnq0Wº|gjo »tSn¼ti|dƒSdS(Nis%s=%ss; (s cookie_strslenshostshlensselfs_cookiesskeyssdomainscpathsdlenspathsmorselsappendskeysvaluesNonesstringsjoin( sselfshostspaths cookie_strshlensdomainscpathsdlensmorsels./VirtualBrowser.pys getCookie±s / , cs¾¿yÀ|d}WnÁtj oÂ|}nXÃyÄ|d}WnÅtj oÆd}nXÈ||f}É|ii|ƒolÊxK|i|dÊr7}Ë|i |i joÌ|i|i |ƒnq§WÍ|i|i |ƒnÏ|g|i|