HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/usr/lib/python3/dist-packages/automat/__pycache__/_methodical.cpython-38.pyc
U

Ձ�]<>�
@snddlZddlmZddlmZzddlmZWn ek
rPddlm	ZYnXddl
Z
ddlZddlm
Z
mZddlmZe�d	d
ddd
dddg�Zdd�Zdd�Zdd�Ze
jdd�Gdd�de��Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Ze
jd%d%d&�Gd'd(�d(e��Ze
jdd�Gd)d*�d*e��Ze
jd%d%d&�Gd+d,�d,e��Z e�Z!d-d.�Z"Gd/d0�d0e�Z#dS)1�N��wraps)�count)�getfullargspec)�
getargspec�)�Transitioner�	Automaton)�preserveName�ArgSpec�args�varargs�varkw�defaults�
kwonlyargs�kwonlydefaults�annotationsc
Cs�t|�}tt|j�|jtjr"|jn|j|j	r2|j	ndtjrDt|j
�ndtjrd|jr`t|j���qfdndtjrzt|j
���ndd�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r
rrrrr)�getArgsSpecr�tuplerr
�sixZPY3r�keywordsrrr�itemsr)�func�specrr�5/usr/lib/python3/dist-packages/automat/_methodical.py�_getArgSpecs 	����rcCs2t|j|j|jrdnd|jr$dnd|j�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rr
rr)rrrr�_getArgNames2s
�����rcst���fdd��}|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.
    cs�|f|�S�Nr)�self�kw��frr�gOsz_keywords_only.<locals>.gr)r#r$rr"r�_keywords_onlyEs
r%T)�frozenc@sDeZdZdZejdd�Ze��Zejdd�Ze	fdd�Z
dd�ZdS)	�MethodicalStatez-
    A state for a L{MethodicalMachine}.
    F��reprcCsjt|j�}|D]B}t|j�}|�|�stdj|jj|jjt|j�t|j�d���q|j�	|||||�dS)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.
        zdmethod {input} signature {inputSignature} does not match output {output} signature {outputSignature})�input�outputZinputSignatureZoutputSignatureN)
r�argSpec�issubset�	TypeError�format�method�__name__r�machine�_oneTransition)r r*Zenter�outputs�	collectorZ	inputArgsr+Z
outputArgsrrr�upon^s


��	zMethodicalState.uponcCs|jjSr�r0r1�r rrr�_name�szMethodicalState._nameN)r1�
__module__�__qualname__�__doc__�attr�ibr2r0�
serialized�listr6r9rrrrr'Us"r'cCs0t||d�}|dkr,t||j�}t|||�|S)z
    Get a L{Transitioner}
    N)�getattrr�initialState�setattr)�oself�symbol�	automaton�transitionerrrr�_transitionerFromInstance�s�rHcCsdSrrrrrr�_empty�srIcCsdS)Z	docstringNrrrrr�
_docstring�srJcCs$|jjtjjtjjfkr td��dS)Nzfunction body must be empty)�__code__�co_coderIrJ�
ValueError)�instZ	attributer#rrr�assertNoCode�s�rOcs�tt|jdd�|��}�jr$|}n�fdd�|D�}t|��|D]\}}�||f7�qBt|jddd�|jddd��}�fdd�|D�}	|	�|��jr�|	}
n*�jdd��j��fdd�|	��D�}
||
fS)	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]
    rNcsg|]\}}|�jkr|�qSr)r��.0�n�v)�
outputSpecrr�
<listcomp>�s
z_filterArgs.<locals>.<listcomp>���csi|]\}}|�kr||�qSrrrP)�passed_arg_namesrr�
<dictcomp>�sz_filterArgs.<locals>.<dictcomp>csi|]\}}|�kr||�qSrrrP)�all_accepted_namesrrrX�s�)	r�ziprr
r�updaterrr)r�kwargsZ	inputSpecrTZ
named_argsZreturn_args�name�valuerZfull_kwargsZ
return_kwargsr)rYrTrWr�_filterArgs�s"
r_F)Zcmp�hashc@sveZdZdZejdd�Zejed�Zejdd�Z	eje�
e�dd�Zejddd�Z
e
jdd��Zdd
d�Zdd
�Zd	S)�MethodicalInputz.
    An input for a L{MethodicalMachine}.
    Fr()Z	validator)�defaultr)�Zinitr)cCs
t|j�Sr�rr0r8rrr�
_buildArgSpec�szMethodicalInput._buildArgSpecNcs8t��j�j��t�j�t�j����fdd���}|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.
        cs��j�f|�|��j}����\}}�j|}g}|D]D}|rL||���t||�j|j�\}}	|�f|�|	�}
|�|
�q8||�Sr)r0�_stateZ
transition�
collectorsr9r_r,�append)rr\Z
previousStater4Z	outTracerr5�valuesr+�a�kr^�rDr rGrr�doInput�s
z(MethodicalInput.__get__.<locals>.doInput)rHrErFr
r0r)r rD�typermrrlr�__get__�s�
zMethodicalInput.__get__cCs|jjSrr7r8rrrr9�szMethodicalInput._name)N)r1r:r;r<r=r>rFrOr0rEZFactory�dictrgr,rbreror9rrrrra�s

rac@sZeZdZdZejdd�Ze��Zejddd�Zej	dd��Z
ddd	�Zd
d�Zdd
�Z
dS)�MethodicalOutputz/
    An output for a L{MethodicalMachine}.
    Fr(rccCs
t|j�Srrdr8rrrreszMethodicalOutput._buildArgSpecNcCstdj|j|jjd���dS)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.)�clsr0N)�AttributeErrorr/r1r0�r rDrnrrrro
s��zMethodicalOutput.__get__cOs|j|f|�|�S)z-
        Call the underlying method.
        )r0)r rDrr\rrr�__call__szMethodicalOutput.__call__cCs|jjSrr7r8rrrr9szMethodicalOutput._name)N)r1r:r;r<r=r>r2r0r,rbrerorur9rrrrrq�s


rqc@s.eZdZejdd�Zejdd�Zddd�ZdS)�MethodicalTracerFr(Ncs t||j|j���fdd�}|S)Ncs��|�dSr)�setTrace)Ztracer�rGrrrw)sz*MethodicalTracer.__get__.<locals>.setTrace)rHrErF)r rDrnrwrrxrro&s
�zMethodicalTracer.__get__)N)r1r:r;r=r>rFrErorrrrrv srvcCsdttt��S)z,
    Create a unique Python identifier.
    Z_symbol_)�str�next�counterrrrr�gensym0sr|c@s|eZdZdZdd�Zddd�Zeddd	��Zed
d��Zedd
��Z	dd�Z
edd��Zedd��Ze
dd��Zdd�ZdS)�MethodicalMachinezj
    A :class:`MethodicalMachine` is an interface to an `Automaton`
    that uses methods on a class.
    cCst�|_i|_t�|_dSr)r	�
_automatonZ	_reducersr|�_symbolr8rrr�__init__>szMethodicalMachine.__init__NcCs|dk	rtd��|S)z�
        L{MethodicalMachine} is an implementation detail for setting up
        class-level state; applications should never need to access it on an
        instance.
        Nz.MethodicalMachine is an implementation detail.)rsrtrrrroDs
�zMethodicalMachine.__get__Fcs���fdd�}|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.
        cst�|�d�}�r|�j_|S)N)r2r0r?)r'r~rB)ZstateMethod�state��initialr r?rr�	decoratorfs�z*MethodicalMachine.state.<locals>.decoratorr)r r�Zterminalr?r�rr�rr�PszMethodicalMachine.statecs�fdd�}|S)zM
        Declare an input.

        This is a decorator for methods.
        cst�j|�jd�S)N)rFr0rE)rar~r)ZinputMethodr8rrr�ws�z*MethodicalMachine.input.<locals>.decoratorr�r r�rr8rr*pszMethodicalMachine.inputcs�fdd�}|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.
        cst�|d�S)N)r2r0)rq)ZoutputMethodr8rrr��sz+MethodicalMachine.output.<locals>.decoratorrr�rr8rr+~s
zMethodicalMachine.outputcCs$|j�|||t|��||j|<dS)z.
        See L{MethodicalState.upon}.
        N)r~Z
addTransitionrrg)r Z
startStateZ
inputTokenZendStateZoutputTokensr5rrrr3�s�z MethodicalMachine._oneTransitioncs�fdd�}|S)�


        cst����fdd��}|S)Ncst|�j�j�}�||jj�Sr)rHrr~rfr?)rDrG��	decorateer rr�	serialize�s�zBMethodicalMachine.serializer.<locals>.decorator.<locals>.serializer)r�r�r8�r�rr��sz/MethodicalMachine.serializer.<locals>.decoratorrr�rr8r�
serializer�szMethodicalMachine.serializercs�fdd�}|S)r�cst����fdd��}|S)NcsL�|f|�|�}i}�j��D]}|||j<qt|�j�j�}|||_dSr)r~Zstatesr?rHrrf)rDrr\r��mappingZ	eachStaterGr�rr�unserialize�s�
zFMethodicalMachine.unserializer.<locals>.decorator.<locals>.unserializer)r�r�r8r�rr��s	z1MethodicalMachine.unserializer.<locals>.decoratorrr�rr8r�unserializer�szMethodicalMachine.unserializercCst|j|j�Sr)rvr~rr8rrr�	_setTrace�szMethodicalMachine._setTracecCs*ddlm}||jdd�dd�dd�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)�makeDigraphcSs|jjSrr7)r�rrr�<lambda>��z-MethodicalMachine.asDigraph.<locals>.<lambda>cSs|jjSrr7)r*rrrr��r�cSs|jjSrr7)r+rrrr��r�)Z
stateAsStringZ
inputAsStringZoutputAsString)Z
_visualizer�r~)r r�rrr�	asDigraph�s
�zMethodicalMachine.asDigraph)N)FFN)r1r:r;r<r�ror%r�r*r+r3r�r��propertyr�r�rrrrr}8s&
�






r})$�collections�	functoolsr�	itertoolsr�inspectrr�ImportErrorrr=rZ_corerr	Z_introspectionr
�
namedtuplerrrr%�s�objectr'rHrIrJrOr_rarqrvr{r|r}rrrr�<module>sF�
.(+
"