a
    w=ic”  ã                   @   s    d Z ddlZG dd„ deƒZdS )z:Generic visitor pattern implementation for Python objects.é    Nc                   @   s€   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZei fd
d„ƒZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚVisitorFc                    s2   ˆ t ksJ dƒ‚dˆ jvr i ˆ _‡ ‡fdd„}|S )NzSubclass Visitor instead.Ú	_visitorsc                    sˆ   | j dksJ ‚ˆD ]p\}}t|ƒtkr,|f}t|ƒtkr>|f}|D ]>}ˆ j |i ¡}|D ]&}||vsvJ d|j |f ƒ‚| ||< qXqBqd S )NÚvisitz?Oops, class '%s' has visitor function for '%s' defined already.)Ú__name__ÚtypeÚtupleÚstrr   Ú
setdefault)ÚmethodÚclazzesÚattrsÚclazzr   Úattr©ÚcelfÚclazzes_attrs© úg/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/fontTools/misc/visitor.pyÚwrapper   s     
ÿÿz"Visitor._register.<locals>.wrapper)r   Ú__dict__r   )r   r   r   r   r   r   Ú	_register
   s
    
zVisitor._registerc                 C   s"   t |ƒtkr|f}|  |dfg¡S )N©N)r   r   r   )r   r   r   r   r   Úregister#   s    zVisitor.registerc                 C   sJ   g }t |ƒtkr|f}t |ƒtkr(|f}|D ]}| ||f¡ q,|  |¡S r   )r   r   r   Úappendr   )r   r   r   r   r   r   r   r   Úregister_attr)   s    zVisitor.register_attrc                 C   s
   |   |¡S r   )r   r   r   r   r   Úregister_attrs4   s    zVisitor.register_attrsc                 C   sP   t |ƒ}|  ¡ D ]:} t| dd ƒ}|d u r, qL| j |d ¡}|d ur|  S q|S )Nr   )r   ÚmroÚgetattrr   Úget)r   ÚthingÚ_defaultÚtypr   Úmr   r   r   Ú_visitorsFor8   s    
zVisitor._visitorsForc                 O   s°   t t|ƒ ¡ ƒ}|  |¡}| dd¡}|D ]€}|d dkr<q*t||ƒ}| ||¡}	|	durŽ|	| |||g|¢R i |¤Ž}
|
dks*|
du rŽ| jrŽq*| j|||g|¢R i |¤Ž q*dS )aÑ  Called to visit an object. This function loops over all non-private
        attributes of the objects and calls any user-registered (via
        @register_attr() or @register_attrs()) visit() functions.

        If there is no user-registered visit function, of if there is and it
        returns True, or it returns None (or doesn't return anything) and
        visitor.defaultStop is False (default), then the visitor will proceed
        to call self.visitAttr()Ú*Nr   Ú_F)ÚsortedÚvarsÚkeysr#   r   r   ÚdefaultStopÚ	visitAttr)ÚselfÚobjÚargsÚkwargsr(   r   ZdefaultVisitorÚkeyÚvalueÚvisitorFuncÚretr   r   r   ÚvisitObjectH   s    


zVisitor.visitObjectc                 O   s   | j |g|¢R i |¤Ž dS )z*Called to visit an attribute of an object.N©r   )r+   r,   r   r0   r-   r.   r   r   r   r*   `   s    zVisitor.visitAttrc                 O   s&   |D ]}| j |g|¢R i |¤Ž qdS )z)Called to visit any value that is a list.Nr4   ©r+   r,   r-   r.   r0   r   r   r   Ú	visitListd   s    zVisitor.visitListc                 O   s*   |  ¡ D ]}| j|g|¢R i |¤Ž qdS )z/Called to visit any value that is a dictionary.N)Úvaluesr   r5   r   r   r   Ú	visitDicti   s    zVisitor.visitDictc                 O   s   dS )zMCalled to visit any value that is not an object, list,
        or dictionary.Nr   )r+   r,   r-   r.   r   r   r   Ú	visitLeafn   s    zVisitor.visitLeafc                 O   sà   |   |¡ dd¡}|durL|| |g|¢R i |¤Ž}|dksH|du rL| jrLdS t|dƒr|t|tjƒs|| j|g|¢R i |¤Ž n`t|tƒr | j	|g|¢R i |¤Ž n<t|t
ƒrÄ| j|g|¢R i |¤Ž n| j|g|¢R i |¤Ž dS )aã  This is the main entry to the visitor. The visitor will visit object
        obj.

        The visitor will first determine if there is a registered (via
        @register()) visit function for the type of object. If there is, it
        will be called, and (visitor, obj, *args, **kwargs) will be passed to
        the user visit function.

        If there is no user-registered visit function, of if there is and it
        returns True, or it returns None (or doesn't return anything) and
        visitor.defaultStop is False (default), then the visitor will proceed
        to dispatch to one of self.visitObject(), self.visitList(),
        self.visitDict(), or self.visitLeaf() (any of which can be overriden in
        a subclass).NFr   )r#   r   r)   ÚhasattrÚ
isinstanceÚenumÚEnumr3   Úlistr6   Údictr8   r9   )r+   r,   r-   r.   r1   r2   r   r   r   r   s   s    

zVisitor.visitN)r   Ú
__module__Ú__qualname__r)   Úclassmethodr   r   r   r   r#   r3   r*   r6   r8   r9   r   r   r   r   r   r      s"   




r   )Ú__doc__r<   Úobjectr   r   r   r   r   Ú<module>   s   