K i?1ddlmZddlZddlZddlZddlmZmZmZm Z m Z m Z ddl m Z ddlmZmZmZmZddlmZdd lmZd gZej.d ZGd d Zy) ) annotationsN)AnyCallableIterableIteratorLiteraloverload)ConcurrencyError) OP_BINARYOP_CONTOP_TEXTFrame)Data)Deadline Assemblerzutf-8ceZdZdZddddf ddZdddZddZeddZedd Zeddd Zeddd Zeddd Zddd ZeddZ eddZ edd dZ dd dZ d!dZ d"dZ d"dZ d"dZ y)#ra Assemble messages from frames. :class:`Assembler` expects only data frames. The stream of frames must respect the protocol; if it doesn't, the behavior is undefined. Args: pause: Called when the buffer of frames goes above the high water mark; should pause reading from the network. resume: Called when the buffer of frames goes below the low water mark; should resume reading from the network. NcyNr^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/websockets/sync/messages.pyzAssembler.&rcyrrrrrrzAssembler.'rrc8tj|_tj|_|||dz}|||dz}|"| |dkr t d||kr t d||c|_|_||_ ||_ d|_ d|_ d|_ y)Nrz%low must be positive or equal to zeroz)high must be greater than or equal to lowF) threadingLockmutexqueue SimpleQueueframes ValueErrorhighlowpauseresumepausedget_in_progressclosed)selfr&r'r(r)s r__init__zAssembler.__init__"s^^% 8=7H7H7J   !)C ?;;   ' & '  ' & ' ' ' 's'B%->AB%AAB%%B.cyrrr-r3decodes rr5z Assembler.gettsHKrcyrrrAs rr5z Assembler.getwsKNrcyrrrAs rr5z Assembler.getzsRUrcyrrrAs rr5z Assembler.get}UXrcyrrrAs rr5z Assembler.getrFrc|j5|jr tdd|_ddd t|}|j |j d}|j5|j ddd|jtus|jtusJ||jtu}|g}|jsy |j |j d}|j5|j ddd|jtusJ|j||jsyd|_djd|D}|r|j!S|S#1swYQxYw#1swY xYw#t$r|j|wxYw#1swYxYw#d|_wxYw)a? Read the next message. :meth:`get` returns a single :class:`str` or :class:`bytes`. If the message is fragmented, :meth:`get` waits until the last frame is received, then it reassembles the message and returns it. To receive messages frame by frame, use :meth:`get_iter` instead. Args: timeout: If a timeout is provided and elapses before a complete message is received, :meth:`get` raises :exc:`TimeoutError`. decode: :obj:`False` disables UTF-8 decoding of text frames and returns :class:`bytes`. :obj:`True` forces UTF-8 decoding of binary frames and returns :class:`str`. Raises: EOFError: If the stream of frames has ended. UnicodeDecodeError: If a text frame contains invalid UTF-8. ConcurrencyError: If two coroutines run :meth:`get` or :meth:`get_iter` concurrently. TimeoutError: If a timeout is provided and elapses before a complete message is received. &get() or get_iter() is already runningTNF)raise_if_elapsedrc34K|]}|jywr)data).0r9s r z Assembler.get..s7u 7s)r!r+r rr:r3 maybe_resumeopcoderr finr8r?r r<joinrB)r-r3rBdeadliner9r$rLs rr5z Assembler.gets4ZZ (##&'OPP#'D  ( )(H''(8(8%(8(PQE $!!# $<<7*elli.G GG~0WFii // ((%(@EZZ(%%'(||w... e$ii $)D xx777 ;;= KW ( ( $ $$$$V,  (( $)D s_E;8G-F>AG!F1 G=F49G;FF GF11G4F=9G G cyrrr-rBs rget_iterzAssembler.get_iters@CrcyrrrUs rrVzAssembler.get_itersCFrcyrrrUs rrVzAssembler.get_itersFIrc#fK|j5|jr tdd|_ddd|j}|j5|j ddd|j t us|j tusJ||j t u}|r3t}|j|j|jn|j|js|j}|j5|j ddd|j tusJ|r)j|j|jn|j|jsd|_y#1swY_xYw#1swY7xYw#1swYxYww)a Stream the next message. Iterating the return value of :meth:`get_iter` yields a :class:`str` or :class:`bytes` for each frame in the message. The iterator must be fully consumed before calling :meth:`get_iter` or :meth:`get` again. Else, :exc:`ConcurrencyError` is raised. This method only makes sense for fragmented messages. If messages aren't fragmented, use :meth:`get` instead. Args: decode: :obj:`False` disables UTF-8 decoding of text frames and returns :class:`bytes`. :obj:`True` forces UTF-8 decoding of binary frames and returns :class:`str`. Raises: EOFError: If the stream of frames has ended. UnicodeDecodeError: If a text frame contains invalid UTF-8. ConcurrencyError: If two coroutines run :meth:`get` or :meth:`get_iter` concurrently. rITNF) r!r+r r:rOrPrr UTF8DecoderrBrLrQr )r-rBr9decoders rrVzAssembler.get_iters`2ZZ (##&'OPP#'D  (##% ZZ     ||w&%,,)*CCC >\\W,F !mG..UYY7 7** ))'')E $!!# $<<7* **nnUZZ;;jj )) %G ( (   $ $sS F1F $F1F#B-F1F%!A!F1F1 FF1F"F1%F.*F1c|j5|jr td|jj ||j dddy#1swYyxYw)z Add ``frame`` to the next message. Raises: EOFError: If the stream of frames has ended. r2N)r!r,r7r$r= maybe_pause)r-r9s rr=z Assembler.putsOZZ {{788 KKOOE "        s AAA"c|jy|jjsJ|jj |jkDr%|j sd|_|j yyy)z7Pause the writer if queue is above the high water mark.NT)r&r!lockedr$qsizer*r(r-s rr]zAssembler.maybe_pause*s` 99  zz  """ ;;    *4;;DK JJL4? *rc|jy|jjsJ|jj |jkr%|j rd|_|j yyy)z7Resume the writer if queue is below the low water mark.NF)r'r!r_r$r`r*r)ras rrOzAssembler.maybe_resume7s` 88  zz  """ ;;   $(( *t{{DK KKM0; *rc|j5|jr dddyd|_|jr|jj d|j rd|_|j dddy#1swYyxYw)z End the stream of frames. Calling :meth:`close` concurrently with :meth:`get`, :meth:`get_iter`, or :meth:`put` is safe. They will raise :exc:`EOFError`. NTF)r!r,r+r$r=r*r)ras rclosezAssembler.closeDsmZZ {{  DK## %{{#     sA>AA>>B) r& int | Noner'rer(Callable[[], Any]r)rfreturnNoner)r3 float | Nonergr)r$zIterable[Frame]rgrh)r3rirB Literal[True]rgstr)r3rirBLiteral[False]rgbytes)NN)r3rirB bool | Nonergr)rBrjrgz Iterator[str])rBrlrgzIterator[bytes])rBrnrgzIterator[Data])r9rrgrh)rgrh)__name__ __module__ __qualname____doc__r.r:r?r r5rVr=r]rOrdrrrrrs   #/$0 $$$! $ " $  $L,',KK NN UU XX XXENCC FF II<%| 2  r) __future__rcodecsr"rtypingrrrrrr exceptionsr r$r r rrrutilsr__all__getincrementaldecoderrZrrrrrzsM" GG)77 -*f**73 FFr