o b2@s8dZgdZddlmZddlmZddlmZddlm Z ddZ Gd d d e Z Gd d d e Z Gd dde ZGddde ZGddde ZGddde ZGddde ZGdddeZGdddeZGddde ZGddde ZGdd d e ZGd!d"d"e ZGd#d$d$e ZGd%d&d&e Zd'S)(z+ Exception definitions for L{twisted.web}. ) Error PageRedirectInfiniteRedirection RenderErrorMissingRenderMethodMissingTemplateLoaderUnexposedMethodError UnfilledSlotUnsupportedTypeFlattenerErrorRedirectWithNoLocation)Sequence)cast) nativeString) RESPONSESc Cs*ztt|WSttfyYdSw)a Returns the response message corresponding to an HTTP code, or None if the code is unknown or unrecognized. @type code: L{bytes} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. @return: A string message or none @rtype: L{bytes} N)rgetint ValueErrorAttributeError)coder3/usr/lib/python3/dist-packages/twisted/web/error.py_codeToMessages  rc@s(eZdZdZdddZdefddZdS) raH A basic HTTP error. @type status: L{bytes} @ivar status: Refers to an HTTP status code, for example C{http.NOT_FOUND}. @type message: L{bytes} @param message: A short error message, for example "NOT FOUND". @type response: L{bytes} @ivar response: A complete HTML document for an error page. NcCsF|pt|}t||||t|trd|f}||_||_||_dS)a) Initializes a basic exception. @type code: L{bytes} or L{int} @param code: Refers to an HTTP status code (for example, 200) either as an integer or a bytestring representing such. If no C{message} is given, C{code} is mapped to a descriptive bytestring that is used instead. @type message: L{bytes} @param message: A short error message, for example "NOT FOUND". @type response: L{bytes} @param response: A complete HTML document for an error page. s%dN)r Exception__init__ isinstancerstatusmessageresponse)selfrrrrrrr>s    zError.__init__returncCst|jd|jS)N )rrrrrrr__str__\sz Error.__str__)NN)__name__ __module__ __qualname____doc__rstrr#rrrrr0s rc@eZdZdZdddZdS)rz A request resulted in an HTTP redirect. @type location: L{bytes} @ivar location: The location of the redirect which was not followed. NcC4t|||||jr|r|jd||_||_dS)a Initializes a page redirect exception. @type code: L{bytes} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. If no C{message} is given, C{code} is mapped to a descriptive string that is used instead. @type message: L{bytes} @param message: A short error message, for example "NOT FOUND". @type response: L{bytes} @param response: A complete HTML document for an error page. @type location: L{bytes} @param location: The location response-header field value. It is an absolute URI used to redirect the receiver to a location other than the Request-URI so the request can be completed.  to Nrrrlocationrrrrr-rrrrh  zPageRedirect.__init__NNNr$r%r&r'rrrrrr`src@r))rz HTTP redirection is occurring endlessly. @type location: L{bytes} @ivar location: The first URL in the series of redirections which was not followed. NcCr*)a Initializes an infinite redirection exception. @type code: L{bytes} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. If no C{message} is given, C{code} is mapped to a descriptive string that is used instead. @type message: L{bytes} @param message: A short error message, for example "NOT FOUND". @type response: L{bytes} @param response: A complete HTML document for an error page. @type location: L{bytes} @param location: The location response-header field value. It is an absolute URI used to redirect the receiver to a location other than the Request-URI so the request can be completed. r+Nr,r.rrrrr/zInfiniteRedirection.__init__r0r1rrrrrsrc@seZdZdZddZdS)r z Exception passed to L{ResponseFailed} if we got a redirect without a C{Location} header field. @type uri: L{bytes} @ivar uri: The URI which failed to give a proper location header field. @since: 11.1 cCs(t||||jd||_||_dS)a Initializes a page redirect exception when no location is given. @type code: L{bytes} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. If no C{message} is given, C{code} is mapped to a descriptive string that is used instead. @type message: L{bytes} @param message: A short error message. @type uri: L{bytes} @param uri: The URI which failed to give a proper location header field. r+N)rrruri)rrrr2rrrrs zRedirectWithNoLocation.__init__Nr1rrrrr s r c@s*eZdZdZdZddZdefddZdS) UnsupportedMethoda^ Raised by a resource when faced with a strange request method. RFC 2616 (HTTP 1.1) gives us two choices when faced with this situation: If the type of request is known to us, but not allowed for the requested resource, respond with NOT_ALLOWED. Otherwise, if the request is something we don't know how to deal with in any case, respond with NOT_IMPLEMENTED. When this exception is raised by a Resource's render method, the server will make the appropriate response. This exception's first argument MUST be a sequence of the methods the resource *does* support. rcGs0tj||g|R||_t|tstddS)Nz`First argument must be a sequence of supported methods, but my first argument is not a sequence.)rrallowedMethodsrr TypeError)rr4argsrrrrs zUnsupportedMethod.__init__r cCs d|jS)NzExpected one of )r4r"rrrr#s zUnsupportedMethod.__str__N)r$r%r&r'r4rr(r#rrrrr3s  r3c@eZdZdZdS)SchemeNotSupportedzB The scheme of a URI was not one of the supported values. Nr$r%r&r'rrrrr8r8c@r7)rz\ Base exception class for all errors which can occur during template rendering. Nr9rrrrrr:rc@&eZdZdZddZdefddZdS)rz Tried to use a render method which does not exist. @ivar element: The element which did not have the render method. @ivar renderName: The name of the renderer which could not be found. cCst|||||_||_dSN)rrelement renderName)rr=r>rrrrs zMissingRenderMethod.__init__r cCsd|jj|j|jS)Nz*{!r}: {!r} had no render method named {!r})format __class__r$r=r>r"rrr__repr__s zMissingRenderMethod.__repr__Nr$r%r&r'rr(rArrrrrsrc@r;)rz L{MissingTemplateLoader} is raised when trying to render an Element without a template loader, i.e. a C{loader} attribute. @ivar element: The Element which did not have a document factory. cCst||||_dSr<)rrr=)rr=rrrrs  zMissingTemplateLoader.__init__r cCs|jjd|jdS)N: z had no loader)r@r$r=r"rrrrAszMissingTemplateLoader.__repr__NrBrrrrrsrc@r7)rzK Raised on any attempt to get a method which has not been exposed. Nr9rrrrrr:rc@r7)rzL During flattening, a slot with no associated data was encountered. Nr9rrrrrr:rc@r7)r z_ During flattening, an object of a type which cannot be flattened was encountered. Nr9rrrrr $r:r c@r7)ExcessiveBufferingErrorz The HTTP/2 protocol has been forced to buffer an excessive amount of outbound data, and has therefore closed the connection and dropped all outbound data. Nr9rrrrrD+r:rDc@s<eZdZdZddZddZdefddZdefd d Zd S) r a  An error occurred while flattening an object. @ivar _roots: A list of the objects on the flattener's stack at the time the unflattenable object was encountered. The first element is least deeply nested object and the last element is the most deeply nested. cCs&||_||_||_t||||dSr<) _exception_roots _tracebackrr)r exceptionroots tracebackrrrr<szFlattenerError.__init__cCsddlm}t|ttfr1t|dkr-t|trd}nd}t|dd||ddSt|St||rN|jdurBd |jd Sd |j|j |j |jfSt|S) a Convert an object from C{self._roots} to a string suitable for inclusion in a render-traceback (like a normal Python traceback, but can include "frame" source locations which are not in Python source files). @param obj: Any object which can be a render step I{root}. Typically, L{Tag}s, strings, and other simple Python types. @return: A string representation of C{obj}. @rtype: L{str} r )Tag(z<...>s<...>NizTag <>z&File "%s", line %d, column %d, in "%s") twisted.web.templaterKrbytesr(lenasciifilenametagName lineNumber columnNumber)robjrKellipsisrrr _formatRootBs$      zFlattenerError._formatRootr csddlm}jrddfddjDd}nd}jr0dd d|jDd}nd}ttd ||jjj d tjdS) z Present a string representation which includes a template traceback, so we can tell where this error occurred in the template, as well as in Python. r ) format_listz z csg|]}|qSr)rY).0rr"rr {sz+FlattenerError.__repr__.. cSsg|] }|D]}|qqSr) splitlines)r[entrylinerrrr]szException while flattening: rC) rJrZrFjoinrGrr(rEr@r$)rrZrIrJrr"rrAns>   zFlattenerError.__repr__cCst|Sr<)reprr"rrrr#szFlattenerError.__str__N) r$r%r&r'rrYr(rAr#rrrrr 3s ,+r c@r7)UnsupportedSpecialHeaderzz A HTTP/2 request was received that contained a HTTP/2 pseudo-header field that is not recognised by Twisted. Nr9rrrrrer:reN)r'__all__collections.abcr typingrtwisted.python.compatrtwisted.web._responsesrrrrrrr r3r8rrrrrr rDr rerrrrs,    0"#! j