o 3a@sddlmZddlmZddlmZddlmZddlm Z m Z m Z ddl m Z ddlmZddlmZdd lmZed ZGd d d ZGd dde ZGdddejZddZddZddZddZdS))BytesIO)settings)signals)base) HttpRequest QueryDict parse_cookie)set_script_prefix)repercent_broken_unicode)cached_property)_lazy_re_compiles/+c@s8eZdZdZd ddZd ddZd dd Zd d d ZdS) LimitedStreamzBWrap another stream to disallow reading it past a number of bytes.cCs||_||_d|_||_dSN)stream remainingbufferbuf_size)selfrlimitrr;/usr/lib/python3/dist-packages/django/core/handlers/wsgi.py__init__s zLimitedStream.__init__NcCsF|dus ||jkr |j}|dkrdS|j|}|jt|8_|S)Nrr)rrreadlenrsizeresultrrr _read_limiteds zLimitedStream._read_limitedcCst|dur|j|}d|_|S|t|jkr(|jd|}|j|d|_|S|j||t|j}d|_|Sr)rrrrrrrr szLimitedStream.readcCsd|jvr;|dust|j|kr;|r||t|j}n|}|s$n|j|7_d|jvr;|dust|j|kst|j}|rH||}n|}||_|S)N )rrrrreadliner)rrchunksiolinerrrr!,s     zLimitedStream.readline)rN)__name__ __module__ __qualname____doc__rrrr!rrrrr s     r c@sZeZdZddZddZeddZddZd d Zed d Z e d dZ e eeZ dS) WSGIRequestc Cst|}t|p d}||_||_d|d|dddf|_||_||jd<||jd<|d|_ | |z t | d}Wn t tfyNd }Ynwt|jd ||_d |_d|_dS) N/z%s/%s PATH_INFO SCRIPT_NAMEREQUEST_METHODCONTENT_LENGTHrz wsgi.inputF)get_script_name get_path_infoenviron path_inforstripreplacepathMETAuppermethod_set_content_type_paramsintget ValueError TypeErrorr _stream _read_startedresolver_match)rr4 script_namer5content_lengthrrrrAs(       zWSGIRequest.__init__cCs |jdS)Nzwsgi.url_scheme)r4r>rrrr _get_scheme[s zWSGIRequest._get_schemecCst|jdd}t||jdS)N QUERY_STRINGr,)encoding)get_bytes_from_wsgir4r _encoding)rraw_query_stringrrrGET^szWSGIRequest.GETcCt|ds ||jS)N_post)hasattr_load_post_and_filesrOrFrrr _get_postds zWSGIRequest._get_postcCs ||_dSr%)rO)rpostrrr _set_postis zWSGIRequest._set_postcCst|jdd}t|S)N HTTP_COOKIEr,)get_str_from_wsgir4r)r raw_cookierrrCOOKIESlszWSGIRequest.COOKIEScCrN)N_files)rPrQrYrFrrrFILESqs zWSGIRequest.FILESN) r&r'r(rrGr rMrRrTrXpropertyrZPOSTrrrrr*@s   r*cs(eZdZeZfddZddZZS) WSGIHandlercstj|i||dSr%)superrload_middleware)rargskwargs __class__rrr}s zWSGIHandler.__init__cCstt|tjj|j|d||}||}|j|_d|j |j f}g| dd|j D}|||t|dddurU|drU|j|j_|d|j|j}|S)N)senderr4z%d %scss |] }d|jddfVqdS)z Set-Cookier,)headerN)output).0crrr sz'WSGIHandler.__call__..file_to_streamzwsgi.file_wrapper)r r2rrequest_startedsendrc request_class get_response_handler_class status_code reason_phraseitemscookiesvaluesgetattrr>closerj block_size)rr4start_responserequestresponsestatusresponse_headersrrr__call__s     zWSGIHandler.__call__)r&r'r(r*rmrr} __classcell__rrrbrr]zs r]cCst|dd}t|S)z0Return the HTTP request's PATH_INFO as a string.r.r+)rJr decode)r4r5rrrr3s  r3cCstjdurtjSt|ddpt|dd}|r7d|vr td|}t|dd}|r1|dt| n|}|St|dd}|S) aE Return the equivalent of the HTTP request's SCRIPT_NAME environment variable. If Apache mod_rewrite is used, return what would have been the script name prior to any rewriting (so it's the script name as seen from the client's perspective), unless the FORCE_SCRIPT_NAME setting is set (to anything). N SCRIPT_URLr, REDIRECT_URLs///r.r/)rFORCE_SCRIPT_NAMErJ _slashes_resubrr)r4 script_urlr5rDrrrr2s    r2cCs|||}|dS)zh Get a value from the WSGI environ dictionary as bytes. key and default should be strings. z iso-8859-1)r>encoder4keydefaultvaluerrrrJs  rJcCst|||}|jddS)zj Get a value from the WSGI environ dictionary as str. key and default should be str objects. r7)errors)rJrrrrrrVs  rVN)ior django.confr django.corerdjango.core.handlersr django.httprrr django.urlsr django.utils.encodingr django.utils.functionalr django.utils.regex_helperr rr r* BaseHandlerr]r3r2rJrVrrrrs"       1: