• File: httpexceptions.pyo
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyo
  • Date Modified: 08/01/2016 7:39 PM
  • File size: 26.93 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

aNc@szdZddlZddlmZddlmZmZmZddlm	Z	ddl
mZmZm
Z
mZdZdZd	efd
YZdefdYZd
efdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefd YZd!efd"YZd#efd$YZd%efd&YZ d'efd(YZ!d)efd*YZ"d+efd,YZ#d-efd.YZ$d/efd0YZ%d1efd2YZ&d3efd4YZ'd5efd6YZ(d7efd8YZ)d9efd:YZ*d;efd<YZ+d=efd>YZ,d?efd@YZ-dAefdBYZ.dCefdDYZ/dEefdFYZ0dGe0fdHYZ1dIe0fdJYZ2dKe0fdLYZ3dMe0fdNYZ4dOe0fdPYZ5dQe0fdRYZ6d	d
dgZ7iZ8xje9j:D]Y\Z;Z<e=e<e>ej?fre@e<ere<jAre<e8e<jA<e7jBe;qqWdSZCdTeDfdUYZEdVZFdddWZHe7jIdTdXgdS(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

iN(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
HTTPExceptioncBseZdZdZdZdZdZdZdZ	dZ
ddddZddZdZ
dZdZdZdd	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 -->cCs|pt|_x|jD]}qW|dk	r>||_n|dk	rV||_ntj|d|j|j	|j
|jfdS(Ns%s %s
%s
%s
(ttupletheaderstrequired_headerstNonetdetailtcommentt	Exceptiont__init__tcodettitletexplanation(tselfRRRtreq((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRs	c
Cs
|p	|}i||jd6||jd6||jd6}tj|jkrx*|jD]\}}||||<qaW|jrx0|jD]"\}}||||j<qWqnxB|jD]4\}}	t|	t	r|	j
dd||<qqW||S(NRRRtutf8txmlcharrefreplace(RRRR	ttemplatetitemsRtlowert
isinstancetunicodetencode(
RtenvironRtescfunctcomment_escfunctargstktvtkeytvalue((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt	make_bodys	 cCs8|j|t|jtt}d|j|j|fS(s, text/plain representation of the exception s%s %s
%s
(R(RRRRRR(RR tbody((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytplains!cCsE|j||jtt}ti|jd6|jd6td6|d6S(s+ text/html representation of the exception RRtserverR)(R(RRRtTEMPLATERRtSERVER_NAME(RR R)((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pythtmls

cCs|jrt|j}ng}d|jddksQd|jddkrst|dd|j|}nt|dd|j|}t|tr|jd}t	|dpd}t|d|d	n||fS(
NR.tHTTP_ACCEPTR
s*/*scontent-types	text/htmls
text/plainRs; charset=utf8(
RtlisttgetRR.R*RRRR(RR Rtcontenttcur_content_type((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytprepare_contents"	cCsVddlm}|j|\}}|d|jd|}|jj||_|S(Ni(tWSGIResponseRR2(tpaste.wsgiwrappersR5R4RRtfromlist(RR R5RR2tresp((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytresponses
cCs<|j|\}}|d|j|jf|||gS(s6
        This exception as a WSGI application
        s%s %s(R4RR(RR tstart_responsetexc_infoRR2((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytwsgi_applications
cCsd|jj|j|jfS(Ns<%s %s; code=%s>(t	__class__t__name__RR(R((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt__repr__sN((R>t
__module__t__doc__RRRRRRRR
RR(R*R.R4R9R<t__call__R?(((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.
    (R>R@RA(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRCstHTTPRedirectioncBseZdZRS(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.
    (R>R@RA(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRD$st	_HTTPMovecBsYeZdZdZdZdZddddZddddZe	eZdZ
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 -->cCsu|p	g}t|d}|sC|}d}|jd|fntj|||||dk	rq||_ndS(NRFR
(RtappendRDRRR(RRRRRF((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.
        tLocationRRR(RRG(tclstdest_uriR RRRRF((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pytrelative_redirectOscCsDx=|jD]"\}}|jdkr
|Sq
Wtd|dS(NRFsNo location set for %s(RRtKeyError(RtnameR'((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRF[s(slocationN(R>R@RAR
RRRRRKtclassmethodRF(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRE.s

tHTTPMultipleChoicescBseZdZdZRS(i,sMultiple Choices(R>R@RR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRObstHTTPMovedPermanentlycBseZdZdZRS(i-sMoved Permanently(R>R@RR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRPfst	HTTPFoundcBseZdZdZdZRS(i.tFoundsThe resource was found at(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRQjstHTTPSeeOthercBseZdZdZRS(i/s	See Other(R>R@RR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRSqstHTTPNotModifiedcBs,eZdZdZdZdZdZRS(i0sNot ModifiedR
cCsdS(NR
((RR ((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR*~scCsdS(s+ text/html representation of the exception R
((RR ((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR.s(R>R@RRtmessageR*R.(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRTus
	tHTTPUseProxycBseZdZdZdZRS(i1s	Use Proxys8The resource must be accessed through a proxy located at(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRVstHTTPTemporaryRedirectcBseZdZdZRS(i3sTemporary Redirect(R>R@RR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRWstHTTPClientErrorcBs 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'
    isBad RequestsdThe server could not comply with the request since
it is either malformed or otherwise incorrect.
(R>R@RARRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRXstHTTPBadRequestcBseZRS((R>R@(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRYstHTTPUnauthorizedcBseZdZdZdZRS(itUnauthorizedsThis 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.
(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRZstHTTPPaymentRequiredcBseZdZdZdZRS(isPayment Requireds(Access was denied for financial reasons.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR\st
HTTPForbiddencBseZdZdZdZRS(it	Forbiddens#Access was denied to this resource.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR]stHTTPNotFoundcBseZdZdZdZRS(is	Not Founds The resource could not be found.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR_stHTTPMethodNotAllowedcBs eZdZdZdZdZRS(tallowisMethod Not AllowedsKThe method %(REQUEST_METHOD)s is not allowed for this resource.
%(detail)s(Ra(R>R@R
RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyR`stHTTPNotAcceptablecBseZdZdZdZRS(isNot AcceptableswThe resource could not be generated that was acceptable to your browser (content
of type %(HTTP_ACCEPT)s).
%(detail)s(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRbstHTTPProxyAuthenticationRequiredcBseZdZdZdZRS(isProxy Authentication Requireds*Authentication /w a local proxy is needed.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRcstHTTPRequestTimeoutcBseZdZdZdZRS(isRequest TimeoutsHThe server has waited too long for the request to be sent by the client.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRdstHTTPConflictcBseZdZdZdZRS(itConflicts:There was a conflict when trying to complete your request.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRestHTTPGonecBseZdZdZdZRS(itGonesFThis resource is no longer available.  No forwarding address is given.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRgstHTTPLengthRequiredcBseZdZdZdZRS(isLength RequiredsContent-Length header required.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRistHTTPPreconditionFailedcBseZdZdZdZRS(isPrecondition FailedsRequest precondition failed.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRjstHTTPRequestEntityTooLargecBseZdZdZdZRS(isRequest Entity Too Larges7The body of your request was too large for this server.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRkstHTTPRequestURITooLongcBseZdZdZdZRS(isRequest-URI Too Longs-The request URI was too long for this server.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRlstHTTPUnsupportedMediaTypecBseZdZdZdZRS(isUnsupported Media TypesTThe request media type %(CONTENT_TYPE)s is not supported by this server.
%(detail)s(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRmstHTTPRequestRangeNotSatisfiablecBseZdZdZdZRS(isRequest Range Not Satisfiables%The Range requested is not available.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRnstHTTPExpectationFailedcBseZdZdZdZRS(isExpectation FailedsExpectation failed.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRostHTTPServerErrorcBs 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'
    isInternal Server ErrorsUThe server has either erred or is incapable of performing
the requested operation.
(R>R@RARRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRpstHTTPInternalServerErrorcBseZRS((R>R@(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRq+stHTTPNotImplementedcBseZdZdZdZRS(isNot ImplementedsUThe request method %(REQUEST_METHOD)s is not implemented for this server.
%(detail)s(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRr.stHTTPBadGatewaycBseZdZdZdZRS(isBad GatewaysBad gateway.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRs5stHTTPServiceUnavailablecBseZdZdZdZRS(isService UnavailablesFThe server is currently unavailable. Please try again at a later time.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRt:stHTTPGatewayTimeoutcBseZdZdZdZRS(isGateway TimeoutsThe gateway has timed out.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRu@stHTTPVersionNotSupportedcBseZdZdZdZRS(isHTTP Version Not Supporteds"The HTTP version is not supported.(R>R@RRR(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRvEscCst|S(N(t_exceptions(R((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt
get_exceptionUstHTTPExceptionHandlercBs#eZdZddZdZRS(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.
    cCsJ|dk	r.ddl}|jdtdn|p7d|_||_dS(Nis4The warning_level parameter is not used or supportedii(RtwarningstwarntDeprecationWarningt
warning_leveltapplication(RR~R}Rz((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRjs	
cCs[||d<|jdgjty|j||SWntk
rV}|||SXdS(Nspaste.httpexceptionsspaste.expected_exceptions(t
setdefaultRGR	R~(RR R:texc((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRBts
	N(R>R@RARRRB(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRy\s
cOs,ddl}|jdtdt||S(Nis\httpexceptions.middleware is deprecated; use make_middleware or HTTPExceptionHandler insteadi(RzR{R|tmake_middleware(R#tkwRz((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}(tintRy(tapptglobal_confR}((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyRsRx(JRAttypest
paste.wsgilibRtpaste.responseRRRt
paste.requestRtpaste.util.quotingRRRRR-R,RR	RCRDRERORPRQRSRTRVRWRXRYRZR\R]R_R`RbRcRdReRgRiRjRkRlRmRnRoRpRqRrRsRtRuRvt__all__RwtglobalsRRMR'Rttypet	ClassTypet
issubclassRRGRxtobjectRyRRRtextend(((sE/opt/alt/python27/lib/python2.7/site-packages/paste/httpexceptions.pyt<module>Jsr"
4		
	!