U vi&$ @szddlZddlZddlmZmZddlmZmZmZmZm Z m Z ddl m Z m Z mZmZmZddlmZmZddlmZeZdZdZd Zd Zd eeeegZeeZdeejej eee ee!fefee"eej#e edddZ$deejeee ee!fefee"eej#e edddZ%deejejeee ee!fefee"e&ee ejej efdddZ'dS)N)datetime timedelta)AnyListMappingOptionalTupleUnion) Notification Observableabc notificationtyping)CompositeDisposable Disposable)NewThreadSchedulerz (\(.*?\))z(-+)z(,)z(#|\||[^-,()#\|]+)|皙?)stringtimespanduetimelookuperror schedulerreturnc s|pt}t|tr||j}t|||||dd}tdgd tjt t tj tj dfdd }t t tjt dfdd } |D] } | \}} | | } ||| qt|S) NT)r time_shiftrr raise_stoppedF)observerrrc s<sW5QRXddfdd }t|S)N)rc s8*zWntk r(YnXW5QRXdSN)remove ValueError)lockr observersr"M/opt/alt/python38/lib/python3.8/site-packages/reactivex/observable/marbles.pydisposeDs z'hot..subscribe..dispose)appendr)rrr& is_stoppedr#r$)rr% subscribe;s zhot..subscribe)r rcs$dtjtddfdd }|S)Nrstaterc s6(D]}|q jdkr(dW5QRXdS)N)CET)acceptkind)rr,r)r)r#r r$r"r%actionNs   z*hot..create_action..action)N)r SchedulerBaser)r r1r(r r% create_actionMs zhot..create_action)N)new_thread_scheduler isinstancernowparse threadingRLockr ObserverBaserrr2DisposableBaser rZScheduledActionschedule_relativer ) rrrrrr _schedulermessagesr*r4messager r1r"r(r%hot!s4   " rA)rrrrrrcsBt||||dddtjtttjtjdfdd }t|S)NT)rrrr)r scheduler_rcsNp |p ttttjttfddfdd }D] }||q<S)N)r@rcs:|\}dtjtddfdd }||dS)Nr+csdSr)r/)rr,)r rr"r%r1zszEfrom_marbles..subscribe..schedule_msg..action)N)r r2raddr=)r@rr1r>Zdisprr3r% schedule_msgusz5from_marbles..subscribe..schedule_msg)r5rrr RelativeTimer r)rrBrEr@r?rrDr%r*os   zfrom_marbles..subscribe)N)r8r r;rrr2r<r )rrrrrr*r"rGr% from_marblesdsrH?F)rrrrrrrcst|p td|pit|tr&|}t|tr8|}|dd}ttttfdddtj tt tj t t fdfdd d td dfd d }d}g}t |D]} |||| \} } } } | r"| ddd}|D] }||qfdd|D}|||t| 7}| r4|t| 7}| rBtd| r|| | }|||t| 7}q|S)aV Convert a marble diagram string to a list of messages. Each character in the string will advance time by timespan (exept for space). Characters that are not special (see the table below) will be interpreted as a value to be emitted. numbers will be cast to int or float. Special characters: +--------+--------------------------------------------------------+ | `-` | advance time by timespan | +--------+--------------------------------------------------------+ | `#` | on_error() | +--------+--------------------------------------------------------+ | `|` | on_completed() | +--------+--------------------------------------------------------+ | `(` | open a group of elements sharing the same timestamp | +--------+--------------------------------------------------------+ | `)` | close a group of elements | +--------+--------------------------------------------------------+ | `,` | separate elements in a group | +--------+--------------------------------------------------------+ | space | used to align multiple diagrams, does not advance time | +--------+--------------------------------------------------------+ In a group of elements, the position of the initial `(` determines the timestamp at which grouped elements will be emitted. E.g. `--(12,3,4)--` will emit 12, 3, 4 at 2 * timespan and then advance virtual time by 8 * timespan. Examples: >>> parse("--1--(2,3)-4--|") >>> parse("a--b--c-", lookup={'a': 1, 'b': 2, 'c': 3}) >>> parse("a--b---#", error=ValueError("foo")) Args: string: String with marble diagram timespan: [Optional] duration of each character in second. If not specified, defaults to 0.1s. lookup: [Optional] dict used to convert an element into a specified value. If not specified, defaults to {}. time_shift: [Optional] time used to delay every elements. If not specified, defaults to 0.0s. error: [Optional] exception that will be use in place of the # symbol. If not specified, defaults to Exception('error'). raise_finished: [optional] raise ValueError if elements are declared after on_completed or on_error symbol. Returns: A list of messages defined as a tuple of (timespan, notification). r )elementrc SsPz t|WStk rJzt|WYStk rD|YYSXYnXdSr)intr!floatrLr"r"r% try_numbers zparse..try_number)timerLrcsP|dkr|tfS|dkr*|tfS|}||}|t|fSdS)Nr#)r Z OnCompletedZOnErrorgetZOnNext)rQrLvalue)error_lookup_rPr"r% map_elements  zparse..map_elementFNcs rrtd|dkrddS)Nz2Elements cannot be declared after a # or | symbol.)rRrT)r!rO)r)rr"r% check_stoppeds zparse..check_stoppedr,csg|]}|dkr|qS)rKr").0elm)rW timestampr"r% szparse..z+Comma is only allowed in group of elements.) Exceptionr6r total_secondsreplacestrr rNrrFrr rtokensfindallsplitextendlenr!r')rrrrrrrXZiframer?resultsgroupZticksZ comma_errorrLelementsr]Z grp_messagesr@r")rUr)rVrWrr^rPr%r8sLA                r8)rrNNN)rNNN)rIrNNF)(rer9rrrrrrrrr Z reactivexr r r r Zreactivex.disposablerrZreactivex.schedulerrr5Z pattern_groupZ pattern_ticksZpattern_comma_errorZpattern_elementjoinpatterncompilerdrcrFZAbsoluteOrRelativeTimerNr`r2rArHboolr8r"r"r"r%sv    E &