Your IP : 18.224.32.243


Current Path : /opt/alt/python33/lib64/python3.3/wsgiref/__pycache__/
Upload File :
Current File : //opt/alt/python33/lib64/python3.3/wsgiref/__pycache__/validate.cpython-33.pyc

�
��f/;c@sNdZdgZddlZddlZddlZejd�Zejd�ZGdd�de�Z	dd	�Z
d
d�Zdd�ZGd
d�d�Z
Gdd�d�ZGdd�d�ZGdd�d�ZGdd�d�Zdd�Zdd�Zdd�Zdd�Zdd �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(uWSGIWarningu:
    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.pyuWSGIWarningysuWSGIWarningcGs|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_type�sucheck_string_typecs�fdd�}|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).
    cs�tt|�dkd�t|d�|\}�t|�g���fdd�}t|d�|d<t|d�|d<�||�}t|dk	o�|d	kd�t|�t|��S(
NiuTwo arguments requireduNo keyword arguments allowedcs�tt|�dkp$t|�dkd|f�t|d�|d}|d}t|�dkrs|d}nd}t|�t|�t||�t|��jd�t�|��S(NiiuInvalid number of arguments: %suNo keyword arguments allowedii(	uassert_ulenuNoneucheck_statusu
check_headersucheck_content_typeucheck_exc_infouappenduWriteWrapper(uargsukwustatusuheadersuexc_info(ustart_responseustart_response_started(u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyustart_response_wrapper�s$







u;validator.<locals>.lint_app.<locals>.start_response_wrapperu
wsgi.inputuwsgi.errorsu>The application must return an iterator, if only an empty listF(	uassert_ulenu
check_environuInputWrapperuErrorWrapperuNoneuFalseucheck_iteratoruIteratorWrapper(uargsukwuenvironustart_response_wrapperuiterator(uapplication(ustart_responseustart_response_startedu5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyulint_app�s

uvalidator.<locals>.lint_app((uapplicationulint_app((uapplicationu5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu	validator�s)cBs\|EeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�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.pyuread�suInputWrapper.readcGsBtt|�dk�|jj|�}tt|�tk�|S(Ni(uassert_ulenuinputureadlineutypeubytes(uselfuargsuv((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyureadline�suInputWrapper.readlinecGsitt|�dk�|jj|�}tt|�tk�x$|D]}tt|�tk�qEW|S(Ni(uassert_ulenuinputu	readlinesutypeulistubytes(uselfuargsulinesuline((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu	readlines�s
uInputWrapper.readlinesccs%x|j�}|sdS|VqdS(N(ureadline(uselfuline((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__iter__�s
uInputWrapper.__iter__cCstdd�dS(Niu input.close() must not be called(uassert_(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuclose�suInputWrapper.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InputWrapper�suInputWrappercBsP|EeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS(uErrorWrappercCs
||_dS(N(uerrors(uselfuwsgi_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.pyuwrite�suErrorWrapper.writecCs|jj�dS(N(uerrorsuflush(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuflush�suErrorWrapper.flushcCs"x|D]}|j|�qWdS(N(uwrite(uselfusequline((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu
writelines�s
uErrorWrapper.writelinescCstdd�dS(Niu!errors.close() must not be called(uassert_(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuclose�suErrorWrapper.closeN(u__name__u
__module__u__qualname__u__init__uwriteuflushu
writelinesuclose(u
__locals__((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyuErrorWrapper�s
uErrorWrappercBs,|EeZdZdd�Zdd�ZdS(uWriteWrappercCs
||_dS(N(uwriter(uselfuwsgi_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WriteWrapper�suWriteWrappercBs,|EeZdZdd�Zdd�ZdS(uPartialIteratorWrappercCs
||_dS(N(uiterator(uselfu
wsgi_iterator((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu__init__suPartialIteratorWrapper.__init__cCst|jd�S(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.pyuPartialIteratorWrapper�suPartialIteratorWrappercBsP|EeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS(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d�t|j�}t|�tk	rItdd|f�n|jdk	rtt|jd�d|_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|jd�r+|jj�ndS(NucloseT(uTrueucloseduhasattruoriginal_iteratoruclose(uself((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucloses	uIteratorWrapper.closecCs0|jstjjd�nt|jd�dS(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	Cs�tt|�tkdt|�|f�xCdddddddd	d
g	D] }t||kd|f�qKWx;dd
gD]-}t||kd||dd�f�q|Wd|kr�tjdt�nx^|j�D]P}d|kr�q�ntt||�tkd|t||�||f�q�Wtt|d�tkd|df�t|dd+kd|d�t	|d�t
|d�|dd,kr�tjd |dt�nt|jd!�p�|d!jd"�d#|d!�t|jd$�p|d$jd"�d%|d$�|jd&�rVtt
|d&�d'kd(|d&�n|jd!�s{td$|kd)�nt|jd!�d"kd*�dS(-Nu:Environment is not of the right type: %r (environment: %r)uREQUEST_METHODuSERVER_NAMEuSERVER_PORTuwsgi.versionu
wsgi.inputuwsgi.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_STRINGu�QUERY_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: %ruSCRIPT_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_utypeudictuwarningsuwarnuWSGIWarningukeysustrutupleucheck_inputucheck_errorsugetu
startswithuint(uenvironukey((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu
check_environ*s`	

#	

u
check_environcCsAx:ddddgD]&}tt||�d||f�qWdS(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.pyucheck_inputksucheck_inputcCs>x7dddgD]&}tt||�d||f�qWdS(Nuflushuwriteu
writelinesu.wsgi.errors (%r) doesn't have the attribute %s(uassert_uhasattr(uwsgi_errorsuattr((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucheck_errorsqsucheck_errorscCs�t|d�}|jdd�d}tt|�dkd|�t|�}t|dkd|�t|�dks�|dd	kr�tjd
|t�ndS(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_ulenuintuwarningsuwarnuWSGIWarning(ustatusustatus_codeu
status_int((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucheck_statusws"ucheck_statusc	Cs}tt|�tkd|t|�f�i}xG|D]?}tt|�tkd|t|�f�tt|�dk�|\}}t|d�}t|d�}t|j�dkd|�d||j�<td|ko�d	|kd
|�ttj	|�d|�t|j
d�o/|j
d
�d|�tj	|�r6tdd|tj	|�jd�f�q6q6WdS(Nu%Headers (%r) must be of type list: %ru1Individual headers (%r) must be of type tuple: %riuHeader nameuHeader valueustatusuyThe Status header cannot be used; it conflicts with CGI script, and HTTP status is not given through headers (value: %r).u
u:u,Header names may not contain ':' or '\n': %ruBad header name: %ru-u_u#Names may not end in '-' or '_': %riu#Bad header value: %r (bad char: %r)(
uassert_utypeulistutupleulenucheck_string_typeuloweruNoneu	header_reusearchuendswithubad_header_value_reugroup(uheadersuheader_namesuitemunameuvalue((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu
check_headers�s0
 	u
check_headerscCs�t|d�}t|jdd�d�}d
}xY|D]Q\}}t|d�}|j�dkr8||krudStdd|�q8q8W||kr�tdd	|�ndS(NuStatusiii�i0uHeader nameucontent-typeuJContent-Type header found in a %s response, which must not return content.u,No Content-Type header found in headers (%s)(i�i0(ucheck_string_typeuintusplituNoneuloweruassert_(ustatusuheadersucodeuNO_MESSAGE_BODYunameuvalue((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucheck_content_type�s	ucheck_content_typecCs9t|dkpt|�tkd|t|�f�dS(Nu exc_info (%r) is not a tuple: %r(uassert_uNoneutypeutuple(uexc_info((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucheck_exc_info�sucheck_exc_infocCs!tt|ttf�d�dS(NuwYou should not return a string as your application iterator, instead return a single-item list containing a bytestring.(uassert_u
isinstanceustrubytes(uiterator((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyucheck_iterator�sucheck_iterator(u__doc__u__all__ureusysuwarningsucompileu	header_reubad_header_value_reuWarninguWSGIWarninguassert_ucheck_string_typeu	validatoruInputWrapperuErrorWrapperuWriteWrapperuPartialIteratorWrapperuIteratorWrapperu
check_environucheck_inputucheck_errorsucheck_statusu
check_headersucheck_content_typeucheck_exc_infoucheck_iterator(((u5/opt/alt/python33/lib64/python3.3/wsgiref/validate.pyu<module>ns.	7#		#A

?>