;ò ðHfCc@sEdZdklZdklZdklZdkZdk Z dk l Z l Z dk lZlZdefd„ƒYZd klZlZyd klZWnnXyd klZWn eZnXd fd „ƒYZdefd„ƒYZd„Zd„Zd„Zd„Zd„Zd„Z e!djo e ƒndS(s$Revision: 1.19 $(smktemp(s StringType(s SimpleCookieN(sSessionsCookieFileImpl(sHTTP_MOVED_PERMANENTLYsHTTP_MOVED_TEMPORARILYs SERVER_RETURNcBstZRS(N(s__name__s __module__(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys SERVER_RETURNs(surlparses urlunparse(s urlencode(sUrls RequestIOcBs°tZdZdd„Zed„Zd„Zd„Zd„Zdd„Z d „Z d „Z d „Z d „Z d „Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s® RequestIO is a proxy ouput stream. Everything writen to it will be buffered until the headers are sent or complete. Then the contents is flused to the real out stream. iÿÿÿÿcCsdSdS(Ns((sselfsn((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysread0scCsdSdS(Ns((sselfslength((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysreadline1scCsgSdS(N((sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys readlines2scCs|idi|ƒƒdS(Ns(sselfswritesjoinslist(sselfslist((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys writelines3scCsdSdS(Ni((sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysisatty5sicCsdS(N((sselfspossmode((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysseek6scCs(d|_d|_d|_t|_dS(Nis(sselfsposs headers_sentsoutsNones header_out(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys__init__8s   cCsZ| odSn|i o|i|7_n|iƒi|ƒ|it|ƒ7_dS(N(sssselfs headers_sentsouts getOutStreamswritesposslen(sselfss((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyswrite>s  cCs#|iƒi|iƒd|_dS(Ns(sselfs getOutStreamswritesout(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysflushFscCs1|itjo|iiƒ|_n|iSdS(N(sselfs header_outsNonesimpls getHeadersOut(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys getHeadersOutKscCs |iSdS(N(sselfspos(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pystellPscCs|iƒ|iƒdS(N(sselfssend_http_headersflush(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyscloseQs cCs d|_dS(Ni(sselfs headers_sent(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys headersSentVscCs|iƒdS(N(sselfsclose(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys__del__YscCs7t|ƒtjot|ƒ}n||iƒ| dict returns a dictionary of cookies. sN(sselfscookiessNones getEnvironsimpls getCookieKeys CookiePotsload(sselfscookies((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys getCookiesÒs cCs|iƒi||ƒSdS(so returns the cookie requested by key otherwise returns default, if default is not given returns None. N(sselfs getCookiessgetskeysdefault(sselfskeysdefault((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys getCookieáscKse|iƒ}||| 1 | 0 tests if a field in a form was filled. N(sselfs getInputsshas_keyskey(sselfskey((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyshasInput%scGsFgi}|D]-}||iƒiƒjo||ƒqq~SdS(N(sappends_[1]skeysskeysselfs getInputs(sselfskeyss_[1]skey((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys hasInputs+scCs¾|i o|ii|ƒ|_n| o |iSnt|idƒo|ii|ƒSn]|ii|ƒoE|ii|ƒ}|ot |ƒt gƒjo|Sq¶|gSngSdS(særeq.getInput(key) -> FiledStorage| List of Fields if key is given will return a list of fields values for that key. if there are no values an empty list is returned. if no key is given returns the cgi.FieldStorage object. sgetlistN( sselfsinputssimpls getInputsskeyshasattrsgetlistshas_keysgetvaluesvaluestype(sselfskeysvalue((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys getInputs0s    cCsv|i o`g|_xT|iƒiƒD]<}|i|ƒ}x$|D]}|ii||fƒqCWq'Wn|iSdS(N(sselfsinputSeqs getInputsskeysskeysvaluessvaluesappend(sselfsvaluessvalueskey((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys getInputSeqFs  "cCsV|i o@h|_x4|iƒiƒD]}|i|ƒ|i| String | default returns the given form field value as a String. If there are multiple values under the same key, it will return the first in the list, unless index is given. If no value is found will return "", unless default is given. iN(sindexsselfs getInputsskeysdefault(sselfskeysdefaultsindex((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysgetInputUs cCsb|i|ƒoJ|iƒ|}|io,t|i_t |i_ t |i_ |SqZn|SdS(sÍreq.getFile(fieldname)-> Field returns an uploaded file. The filed has the usual cgi.Field members plus filename - the given file name file - the actual file uploaded tempname - is None until keep() is called. the methods: keep() - The file object is a temporay file that will be deleted when the cgi terminates. keep asigns the file a a temp file name. save(name) - This method can be used to save the tempfile under the given name. N( sselfshasInputskeys getInputssfilesfilenamesNones __class__stempnameskeepssavesdefault(sselfskeysdefaultsfile((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysgetFilees      cCs8|itjotd|iƒƒ|_n|iSdS(Ns#http://%(HTTP_HOST)s%(REQUEST_URI)s(sselfs_urlsNonesUrls getEnviron(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysgetUrl~scCsât o d‚nd|iƒ}tt|ƒƒ}|iddƒ}|d}|o|i |ƒ\}}n|i dƒ}|djo||}|| }n |}d}||d<|id|ƒ|id |ƒ|SdS( Ns&under mod_python urlparse has problemss#http://%(HTTP_HOST)s%(REQUEST_URI)ss PATH_INFOsis/iÿÿÿÿii(sUrlsselfs getEnvironsurlslistsurlparsespartss info_pathspathssplitsdummysrfindsindxsscriptsinsert(sselfsdummysscriptsindxs info_pathsurlspartsspath((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysuriParts…s$     c Ks,h} d}xVdddddddfD]9}|i|ƒo||||<||=n|d 7}q(W|od |d \} } | i| ƒo| | i| ƒqÐ| g| | ¬ssdoseqis%s%s%siis%s%si(squerysiskeyskwsshas_keyspartsscleansqsstypessplitsquerySeqsmapsksvsappendsupdatesitemssvaluessvalues urlencodestuples urlunparse( sselfspartsscleanskwssqsskeysisquerySeqsvaluesvaluessvsquerysk((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysbuildUri›sL         icKs/t|iƒƒ}|i|||�}|SdS(N(slistsselfsuriPartsspartssbuildUriscleanskwssurl(sselfscleanskwssurlsparts((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys serviceUriÇscCs(t|iƒƒ}dt|d ƒSdS(Ns %s://%s%s/i(slistsselfsuriPartsspartsstuple(sselfsparts((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysbaseUriÌscCs|iƒ|SdS(N(sselfsbaseUrispage(sselfspage((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyspageUriÐscGsltt|ƒ}dtiƒdi|ƒf}ytii |ƒWn#dk }|i d|iƒnXdS(Ns %s: %ss sfile( smapsstrsargsstimesctimesjoinspostssyssstderrswrites tracebacks print_excsself(sselfsargss tracebackspost((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyslogÔs (/s__name__s __module__s__doc__sNonesinputssinputSeqs inputDictscookiessenvirons_sessions__init__s__call__spsos getOutStreams getInStreamssetupscloses getStatusCodes getEnvirons setEnvironsCookieFileImpls getSessions setSessionssessions getCookieKeys getCookiess getCookies setCookiessend_http_headersredirects setStatuss sendStatusshasInputs hasInputss getInputss getInputSeqs getInputDictsgetInputsgetFiles_urlsgetUrlsuriPartssbuildUris serviceUrisbaseUrispageUrislog(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysServiceRequestmsV                         ,   cCss|i odtƒ|_|iidƒt|idƒ}|i|iiƒƒ|i ƒt|iƒ|_ndS(s8 req.getFile(key).keep() -> file This method is added to file form fields. Files that are uploaded are stored as nameless temporary files. This method allows you to store the file, so it can be processed at a later stage. Calling it replaces the nameless temp file with the new named temp file. iswbN( s fileFieldstempnamesmktempsfilesseeksopensfpswritesreadsclose(s fileFieldsfp((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyskeepàs   cCsS|i o(|iƒ|iiƒ|iiƒndk}|i|i|ƒdS(sÙ req.getFile(key).saveAs(somename) -> None This method is added to file form fields. Files that are uploaded are stored as nameless temporary files. This method alows you to store the file with a given name. N( s fileFieldstempnameskeepsfilesflushsclosesossrenamesnewName(s fileFieldsnewNamesos((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyssaveòs    cCsp| o tƒ}n|iƒiƒytdcd7