;ς šτ/Ec@sιdkZdkZdkZdkZdkZeadfd„ƒYZdefd„ƒYZdfd„ƒYZ dfd„ƒYZ d efd „ƒYZ d efd „ƒYZ ei d ƒZdefd„ƒYZd„Zd„ZdS(NsServercBs#tZd„Zd„Zd„ZRS(NcCs h|_dS(N(sselfs pageGlobals(sself((s lib/sapi.pys__init__scCs|SdS(N(sself(sself((s lib/sapi.pysself"scCsdS(N((sself((s lib/sapi.pysclose%s(s__name__s __module__s__init__sselfsclose(((s lib/sapi.pysServers  sThreadedServercBs#tZd„Zd„Zd„ZRS(NcCslti|ƒd|_tttƒ o tƒanttit ƒ ot tƒt_nti |ƒdS(Ni( sServers__init__sselfsinheritableOuts isinstancesserversThreadedServerProxyssyssstdoutsFilesregisterThread(sself((s lib/sapi.pys__init__*s   cCst|ƒSdS(N(sFilesself(sself((s lib/sapi.pysfile6scCstiƒdS(N(sserversunregisterThread(sself((s lib/sapi.pysclose9s(s__name__s __module__s__init__sfilesclose(((s lib/sapi.pysThreadedServer)s sThreadedServerProxycBsMtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(sΘIn a multithreaded server environment, ThreadedServerProxy stores the different server objects being used to display pages and transparently forwards access to them based on the current thread id.cCsh|idtZd„Zd„Zd„Zd„Zd„Zd„ZRS(NcCs1d|_d|_d|_d|_||_dS(Nisws(sselfsclosedsmodesnames softspacesserver(sselfsserver((s lib/sapi.pys__init__]s     cCs|ii|ƒdS(N(sselfsserverswritess(sselfss((s lib/sapi.pyswritedscCs%x|D]}|ii|ƒqWdS(N(slistsssselfsserverswrite(sselfslistss((s lib/sapi.pys writelinesgscCs|iiƒdS(N(sselfsserversflush(sself((s lib/sapi.pysflushkscCsdS(N((sselfssize((s lib/sapi.pystruncatenscCsdS(N((sself((s lib/sapi.pyscloseqs(s__name__s __module__s__init__swrites writelinessflushstruncatesclose(((s lib/sapi.pysFile\s      s CgiServercBstZdd„Zd„Zded„Zd„Zed„Zed„Zd „Z eed e i d d d „Z d „Z d„Zd„ZRS(NicCsti|ƒd|_g|_||_tiiddƒd dj|_ t i djo|o)dk }|i t iiƒtiƒn|adkadS(NisSERVER_SOFTWAREsi s Microsoft-IISswin32(sServers__init__sselfs headerSentsheaderssinheritableOutsossenvironsgetsiisssyssplatformsmsvcrtssetmodesstdoutsfilenosO_BINARYsserverscgi(sselfsinheritableOutsmsvcrt((s lib/sapi.pys__init__vs    "  cCs|ii||fƒdS(N(sselfsheaderssappendsnamesvalue(sselfsnamesvalue((s lib/sapi.pys addheader‡sstext/html; charset=UTF-8cCs©|i ošd|_d}x+|iD] \}}|d||f}q$W|tjp|d djo|io d}n d|}t i i d|||fƒndS(Niss%s: %s is304s Status: %s s%sContent-Type: %s %s ( sselfs headerSents extraheaderssheaderssnamesvaluesstatussNonesiisssyssstdoutswrites content_type(sselfs content_typesstatussnames extraheaderssvalue((s lib/sapi.pysheaderŠs   (  cCsW|iot||ƒ}n|id|ƒ|iddƒd|GHtidƒdS(NsLocationsstatuss 301 Moveds/This document is located here.i(sselfsiiss fix_iis_urlsurls addheadersheaderssyssexit(sselfsurl((s lib/sapi.pysredirects   cCsti||ƒSdS(N(scgisescapesssquote(sselfsssquote((s lib/sapi.pysescape€scCsNtii||ƒ}|io|djo|ot||ƒ}n|SdS(Ns PATH_INFO( sossenvironsgetsnamesvaluesretsselfsiissfix_iis_path_info(sselfsnamesvaluesret((s lib/sapi.pysgetenv§scCstiƒSdS(N(scgisparse(sself((s lib/sapi.pysparams­ssicCs ti||||||ƒSdS(N(scgis FieldStoragesfpsheaderss outerboundarysenvironskeep_blank_valuessstrict_parsing(sfpsheaderss outerboundarysenvironskeep_blank_valuessstrict_parsing((s lib/sapi.pys FieldStorage°scCstii|ƒdS(N(ssyssstdoutswritess(sselfss((s lib/sapi.pyswrite΅scCstiiƒdS(N(ssyssstdoutsflush(sself((s lib/sapi.pysflushΈscCs tiSdS(N(ssyssstdout(sself((s lib/sapi.pysfile»s(s__name__s __module__s__init__s addheadersNonesheadersredirectsescapesgetenvsparamssossenvirons FieldStorageswritesflushsfile(((s lib/sapi.pys CgiServerus        s AspServercBsƒtZd„Zd„Zeed„Zd„Zed„Zed„Zd„Z eede i d d d „Z d „Z d „ZRS( NcCs>ti|ƒd|_||_||_||_ ||_ dS(Ni( sThreadedServers__init__sselfs headerSentsServersserversRequestsrequestsResponsesresponses Applications application(sselfsServersRequestsResponses Application((s lib/sapi.pys__init__ΐs      cCs|ii||ƒdS(N(sselfsresponses AddHeadersnamesvalue(sselfsnamesvalue((s lib/sapi.pys addheaderΘscCs||i omySd|_|tjod|i_n ||i_|tj o||i_nWqxtj oqxXndS(Nistext/html; charset=UTF-8( sselfs headerSents content_typesNonesresponses ContentTypesstatussStatussAttributeError(sselfs content_typesstatus((s lib/sapi.pysheaderΛs     cCs|ii|ƒtiƒdS(N(sselfsresponsesRedirectsurlssyssexit(sselfsurl((s lib/sapi.pysredirectάscCs|iit|ƒƒSdS(N(sselfsservers HTMLEncodesstrss(sselfsssquote((s lib/sapi.pysescapeΰscCsh|ii|ƒƒ}t|ƒtij o|Snt |ƒ}|djot ||ƒ}n|SdS(Ns PATH_INFO( sselfsrequestsServerVariablessnamesretstypestypess UnicodeTypesvaluesstrsfix_iis_path_info(sselfsnamesvaluesret((s lib/sapi.pysgetenvγs  cCs‚h}x7|iiD])}tt|ii|ƒ|t|ƒ%s( smod_python.apaches mod_pythonsurlsselfsrequests headers_outsapachesHTTP_MOVED_TEMPORARILYsstatusswritessyssexit(sselfsurls mod_python((s lib/sapi.pysredirect2s  cCsti||ƒSdS(N(scgisescapesssquote(sselfsssquote((s lib/sapi.pysescape:scCs0y|ii|SWntj o |SnXdS(N(sselfsrequestssubprocess_envsnamesKeyErrorsvalue(sselfsnamesvalue((s lib/sapi.pysgetenv=scCs>dk}|iitjohSn|ii|iiƒSdS(N(smod_python.utils mod_pythonsselfsrequestsargssNonesutilsparse_qs(sselfs mod_python((s lib/sapi.pysparamsCs sicCs&dk}|ii|i||ƒSdS(N(smod_python.utils mod_pythonsutils FieldStoragesselfsrequestskeep_blank_valuessstrict_parsing(sselfsfpsheaderss outerboundarysenvironskeep_blank_valuessstrict_parsings mod_python((s lib/sapi.pys FieldStorageJs cCs|ii|ƒdS(N(sselfsrequestswritess(sselfss((s lib/sapi.pyswriteOscCsdS(N((sself((s lib/sapi.pysflushRs(s__name__s __module__s__init__s addheadersNonesheadersredirectsescapesgetenvsparamssossenvirons FieldStorageswritesflush(((s lib/sapi.pysModPythonServers       cCs›|ddjo‚|idƒdjod}d}n d}d}||id ƒ}|id ƒ|jo|d |id ƒ}n||Sn|Sd S( s‰When a CGI application under IIS outputs a "Location" header with a url beginning with a forward slash, IIS tries to optimise the redirect by not returning any output from the original CGI script at all and instead just returning the new page in its place. Because of this, the browser does not know it is getting a different page than it requested. As a result, The address bar that appears in the browser window shows the wrong location and if the new page is in a different folder than the old one, any relative links on it will be broken. This function can be used to circumvent the IIS "optimization" of local redirects. If it is passed a location that begins with a forward slash it will return a URL constructed with the information in CGI environment. If it is passed a URL or any location that doens't begin with a forward slash it will return just argument unaltered. is/sHTTPSsons443shttps://s80shttp://s HTTP_HOSTs SERVER_PORTs:N(surlsserversgetenvsdportsprefix(sserversurlsdportsprefix((s lib/sapi.pys fix_iis_urlVs  cCs|t|iddƒƒSdS(sFix the PATH_INFO value in IISs SCRIPT_NAMEsN(s path_infoslensserversgetenv(sservers path_info((s lib/sapi.pysfix_iis_path_infots(stypessstringsosssyssresNonesserversServersThreadedServersThreadedServerProxysFiles CgiServers AspServerscompiles _re_statussModPythonServers fix_iis_urlsfix_iis_path_info(s AspServers CgiServersModPythonServersstrings _re_statussThreadedServerssyssres fix_iis_urlsThreadedServerProxysFilesfix_iis_path_infosServersosstypes((s lib/sapi.pys?s      JX<