m mEc @smdZdkZdkZdkZdkZdkZdkZdklZdk l Z dZ dZ dZ hZxeiD]Zdee 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). N(s TupleType(sStringIOcCs5t|t|jotSn|t| |jS(N(tlentinitialtstringtFalse(RR((t./data/zmath/zope/lib/python/mechanize/_util.pyt startswithscCs6t|t|jotSn|t| |jS(N(RtfinalRR(RR((RtendswithscCs"y |dWn tSnXtSdS(Nt(txRtTrue(R ((Rt isstringlikes  cCs-x&|D]}ti|ptSqqWtS(N(Rtct SPACE_DICTthas_keyRR (RR ((Rtisspace s  cCsg}d}d}x|i|D]}t|do7|od|ti |f}qti |}q"|o|i |nti |ti |dd}d}q"W|o|i |n|S(sGet all values for a header. This returns a list of values for headers given more than once; each value in the result list is stripped in the same way as the result of getheader(). If the header is not given, return an empty list. Ris%s %st:iN( tresulttcurrentt have_headertmsgtgetallmatchingheaderstnametsRRtstriptappendtfind(RRRRRR((Rt getheaders/s"# (stimegmicCs|d \}}}}}}|tjod|jo djnod|jo djnohd|jo djnoJd|jo djno,d|jo djnot|SndSdS( Niii iiii;i=( ttttyeartmonthtmdaythourtmintsectEPOCHttimegmtNone(RRR R!RR"R((Rt my_timegmMstMontTuetWedtThutFritSattSuntJantFebtMartAprtMaytJuntJultAugtSeptOcttNovtDeccCs\|djoti}nti|d \}}}}}}d||||||fS(sHReturn a string representing time in seconds since epoch, t. If the function is called without an argument, it will use the current time. The format of the returned string is like "YYYY-MM-DD hh:mm:ssZ", representing Universal Time (UTC, aka GMT). An example of this format is: 1994-11-24 08:49:37Z is%04d-%02d-%02d %02d:%02d:%02dZN( ttR%ttimetgmtimeRtmonRR R!R"(R:RR R!R"RR=((Rt time2isoz\s  %cCsn|djoti}nti|d \}}}}}}}dt ||t |d||||fS(sReturn a string representing time in seconds since epoch, t. If the function is called without an argument, it will use the current time. The format of the returned string is like this: Wed, DD-Mon-YYYY HH:MM:SS GMT is"%s %02d-%s-%04d %02d:%02d:%02d GMTiN( R:R%R;R<RR=RR R!R"twdaytdaystmonths(R:RR R!R"RR?R=((Rt time2netscapems  (tGMTtUTCtUTtZs^([-+])?(\d\d?):?(\d\d)?$cCsd}ti|o d}nti|}|oodt|i d}|i do!|dt|i d}n|i ddjo | }qn|S(Niiiii<it-( R%toffsett UTC_ZONESRttzt timezone_retsearchtmtinttgroup(RJRMRH((Rtoffset_from_tz_strings !c Cs"y titi|d}Wnitj o]yt|}Wntj o dSnXd|jo djno |}qdSnX|djo d}n|djo d}n|djo d}nt|}t|}t|}t|}t|}|djotitid} | d} |}|| | }| |} t| djo)| djo|d}q|d}qnt|||||||f} | dj oU|djo d}nti|}t|} | djodSn| | } n| S(Nii iiidi2RD(t months_lowertindexRtlowerR=t ValueErrorRNtimonR%thrR!R"tyrtdayR;t localtimetcur_yrRMttmptabsR&RJR:tupperRPRH( RXR=RWRVR!R"RJR[RURZRHRMR:((Rt _str2timesR                !     sV^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$s+^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*s^ (\d\d?) # day (?:\s+|[-\/]) (\w+) # month (?:\s+|[-\/]) (\d+) # year (?: (?:\s+|:) # separator before clock (\d\d?):(\d\d) # hour:min (?::(\d\d))? # optional seconds )? # optional clock \s* ([-+]?\d{2,4}|(?![APap][Mm]\b)[A-Za-z]+)? # timezone \s* (?:\(\w+\))? # ASCII representation of timezone in parens. \s*$c CsAti|}|o|i}titi |dd}t |d|t |dt |dt |dt |df}t|Snti|}tid|d}d gd\} }} }}}}ti|}|d j o%|i\} }} }}}}nd St| || ||||S( sReturns time in seconds since epoch of time represented by a string. Return value is an integer. None is returned if the format of str is unrecognized, the time is outside the representable range, or the timezone string is not recognized. If the string contains no timezone, UTC is assumed. The timezone in the string may be numerical (like "-0800" or "+0100") or a string timezone (like "UTC", "GMT", "BST" or "EST"). Currently, only the timezone strings equivalent to UTC (zero offset) are known to the function. The function loosely parses the following formats: Wed, 09 Feb 1994 22:23:32 GMT -- HTTP format Tuesday, 08-Feb-94 14:15:29 GMT -- old rfc850 HTTP format Tuesday, 08-Feb-1994 14:15:29 GMT -- broken rfc850 HTTP format 09 Feb 1994 22:23:32 GMT -- HTTP format (no weekday) 08-Feb-94 14:15:29 GMT -- rfc850 format (no weekday) 08-Feb-1994 14:15:29 GMT -- broken rfc850 format (no weekday) The parser ignores leading and trailing whitespace. The time may be absent. If the year is given with only 2 digits, the function will select the century that makes the year closest to the current date. iiiiiiRiN(t strict_reRLttextRMtgroupstgRQRRRRSR=RNtfloatRR&tlstriptwkday_retsubR%RXRWRVR!R"RJt loose_http_reR^( R`RJRbR!RRMRVR"R=RWRX((Rt http2times  J" %s^ (\d{4}) # year [-\/]? (\d\d?) # numerical month [-\/]? (\d\d?) # day (?: (?:\s+|[-:Tt]) # separator before clock (\d\d?):?(\d\d) # hour:min (?::?(\d\d(?:\.\d*)?))? # optional seconds (and fractional) )? # optional clock \s* ([-+]?\d\d?:?(:?\d\d)? |Z|z)? # timezone (Z is "zero meridian", i.e. GMT) \s*$c Csti|}dgd\}}}}}}}t i |}|dj o(|i\}}}}}}}} ndSt|||||||S(sv As for http2time, but parses the ISO 8601 formats: 1994-02-03 14:15:29 -0100 -- ISO 8601 format 1994-02-03 14:15:29 -- zone is optional 1994-02-03 -- only date 1994-02-03T14:15:29 -- Use T as separator 19940203T141529Z -- ISO 8601 compact format 19940203 -- only date iN(RRdR`R%RXR=RWRVR!R"RJtiso_reRLRMRat_R^( R`RJR!RVRMR"R=RWRXRj((Rtiso2time"s " (t seek_wrappercBstZdZdZdZdZddZdZdZdZ d d Z d d Z d d Z d Z dZe ZdZRS(sAdds a seek method to a file object. This is only designed for seeking on readonly file-like objects. Wrapped file-like object must have a read method. The readline method is only supported if that method is present on the wrapped object. The readlines method is always supported. xreadlines and iteration are supported only for Python 2.2 and above. Public attribute: wrapped (the wrapped file object). WARNING: All other attributes of the wrapped object (ie. those that are not one of wrapped, read, readline, readlines, xreadlines, __iter__ and next) are passed through unaltered, which may or may not make sense for your particular file object. cCs7||_t|id|_t|_d|_dS(Ntreadlinei(twrappedtselfthasattrt_seek_wrapper__have_readlinetStringIOt_seek_wrapper__cachet_seek_wrapper__pos(RoRn((Rt__init__ds  cCs"|iit|iijS(N(RoRnttellRRstgetvalue(Ro((Rt invariantjscCs:|iid}|ot||Snt|i|S(NRn(Rot__dict__tgetRntgetattrRt __class__(RoRRn((Rt __getattr__osicCs|dddgjpt|djo'|djotdnd}n|djo'|djotdn|}n1|i}||jotdn||}t |i i }||}|djo d}n|djo|i idd|djoG|djpt|i i|ii|i i||_q|i i|ii|||_n ||_dS(Niiisnegative seek offsetsseek to before start of file(twhencetAssertionErrorRHRTR%tto_readtdestRoRttposRRsRwtendtseektwriteRntreadRv(RoRHR~RRRR((RRus4               cCs|iS(N(RoRt(Ro((RRvscCs"|i|i}|i|_|S(N(RoR|RntcpyRs(RoR((Rt__copy__s cCs8|i}z|id|idSWd||_XdS(Nii(RoRtRRR(RoR((Rtget_datas   icCs^|i}t|ii}||}||jo>|djo1|ii ||||_|ii |Sn|i i djodSn|ii dd|djo|ii |i i n;||}|djpt|ii |i i ||ii ||ii |}|ii|_|i|t|jpt|S(NiRii(RoRtRRRsRwRt availabletsizeRRRnR%RRRtdataRv(RoRRRRRR((RRs(     !cCs|iptdn|i}|iidd|ii|ii |ii||ii }|djo|| }|||_n|}|t ||_|S(Ns$no readline method on wrapped objectiii(RoRqtNotImplementedErrorRtRRsRRRnRmRRtrR(RoRRRR((RRms    cCsm|i}|iidd|ii|ii|ii||ii|}|ii |_|S(Nii( RoRtRRsRRRnRt readlinestsizehintRRv(RoRRR((RRs cCs|S(N(Ro(Ro((Rt__iter__scCs'|i}|djo tn|S(NR(RoRmtlinet StopIteration(RoR((Rtnexts  cCs&d|iitt||ifS(Ns$<%s at %s whose wrapped object = %r>(RoR|t__name__thextidRn(Ro((Rt__repr__s(Rt __module__t__doc__RuRxR}RRvRRRRmRRRt xreadlinesR(((RRlLs     )       tresponse_seek_wrappercBs2tZdZdZdZdZdZRS(sL Supports copying response objects and setting response body data. cCs&ti|||ii|_dS(N(RlRuRoRntinfot_headers(RoRn((RRuscCs+ti|}ti|i|_|S(N(RlRRoRtcopyRR(RoR((RRscCs|iS(N(RoR(Ro((RRscCsO|id|i|it}|_|i||iddS(Ni( RoRRtcloseRrtcacheRsRR(RoRR((Rtset_data s     (RRRRuRRR(((RRs    teoffilecBs;tZddZddZdZdZdZRS(NicCsdS(NR((RoR((RRscCsdS(NR((RoR((RRmscCs|S(N(Ro(Ro((RRscCsdS(NR((Ro((RRscCsdS(N((Ro((RRs(RRRRmRRR(((RRs     t eofresponsecBs#tZdZdZdZRS(NcCs(||_||_||_||_dS(N(turlRot_urltheadersRtcodeR(RoRRRR((RRus   cCs|iS(N(RoR(Ro((Rtgeturl!scCs|iS(N(RoR(Ro((RR"s(RRRuRR(((RRs  tcloseable_responsecBsStZdZeZdZdZdZdZdZ dZ dZ RS(s Avoids unnecessarily clobbering urllib.addinfourl methods on .close(). Only supports responses returned by mechanize.HTTPHandler. After .close(), the following methods are supported: .read() .readline() .readlines() .seek() .tell() .info() .geturl() .__iter__() .next() .close() and the following attributes are supported: .code .msg Also supports pickling (but the stdlib currently does something to prevent it: http://python.org/sf/1144636). cCs5|i|||_||_||_||_dS(N( Rot_set_fptfpRRRRRR(RoRRRRR((RRuCs     cCs||_|ii|_|ii|_t|ido|ii|_nt|ido|ii|_n d|_t|ido9|ii|_t|ido|ii|_qndS(NRtfilenocCsdS(N(R%(((RtRsRR( RRoRRmRpRRRR(RoR((RRJs  cCs&d|iitt||ifS(Ns<%s at %s whose fp = %r>(RoR|RRRR(Ro((RRXscCs|iS(N(RoR(Ro((RR\scCs|iS(N(RoR(Ro((RR_scCsE|i}|it|i|i|i|i}|i |dS(N( RoRRnRRRRRRt new_wrappedR(RoRnR((RRbs  !cCs>|ii}t|i|i|i|i}||d<|S(NRn( RoRyRtstateRRRRRR(RoRR((Rt __getstate__is! ( RRRR%RRuRRRRRR(((RR%s       c Csng}x|D]}|id|q Wtitdi|}t t|||||}t|S(sConvenient factory for objects implementing response interface. data: string containing response body data headers: sequence of (name, value) pairs url: URL of response code: integer response code (e.g. 200) msg: string response code message (e.g. "OK") s%s: %ss N(thdr_textRt name_valueRt mimetoolstMessageRrtjoint mime_headersRRRRRRR( RRRRRRRRR((Rt make_responses (3RtreRR;RturllibRttypest TupleTypet cStringIORrRRR R t whitespaceR R%RRtcalendarR$R#R&R@RARQRRRSR>RBRItcompileRKRPR^R_tIRetXRgRhRiRkRlRRRRR((RReRKRgRRlR$RRRRkRRR&RRRBR^RiRIRRRR#R RR>RR RQRrRR RARhR@RPR;R_R((Rt? sP6          *  *  6 9 * Z