K i 2dZddlmZddlZddlmZgdZGddeZGd d eZ Gd d e Z Gd de Z GddeZ GddeZ GddeZGddeZGddeZGddeZGddeZGddeZGdd eZGd!d"eZGd#d$eZGd%d&eZGd'd(eZGd)d*eZGd+d,eZGd-d.eZGd/d0eZGd1d2eZGd3d4eZGd5d6eZGd7d8ee Z!Gd9d:ee"Z#dd;l$m%Z%m&Z&ee'dy)?aU :mod:`websockets.exceptions` defines the following hierarchy of exceptions. * :exc:`WebSocketException` * :exc:`ConnectionClosed` * :exc:`ConnectionClosedOK` * :exc:`ConnectionClosedError` * :exc:`InvalidURI` * :exc:`InvalidProxy` * :exc:`InvalidHandshake` * :exc:`SecurityError` * :exc:`ProxyError` * :exc:`InvalidProxyMessage` * :exc:`InvalidProxyStatus` * :exc:`InvalidMessage` * :exc:`InvalidStatus` * :exc:`InvalidStatusCode` (legacy) * :exc:`InvalidHeader` * :exc:`InvalidHeaderFormat` * :exc:`InvalidHeaderValue` * :exc:`InvalidOrigin` * :exc:`InvalidUpgrade` * :exc:`NegotiationError` * :exc:`DuplicateParameter` * :exc:`InvalidParameterName` * :exc:`InvalidParameterValue` * :exc:`AbortHandshake` (legacy) * :exc:`RedirectHandshake` (legacy) * :exc:`ProtocolError` (Sans-I/O) * :exc:`PayloadTooBig` (Sans-I/O) * :exc:`InvalidState` (Sans-I/O) * :exc:`ConcurrencyError` ) annotationsN) lazy_import)WebSocketExceptionConnectionClosedConnectionClosedOKConnectionClosedError InvalidURI InvalidProxyInvalidHandshake SecurityError ProxyErrorInvalidProxyMessageInvalidProxyStatusInvalidMessage InvalidStatus InvalidHeaderInvalidHeaderFormatInvalidHeaderValue InvalidOriginInvalidUpgradeNegotiationErrorDuplicateParameterInvalidParameterNameInvalidParameterValue ProtocolError PayloadTooBig InvalidStateConcurrencyErrorceZdZdZy)rz? Base class for all exceptions defined by websockets. N__name__ __module__ __qualname____doc__[/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/websockets/exceptions.pyrrIr'rcVeZdZdZ d ddZd dZed dZed dZy) ra Raised when trying to interact with a closed connection. Attributes: rcvd: If a close frame was received, its code and reason are available in ``rcvd.code`` and ``rcvd.reason``. sent: If a close frame was sent, its code and reason are available in ``sent.code`` and ``sent.reason``. rcvd_then_sent: If close frames were received and sent, this attribute tells in which order this happened, from the perspective of this side of the connection. Nc||_||_||_|jdu|jduxs|jduk(sJyNrcvdsentrcvd_then_sent)selfr.r/r0s r(__init__zConnectionClosed.__init___sK   ,##t+d1B1WdiiSWFWXXXr'c|j|jyd|jdS|jd|jdS|jrd|jd|jSd|jd|jS)Nzno close frame received or sentzsent z; no close frame receivedz received z; no close frame sentz ; then sent z; then received r-r1s r(__str__zConnectionClosed.__str__js 99 yy 8tyyk)BCCyy "499+-BCC&&&tyykdii[II"499+-=dii[IIr'ctjdt|jtj j S|jjS)NzZConnectionClosed.code is deprecated; use Protocol.close_code or ConnectionClosed.rcvd.code)warningswarnDeprecationWarningr.frames CloseCodeABNORMAL_CLOSUREcoder4s r(r=zConnectionClosed.code{sC  D  99 ##44 4yy~~r'c|tjdt|jy|jjS)Nz`ConnectionClosed.reason is deprecated; use Protocol.close_reason or ConnectionClosed.rcvd.reason)r7r8r9r.reasonr4s r(r@zConnectionClosed.reasons6  H  99 yyr'r,)r.frames.Close | Noner/rAr0z bool | NonereturnNonerBstr)rBint) r"r#r$r%r2r5propertyr=r@r&r'r(rrPsj $'+ Y! Y" Y$ Y  Y J"  r'rceZdZdZy)rz Like :exc:`ConnectionClosed`, when the connection terminated properly. A close code with code 1000 (OK) or 1001 (going away) or without a code was received and sent. Nr!r&r'r(rrr'rceZdZdZy)r z Like :exc:`ConnectionClosed`, when the connection terminated with an error. A close frame with a code other than 1000 (OK) or 1001 (going away) was received or sent, or the closing handshake didn't complete properly. Nr!r&r'r(r r rIr'r c eZdZdZddZddZy)r zL Raised when connecting to a URI that isn't a valid WebSocket URI. c ||_||_yr,urimsg)r1rNrOs r(r2zInvalidURI.__init__sr'c8|jd|jS)Nz isn't a valid URI: rMr4s r(r5zInvalidURI.__str__s((/z::r'N)rNrErOrErBrCrDr"r#r$r%r2r5r&r'r(r r s ;r'r c eZdZdZddZddZy)r z? Raised when connecting via a proxy that isn't valid. c ||_||_yr,proxyrO)r1rUrOs r(r2zInvalidProxy.__init__s r'c8|jd|jS)Nz isn't a valid proxy: rTr4s r(r5zInvalidProxy.__str__s**3DHH:>>r'N)rUrErOrErBrCrDrQr&r'r(r r s ?r'r ceZdZdZy)r zM Base class for exceptions raised when the opening handshake fails. Nr!r&r'r(r r r)r'r ceZdZdZy)r z Raised when a handshake request or response breaks a security rule. Security limits can be configured with :doc:`environment variables <../reference/variables>`. Nr!r&r'r(r r rIr'r ceZdZdZy)rz5 Raised when failing to connect to a proxy. Nr!r&r'r(rrr)r'rceZdZdZy)rz; Raised when an HTTP proxy response is malformed. Nr!r&r'r(rrr)r'rc eZdZdZddZddZy)rz< Raised when an HTTP proxy rejects the connection. c||_yr,responser1r^s r(r2zInvalidProxyStatus.__init__   r'c6d|jjdS)Nz proxy rejected connection: HTTP dr^ status_coder4s r(r5zInvalidProxyStatus.__str__s1$--2K2KA1NOOr'Nr^zhttp11.ResponserBrCrDrQr&r'r(rrs !Pr'rceZdZdZy)rzD Raised when a handshake request or response is malformed. Nr!r&r'r(rrr)r'rc eZdZdZddZddZy)rzJ Raised when a handshake response rejects the WebSocket upgrade. c||_yr,r]r_s r(r2zInvalidStatus.__init__r`r'c6d|jjdS)Nz+server rejected WebSocket connection: HTTP rbrcr4s r(r5zInvalidStatus.__str__s9$--:S:STU9V W r'NrerDrQr&r'r(rrs ! r'rc"eZdZdZdddZddZy)rzK Raised when an HTTP header doesn't have a valid format or value. Nc ||_||_yr,namevaluer1rmrns r(r2zInvalidHeader.__init__   r'c|jd|jdS|jdk(rd|jdSd|jd|jS)Nzmissing z headerr?zempty zinvalid z header: rnrmr4s r(r5zInvalidHeader.__str__sY :: dii[0 0 ZZ2 DII;g. .dii[ $**> >r'r,rmrErn str | NonerBrCrDrQr&r'r(rrs ?r'rc$eZdZdZdfd ZxZS)rz Raised when an HTTP header cannot be parsed. The format of the header doesn't match the grammar for that header. c6t|||d|d|y)Nz at z in superr2)r1rmerrorheaderpos __class__s r(r2zInvalidHeaderFormat.__init__s# %SEfX>?r') rmrEryrErzrEr{rFrBrCr"r#r$r%r2 __classcell__r|s@r(rrs@@r'rceZdZdZy)rz Raised when an HTTP header has a wrong value. The format of the header is correct but the value isn't acceptable. Nr!r&r'r(rr#sr'rc$eZdZdZdfd ZxZS)rzD Raised when the Origin header in a request isn't allowed. c&t|d|y)NOriginrw)r1originr|s r(r2zInvalidOrigin.__init__2s 6*r')rrtrBrCr}rs@r(rr,s ++r'rceZdZdZy)rzF Raised when the Upgrade or Connection header isn't correct. Nr!r&r'r(rr6r)r'rceZdZdZy)rzG Raised when negotiating an extension or a subprotocol fails. Nr!r&r'r(rr=r)r'rc eZdZdZddZddZy)rzK Raised when a parameter name is repeated in an extension header. c||_yr,rmr1rms r(r2zDuplicateParameter.__init__J  r'c d|jS)Nzduplicate parameter: rr4s r(r5zDuplicateParameter.__str__Ms&tyyk22r'NrmrErBrCrDrQr&r'r(rrDs 3r'rc eZdZdZddZddZy)rzJ Raised when a parameter name in an extension header is invalid. c||_yr,rrs r(r2zInvalidParameterName.__init__Wrr'c d|jS)Nzinvalid parameter name: rr4s r(r5zInvalidParameterName.__str__Zs)$))55r'NrrDrQr&r'r(rrQs 6r'rc eZdZdZddZddZy)rzK Raised when a parameter value in an extension header is invalid. c ||_||_yr,rlros r(r2zInvalidParameterValue.__init__drpr'c|jd|jS|jdk(rd|jSd|jd|jS)Nzmissing value for parameter r?zempty value for parameter zinvalid value for parameter z: rrr4s r(r5zInvalidParameterValue.__str__hsU :: 1$))= = ZZ2 / {; ;1$))BtzzlK Kr'NrsrDrQr&r'r(rr^s Lr'rceZdZdZy)ra Raised when receiving or sending a frame that breaks the protocol. The Sans-I/O implementation raises this exception when: * receiving or sending a frame that contains invalid data; * receiving or sending an invalid sequence of frames. Nr!r&r'r(rrqsr'rc<eZdZdZ d ddZddZd dZy) raU Raised when parsing a frame with a payload that exceeds the maximum size. The Sans-I/O layer uses this exception internally. It doesn't bubble up to the I/O layer. The :meth:`~websockets.extensions.Extension.decode` method of extensions must raise :exc:`PayloadTooBig` if decoding a frame would exceed the limit. Nct|tr*|J|Jtjdt||_yd|_||_|J||_d|_|j|y)NzMPayloadTooBig(message) is deprecated; change to PayloadTooBig(size, max_size)) isinstancerEr7r8r9messagesizemax_sizecur_sizeset_current_size)r1size_or_messagerrs r(r2zPayloadTooBig.__init__sy os +# ### ## MM:"  (7DLDL$3DI' ''!)DM(,DM  ! !( +r'c|j |jSd}|j|d|jdz }|j|d|jdz }|d|jdz }|S)Nzframe zwith z bytes zafter reading zexceeds limit of z bytes)rrrr)r1rs r(r5zPayloadTooBig.__str__sz << #<< Gyy$U499+W55}}(^DMM?'BB *4==/@ @GNr'c^|jJ||xj|z c_||_yyr,)rr)r1rs r(rzPayloadTooBig.set_current_sizes2}}$$$   MMX %M$DM r')NN)rzint | None | strr int | NonerrrBrCrD)rrrBrC)r"r#r$r%r2r5rr&r'r(rr}sD  $# ,),, ,  ,. %r'rceZdZdZy)ra Raised when sending a frame is forbidden in the current state. Specifically, the Sans-I/O layer raises this exception when: * sending a data frame to a connection in a state other :attr:`~websockets.protocol.State.OPEN`; * sending a control frame to a connection in a state other than :attr:`~websockets.protocol.State.OPEN` or :attr:`~websockets.protocol.State.CLOSING`. Nr!r&r'r(rrs r'rceZdZdZy)rz Raised when receiving or sending messages concurrently. WebSocket is a connection-oriented protocol. Reads must be serialized; so must be writes. However, reading and writing concurrently is possible. Nr!r&r'r(rrrIr'r)r:http11z.legacy.exceptions)AbortHandshakeInvalidStatusCodeRedirectHandshakeWebSocketProtocolError)deprecated_aliases)(r% __future__rr7importsr__all__ Exceptionrrrr r r r r rrrrrrrrrrrrrrrrAssertionErrorr RuntimeErrorrr?r:rglobalsr&r'r(rs!F#  <? )? D), ;# ; ?% ?)$!* P P%  $  ?$?& @- @+M+]' 3) 3 6+ 6L,L& & 3%&3%l %~ )<  I/11"6  r'