
    BPcq                        d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 dZ
 ed          \  ZZej        d         dk    ZdZd	e d
ZeZdZde de dZd	e de de dZd	e e de e dZ ej        d	e de de de d	          Zd Zd Zd Z G d de          ZdefdZd Z d Z!d Z"d Z#d Z$ G d d e%          Z& G d! d"e'          Z( G d# d$e%          Z)d% Z*e+fd&Z, G d' d(          Z-d) Z.d/d+Z/i Z0e01                    ej2                   e01                    ej2                   d0d-Z3d. Z4dS )1z6
Basic common utility functions for calculated things
    N)ArgumentTypeError)tee      z[0-9]z(?:z+)z[+-]z(?:[eE]?)z?\.|z\.)z?|c               #      K   t           j                            dd                              d          D ]%} t           j                            |           r| V  &d S )N
PYTHONPATH :)osenvirongetsplitpathisdirpths    -/usr/share/inkscape/extensions/inkex/utils.py_pythonpathr   3   s]      z~~lB//55c::  7== 	III     c                     dt           j        v rjt           j                            t           j                            t           j                            t           j        d         d                              S t           j                            d          } t                      D ]}|                    |           r|c S dS )zQReturn the user directory where extensions are stored.

    .. versionadded:: 1.1INKSCAPE_PROFILE_DIR
extensions~N)r   r   r   abspath
expanduserjoinr   
startswith)homer   s     r   get_user_directoryr#   9   s     ++wGRZ(>?NN 
 
 	
 7c""D}}  >>$ 	JJJ	4r   c                      t                      D ]C} t          j                            t          j                            | d                    r| c S Dt          d          )zPReturn the system directory where inkscape's core is.

    .. versionadded:: 1.1inkexz,Unable to determine the location of Inkscape)r   r   r   r   r    
ValueErrorr   s    r   get_inkscape_directoryr'   K   sZ     }}  7==c73344 	JJJ	
C
D
DDr   c                   "     e Zd ZdZ fdZ xZS )KeyDictz
    A normal dictionary, except asking for anything not in the dictionary
    always returns the key itself. This is used for translation dictionaries.
    c                 l    	 t                                          |          S # t          $ r |cY S w xY wN)super__getitem__KeyError)selfkey	__class__s     r   r-   zKeyDict.__getitem__[   sD    	77&&s+++ 	 	 	JJJ	s    $ 33)__name__
__module____qualname____doc__r-   __classcell__)r1   s   @r   r)   r)   U   sB         
        r   r)   valc                     |                                  } |                     d          rt          | dd                   dz  S t          |           S )z}Parse strings that are either values (i.e., '3.14159') or percentages
    (i.e. '75%') to a float.

    .. versionadded:: 1.2%Nd   )stripendswithfloat)r7   s    r   parse_percentr?   b   sJ    
 ))++C
||C %S"X$$::r   c                 n    |                                  dk    rdS |                                  dk    rdS dS )zAArgParser function to turn a boolean string into a python booleanTRUETFALSEFN)upper)values    r   BooleanrE   m   s7    {{}}t{{}}u4r   c                 t    t          | t                    r| S t          |                               d          S )z7Ensures the content is bytes

    .. versionadded:: 1.1utf8)
isinstancebytesstrencode)contents    r   to_bytesrM   v   s5     '5!! w<<v&&&r   c                 $    t          |            | S )z/Print debug message if debugging is switched on)errormsg)whats    r   debugrQ      s    TNNNKr   c                      dS )z9A blank function to do nothing

    .. versionadded:: 1.1N )argskwargss     r   
do_nothingrV      s      r   c                    	 t           j                            |            n# t          $ r/ t           j                            t	          |                      Y nUt
          $ rI t           j        j        pd}t           j                            |                     |d                     Y nw xY wt           j                            d           dS )a  Intended for end-user-visible error messages.

    (Currently just writes to stderr with an appended newline, but could do
    something better in future: e.g. could add markup to distinguish error
    messages from status messages or debugging output.)

    Note that this should always be combined with translation::

      import inkex
      ...
      inkex.errormsg(_("This extension requires two selected paths."))
    asciibackslashreplace
N)sysstderrwrite	TypeErrorrJ   UnicodeEncodeErrorencodingrK   )msgr`   s     r   rO   rO      s    C
 # # #
S""""" C C C :&1'
H.@AABBBBBC JTs   " 6B,AB,+B,c                       e Zd ZdZdS )AbortExtensionz7Raised to print a message to the user without backtraceNr2   r3   r4   r5   rS   r   r   rc   rc      s        AAAAr   rc   c                       e Zd ZdZdS )DependencyErrorzBRaised when we need an external python module that isn't availableNrd   rS   r   r   rf   rf      s        LLLLr   rf   c                       e Zd ZdZdS )FragmentErrorz8Raised when trying to do rooty things on an xml fragmentNrd   rS   r   r   rh   rh      s        BBBBr   rh   c                       fd}|S )zX
    Decorator which will turn a generator into a list, tuple or other object type.
    c                       fd}|S )Nc                  &      | i |          S r+   rS   )rT   kwcallkinds     r   _outerz"to.<locals>._inner.<locals>._outer   s"    4d)b))***r   rS   )rm   ro   rn   s   ` r   _innerzto.<locals>._inner   s)    	+ 	+ 	+ 	+ 	+ 	+ r   rS   )rn   rp   s   ` r   torq      s#    
     Mr   c                 P    fdt                               |           D             S )a+  Returns a list of floats from a string

    .. versionchanged:: 1.1
        also splits at -(minus) signs by adding a space in front of the - sign

    .. versionchanged:: 1.2
        Full support for the `SVG Path data BNF
        <https://www.w3.org/Graphics/SVG/1.1/paths.html#PathDataBNF>`_
    c                 &    g | ]} |          S rS   rS   ).0r7   rn   s     r   
<listcomp>zstrargs.<locals>.<listcomp>   s!    <<<#DDII<<<r   )
NUMBER_REXfindall)stringrn   s    `r   strargsry      s-     =<<<!3!3F!;!;<<<<r   c                       e Zd ZdZd Zd ZdS )classpropertyz+Combine classmethod and property decoratorsc                     || _         d S r+   func)r/   r~   s     r   __init__zclassproperty.__init__   s    			r   c                 ,    |                      |          S r+   r}   )r/   objowners      r   __get__zclassproperty.__get__   s    yyr   N)r2   r3   r4   r5   r   r   rS   r   r   r{   r{      s8        55           r   r{   c                     t           j                            t           j                            |                     }t           j                            |          st          d|            |S )z8Existing file to read or option used in script argumentszFile not found: )r   r   r   r   isfiler   )namefilenames     r   filename_argr      sW    wrw11$7788H7>>(## ; 94 9 9:::Or   Tc                     t          |           \  }}dt          |d          fg}|sg }|t          t          ||                    z   S )zBIterate over a list with overlapping pairs (see itertools recipes)N)r   nextlistzip)iterablestartfirstthenstarters        r   pairwiser      sR    h--KE4d4&&'(G T#eT**++++r   xc                     	 | dk    r2t          d| d|                     d          pdz   t          i           S n# t          $ r Y nw xY wdS )zInterpret a function string. All functions from math and random may be used.

    .. versionadded:: 1.1

    Returns:
        a lambda expression if sucessful; otherwise None.
    r   zlambda z: "tN)evalr<   EVAL_GLOBALSSyntaxError)functionvariables     r   	math_evalr      sw    r>>&(&&&(..*=*=*DE|UW   
    4s   7; 
AAc                 H    	 t          |            dS # t          $ r Y dS w xY w)z8Checks if a value is a number

    .. versionadded:: 1.2TF)r>   r&   )rx   s    r   	is_numberr     s9    ft   uus    
!!)T)r   )5r5   r   r[   randomremathargparser   	itertoolsr   ABORT_STATUSrangeXYversion_infoPY3DIGIT_REX_PARTDIGIT_SEQUENCE_REX_PARTINTEGER_CONSTANT_REX_PARTSIGN_REX_PARTEXPONENT_REX_PARTFRACTIONAL_CONSTANT_REX_PART FLOATING_POINT_CONSTANT_REX_PARTcompilerv   r   r#   r'   dictr)   rJ   r?   rE   rM   rQ   rV   rO   	Exceptionrc   NotImplementedErrorrf   rh   rq   r>   ry   r{   r   r   r   update__dict__r   r   rS   r   r   <module>r      s  (  
			 



  				  & & & & & &      	qA	qQ 3333 3 I}II/FIII x&=xxBYxx\sxxx  $K*F  $KHY  $K  $K]t  $K  wH  $K  $K  $K  RZj=jj;jjmjjNgjjj 
    $E E E
 
 
 
 
d 
 
 
s      ' ' '      DB B B B BY B B BM M M M M) M M MC C C C CI C C C    
= 
= 
= 
=                 , , , ,    FO $ $ $   DM " " "   &    r   