
    BPc              
           d Z ddlmZ ddlZdddddd	d
ddd	Z ed e                                D                       ZddZd Z	d Z
 ej        d          fdZ G d de          Z G d d          ZdS )z
Useful utilities specifically for elements (that aren't base classes)

.. versionadded:: 1.1
    Most of the methods in this module were moved from inkex.utils.
    )defaultdictNz2http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtdzhttp://creativecommons.org/ns#zhttp://web.resource.org/cc/zhttp://www.w3.org/2000/svgz http://purl.org/dc/elements/1.1/z+http://www.w3.org/1999/02/22-rdf-syntax-ns#z+http://www.inkscape.org/namespaces/inkscapezhttp://www.w3.org/1999/xlinkz$http://www.w3.org/XML/1998/namespace)	sodipodiccccOLDsvgdcrdfinkscapexlinkxmlc              #   $   K   | ]\  }}||fV  d S N ).0abs      7/usr/share/inkscape/extensions/inkex/elements/_utils.py	<genexpr>r   )   s*      
,
,fq!Aq6
,
,
,
,
,
,    c                 6   |                      d          r|rt          |           \  }} |                      d          sZ|                     dd          } d| v r|                     dd          \  }} t                              |d          p|}|d| d|  S | S )z1Add a known namespace to a name for use with lxml{__:   N})
startswithremoveNSreplacersplitNSSget)tagns_s      r   addNSr%   ,   s    
~~c r #3>># $kk$$$#::

3**IRWWR$">###c###Jr   c                     | d         dk    r>| dd                              dd          \  }}t                              |d          |fS d| v r|                     dd          S d| fS )zEThe reverse of addNS, finds any namespace and returns tuple (ns, tag)r   r   r   Nr   r   r   )splitSSNr!   r   )nameurlr"   s      r   r   r   :   sn    Aw#~~!""X^^C++
cwwsE""C''
d{{{{3"""$;r   c                 D    t          |           \  }}t          |         |fS )z4Like removeNS, but returns a url instead of a prefix)r   r    )r)   prefixr"   s      r   splitNSr-   D   s     TNNMVSKr   z([0-9]+)c                 @    d |                     |           D             S )zOHelper for a natural sort, see
    https://stackoverflow.com/a/16090640/3298143c                 |    g | ]9}|                                 rt          |          n|                                :S r   )isdigitintlower)r   texts     r   
<listcomp>z$natural_sort_key.<locals>.<listcomp>M   s7    WWWd9CIIITZZ\\WWWr   )r'   )key_nsres     r   natural_sort_keyr7   J   s&     XWekkRUFVFVWWWWr   c                   N     e Zd ZdZd	 fd	Zd
dZd Zd Zed             Z xZ	S )ChildToPropertyzjUse when you have a singleton child element who's text
    content is the canonical value for the propertyFc                 d    t                                                       || _        || _        d S r   )super__init__r"   prepend)selfr"   r=   	__class__s      r   r<   zChildToProperty.__init__T   s+    r   Nc                 L    |                     | j                  }||j        nd S r   )findoner"   r3   )r>   objklasselems       r   __get__zChildToProperty.__get__Y   s&    {{48$$ ,tyy$6r   c                 V    |                     | j        | j                  }||_        d S )N)r=   )get_or_creater"   r=   r3   )r>   rB   valuerD   s       r   __set__zChildToProperty.__set__]   s)      4< @@			r   c                 :    |                     | j                   d S r   )
remove_allr"   )r>   rB   s     r   
__delete__zChildToProperty.__delete__a   s    tx     r   c                     d| j          dS )NzGet, set or delete the z
 property.)r"   )r>   s    r   __doc__zChildToProperty.__doc__d   s    =====r   )Fr   )
__name__
__module____qualname__rN   r<   rE   rI   rL   property__classcell__)r?   s   @r   r9   r9   P   s        7 7     
7 7 7 7  ! ! ! > > X> > > > >r   r9   c                   (    e Zd ZdZd ZddZd	dZdS )

CloningVatz
    When modifying defs, sometimes we want to know if every backlink would have
    needed changing, or it was just some of them.

    This tracks the def elements, their promises and creates clones if needed.
    c                 x    || _         t          t                    | _        t          t                    | _        d S r   )r   r   settrackslistset_ids)r>   r   s     r   r<   zCloningVat.__init__q   s+    !#&&"4((r   Nc                     |                     d          }|                     d          }| j        |                             |           | j        |                             ||f           dS )z&Track the element and connected parentidN)r!   rX   addrZ   append)r>   rD   parentset_idkwargselem_id	parent_ids          r   trackzCloningVat.trackv   sc    ((4..JJt$$	G  +++W$$ff%566666r   r   Tc                     t          | j                  D ]}| j        |         }| j                            |          }d  |j        | D             }||k    r
 ||fi | M|r|                                }	|                                                    |	           |	                                 | j	        
                    |d          D ]5\  }
} |
|
                    d          |	
                    d          fi | 6 ||	fi | dS )z
        Process each tracked item if the backlinks match the parents

        Optionally make clones, process the clone and set the new id.
        c                 8    h | ]}|                     d           S )r\   )r!   )r   blks     r   	<setcomp>z%CloningVat.process.<locals>.<setcomp>   s"    III3IIIr   r   r\   N)rY   rX   r   getElementById	backlinkscopy	getparentr^   set_random_idrZ   r!   )r>   processtypesmake_clonesra   rb   parentsrD   rj   cloneupdateupkws               r   rn   zCloningVat.process}   s@    DK(( 	) 	)Gk'*G8**733DII.$.%2HIIIIG##'''''' )		  ''...##%%%$(L$4$4Wb$A$A D DLFDF488D>>599T??CCdCCCC(((((	) 	)r   r   )r   T)rO   rP   rQ   rN   r<   rd   rn   r   r   r   rU   rU   i   sU         ) ) )
7 7 7 7) ) ) ) ) )r   rU   r   )rN   collectionsr   rer    dictitemsr(   r%   r   r-   compiler7   rR   r9   rU   r   r   r   <module>rz      s5  &  $ # # # # # 				 E
**'
,8=+1
 
 d
,
,		
,
,
,,,        !+
: 6 6 X X X X> > > > >h > > >2') ') ') ') ') ') ') ') ') ')r   