U ,a@svdZddlZddddddgZGd ddZd dZd dZdd dZddZddZddddddddhj Z ddZ dS)z$Miscellaneous WSGI-related UtilitiesN FileWrapper guess_schemeapplication_uri request_urishift_path_infosetup_testing_defaultsc@s2eZdZdZd ddZddZddZd d Zd S) rz1Wrapper to convert file-like objects to iterables cCs"||_||_t|dr|j|_dS)Nclose)filelikeblksizehasattrr )selfr r r1/opt/alt/python38/lib64/python3.8/wsgiref/util.py__init__s zFileWrapper.__init__cCs6ddl}|jdtdd|j|j}|r.|StdS)NrzXFileWrapper's __getitem__ method ignores 'key' parameter. Use iterator protocol instead.) stacklevel)warningswarnDeprecationWarningr readr IndexError)r keyrdatarrr __getitem__szFileWrapper.__getitem__cCs|SNr)r rrr__iter__!szFileWrapper.__iter__cCs|j|j}|r|StdSr)r rr StopIteration)r rrrr__next__$szFileWrapper.__next__N)r)__name__ __module__ __qualname____doc__rrrrrrrrr s   cCs|ddkrdSdSdS)zMReturn a guess for whether 'wsgi.url_scheme' should be 'http' or 'https' ZHTTPS)ZyesZon1httpshttpN)get)environrrrr*scCs|dd}ddlm}|dr0||d7}nR||d7}|ddkrf|dd kr|d |d7}n|dd kr|d |d7}|||d pd dd7}|S)z@Return the application's base URI (no PATH_INFO or QUERY_STRING)wsgi.url_schemez://rquote HTTP_HOST SERVER_NAMEr$ SERVER_PORT443:80 SCRIPT_NAME/latin1)encoding) urllib.parser*r&)r'urlr*rrrr2s       TcCspt|}ddlm}||ddddd}|dsF||d d 7}n||7}|rl|d rl|d |d 7}|S) zBReturn the full request URI, optionally including the query stringrr) PATH_INFOz/;=,r3)Zsafer4r1NZ QUERY_STRING?)rr5r*r&)r'Z include_queryr6r* path_inforrrrFs  cCs|dd}|sdS|d}dd|ddD|dd<|d}|d=|d d}t|d|}|dr~|dd}|s|ds|d7}||d <d||d<|d krd}|S) aZShift a name from PATH_INFO to SCRIPT_NAME, returning it If there are no remaining path segments in PATH_INFO, return None. Note: 'environ' is modified in-place; use a copy if you need to keep the original PATH_INFO or SCRIPT_NAME. Note: when PATH_INFO is just a '/', this returns '' and appends a trailing '/' to SCRIPT_NAME, even though empty path segments are normally ignored, and SCRIPT_NAME doesn't normally end in a '/'. This is intentional behavior, to ensure that an application can tell the difference between '/x' and '/x/' when traversing to objects. r7r8Nr2cSsg|]}|r|dkr|qS).r).0prrr esz#shift_path_info..r9r1r<)r&split posixpathnormpathendswithjoin)r'r; path_partsnameZ script_namerrrrSs$     cCs|dd|dd|d|d|ddd|kr\d |kr\|dd |d d |d d |dd|dd|ddddlm}m}|d||d||dt||ddkr|ddn|ddkr|dddS)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_METHODZGETr1r7r8r2z wsgi.version)r9rz wsgi.run_oncerzwsgi.multithreadzwsgi.multiprocess)StringIOBytesIOz wsgi.inputz wsgi.errorsr(r%r-r0r$r.N) setdefaultiorHrIr)r'rHrIrrrr|s&           Z connectionz keep-alivezproxy-authenticatezproxy-authorizationZteZtrailersztransfer-encodingZupgradecCs t|S)z?Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header)_hoppishlower)Z header_namerrr is_hop_by_hopsrN)T) r"rB__all__rrrrrr __contains__rLrNrrrrs0 ))