; HfCc@sEdZdklZdklZdklZdkZdk Z dk l Z l Z dk lZlZdefdYZd klZlZyd klZWnnXyd klZWn eZnXd fd YZdefdYZdZdZdZdZdZdZ 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 RequestIOcBstZdZddZedZdZdZdZddZ d Z d Z d Z d Z d ZdZdZdZdZdZdZRS(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. icCsdSdS(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|ii||it|7_dS(N(sssselfs headers_sentsouts getOutStreamswritesposslen(sselfss((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyswrite>s  cCs#|ii|id|_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|idS(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|idS(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 getCookiess cCs|ii||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 getCookiescKse|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]-}||iijo||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|ido|ii|Sn]|ii|oE|ii|}|ot |t gjo|Sq|gSngSdS(sreq.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|iiD]<}|i|}x$|D]}|ii||fqCWq'Wn|iSdS(N(sselfsinputSeqs getInputsskeysskeysvaluessvaluesappend(sselfsvaluessvalueskey((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys getInputSeqFs  "cCsV|i o@h|_x4|iiD]}|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(sreq.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~scCst o dnd|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/iii(sUrlsselfs getEnvironsurlslistsurlparsespartss info_pathspathssplitsdummysrfindsindxsscriptsinsert(sselfsdummysscriptsindxs info_pathsurlspartsspath((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysuriPartss$     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.pysbuildUrisL         icKs/t|i}|i|||}|SdS(N(slistsselfsuriPartsspartssbuildUriscleanskwssurl(sselfscleanskwssurlsparts((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pys serviceUriscCs(t|i}dt|d SdS(Ns %s://%s%s/i(slistsselfsuriPartsspartsstuple(sselfsparts((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pysbaseUriscCs|i|SdS(N(sselfsbaseUrispage(sselfspage((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyspageUriscGsltt|}dtidi|f}ytii |Wn#dk }|i d|inXdS(Ns %s: %ss sfile( smapsstrsargsstimesctimesjoinspostssyssstderrswrites tracebacks print_excsself(sselfsargss tracebackspost((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/request.pyslogs (/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|_|iidt|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.pyskeeps   cCsS|i o(|i|ii|iindk}|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.pyssaves    cCsp| o t}n|iiytdcd7