JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbrў f/;c@sNdZdgZddlZddlZddlZejdZejdZGdddeZ dd Z d d Z d dZ Gd ddZ GdddZGdddZGdddZGdddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&ZdS('u& Middleware to check for obedience to the WSGI specification. Some of the things this checks: * Signature of the application and start_response (including that keyword arguments are not used). * Environment checks: - Environment is a dictionary (and not a subclass). - That all the required keys are in the environment: REQUEST_METHOD, SERVER_NAME, SERVER_PORT, wsgi.version, wsgi.input, wsgi.errors, wsgi.multithread, wsgi.multiprocess, wsgi.run_once - That HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH are not in the environment (these headers should appear as CONTENT_LENGTH and CONTENT_TYPE). - Warns if QUERY_STRING is missing, as the cgi module acts unpredictably in that case. - That CGI-style variables (that don't contain a .) have (non-unicode) string values - That wsgi.version is a tuple - That wsgi.url_scheme is 'http' or 'https' (@@: is this too restrictive?) - Warns if the REQUEST_METHOD is not known (@@: probably too restrictive). - That SCRIPT_NAME and PATH_INFO are empty or start with / - That at least one of SCRIPT_NAME or PATH_INFO are set. - That CONTENT_LENGTH is a positive integer. - That SCRIPT_NAME is not '/' (it should be '', and PATH_INFO should be '/'). - That wsgi.input has the methods read, readline, readlines, and __iter__ - That wsgi.errors has the methods flush, write, writelines * The status is a string, contains a space, starts with an integer, and that integer is in range (> 100). * That the headers is a list (not a subclass, not another kind of sequence). * That the items of the headers are tuples of strings. * That there is no 'status' header (that is used in CGI, but not in WSGI). * That the headers don't contain newlines or colons, end in _ or -, or contain characters codes below 037. * That Content-Type is given if there is content (CGI often has a default content type, but WSGI does not). * That no Content-Type is given when there is no content (@@: is this too restrictive?) * That the exc_info argument to start_response is a tuple or None. * That all calls to the writer are with strings, and no other methods on the writer are accessed. * That wsgi.input is used properly: - .read() is called with zero or one argument - That it returns a string - That readline, readlines, and __iter__ return strings - That .close() is not called - No other methods are provided * That wsgi.errors is used properly: - .write() and .writelines() is called with a string - That .close() is not called, and no other methods are provided. * The response iterator: - That it is not a string (it should be a list of a single string; a string will work, but perform horribly). - That .__next__() returns a string - That the iterator is not iterated over until start_response has been called (that can signal either a server or application error). - That .close() is called (doesn't raise exception, only prints to sys.stderr, because we only know it isn't called when the object is garbage collected). u validatoriNu^[a-zA-Z][a-zA-Z0-9\-_]*$u [\000-\037]cBs|EeZdZdZdS(u WSGIWarningu: Raised in response to WSGI-spec-related warnings N(u__name__u __module__u __qualname__u__doc__(u __locals__((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu WSGIWarningysu WSGIWarningcGs|st|ndS(N(uAssertionError(uconduargs((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuassert_~suassert_cCs8t|tkr|Stdj|t|dS(Nu!{0} must be of type str (got {1})(utypeustruAssertionErroruformaturepr(uvalueutitle((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucheck_string_typesucheck_string_typecsfdd}|S(u When applied between a WSGI server and a WSGI application, this middleware will check for WSGI compliancy on a number of levels. This middleware does not modify the request or response in any way, but will raise an AssertionError if anything seems off (except for a failure to close the application iterator, which will be printed to stderr -- there's no way to raise an exception at that point). cstt|dkdt| d|\}t|gfdd}t|d|d.lint_app..start_response_wrapperu wsgi.inputu wsgi.errorsu>The application must return an iterator, if only an empty listF( uassert_ulenu check_environu InputWrapperu ErrorWrapperuNoneuFalseucheck_iteratoruIteratorWrapper(uargsukwuenvironustart_response_wrapperuiterator(u application(ustart_responseustart_response_startedu5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyulint_apps   uvalidator..lint_app((u applicationulint_app((u applicationu5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu validators )cBs\|EeZdZddZddZddZddZd d Zd d Zd S(u InputWrappercCs ||_dS(N(uinput(uselfu wsgi_input((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__init__suInputWrapper.__init__cGsBtt|dk|jj|}tt|tk|S(Ni(uassert_ulenuinputureadutypeubytes(uselfuargsuv((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyureadsuInputWrapper.readcGsBtt|dk|jj|}tt|tk|S(Ni(uassert_ulenuinputureadlineutypeubytes(uselfuargsuv((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyureadlinesuInputWrapper.readlinecGsitt|dk|jj|}tt|tkx$|D]}tt|tkqEW|S(Ni(uassert_ulenuinputu readlinesutypeulistubytes(uselfuargsulinesuline((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu readliness  uInputWrapper.readlinesccs%x|j}|sdS|VqdS(N(ureadline(uselfuline((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__iter__s  uInputWrapper.__iter__cCstdddS(Niu input.close() must not be called(uassert_(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuclosesuInputWrapper.closeN( u__name__u __module__u __qualname__u__init__ureadureadlineu readlinesu__iter__uclose(u __locals__((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu InputWrappers      u InputWrappercBsP|EeZdZddZddZddZddZd d Zd S( u ErrorWrappercCs ||_dS(N(uerrors(uselfu wsgi_errors((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__init__suErrorWrapper.__init__cCs*tt|tk|jj|dS(N(uassert_utypeustruerrorsuwrite(uselfus((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuwritesuErrorWrapper.writecCs|jjdS(N(uerrorsuflush(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuflushsuErrorWrapper.flushcCs"x|D]}|j|qWdS(N(uwrite(uselfusequline((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu writeliness uErrorWrapper.writelinescCstdddS(Niu!errors.close() must not be called(uassert_(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuclosesuErrorWrapper.closeN(u__name__u __module__u __qualname__u__init__uwriteuflushu writelinesuclose(u __locals__((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu ErrorWrappers     u ErrorWrappercBs,|EeZdZddZddZdS(u WriteWrappercCs ||_dS(N(uwriter(uselfu wsgi_writer((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__init__suWriteWrapper.__init__cCs'tt|tk|j|dS(N(uassert_utypeubytesuwriter(uselfus((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__call__suWriteWrapper.__call__N(u__name__u __module__u __qualname__u__init__u__call__(u __locals__((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu WriteWrappers u WriteWrappercBs,|EeZdZddZddZdS(uPartialIteratorWrappercCs ||_dS(N(uiterator(uselfu wsgi_iterator((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__init__suPartialIteratorWrapper.__init__cCst|jdS(N(uIteratorWrapperuiteratoruNone(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__iter__suPartialIteratorWrapper.__iter__N(u__name__u __module__u __qualname__u__init__u__iter__(u __locals__((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuPartialIteratorWrappers uPartialIteratorWrappercBsP|EeZdZddZddZddZddZd d Zd S( uIteratorWrappercCs.||_t||_d|_||_dS(NF(uoriginal_iteratoruiteruiteratoruFalseucloseducheck_start_response(uselfu wsgi_iteratorucheck_start_response((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__init__ s  uIteratorWrapper.__init__cCs|S(N((uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__iter__suIteratorWrapper.__iter__cCsxt|j dt|j}t|tk rItdd|fn|jdk rtt|jdd|_n|S(NuIterator read after closedu$Iterator yielded non-bytestring (%r)ujThe application returns and we started iterating over its body, but start_response has not yet been calledF( uassert_uclosedunextuiteratorutypeubytesuFalseucheck_start_responseuNone(uselfuv((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__next__s   uIteratorWrapper.__next__cCs/d|_t|jdr+|jjndS(NucloseT(uTrueucloseduhasattruoriginal_iteratoruclose(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucloses uIteratorWrapper.closecCs0|jstjjdnt|jddS(Nu/Iterator garbage collected without being closed(uclosedusysustderruwriteuassert_(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__del__#s     uIteratorWrapper.__del__N(u__name__u __module__u __qualname__u__init__u__iter__u__next__ucloseu__del__(u __locals__((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuIteratorWrappers    uIteratorWrapperc Cstt|tkdt||fxCdddddddd d g D] }t||kd |fqKWx;d d gD]-}t||kd||ddfq|Wd|krtjdtnx^|jD]P}d|krqntt||tkd|t||||fqWtt|dtkd|dft|dd+kd|dt |dt |d|dd,krtjd |dtnt|j d! p|d!j d"d#|d!t|j d$ p|d$j d"d%|d$|j d&rVtt |d&d'kd(|d&n|j d!s{td$|kd)nt|j d!d"kd*dS(-Nu:Environment is not of the right type: %r (environment: %r)uREQUEST_METHODu SERVER_NAMEu SERVER_PORTu wsgi.versionu wsgi.inputu wsgi.errorsuwsgi.multithreaduwsgi.multiprocessu wsgi.run_onceu$Environment missing required key: %ruHTTP_CONTENT_TYPEuHTTP_CONTENT_LENGTHu8Environment should not have the key: %s (use %s instead)iu QUERY_STRINGuQUERY_STRING is not in the WSGI environment; the cgi module will use sys.argv when this variable is missing, so application errors are more likelyu.u9Environmental variable %s is not a string: %r (value: %r)u#wsgi.version should be a tuple (%r)uwsgi.url_schemeuhttpuhttpsuwsgi.url_scheme unknown: %ruGETuHEADuPOSTuOPTIONSuPUTuDELETEuTRACEuUnknown REQUEST_METHOD: %ru SCRIPT_NAMEu/u$SCRIPT_NAME doesn't start with /: %ru PATH_INFOu"PATH_INFO doesn't start with /: %ruCONTENT_LENGTHiuInvalid CONTENT_LENGTH: %rugOne of SCRIPT_NAME or PATH_INFO are required (PATH_INFO should at least be '/' if SCRIPT_NAME is empty)uOSCRIPT_NAME cannot be '/'; it should instead be '', and PATH_INFO should be '/'(uhttpuhttps(uGETuHEADuPOSTuOPTIONSuPUTuDELETEuTRACE(uassert_utypeudictuwarningsuwarnu WSGIWarningukeysustrutupleu check_inputu check_errorsugetu startswithuint(uenvironukey((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu check_environ*s`        #     u check_environcCsAx:ddddgD]&}tt||d||fqWdS(Nureadureadlineu readlinesu__iter__u-wsgi.input (%r) doesn't have the attribute %s(uassert_uhasattr(u wsgi_inputuattr((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu check_inputksu check_inputcCs>x7dddgD]&}tt||d||fqWdS(Nuflushuwriteu writelinesu.wsgi.errors (%r) doesn't have the attribute %s(uassert_uhasattr(u wsgi_errorsuattr((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu check_errorsqsu check_errorscCst|d}|jddd}tt|dkd|t|}t|dkd|t|dks|dd krtjd |tndS( NuStatusiiiu)Status codes must be three characters: %riduStatus code is invalid: %riu ujThe status string (%r) should be a three-digit integer followed by a single space and a status explanation( ucheck_string_typeusplituNoneuassert_ulenuintuwarningsuwarnu WSGIWarning(ustatusu status_codeu status_int((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu check_statusws  "u check_statusc Cs}tt|tkd|t|fi}xG|D]?}tt|tkd|t|ftt|dk|\}}t|d}t|d}t|jdkd|d||jns.       7#  # A