Ë
    —~ªbÝ=  ã                   óä  — d dl Z d dlmZ d dlmZ d dlmZ d dlZddl	m
Z
mZ ddlmZ  e j                  dg d	¢«      Zd
„ Zd„ Zd„ Z ej&                  d¬«       G d„ de«      «       Zd„ Zd„ Zd„ Zd„ Zd„ Z ej&                  dd¬«       G d„ de«      «       Z ej&                  d¬«       G d„ de«      «       Z ej&                  dd¬«       G d„ de«      «       Z e«       Zd„ Z G d„ d e«      Z y)!é    N©Úwraps)Úcount)Úgetfullargspecé   )ÚTransitionerÚ	Automaton)ÚpreserveNameÚArgSpec©ÚargsÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚkwonlydefaultsÚannotationsc                 ó€  — t        | «      }t        t        |j                  «      |j                  |j
                  |j                  r|j                  ndt        |j                  «      |j                  r#t        |j                  j                  «       «      ndt        |j                  j                  «       «      ¬«      S )zÑ
    Normalize inspect.ArgSpec across python versions
    and convert mutable attributes to immutable types.

    :param Callable func: A function.
    :return: The function's ArgSpec.
    :rtype: ArgSpec
    © r   )ÚgetArgsSpecr   Útupler   r   r   r   r   r   Úitemsr   )ÚfuncÚspecs     ú5/usr/lib/python3/dist-packages/automat/_methodical.pyÚ_getArgSpecr      sŽ   € ô �tÓ€DÜÜ�4—9‘9ÓØ—‘Ø�j‰jØ"&§-¢-�—’°RÜ˜Ÿ™Ó)ð ×"Ò"ô �$×%Ñ%×+Ñ+Ó-Ô.Ø(*ä˜$×*Ñ*×0Ñ0Ó2Ó3ôð ó    c                 ó¤   — t        | j                  | j                  z   | j                  rdndz   | j                  rdndz   | j
                  z   «      S )a0  
    Get the name of all arguments defined in a function signature.

    The name of * and ** arguments is normalized to "*args" and "**kwargs".

    :param ArgSpec spec: A function to interrogate for a signature.
    :return: The set of all argument names in `func`s signature.
    :rtype: Set[str]
    )z*argsr   )z**kwargs)Úsetr   r   r   r   r   )r   s    r   Ú_getArgNamesr    ,   sV   € ô Ø�	‰	Ø
�/‰/ñ	àŸš‰:¨2ñ	/ð !ŸJšJ‰=¨Bñ	0ð ×
Ñ
ñ		óð r   c                 ó.   ‡ — t        ‰ «      ˆ fd„«       }|S )a  
    Decorate a function so all its arguments must be passed by keyword.

    A useful utility for decorators that take arguments so that they don't
    accidentally get passed the thing they're decorating as their first
    argument.

    Only works for methods right now.
    c                 ó   •—  ‰| fi |¤ŽS ©Nr   )ÚselfÚkwÚfs     €r   Úgz_keywords_only.<locals>.gI   s   ø€ á�‰}˜‰}Ðr   r   )r&   r'   s   ` r   Ú_keywords_onlyr(   ?   s    ø€ ô ˆ1ƒXóó ðà€Hr   T)Úfrozenc                   ó’   — e Zd ZdZ ej
                  d¬«      Z ej
                  «       Z ej
                  d¬«      Zdde	fd„Z
d„ Zy)ÚMethodicalStatez-
    A state for a L{MethodicalMachine}.
    F©ÚreprNc                 ó®  — |€| }|€g }t        |j                  «      }|D ]”  }t        |j                  «      }|j                  |«      rŒ*t        dj	                  |j
                  j                  |j
                  j                  t        |j
                  «      t        |j
                  «      ¬«      «      ‚ | j                  j                  | ||||«       y)ac  
        Declare a state transition within the :class:`automat.MethodicalMachine`
        associated with this :class:`automat.MethodicalState`:
        upon the receipt of the `input`, enter the `state`,
        emitting each output in `outputs`.

        :param MethodicalInput input: The input triggering a state transition.
        :param MethodicalState enter: The resulting state.
        :param Iterable[MethodicalOutput] outputs: The outputs to be triggered
            as a result of the declared state transition.
        :param Callable collector: The function to be used when collecting
            output return values.

        :raises TypeError: if any of the `outputs` signatures do not match
            the `inputs` signature.
        :raises ValueError: if the state transition from `self` via `input`
            has already been defined.
        Nzdmethod {input} signature {inputSignature} does not match output {output} signature {outputSignature})ÚinputÚoutputÚinputSignatureÚoutputSignature)
r    ÚargSpecÚissubsetÚ	TypeErrorÚformatÚmethodÚ__name__r   ÚmachineÚ_oneTransition)r$   r/   ÚenterÚoutputsÚ	collectorÚ	inputArgsr0   Ú
outputArgss           r   ÚuponzMethodicalState.uponX   sÀ   € ð& ˆ=ØˆEØˆ?ØˆGÜ  §¡Ó/ˆ	Øò 	ˆFÜ% f§n¡nÓ5ˆJØ×&Ñ& yÕ1Üð2ç28±&Ø#Ÿl™l×3Ñ3Ø%Ÿ}™}×5Ñ5Ü'2°5·<±<Ó'@Ü(3°F·M±MÓ(Bð	 39ó 3óð ð	ð 	�‰×#Ñ# D¨%°¸ÀÕKr   c                 ó.   — | j                   j                  S r#   ©r7   r8   ©r$   s    r   Ú_namezMethodicalState._name~   ó   € Ø�{‰{×#Ñ#Ð#r   )r8   Ú
__module__Ú__qualname__Ú__doc__ÚattrÚibr9   r7   Ú
serializedÚlistr@   rD   r   r   r   r+   r+   O   sI   „ ñð ˆd�g‰g˜5Ô!€GØˆT�W‰W‹Y€FØ�—‘˜eÔ$€Jà $¨d¸dó $LóL$r   r+   c                 ój   — t        | |d«      }|€#t        ||j                  «      }t        | ||«       |S )z
    Get a L{Transitioner}
    N)Úgetattrr   ÚinitialStateÚsetattr)ÚoselfÚsymbolÚ	automatonÚtransitioners       r   Ú_transitionerFromInstancerU   ‚   sB   € ô ˜5 &¨$Ó/€LØÐÜ#ØØ×"Ñ"ó
ˆô 	��v˜|Ô,ØÐr   c                   ó   — y r#   r   r   r   r   Ú_emptyrW   �   s   € Ør   c                   ó   — y)Ú	docstringNr   r   r   r   Ú
_docstringrZ   “   s   � r   c                 ó®   — |j                   j                  t        j                   j                  t        j                   j                  fvrt	        d«      ‚y )Nzfunction body must be empty)Ú__code__Úco_coderW   rZ   Ú
ValueError)ÚinstÚ	attributer&   s      r   ÚassertNoCodera   –   sG   € ð 	‡z�z×Ñ¤&§/¡/×"9Ñ"9Ü",×"5Ñ"5×"=Ñ"=ð"?ñ ?äÐ6Ó7Ð7ð?r   c                 óf  — t        t        |j                  dd | «      «      }|j                  r| }n#|D ��cg c]  \  }}||j                  v sŒ|‘Œ }}}t        |«      }|D ]  \  }	}
||	|
fz  }Œ t        |j                  ddd…   |j                  ddd…   «      }|D ��ci c]  \  }}||vsŒ||“Œ }}}|j                  |«       |j                  r|}||fS |j                  dd |j                  z   }|j                  «       D ��ci c]  \  }}||v r||“Œ }}}||fS c c}}w c c}}w c c}}w )a†  
    Filter out arguments that were passed to input that output won't accept.

    :param tuple args: The *args that input received.
    :param dict kwargs: The **kwargs that input received.
    :param ArgSpec inputSpec: The input's arg spec.
    :param ArgSpec outputSpec: The output's arg spec.
    :return: The args and kwargs that output will accept.
    :rtype: Tuple[tuple, dict]
    r   Néÿÿÿÿ)	r   Úzipr   r   r   Úupdater   r   r   )r   ÚkwargsÚ	inputSpecÚ
outputSpecÚ
named_argsÚreturn_argsÚnÚvÚpassed_arg_namesÚnameÚvaluer   Úfull_kwargsÚreturn_kwargsÚall_accepted_namess                  r   Ú_filterArgsrs   §   sf  € ô ”s˜9Ÿ>™>¨!¨"Ð-¨tÓ4Ó5€JØ×Òà‰ð &0×H™T˜Q °1¸
¿¹Ò3G’qÐHˆÑHô ˜V“}ÐØ!ò *‰ˆˆeØ˜T 5˜MÑ)Ñð*ä�9—>‘>¡$ B $Ñ'¨×);Ñ);¹D¸b¸DÑ)AÓB€HØ$,×J™D˜A˜q°Ð9IÒ0I�1�a‘4ÐJ€KÑJØ×Ñ�vÔà×Òà#ˆð ˜Ð%Ð%ð	 (Ÿ_™_¨Q¨RÐ0°:×3HÑ3HÑHÐØ*5×*;Ñ*;Ó*=÷ 5¡$ ! QØÐ!3Ñ3ð ˜A™ð 5ˆñ 5ð ˜Ð%Ð%ùó' Iùó Kùó5s   ·D!ÁD!Â"D'Â/D'Ä	D-F)ÚeqÚhashc                   ó$  — e Zd ZdZ ej
                  d¬«      Z ej
                  e¬«      Z ej
                  d¬«      Z	 ej
                   ej                  e«      d¬«      Z ej
                  dd¬«      Zej                  d„ «       Zdd	„Zd
„ Zy)ÚMethodicalInputz.
    An input for a L{MethodicalMachine}.
    Fr,   )Ú	validator)Údefaultr-   ©Úinitr-   c                 ó,   — t        | j                  «      S r#   ©r   r7   rC   s    r   Ú_buildArgSpeczMethodicalInput._buildArgSpecÚ   ó   € ä˜4Ÿ;™;Ó'Ð'r   Nc                 ó¼   ‡ ‡‡— t        ‰‰ j                  ‰ j                  «      Št        ‰ j                  «      t        ‰ j                  «      ˆˆ ˆfd„«       «       }|S )zÁ
        Return a function that takes no arguments and returns values returned
        by output functions produced by the given L{MethodicalInput} in
        C{oself}'s current state.
        c                  ód  •—  ‰j                   ‰g| ¢­i |¤Ž ‰j                  }‰j                  ‰«      \  }}‰j                  |   }g }|D ]\  }|r ||j	                  «       «       t        | |‰j                  |j                  «      \  }}	 |‰g|¢­i |	¤Ž}
|j                  |
«       Œ^  ||«      S r#   )r7   Ú_stateÚ
transitionÚ
collectorsrD   rs   r3   Úappend)r   rf   ÚpreviousStater<   Ú	outTracerr=   Úvaluesr0   ÚaÚkro   rQ   r$   rT   s              €€€r   ÚdoInputz(MethodicalInput.__get__.<locals>.doInputæ   s¹   ø€ ð ˆD�K‰K˜Ð/ Ò/¨Ò/Ø(×/Ñ/ˆMØ#/×#:Ñ#:¸4Ó#@Ñ ˆW�iØŸ™¨Ñ6ˆIØˆFØ!ò %�ÙÙ˜fŸl™l›nÔ-Ü" 4¨°·±¸v¿~¹~ÓN‘��1Ù˜uÐ. qÒ.¨AÑ.�Ø—‘˜eÕ$ð%ñ ˜VÓ$Ð$r   )rU   rR   rS   r
   r7   r   )r$   rQ   Útyper‹   rT   s   ``  @r   Ú__get__zMethodicalInput.__get__Þ   sR   ú€ ô 1°¸¿¹Ø15·±óAˆä	�d—k‘kÓ	"Ü	ˆt�{‰{Ó	õ	%ó 
ó 
#ð	%ð ˆr   c                 ó.   — | j                   j                  S r#   rB   rC   s    r   rD   zMethodicalInput._name÷   rE   r   r#   )r8   rF   rG   rH   rI   rJ   rS   ra   r7   rR   ÚFactoryÚdictr„   r3   ry   r~   r�   rD   r   r   r   rw   rw   Ï   sˆ   „ ñð �—‘˜UÔ#€IØˆT�W‰W˜|Ô,€FØˆT�W‰W˜%Ô €FØ�—‘  §¡¨dÓ!3¸%Ô@€JØˆd�g‰g˜5 uÔ-€Gà‡_�_ñ(ó ð(óó2$r   rw   c                   ó¸   — e Zd ZdZ ej
                  d¬«      Z ej
                  «       Z ej
                  dd¬«      Zej                  d„ «       Z
d
d„Zd„ Zd	„ Zy)ÚMethodicalOutputz/
    An output for a L{MethodicalMachine}.
    Fr,   rz   c                 ó,   — t        | j                  «      S r#   r}   rC   s    r   r~   zMethodicalOutput._buildArgSpec  r   r   Nc                 óv   — t        dj                  |j                  | j                  j                  ¬«      «      ‚)zX
        Outputs are private, so raise an exception when we attempt to get one.
        zf{cls}.{method} is a state-machine output method; to produce this output, call an input method instead.)Úclsr7   )ÚAttributeErrorr6   r8   r7   ©r$   rQ   rŒ   s      r   r�   zMethodicalOutput.__get__  s=   € ô ðDßDJÁFØ—M‘MØ—{‘{×+Ñ+ð EKó Eó
ð 	
r   c                 ó.   —  | j                   |g|¢­i |¤ŽS )z-
        Call the underlying method.
        )r7   )r$   rQ   r   rf   s       r   Ú__call__zMethodicalOutput.__call__  s   € ð ˆt�{‰{˜5Ð2 4Ò2¨6Ñ2Ð2r   c                 ó.   — | j                   j                  S r#   rB   rC   s    r   rD   zMethodicalOutput._name  rE   r   r#   )r8   rF   rG   rH   rI   rJ   r9   r7   r3   ry   r~   r�   r™   rD   r   r   r   r’   r’   û   s]   „ ñð ˆd�g‰g˜5Ô!€GØˆT�W‰W‹Y€FØˆd�g‰g˜5 uÔ-€Gà‡_�_ñ(ó ð(ó

ò3ó$r   r’   c                   ó`   — e Zd Z ej                  d¬«      Z ej                  d¬«      Zdd„Zy)ÚMethodicalTracerFr,   Nc                 óT   ‡— t        || j                  | j                  «      Šˆfd„}|S )Nc                 ó(   •— ‰j                  | «       y r#   )ÚsetTrace)ÚtracerrT   s    €r   rŸ   z*MethodicalTracer.__get__.<locals>.setTrace'  s   ø€ Ø×!Ñ! &Õ)r   )rU   rR   rS   )r$   rQ   rŒ   rŸ   rT   s       @r   r�   zMethodicalTracer.__get__$  s'   ø€ Ü0°¸¿¹Ø15·±óAˆô	*àˆr   r#   )r8   rF   rG   rI   rJ   rS   rR   r�   r   r   r   rœ   rœ     s'   „ à�—‘˜UÔ#€IØˆT�W‰W˜%Ô €Fôr   rœ   c                  ó8   — dt        t        t        «      «      z   S )z,
    Create a unique Python identifier.
    Ú_symbol_)ÚstrÚnextÚcounterr   r   r   Úgensymr¦   .  s   € ð œœD¤›MÓ*Ñ*Ð*r   c                   ó�   — e Zd ZdZd„ Zdd„Ze	 	 dd„«       Zed„ «       Zed„ «       Z	d„ Z
ed	„ «       Zed
„ «       Zed„ «       Zd„ Zy)ÚMethodicalMachinezj
    A :class:`MethodicalMachine` is an interface to an `Automaton`
    that uses methods on a class.
    c                 óN   — t        «       | _        i | _        t        «       | _        y r#   )r	   Ú
_automatonÚ	_reducersr¦   Ú_symbolrC   s    r   Ú__init__zMethodicalMachine.__init__<  s   € Ü#›+ˆŒØˆŒÜ“xˆ�r   Nc                 ó    — |�t        d«      ‚| S )z°
        L{MethodicalMachine} is an implementation detail for setting up
        class-level state; applications should never need to access it on an
        instance.
        z.MethodicalMachine is an implementation detail.)r–   r—   s      r   r�   zMethodicalMachine.__get__B  s!   € ð ÐÜ Ø@óBð Bàˆr   c                 ó   ‡ ‡‡— ˆˆ ˆfd„}|S )a  
        Declare a state, possibly an initial state or a terminal state.

        This is a decorator for methods, but it will modify the method so as
        not to be callable any more.

        :param bool initial: is this state the initial state?
            Only one state on this :class:`automat.MethodicalMachine`
            may be an initial state; more than one is an error.

        :param bool terminal: Is this state a terminal state?
            i.e. a state that the machine can end up in?
            (This is purely informational at this point.)

        :param Hashable serialized: a serializable value
            to be used to represent this state to external systems.
            This value should be hashable;
            :py:func:`unicode` is a good type to use.
        c                 óJ   •— t        ‰| ‰¬«      }‰r|‰j                  _        |S )N)r9   r7   rK   )r+   rª   rO   )ÚstateMethodÚstateÚinitialr$   rK   s     €€€r   Ú	decoratorz*MethodicalMachine.state.<locals>.decoratord  s+   ø€ Ü#¨DØ+6Ø/9ô;ˆEñ Ø/4�—‘Ô,ØˆLr   r   )r$   r³   ÚterminalrK   r´   s   `` ` r   r²   zMethodicalMachine.stateN  s   ú€ ö,	ð Ðr   c                 ó   ‡ — ˆ fd„}|S )zM
        Declare an input.

        This is a decorator for methods.
        c                 óH   •— t        ‰j                  | ‰j                  ¬«      S )N)rS   r7   rR   )rw   rª   r¬   )ÚinputMethodr$   s    €r   r´   z*MethodicalMachine.input.<locals>.decoratoru  s    ø€ Ü"¨T¯_©_Ø*5Ø*.¯,©,ô8ð 8r   r   ©r$   r´   s   ` r   r/   zMethodicalMachine.inputn  s   ø€ ô	8ð Ðr   c                 ó   ‡ — ˆ fd„}|S )zÚ
        Declare an output.

        This is a decorator for methods.

        This method will be called when the state machine transitions to this
        state as specified in the decorated `output` method.
        c                 ó   •— t        ‰| ¬«      S )N)r9   r7   )r’   )ÚoutputMethodr$   s    €r   r´   z+MethodicalMachine.output.<locals>.decorator†  s   ø€ Ü#¨D¸ÔFÐFr   r   r¹   s   ` r   r0   zMethodicalMachine.output|  s   ø€ ô	GàÐr   c                 óp   — | j                   j                  |||t        |«      «       ||j                  |<   y)z.
        See L{MethodicalState.upon}.
        N)rª   ÚaddTransitionr   r„   )r$   Ú
startStateÚ
inputTokenÚendStateÚoutputTokensr=   s         r   r:   z MethodicalMachine._oneTransition‹  s4   € ð& 	�‰×%Ñ% j°*¸hÜ&+¨LÓ&9ô	;à,5ˆ
×Ñ˜jÒ)r   c                 ó   ‡ — ˆ fd„}|S )ú


        c                 ó2   •‡ — t        ‰ «      ˆ ˆfd„«       }|S )Nc                 ó€   •— t        | ‰j                  ‰j                  «      } ‰| |j                  j                  «      S r#   )rU   r¬   rª   r‚   rK   )rQ   rT   Ú	decorateer$   s     €€r   Ú	serializezBMethodicalMachine.serializer.<locals>.decorator.<locals>.serialize©  s6   ø€ ä8¸ÀÇÁØ9=¿¹ó J�á  ¨×(;Ñ(;×(FÑ(FÓGÐGr   r   )rÇ   rÈ   r$   s   ` €r   r´   z/MethodicalMachine.serializer.<locals>.decorator¨  s$   ù€ Ü�9ÓôHó ðHð Ðr   r   r¹   s   ` r   Ú
serializerzMethodicalMachine.serializer£  s   ø€ ô
	ð Ðr   c                 ó   ‡ — ˆ fd„}|S )rÄ   c                 ó2   •‡ — t        ‰ «      ˆ ˆfd„«       }|S )Nc                 óÔ   •—  ‰| g|¢­i |¤Ž}i }‰j                   j                  «       D ]  }|||j                  <   Œ t        | ‰j                  ‰j                   «      }||   |_        y r#   )rª   ÚstatesrK   rU   r¬   r‚   )	rQ   r   rf   r²   ÚmappingÚ	eachStaterT   rÇ   r$   s	          €€r   ÚunserializezFMethodicalMachine.unserializer.<locals>.decorator.<locals>.unserialize·  sp   ø€ á! %Ð9¨$Ò9°&Ñ9�Ø�Ø!%§¡×!7Ñ!7Ó!9ò >�IØ4=�G˜I×0Ñ0Ò1ð>ä8Ø˜4Ÿ<™<¨¯©ó :�à&-¨e¡n�Ô#Ør   r   )rÇ   rÐ   r$   s   ` €r   r´   z1MethodicalMachine.unserializer.<locals>.decorator¶  s"   ù€ Ü�9Óôó ðð Ðr   r   r¹   s   ` r   ÚunserializerzMethodicalMachine.unserializer±  s   ø€ ô
	ð Ðr   c                 óB   — t        | j                  | j                  «      S r#   )rœ   rª   r¬   rC   s    r   Ú	_setTracezMethodicalMachine._setTraceÄ  s   € ä §¡°·±Ó>Ð>r   c                 ó@   — ddl m}  || j                  d„ d„ d„ ¬«      S )a  
        Generate a L{graphviz.Digraph} that represents this machine's
        states and transitions.

        @return: L{graphviz.Digraph} object; for more information, please
            see the documentation for
            U{graphviz<https://graphviz.readthedocs.io/>}

        r   )ÚmakeDigraphc                 ó.   — | j                   j                  S r#   rB   )r²   s    r   ú<lambda>z-MethodicalMachine.asDigraph.<locals>.<lambda>Õ  ó   € ¨¯©×(=Ñ(=€ r   c                 ó.   — | j                   j                  S r#   rB   )r/   s    r   r×   z-MethodicalMachine.asDigraph.<locals>.<lambda>Ö  rØ   r   c                 ó.   — | j                   j                  S r#   rB   )r0   s    r   r×   z-MethodicalMachine.asDigraph.<locals>.<lambda>×  s   € ¨&¯-©-×*@Ñ*@€ r   )ÚstateAsStringÚinputAsStringÚoutputAsString)Ú
_visualizerÕ   rª   )r$   rÕ   s     r   Ú	asDigraphzMethodicalMachine.asDigraphÈ  s$   € õ 	,ÙØ�O‰OÙ=Ù=Ù@ô	
ð 	
r   r#   )FFN)r8   rF   rG   rH   r­   r�   r(   r²   r/   r0   r:   rÉ   rÑ   ÚpropertyrÓ   rß   r   r   r   r¨   r¨   6  s™   „ ñò
 ó	ð Ø,1Øòó ðð> ñ
ó ð
ð ñó ðò6ð0 ñó ðð ñó ðð$ ñ?ó ð?ó
r   r¨   )!ÚcollectionsÚ	functoolsr   Ú	itertoolsr   Úinspectr   r   rI   Ú_corer   r	   Ú_introspectionr
   Ú
namedtupler   r   r    r(   ÚsÚobjectr+   rU   rW   rZ   ra   rs   rw   r’   rœ   r¥   r¦   r¨   r   r   r   ú<module>rê      s  ðó Ý Ý å 1ã ç *Ý (ð !ˆ+×
 Ñ
  ò -Nó O€ò
ò0ò&ð  €‡�ˆtÔô/$�fó /$ó ð/$òdò	òò8ò"%&ðP €‡�ˆ5�uÔô($�fó ($ó ð($ðV €‡�ˆtÔô $�vó  $ó ð $ðD €‡�ˆ5�uÔô
�vó 
ó ð
ñ ‹'€ò+ôb
˜õ b
r   