• File: lint.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/paste/__pycache__/lint.cpython-37.pyc
  • Date Modified: 12/01/2019 7:09 PM
  • File size: 14.21 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

aN:@sdZddlZddlZddlmZmZmZmZddlZe	dZ
e	dZGdddeZ
d&dd	ZGd
ddeZGdd
d
eZGdddeZGdddeZGdddeZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zee_d	d%gZdS)'a"
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).
N)DictType
StringType	TupleTypeListTypez^[a-zA-Z][a-zA-Z0-9\-_]*$z[\000-\037]c@seZdZdZdS)WSGIWarningz:
    Raised in response to WSGI-spec-related warnings
    N)__name__
__module____qualname____doc__rr;/opt/alt/python37/lib/python3.7/site-packages/paste/lint.pyrxsrcsfdd}|S)a
    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 throw 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 throw an exception
    at that point).
    cst|dkstd|r td|\}t|gfdd}t|d|d<t|d|d<||}|dk	r||dkstd	t|t|S)
NzTwo arguments requiredzNo keyword arguments allowedcst|dks$t|dks$td||r0td|d}|d}t|dkrV|d}nd}t|t|t||t|dt|S)Nr
zInvalid number of arguments: %szNo keyword arguments allowedr)lenAssertionErrorcheck_status
check_headerscheck_content_typecheck_exc_infoappendWriteWrapper)argskwstatusheadersexc_info)start_responsestart_response_startedrrstart_response_wrappers



z<middleware.<locals>.lint_app.<locals>.start_response_wrapperz
wsgi.inputzwsgi.errorsFz>The application must return an iterator, if only an empty list)rr
check_environInputWrapperErrorWrappercheck_iteratorIteratorWrapper)rrenvironriterator)application)rrrlint_apps
zmiddleware.<locals>.lint_appr)r'global_confr(r)r'r
middleware}s)r*c@s<eZdZddZddZddZddZd	d
ZddZd
S)r!cCs
||_dS)N)input)self
wsgi_inputrrr__init__szInputWrapper.__init__cGs4t|dkst|jj|}t|tdks0t|S)Nr)rrr+readtype)r,rvrrrr0szInputWrapper.readcGs$|jj|}t|tdks t|S)Nr/)r+readliner1r)r,rr2rrrr3szInputWrapper.readlinecGsVt|dkst|jj|}t|tgks0tx |D]}t|tdks6tq6W|S)Nrr/)rrr+	readlinesr1)r,rlineslinerrrr4s
zInputWrapper.readlinesccs x|}|sdS|VqWdS)N)r3)r,r6rrr__iter__s
zInputWrapper.__iter__cCsdstddS)Nrz input.close() must not be called)r)r,rrrcloseszInputWrapper.closeN)	rrr	r.r0r3r4r7r8rrrrr!sr!c@s4eZdZddZddZddZddZd	d
ZdS)r"cCs
||_dS)N)errors)r,wsgi_errorsrrrr.szErrorWrapper.__init__cCs$t|tdkst|j|dS)Nr/)r1rr9write)r,srrrr;szErrorWrapper.writecCs|jdS)N)r9flush)r,rrrr=szErrorWrapper.flushcCsx|D]}||qWdS)N)r;)r,seqr6rrr
writeliness
zErrorWrapper.writelinescCsdstddS)Nrz!errors.close() must not be called)r)r,rrrr8szErrorWrapper.closeN)rrr	r.r;r=r?r8rrrrr"s
r"c@seZdZddZddZdS)rcCs
||_dS)N)writer)r,Zwsgi_writerrrrr.szWriteWrapper.__init__cCs"t|tdkst||dS)Nr/)r1rr@)r,r<rrr__call__szWriteWrapper.__call__N)rrr	r.rArrrrrsrc@seZdZddZddZdS)PartialIteratorWrappercCs
||_dS)N)r&)r,
wsgi_iteratorrrrr.szPartialIteratorWrapper.__init__cCs
t|jS)N)r$r&)r,rrrr7szPartialIteratorWrapper.__iter__N)rrr	r.r7rrrrrBsrBc@s4eZdZddZddZddZddZd	d
ZdS)r$cCs ||_t||_d|_||_dS)NF)original_iteratoriterr&closedcheck_start_response)r,rCrGrrrr.s
zIteratorWrapper.__init__cCs|S)Nr)r,rrrr7szIteratorWrapper.__iter__cCs:|jrtd|j}|jdk	r6|js0tdd|_|S)NzIterator read after closedzjThe application returns and we started iterating over its body, but start_response has not yet been called)rFrr&nextrG)r,r2rrrrHs

zIteratorWrapper.nextcCs d|_t|jdr|jdS)NTr8)rFhasattrrDr8)r,rrrr8szIteratorWrapper.closecCs$|jstjd|js tddS)Nz/Iterator garbage collected without being closed)rFsysstderrr;r)r,rrr__del__s
zIteratorWrapper.__del__N)rrr	r.r7rHr8rLrrrrr$s

r$cCst|tks tdt||fx dD]}||ks&td|q&Wx,dD]$}||ksHtd||ddfqHWd|krtdtxH|D]<}d	|krqt||tkstd
|t||||fqWt|dtkstd|d|d
dkstd|d
t	|dt
|d|ddkrFtd|dt|drr|ddsrtd|d|dr|ddstd|d|drt
|ddkstd|d|ds|dstd|ddkstddS)Nz:Environment is not of the right type: %r (environment: %r))	REQUEST_METHODZSERVER_NAMEZSERVER_PORTzwsgi.versionz
wsgi.inputzwsgi.errorszwsgi.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)zwsgi.versionz#wsgi.version should be a tuple (%r)zwsgi.url_scheme)httphttpszwsgi.url_scheme unknown: %rz
wsgi.inputzwsgi.errorsrM)ZGETZHEADZPOSTZOPTIONSZPUTZDELETEZTRACEzUnknown REQUEST_METHOD: %rZSCRIPT_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 '/')r1rrwarningswarnrkeysrrcheck_inputcheck_errorsget
startswithintZhas_key)r%keyrrrr sZ




r cCs,x&dD]}t||std||fqWdS)N)r0r3r4r7z-wsgi.input (%r) doesn't have the attribute %s)rIr)r-attrrrrrV]s
rVcCs,x&dD]}t||std||fqWdS)N)r=r;r?z.wsgi.errors (%r) doesn't have the attribute %s)rIr)r:r\rrrrWcs
rWcCst|tkstd||ddd}t|dks@td|t|}|dks\td|t|dkst|dd	krtd
|tdS)Nz Status must be a string (not %r)rrrz)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)	r1rrsplitrrZrSrTr)rZstatus_codeZ
status_intrrrris

rcCs
t|tks td|t|fi}x|D]}t|tksNtd|t|ft|dks^t|\}}|dks~td|d||<d|krd|kstd|t|std	||d
s|drtd|t	|r*td
|t	|
dfq*WdS)Nz%Headers (%r) must be of type list: %rz1Individual headers (%r) must be of type tuple: %rr
rzyThe 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 '_': %rz#Bad header value: %r (bad char: %r)r)r1rrrrlower	header_researchendswithbad_header_value_regroup)rZheader_namesitemnamevaluerrrrxs,


rcCsrt|ddd}d}d}x8|D]0\}}|dkr"||krBdSds"td|q"W||krndsntd|dS)Nrr)i0zcontent-typezJContent-Type header found in a %s response, which must not return content.z,No Content-Type header found in headers (%s))rZr`rer)rrcodeZNO_MESSAGE_BODYZNO_MESSAGE_TYPErlrmrrrrsrcCs0|dks,t|tdks,td|t|fdS)Nrz exc_info (%r) is not a tuple: %r)r1r)rrrrrsrcCst|trtddS)NzvYou should not return a string as your application iterator, instead return a single-item list containing that string.)
isinstancestrr)r&rrrr#sr#cCst|S)N)r*)r'r)rrrmake_middlewaresrr)N)r
rerJtypesrrrrrScompilerfriWarningrr*objectr!r"rrBr$r rVrWrrrrr#rr__all__rrrr<module>ns0


7"		!A