%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyc

�
a�Nc@szdZddlZddlmZddlmZmZmZddlm	Z	ddl
mZmZm
Z
mZdZdZd	efd
��YZdefd��YZd
efd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd ��YZd!efd"��YZd#efd$��YZd%efd&��YZ d'efd(��YZ!d)efd*��YZ"d+efd,��YZ#d-efd.��YZ$d/efd0��YZ%d1efd2��YZ&d3efd4��YZ'd5efd6��YZ(d7efd8��YZ)d9efd:��YZ*d;efd<��YZ+d=efd>��YZ,d?efd@��YZ-dAefdB��YZ.dCefdD��YZ/dEefdF��YZ0dGe0fdH��YZ1dIe0fdJ��YZ2dKe0fdL��YZ3dMe0fdN��YZ4dOe0fdP��YZ5dQe0fdR��YZ6d	d
dgZ7iZ8xje9�j:�D]Y\Z;Z<e=e<e>ej?f�r�e@e<e�r�e<jAr�e<e8e<jA<e7jBe;�q�q�WdS�ZCdTeDfdU��YZEdV�ZFdddW�ZHe7jIdTdXg�dS(Ys�	
HTTP Exception Middleware

This module processes Python exceptions that relate to HTTP exceptions
by defining a set of exceptions, all subclasses of HTTPException, and a
request handler (`middleware`) that catches these exceptions and turns
them into proper responses.

This module defines exceptions according to RFC 2068 [1]_ : codes with
100-300 are not really errors; 400's are client errors, and 500's are
server errors.  According to the WSGI specification [2]_ , the application
can call ``start_response`` more then once only under two conditions:
(a) the response has not yet been sent, or (b) if the second and
subsequent invocations of ``start_response`` have a valid ``exc_info``
argument obtained from ``sys.exc_info()``.  The WSGI specification then
requires the server or gateway to handle the case where content has been
sent and then an exception was encountered.

Exceptions in the 5xx range and those raised after ``start_response``
has been called are treated as serious errors and the ``exc_info`` is
filled-in with information needed for a lower level module to generate a
stack trace and log information.

Exception
  HTTPException
    HTTPRedirection
      * 300 - HTTPMultipleChoices
      * 301 - HTTPMovedPermanently
      * 302 - HTTPFound
      * 303 - HTTPSeeOther
      * 304 - HTTPNotModified
      * 305 - HTTPUseProxy
      * 306 - Unused (not implemented, obviously)
      * 307 - HTTPTemporaryRedirect
    HTTPError
      HTTPClientError
        * 400 - HTTPBadRequest
        * 401 - HTTPUnauthorized
        * 402 - HTTPPaymentRequired
        * 403 - HTTPForbidden
        * 404 - HTTPNotFound
        * 405 - HTTPMethodNotAllowed
        * 406 - HTTPNotAcceptable
        * 407 - HTTPProxyAuthenticationRequired
        * 408 - HTTPRequestTimeout
        * 409 - HTTPConfict
        * 410 - HTTPGone
        * 411 - HTTPLengthRequired
        * 412 - HTTPPreconditionFailed
        * 413 - HTTPRequestEntityTooLarge
        * 414 - HTTPRequestURITooLong
        * 415 - HTTPUnsupportedMediaType
        * 416 - HTTPRequestRangeNotSatisfiable
        * 417 - HTTPExpectationFailed
      HTTPServerError
        * 500 - HTTPInternalServerError
        * 501 - HTTPNotImplemented
        * 502 - HTTPBadGateway
        * 503 - HTTPServiceUnavailable
        * 504 - HTTPGatewayTimeout
        * 505 - HTTPVersionNotSupported

References:

.. [1] http://www.python.org/peps/pep-0333.html#error-handling
.. [2] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5

i����N(tcatch_errors_app(t
has_headertheader_valuetreplace_header(tresolve_relative_url(t
strip_htmlt
html_quotetno_quotet
comment_quotesWSGI Servers�<html>
  <head><title>%(title)s</title></head>
  <body>
    <h1>%(title)s</h1>
    <p>%(body)s</p>
    <hr noshade>
    <div align="right">%(server)s</div>
  </body>
</html>
t
HTTPExceptioncBs�eZdZdZdZdZdZdZdZ	dZ
dddd�Zdd�Zd�Z
d�Zd�Zd�Zdd	�ZeZd
�ZRS(
s�	
    the HTTP exception base class

    This encapsulates an HTTP response that interrupts normal application
    flow; but one which is not necessarly an error condition. For
    example, codes in the 300's are exceptions in that they interrupt
    normal processing; however, they are not considered errors.

    This class is complicated by 4 factors:

      1. The content given to the exception may either be plain-text or
         as html-text.

      2. The template may want to have string-substitutions taken from
         the current ``environ`` or values from incoming headers. This
         is especially troublesome due to case sensitivity.

      3. The final output may either be text/plain or text/html
         mime-type as requested by the client application.

      4. Each exception has a default explanation, but those who
         raise exceptions may want to provide additional detail.

    Attributes:

       ``code``
           the HTTP status code for the exception

       ``title``
           remainder of the status line (stuff after the code)

       ``explanation``
           a plain-text explanation of the error message that is
           not subject to environment or header substitutions;
           it is accessible in the template via %(explanation)s

       ``detail``
           a plain-text message customization that is not subject
           to environment or header substitutions; accessible in
           the template via %(detail)s

       ``template``
           a content fragment (in HTML) used for environment and
           header substitution; the default template includes both
           the explanation and further detail provided in the
           message

       ``required_headers``
           a sequence of headers which are required for proper
           construction of the exception

    Parameters:

       ``detail``
         a plain-text override of the default ``detail``

       ``headers``
         a list of (k,v) header pairs

       ``comment``
         a plain-text additional information which is
         usually stripped/hidden for end-users

    To override the template (which is HTML content) or the plain-text
    explanation, one must subclass the given exception; or customize it
    after it has been created.  This particular breakdown of a message
    into explanation, detail and template allows both the creation of
    plain-text and html messages for various clients as well as
    error-free substitution of environment variables and headers.
    ts6%(explanation)s
<br/>%(detail)s
<!-- %(comment)s -->cCsP|jstd��t|td�tf�s@td|��t|td�tf�sktd|��t|td�tf�s�td|��|p�t�|_xE|j	D]:}|r�t
||�s�td|jj||f��q�W|dk	r||_
n|dk	r ||_ntj|d|j|j|j|j
f�dS(Ns0Do not directly instantiate abstract exceptions.s"headers must be None or a list: %rs#detail must be None or a string: %rs$comment must be None or a string: %rs;Exception %s must be passed the header %r (got headers: %r)s%s %s
%s
%s
(tcodetAssertionErrort
isinstancettypetNonetlistt
basestringttupletheaderstrequired_headersRt	__class__t__name__tdetailtcommentt	Exceptiont__init__ttitletexplanation(tselfRRRtreq((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR�s&


c
Cs
|p	|}i||j�d6||j�d6||j�d6}tj|jkr�x*|j�D]\}}||�||<qaW|jr�x0|jD]"\}}||�||j�<q�Wq�nxB|j�D]4\}}	t|	t	�r�|	j
dd�||<q�q�W||S(NRRRtutf8txmlcharrefreplace(RRRR	ttemplatetitemsRtlowerR
tunicodetencode(
RtenvironR!tescfunctcomment_escfunctargstktvtkeytvalue((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt	make_body�s	 cCs8|j|t|j�tt�}d|j|j|fS(s, text/plain representation of the exception s%s %s
%s
(R.RR!RRRR(RR&tbody((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytplain�s!cCsE|j||jtt�}ti|jd6|jd6td6|d6S(s+ text/html representation of the exception RRtserverR/(R.R!RRtTEMPLATERRtSERVER_NAME(RR&R/((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pythtml�s

cCs�|jrt|j�}ng}d|jdd�ksQd|jdd�krst|dd�|j|�}nt|dd�|j|�}t|t�r�|jd�}t	|d�p�d}t|d|d	�n||fS(
NR4tHTTP_ACCEPTR
s*/*scontent-types	text/htmls
text/plainRs; charset=utf8(
RRtgetRR4R0R
R$R%R(RR&Rtcontenttcur_content_type((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytprepare_content�s"	cCsVddlm}|j|�\}}|d|jd|�}|jj|�|_|S(Ni����(tWSGIResponseRR7(tpaste.wsgiwrappersR:R9RRtfromlist(RR&R:RR7tresp((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytresponse�s
cCs<|j|�\}}|d|j|jf||�|gS(s6
        This exception as a WSGI application
        s%s %s(R9RR(RR&tstart_responsetexc_infoRR7((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytwsgi_applications
cCsd|jj|j|jfS(Ns<%s %s; code=%s>(RRRR(R((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt__repr__sN((Rt
__module__t__doc__RRRRRRR!RRR.R0R4R9R>RAt__call__RB(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR	_s"F					
t	HTTPErrorcBseZdZRS(s�
    base class for status codes in the 400's and 500's

    This is an exception which indicates that an error has occurred,
    and that any work in progress should not be committed.  These are
    typically results in the 400's and 500's.
    (RRCRD(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRFstHTTPRedirectioncBseZdZRS(s
    base class for 300's status code (redirections)

    This is an abstract base class for 3xx redirection.  It indicates
    that further action needs to be taken by the user agent in order
    to fulfill the request.  It does not necessarly signal an error
    condition.
    (RRCRD(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRG$st	_HTTPMovecBsYeZdZdZdZdZdddd�Zdddd�Ze	e�Zd�Z
RS(	s�
    redirections which require a Location field

    Since a 'Location' header is a required attribute of 301, 302, 303,
    305 and 307 (but not 304), this base class provides the mechanics to
    make this easy.  While this has the same parameters as HTTPException,
    if a location is not provided in the headers; it is assumed that the
    detail _is_ the location (this for backward compatibility, otherwise
    we'd add a new attribute).
    tlocationsThe resource has been moved tos�%(explanation)s <a href="%(location)s">%(location)s</a>;
you should be redirected automatically.
%(detail)s
<!-- %(comment)s -->cCs�t|td�tf�s!t�|p*g}t|d�}|sd|}d}|jd|f�n|svtd��tj||||�|dk	r�||_	ndS(NRIR
saHTTPRedirection specified neither a location in the headers nor did it provide a detail argument.(
R
RRRRRtappendRGRR(RRRRRI((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR@s!cCsGt||�}|pg}|jd|f�|d|d|d|�S(s�
        Create a redirect object with the dest_uri, which may be relative,
        considering it relative to the uri implied by the given environ.
        tLocationRRR(RRJ(tclstdest_uriR&RRRRI((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytrelative_redirectOscCsDx=|jD]"\}}|j�dkr
|Sq
Wtd|��dS(NRIsNo location set for %s(RR#tKeyError(RtnameR-((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRI[s(slocationN(RRCRDRRR!RRRNtclassmethodRI(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRH.s

tHTTPMultipleChoicescBseZdZdZRS(i,sMultiple Choices(RRCRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRRbstHTTPMovedPermanentlycBseZdZdZRS(i-sMoved Permanently(RRCRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRSfst	HTTPFoundcBseZdZdZdZRS(i.tFoundsThe resource was found at(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRTjstHTTPSeeOthercBseZdZdZRS(i/s	See Other(RRCRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRVqstHTTPNotModifiedcBs,eZdZdZdZd�Zd�ZRS(i0sNot ModifiedR
cCsdS(NR
((RR&((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR0~scCsdS(s+ text/html representation of the exception R
((RR&((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR4�s(RRCRRtmessageR0R4(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRWus
	tHTTPUseProxycBseZdZdZdZRS(i1s	Use Proxys8The resource must be accessed through a proxy located at(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRY�stHTTPTemporaryRedirectcBseZdZdZRS(i3sTemporary Redirect(RRCRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRZ�stHTTPClientErrorcBs eZdZdZdZdZRS(s8
    base class for the 400's, where the client is in-error

    This is an error condition in which the client is presumed to be
    in-error.  This is an expected problem, and thus is not considered
    a bug.  A server-side traceback is not warranted.  Unless specialized,
    this is a '400 Bad Request'
    i�sBad RequestsdThe server could not comply with the request since
it is either malformed or otherwise incorrect.
(RRCRDRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR[�stHTTPBadRequestcBseZRS((RRC(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR\�stHTTPUnauthorizedcBseZdZdZdZRS(i�tUnauthorizeds�This server could not verify that you are authorized to
access the document you requested.  Either you supplied the
wrong credentials (e.g., bad password), or your browser
does not understand how to supply the credentials required.
(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR]�stHTTPPaymentRequiredcBseZdZdZdZRS(i�sPayment Requireds(Access was denied for financial reasons.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR_�st
HTTPForbiddencBseZdZdZdZRS(i�t	Forbiddens#Access was denied to this resource.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR`�stHTTPNotFoundcBseZdZdZdZRS(i�s	Not Founds The resource could not be found.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRb�stHTTPMethodNotAllowedcBs eZdZdZdZdZRS(tallowi�sMethod Not AllowedsKThe method %(REQUEST_METHOD)s is not allowed for this resource.
%(detail)s(Rd(RRCRRRR!(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRc�stHTTPNotAcceptablecBseZdZdZdZRS(i�sNot AcceptableswThe resource could not be generated that was acceptable to your browser (content
of type %(HTTP_ACCEPT)s).
%(detail)s(RRCRRR!(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRe�stHTTPProxyAuthenticationRequiredcBseZdZdZdZRS(i�sProxy Authentication Requireds*Authentication /w a local proxy is needed.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRf�stHTTPRequestTimeoutcBseZdZdZdZRS(i�sRequest TimeoutsHThe server has waited too long for the request to be sent by the client.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRg�stHTTPConflictcBseZdZdZdZRS(i�tConflicts:There was a conflict when trying to complete your request.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRh�stHTTPGonecBseZdZdZdZRS(i�tGonesFThis resource is no longer available.  No forwarding address is given.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRj�stHTTPLengthRequiredcBseZdZdZdZRS(i�sLength RequiredsContent-Length header required.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRl�stHTTPPreconditionFailedcBseZdZdZdZRS(i�sPrecondition FailedsRequest precondition failed.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRm�stHTTPRequestEntityTooLargecBseZdZdZdZRS(i�sRequest Entity Too Larges7The body of your request was too large for this server.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRn�stHTTPRequestURITooLongcBseZdZdZdZRS(i�sRequest-URI Too Longs-The request URI was too long for this server.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRo�stHTTPUnsupportedMediaTypecBseZdZdZdZRS(i�sUnsupported Media TypesTThe request media type %(CONTENT_TYPE)s is not supported by this server.
%(detail)s(RRCRRR!(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRp�stHTTPRequestRangeNotSatisfiablecBseZdZdZdZRS(i�sRequest Range Not Satisfiables%The Range requested is not available.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRqstHTTPExpectationFailedcBseZdZdZdZRS(i�sExpectation FailedsExpectation failed.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRrstHTTPServerErrorcBs eZdZdZdZdZRS(sF
    base class for the 500's, where the server is in-error

    This is an error condition in which the server is presumed to be
    in-error.  This is usually unexpected, and thus requires a traceback;
    ideally, opening a support ticket for the customer. Unless specialized,
    this is a '500 Internal Server Error'
    i�sInternal Server ErrorsUThe server has either erred or is incapable of performing
the requested operation.
(RRCRDRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRsstHTTPInternalServerErrorcBseZRS((RRC(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRt+stHTTPNotImplementedcBseZdZdZdZRS(i�sNot ImplementedsUThe request method %(REQUEST_METHOD)s is not implemented for this server.
%(detail)s(RRCRRR!(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRu.stHTTPBadGatewaycBseZdZdZdZRS(i�sBad GatewaysBad gateway.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRv5stHTTPServiceUnavailablecBseZdZdZdZRS(i�sService UnavailablesFThe server is currently unavailable. Please try again at a later time.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRw:stHTTPGatewayTimeoutcBseZdZdZdZRS(i�sGateway TimeoutsThe gateway has timed out.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRx@stHTTPVersionNotSupportedcBseZdZdZdZRS(i�sHTTP Version Not Supporteds"The HTTP version is not supported.(RRCRRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRyEscCst|S(N(t_exceptions(R((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt
get_exceptionUstHTTPExceptionHandlercBs#eZdZdd�Zd�ZRS(s
    catches exceptions and turns them into proper HTTP responses

    This middleware catches any exceptions (which are subclasses of
    ``HTTPException``) and turns them into proper HTTP responses.
    Note if the headers have already been sent, the stack trace is
    always maintained as this indicates a programming error.

    Note that you must raise the exception before returning the
    app_iter, and you cannot use this with generator apps that don't
    raise an exception until after their app_iter is iterated over.
    cCso|s%|dkr|dks%t�|dk	rSddl}|jdtd�n|p\d|_||_dS(NiciXi����s4The warning_level parameter is not used or supportedii�(RRtwarningstwarntDeprecationWarningt
warning_leveltapplication(RR�R�R}((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRjs	
cCs[||d<|jdg�jt�y|j||�SWntk
rV}|||�SXdS(Nspaste.httpexceptionsspaste.expected_exceptions(t
setdefaultRJR	R�(RR&R?texc((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyREts
	N(RRCRDRRRE(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR|\s
cOs,ddl}|jdtd�t||�S(Ni����s\httpexceptions.middleware is deprecated; use make_middleware or HTTPExceptionHandler insteadi(R}R~Rtmake_middleware(R)tkwR}((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt
middleware}s	
cCs%|rt|�}nt|d|�S(s�
    ``httpexceptions`` middleware; this catches any
    ``paste.httpexceptions.HTTPException`` exceptions (exceptions like
    ``HTTPNotFound``, ``HTTPMovedPermanently``, etc) and turns them
    into proper HTTP responses.

    ``warning_level`` can be an integer corresponding to an HTTP code.
    Any code over that value will be passed 'up' the chain, potentially
    reported on by another piece of middleware.
    R�(tintR|(tapptglobal_confR�((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR��sR{(JRDttypest
paste.wsgilibRtpaste.responseRRRt
paste.requestRtpaste.util.quotingRRRRR3R2RR	RFRGRHRRRSRTRVRWRYRZR[R\R]R_R`RbRcReRfRgRhRjRlRmRnRoRpRqRrRsRtRuRvRwRxRyt__all__RztglobalsR"RPR-R
Rt	ClassTypet
issubclassRRJR{tobjectR|R�RR�textend(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt<module>Jsr"�
4		
	!	

Zerion Mini Shell 1.0