U e5d:@sdgZddlZddlZddlZedZedZGdddeZddZ d d Z d dZ Gd d d Z GdddZ GdddZGdddZGdddZddZddZddZddZddZd d!Zd"d#Zd$d%ZdS)& validatorNz^[a-zA-Z][a-zA-Z0-9\-_]*$z [\000-\037]c@s eZdZdS) WSGIWarningN)__name__ __module__ __qualname__rr(/usr/lib64/python3.8/wsgiref/validate.pyrysrcGs|s t|dSN)AssertionError)Zcondargsrrrassert_~sr cCs(t|tkr|Std|t|dS)Nz!{0} must be of type str (got {1}))typestrr formatrepr)valuetitlerrrcheck_string_types  rcsfdd}|S)Ncstt|dkdt| d|\}t|gfdd}t|d|d<t|d|d<||}t|dk oz|dkd t|t|S) NzTwo arguments requiredNo keyword arguments allowedcstt|dkpt|dkd|ft| d|d}|d}t|dkrV|d}nd}t|t|t||t|dt|S)NrzInvalid number of arguments: %srr)r len check_status check_headerscheck_content_typecheck_exc_infoappend WriteWrapper)r kwstatusheadersexc_infoZstart_responseZstart_response_startedrrstart_response_wrappers     z;validator..lint_app..start_response_wrapper wsgi.input wsgi.errorsFz>The application must return an iterator, if only an empty list)r r check_environ InputWrapper ErrorWrappercheck_iteratorIteratorWrapper)r renvironr$iterator applicationr#rlint_apps  zvalidator..lint_appr)r/r0rr.rrs )c@s<eZdZddZddZddZddZd d Zd d Zd S)r(cCs ||_dSr )input)self wsgi_inputrrr__init__szInputWrapper.__init__cGs0tt|dk|jj|}tt|tk|SNr)r rr1readr bytesr2r vrrrr6s zInputWrapper.readcGs0tt|dk|jj|}tt|tk|Sr5)r rr1readliner r7r8rrrr:s zInputWrapper.readlinecGsJtt|dk|jj|}tt|tk|D]}tt|tkq0|Sr5)r rr1 readlinesr listr7)r2r lineslinerrrr;s  zInputWrapper.readlinesccs|}|sdS|VqdSr )r:)r2r>rrr__iter__szInputWrapper.__iter__cCstdddS)Nrz input.close() must not be calledr r2rrrcloseszInputWrapper.closeN) rrrr4r6r:r;r?rBrrrrr(s r(c@s4eZdZddZddZddZddZd d Zd S) r)cCs ||_dSr )errors)r2 wsgi_errorsrrrr4szErrorWrapper.__init__cCs tt|tk|j|dSr )r r rrCwriter2srrrrEszErrorWrapper.writecCs|jdSr )rCflushrArrrrHszErrorWrapper.flushcCs|D]}||qdSr )rE)r2seqr>rrr writelinesszErrorWrapper.writelinescCstdddS)Nrz!errors.close() must not be calledr@rArrrrBszErrorWrapper.closeN)rrrr4rErHrJrBrrrrr)s r)c@seZdZddZddZdS)rcCs ||_dSr )writer)r2Z wsgi_writerrrrr4szWriteWrapper.__init__cCstt|tk||dSr )r r r7rKrFrrr__call__szWriteWrapper.__call__N)rrrr4rLrrrrrsrc@seZdZddZddZdS)PartialIteratorWrappercCs ||_dSr r-)r2 wsgi_iteratorrrrr4szPartialIteratorWrapper.__init__cCs t|jdSr )r+r-rArrrr?szPartialIteratorWrapper.__iter__N)rrrr4r?rrrrrMsrMc@s4eZdZddZddZddZddZd d Zd S) r+cCs ||_t||_d|_||_dS)NF)original_iteratoriterr-closedcheck_start_response)r2rOrSrrrr4 s zIteratorWrapper.__init__cCs|Sr rrArrrr?szIteratorWrapper.__iter__cCsTt|j dt|j}t|tk r4tdd|f|jdk rPt|jdd|_|S)NzIterator read after closedFz$Iterator yielded non-bytestring (%r)zjThe application returns and we started iterating over its body, but start_response has not yet been called)r rRnextr-r r7rS)r2r9rrr__next__s   zIteratorWrapper.__next__cCs d|_t|jdr|jdS)NTrB)rRhasattrrPrBrArrrrBs zIteratorWrapper.closecCs"|jstjdt|jddS)Nz/Iterator garbage collected without being closed)rRsysstderrrEr rArrr__del__#szIteratorWrapper.__del__N)rrrr4r?rUrBrYrrrrr+s  r+cCstt|tkdt||fdD]}t||kd|fq"dD]"}t||kd||ddfq@d|krxtdt|D]:}d |krqtt||tkd |t||||fqtt|d tkd |d ft|d dkd|d t |dt |d|ddkr0td|dtt| d pL|d dd|dt| d pv|d dd|d| drtt |ddkd|d| dstd|kdt| ddkddS)Nz:Environment is not of the right type: %r (environment: %r)) REQUEST_METHODZ SERVER_NAMEZ SERVER_PORT wsgi.versionr%r&zwsgi.multithreadzwsgi.multiprocessz wsgi.run_oncez$Environment missing required key: %r)ZHTTP_CONTENT_TYPEZHTTP_CONTENT_LENGTHz8Environment should not have the key: %s (use %s instead)Z QUERY_STRINGzQUERY_STRING is not in the WSGI environment; the cgi module will use sys.argv when this variable is missing, so application errors are more likely.z9Environmental variable %s is not a string: %r (value: %r)r[z#wsgi.version should be a tuple (%r)zwsgi.url_scheme)ZhttpZhttpszwsgi.url_scheme unknown: %rr%r&rZ)ZGETZHEADZPOSTZOPTIONSZPATCHZPUTZDELETEZTRACEzUnknown REQUEST_METHOD: %rZ SCRIPT_NAME/z$SCRIPT_NAME doesn't start with /: %rZ PATH_INFOz"PATH_INFO doesn't start with /: %rZCONTENT_LENGTHrzInvalid CONTENT_LENGTH: %rzgOne of SCRIPT_NAME or PATH_INFO are required (PATH_INFO should at least be '/' if SCRIPT_NAME is empty)zOSCRIPT_NAME cannot be '/'; it should instead be '', and PATH_INFO should be '/')r r dictwarningswarnrkeysrtuple check_input check_errorsget startswithint)r,keyrrrr'*sx                r'cCs&dD]}tt||d||fqdS)N)r6r:r;r?z-wsgi.input (%r) doesn't have the attribute %sr rV)r3attrrrrrdks  rdcCs&dD]}tt||d||fqdS)N)rHrErJz.wsgi.errors (%r) doesn't have the attribute %srj)rDrkrrrreqs  recCsvt|d}|ddd}tt|dkd|t|}t|dkd|t|dksb|dd krrtd |tdS) NStatusrrrz)Status codes must be three characters: %rdzStatus code is invalid: %r zjThe status string (%r) should be a three-digit integer followed by a single space and a status explanation)rsplitr rrhr`rar)r Z status_codeZ status_intrrrrws  rcCstt|tkd|t|f|D]}tt|tkd|t|ftt|dk|\}}t|d}t|d}t|dkd|td|kod |kd |tt|d |t| d  o| d  d|t |r"tdd|t | dfq"dS)Nz%Headers (%r) must be of type list: %rz1Individual headers (%r) must be of type tuple: %rr Header namez Header valuer zyThe Status header cannot be used; it conflicts with CGI script, and HTTP status is not given through headers (value: %r). :z,Header names may not contain ':' or '\n': %rzBad header name: %r-_z#Names may not end in '-' or '_': %rrz#Bad header value: %r (bad char: %r)) r r r<rcrrlower header_researchendswithbad_header_value_regroup)r!itemnamerrrrrs>        rcCs|t|d}t|ddd}d}|D]:\}}t|d}|dkr&||krRdStdd|q&||krxtdd|dS) Nrlrr)i0rqz content-typezJContent-Type header found in a %s response, which must not return content.z,No Content-Type header found in headers (%s))rrhrprvr )r r!codeZNO_MESSAGE_BODYr}rrrrrs    rcCs*t|dkpt|tkd|t|fdS)Nz exc_info (%r) is not a tuple: %r)r r rc)r"rrrrsrcCstt|ttf ddS)NzwYou should not return a string as your application iterator, instead return a single-item list containing a bytestring.)r isinstancerr7rNrrrr*sr*)__all__rerWr`compilerwrzWarningrr rrr(r)rrMr+r'rdrerrrrr*rrrros,  7#  #A