î i fã@sÍdZddlZddddddgZGd d„dƒZd d„Zd d„Zd d d„Zdd„Zdd„Zidd6dd6dd6dd6dd6dd6dd6dd6j Z dd„Z dS)z$Miscellaneous WSGI-related UtilitieséNÚ FileWrapperÚ guess_schemeÚapplication_uriÚ request_uriÚshift_path_infoÚsetup_testing_defaultsc@sIeZdZdZddd„Zdd„Zdd„Zd d „Zd S) rz1Wrapper to convert file-like objects to iterablesi cCs4||_||_t|dƒr0|j|_ndS)NÚclose)ÚfilelikeÚblksizeÚhasattrr)Úselfr r ©r ú1/opt/alt/python34/lib64/python3.4/wsgiref/util.pyÚ__init__s  zFileWrapper.__init__cCs)|jj|jƒ}|r|St‚dS)N)r Úreadr Ú IndexError)r ÚkeyÚdatar r rÚ __getitem__szFileWrapper.__getitem__cCs|S)Nr )r r r rÚ__iter__szFileWrapper.__iter__cCs)|jj|jƒ}|r|St‚dS)N)r rr Ú StopIteration)r rr r rÚ__next__szFileWrapper.__next__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrr r r rr s   cCs!|jdƒdkrdSdSdS) zMReturn a guess for whether 'wsgi.url_scheme' should be 'http' or 'https' ZHTTPSÚyesÚonÚ1ÚhttpsÚhttpN)zyesrr)Úget)Úenvironr r rr#scCsÒ|dd}ddlm}|jdƒr>||d7}nk||d7}|ddkr„|dd kr©|d |d7}q©n%|dd kr©|d |d7}n|||jd ƒpÁd ddƒ7}|S)z@Return the application's base URI (no PATH_INFO or QUERY_STRING)zwsgi.url_schemez://r)ÚquoteÚ HTTP_HOSTÚ SERVER_NAMErÚ SERVER_PORTÚ443ú:Ú80Ú SCRIPT_NAMEú/ÚencodingÚlatin1)Ú urllib.parser#r!)r"Úurlr#r r rr+s%TcCsžt|ƒ}ddlm}||jddƒddddƒ}|jd ƒsf||d d …7}n ||7}|rš|jd ƒrš|d |d 7}n|S)zBReturn the full request URI, optionally including the query stringr)r#Ú PATH_INFOÚZsafez/;=,r,r-r*éNZ QUERY_STRINGú?)rr.r#r!)r"Z include_queryr/r#Ú path_infor r rr?s $ cCs|jddƒ}|sdS|jdƒ}dd„|dd …Dƒ|dd …<|d}|d=|jddƒ}tj|d|ƒ}|jdƒr®|dd …}n| rÒ|jdƒ rÒ|d7}n||d^s z#shift_path_info..r2r*r5éÿÿÿÿr9r9)r!ÚsplitÚ posixpathÚnormpathÚendswithÚjoin)r"r4Ú path_partsÚnameZ script_namer r rrLs$ '     cCs[|jddƒ|jddƒ|jd|dƒ|jddƒd|krd |kr|jdd ƒ|jd d ƒn|jd dƒ|jddƒ|jddƒ|jddƒddlm}m}|jd|ƒƒ|jd|ƒƒ|jdt|ƒƒ|ddkr4|jddƒn#|ddkrW|jddƒndS)a:Update 'environ' with trivial defaults for testing purposes This adds various parameters required for WSGI, including HTTP_HOST, SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO, and all of the wsgi.* variables. It only supplies default values, and does not replace any existing settings for these variables. This routine is intended to make it easier for unit tests of WSGI servers and applications to set up dummy environments. It should *not* be used by actual WSGI servers or applications, since the data is fake! r%z 127.0.0.1ZSERVER_PROTOCOLzHTTP/1.0r$ZREQUEST_METHODZGETr*r0r1r+z wsgi.versionr2rz wsgi.run_oncezwsgi.multithreadzwsgi.multiprocess)ÚStringIOÚBytesIOz wsgi.inputz wsgi.errorszwsgi.url_schemer r&r)rr'N)r2r)Ú setdefaultÚiorArBr)r"rArBr r rrus& r2Z connectionz keep-alivezproxy-authenticatezproxy-authorizationZteZtrailersztransfer-encodingZupgradecCst|jƒƒS)z?Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header)Ú_hoppishÚlower)Z header_namer r rÚ is_hop_by_hop£srG) rr;Ú__all__rrrrrrÚ __contains__rErGr r r rÚs      ) (