K i*ddlmZddlZddlZddlZddlmZmZddlm Z m Z m Z m Z m Z mZddlmZddlmZmZmZmZddlmZd gZej0d Ze d ZGd d e eZGdd Zy)) annotationsN) AsyncIteratorIterable)AnyCallableGenericLiteralTypeVaroverload)ConcurrencyError) OP_BINARYOP_CONTOP_TEXTFrame)Data Assemblerzutf-8TcBeZdZdZd dZd dZd dZd d dZddZd dZ y) SimpleQueuez Simplified version of :class:`asyncio.Queue`. Provides only the subset of functionality needed by :class:`Assembler`. cvtj|_d|_t j |_yN)asyncioget_running_looploop get_waiter collectionsdequequeueselfs a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/websockets/asyncio/messages.py__init__zSimpleQueue.__init__s),,. 7;+6+<+<+> c,t|jSr)lenrr s r"__len__zSimpleQueue.__len__"s4::r$c|jj||j7|jjs|jj dyyy)z+Put an item into the queue without waiting.N)rappendrdone set_result)r!items r"putzSimpleQueue.put%sH $ ?? &t/C/C/E OO & &t ,0F &r$cK|jsu|s td|jJd|jj |_ |jd{|jj d|_|jj S7?#|jj d|_wxYww)z?Remove and return an item from the queue, waiting if necessary.stream of frames endedNzcannot call get() concurrently)rEOFErrorrr create_futurecancelpopleft)r!blocks r"getzSimpleQueue.get+szz788??* L,L L*"ii557DO 'oo%%&&("&zz!!## &&&("&s0A CB BB #;CB #CCc|jJd|jrJd|jj|y)z)Put back items into an empty, idle queue.Nz%cannot reset() while get() is runningz&cannot reset() while queue isn't empty)rrextend)r!itemss r"resetzSimpleQueue.reset9s<&O(OO&::GGG~ % r$c|j@|jjs%|jjtdyyy)z8Close the queue, raising EOFError in get() if necessary.Nr/)rr* set_exceptionr0r s r"abortzSimpleQueue.abort?s< ?? &t/C/C/E OO ) )(3K*L M0F &r$NreturnNone)r>int)r,rr>r?)T)r4boolr>r)r8z Iterable[T]r>r?) __name__ __module__ __qualname____doc__r#r'r-r5r9r<r$r"rrs&? - $! Nr$rceZdZdZddddf ddZeddZeddZedddZddd Zedd Zedd Zeddd Zddd ZddZddZ ddZ ddZ 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. NcyrrFrFr$r"zAssembler.Yr$cyrrFrFr$r"rIzAssembler.ZrJr$ct|_|||dz}|||dz}|"| |dkr td||kr td||c|_|_||_||_d|_d|_d|_ y)Nrz%low must be positive or equal to zeroz)high must be greater than or equal to lowF) rframes ValueErrorhighlowpauseresumepausedget_in_progressclosed)r!rPrQrRrSs r"r#zAssembler.__init__Us+6-   !)C z Assembler.get..s7u 7s)rUr rNr5rV maybe_resumeopcoderrfinrCancelledErrorr9rr)joinrY)r!rYrbrNr`s r"r5z Assembler.getsZ,   "#KL L#  )++//dkk/::E    <<7*elli.G GG~0WFii"&++//dkk/"BBE !!#||w... e$ii$)D xx777 ;;= K7;C--KK%%f- $)D sZF)F E  AF*)EEEAF3F FE0FF FFcyrrFrXs r"get_iterzAssembler.get_itersEHr$cyrrFrXs r"rjzAssembler.get_itersHKr$cyrrFrXs r"rjzAssembler.get_itersKNr$cfK|jr tdd|_ |jj|j d{}|j|jtus|jtusJ||jtu}|r4t}|j|j|jn|j|js|jj|j d{}|j|jtusJ|r*j|j|jn|j|jsd|_y7B#t j $r d|_wxYw7w)a Stream the next message. Iterating the return value of :meth:`get_iter` asynchronously 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. r^TNF)rUr rNr5rVrrgrdrerr UTF8DecoderrYr`rfr)r!rYrbdecoders r"rjzAssembler.get_itersW2   "#KL L# ++//dkk/::E ||w&%,,)*CCC >\\W,F !mG..UYY7 7** )) ++//dkk/::E    <<7* **nnUZZ;;jj )) %9;%% #(D  &;sBF1)F F  FCF1F/A/F1F1 FF,,F1c|jr td|jj||j y)z Add ``frame`` to the next message. Raises: EOFError: If the stream of frames has ended. r/N)rVr0rNr- maybe_pause)r!rbs r"r-z Assembler.puts3 ;;34 4  r$c|jyt|j|jkDr%|jsd|_|j yyy)z7Pause the writer if queue is above the high water mark.NT)rPr&rNrTrRr s r"rqzAssembler.maybe_pausesF 99   t{{ dii ' DK JJL1< 'r$c|jyt|j|jkr%|jrd|_|j yyy)z7Resume the writer if queue is below the low water mark.NF)rQr&rNrTrSr s r"rdzAssembler.maybe_resume!sF 88   t{{ txx 'DKKDK KKM-8 'r$c`|jryd|_|jjy)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`. NT)rVrNr<r s r"closezAssembler.close,s' ;;   r$) rP int | NonerQrvrRCallable[[], Any]rSrwr>r?)rY Literal[True]r>str)rYLiteral[False]r>bytesr)rY bool | Noner>r)rYrxr>zAsyncIterator[str])rYrzr>zAsyncIterator[bytes])rYr|r>zAsyncIterator[Data])rbrr>r?r=) rBrCrDrEr#r r5rjr-rqrdrurFr$r"rrEs " #/$0   !  "   D:: == @@:xHH KK NNA%F   r$) __future__rrcodecsrcollections.abcrrtypingrrrr r r exceptionsr rNrrrrr__all__getincrementaldecoderrnrrrrFr$r"rsi" 3EE)77 -*f**73  CL-N'!*-N`uur$