o [d@sbdZddlZgdZGdddZddZdd Zdd d Zd dZddZhdj 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|_dSdS)Nclose)filelikeblksizehasattrr )selfr r r#/usr/lib/python3.10/wsgiref/util.py__init__s   zFileWrapper.__init__cCs2ddl}|jdtdd|j|j}|r|St)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 |Str)r rr StopIteration)r rrrr__next__$szFileWrapper.__next__N)r)__name__ __module__ __qualname____doc__rrrrrrrrr s   rcCs|ddvr dSdS)zMReturn a guess for whether 'wsgi.url_scheme' should be 'http' or 'https' HTTPS)yeson1httpshttp)get)environrrrr*srcCs|dd}ddlm}|dr||d7}n)||d7}|ddkr3|dd kr2|d |d7}n|dd krA|d |d7}|||d pId 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       rTcCspt|}ddlm}||ddddd}|ds#||d d 7}n||7}|r6|d r6|d |d 7}|S) zBReturn the full request URI, optionally including the query stringrr, PATH_INFOz/;=,r6)safer7r4N QUERY_STRING?)rr8r-r))r* include_queryr9r- path_inforrrrFs  rcCs|dd}|s dS|d}dd|ddD|dd<|d}|d=|d d}t|d|}|dr?|dd}|sJ|dsJ|d7}||d <d||d<|d kr[d}|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. r:r;Nr5cSsg|] }|r|dkr|qS).r).0prrr esz#shift_path_info..r=r4rB)r)split posixpathnormpathendswithjoin)r*rA path_partsname script_namerrrrSs$     rcCs|dd|dd|d|d|ddd|vr.d |vr.|dd |d d |d d |dd|dd|ddddlm}m}|d||d||dt||ddkrr|dddS|ddkr|dddSdS)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.1SERVER_PROTOCOLzHTTP/1.0r.REQUEST_METHODGETr4r:r;r5z wsgi.version)r=rz wsgi.run_oncerzwsgi.multithreadzwsgi.multiprocess)StringIOBytesIOz wsgi.inputz wsgi.errorsr+r(r0r3r'r1N) setdefaultiorRrSr)r*rRrSrrrr|s(          r> keep-alivetransfer-encodingproxy-authenticateproxy-authorizationteupgradetrailers connectioncCs t|S)z?Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header)_hoppishlower) header_namerrr is_hop_by_hops ra)T) r"rH__all__rrrrrr __contains__r^rarrrrs  )(