Ë
    |D™j$,  ã                   ó®   — d Z ddlmZ ddlZddlmZmZ ddlmZ  G d„ de	«      Z
 e
«       Zg d¢Z G d	„ d
e	«      Z ee«      Z G d„ de	«      Z e«       Zy)a¯   Small hand-written recursive descent parser for SVG <path> data.


In [1]: from svg_regex import svg_parser

In [3]: svg_parser.parse('M 10,20 30,40V50 60 70')
Out[3]: [('M', [(10.0, 20.0), (30.0, 40.0)]), ('V', [50.0, 60.0, 70.0])]

In [4]: svg_parser.parse('M 0.6051.5')  # An edge case
Out[4]: [('M', [(0.60509999999999997, 0.5)])]

In [5]: svg_parser.parse('M 100-200')  # Another edge case
Out[5]: [('M', [(100.0, -200.0)])]
é    )Úabsolute_importN)ÚDecimalÚ
getcontext)Úpartialc                   ó   — e Zd Zd„ Zy)Ú_EOFc                  ó   — y)NÚEOF© )Úselfs    ú[/var/www/html/Astrologybackend/backend/venv/lib/python3.12/site-packages/scour/svg_regex.pyÚ__repr__z_EOF.__repr__8   s   € Øó    N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   6   s   „ ór   r   ))Úfloatz=[-+]?(?:(?:[0-9]*\.[0-9]+)|(?:[0-9]+\.?))(?:[Ee][-+]?[0-9]+)?)Úintz[-+]?[0-9]+)Úcommandz[AaCcHhLlMmQqSsTtVvZz]c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚLexera   Break SVG path data into tokens.

    The SVG spec requires that tokens are greedy. This lexer relies on Python's
    regexes defaulting to greediness.

    This style of implementation was inspired by this article:

        http://www.gooli.org/blog/a-simple-lexer-in-python/
    c                 óÎ   — || _         g }|D ]  \  }}|j                  d|›d|›d�«       Œ dj                  |«      | _        t	        j
                  | j                  «      | _        y )Nz(?P<ú>ú)ú|)ÚlexiconÚappendÚjoinÚregex_stringÚreÚcompileÚregex)r   r   ÚpartsÚnamer"   s        r   Ú__init__zLexer.__init__P   sX   € ØˆŒØˆØ"ò 	7‰KˆD�%Ø�LŠLªªuÐ5Õ6ð	7àŸH™H U›OˆÔÜ—Z‘Z × 1Ñ 1Ó2ˆ�
r   c              #   ó¾   K  — | j                   j                  |«      D ]1  }| j                  D ]   \  }}|j                  |«      }|€Œ||f–—  Œ1 Œ3 t        df–— y­w)zœ Yield (token_type, str_data) tokens.

        The last token will be (EOF, None) where EOF is the singleton object
        defined in this module.
        N)r"   Úfinditerr   Úgroupr
   )r   ÚtextÚmatchr$   Ú_Úms         r   Úlexz	Lexer.lexX   sh   è ø€ ð —Z‘Z×(Ñ(¨Ó.ò 	ˆEØŸ<™<ò ‘��aØ—K‘K Ó%�Ø‘=Ø ˜)’OÙñ	ð	ô �DˆkÓùs   ‚AAÁAN)r   r   r   Ú__doc__r%   r-   r   r   r   r   r   E   s   „ ñò3ór   r   c                   ó\   — e Zd ZdZefd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zy)ÚSVGPathParseraq   Parse SVG <path> data into a list of commands.

    Each distinct command will take the form of a tuple (command, data). The
    `command` is just the character string that starts the command group in the
    <path> data, so 'M' for absolute moveto, 'm' for relative moveto, 'Z' for
    closepath, etc. The kind of data it carries with it depends on the command.
    For 'Z' (closepath), it's just None. The others are lists of individual
    argument groups. Multiple elements in these lists usually mean to repeat the
    command. The notable exception is 'M' (moveto) where only the first element
    is truly a moveto. The remainder are implicit linetos.

    See the SVG documentation for the interpretation of the individual elements
    for each command.

    The main method is `parse(text)`. It can only consume actual strings, not
    filelike objects or iterators.
    c                 óF  — || _         i d| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d	| j                  “d
| j                  “d| j                  “d| j                  “d| j
                  “d| j
                  “d| j
                  “d| j
                  “d| j                  “| j                  | j                  | j                  dœ¥| _        t        ddg«      | _
        y )NÚZÚzÚMr,   ÚLÚlÚHÚhÚVÚvÚCÚcÚSÚsÚQÚqÚT)ÚtÚAÚar   r   )ÚlexerÚrule_closepathÚrule_moveto_or_linetoÚrule_orthogonal_linetoÚrule_curveto3Úrule_curveto2Úrule_curveto1Úrule_elliptical_arcÚcommand_dispatchÚlistÚnumber_tokens)r   rE   s     r   r%   zSVGPathParser.__init__}   sw  € ØˆŒ
ð!
Ø�×$Ñ$ð!
à�×$Ñ$ð!
ð �×+Ñ+ð!
ð �×+Ñ+ð	!
ð
 �×+Ñ+ð!
ð �×+Ñ+ð!
ð �×,Ñ,ð!
ð �×,Ñ,ð!
ð �×,Ñ,ð!
ð �×,Ñ,ð!
ð �×#Ñ#ð!
ð �×#Ñ#ð!
ð �×#Ñ#ð!
ð �×#Ñ#ð!
ð �×#Ñ#ð!
ð  �×#Ñ#ð!!
ð" �×#Ñ#ð#!
ð$ ×#Ñ#Ø×)Ñ)Ø×)Ñ)ò)!
ˆÔô0 " 5¨'Ð"2Ó3ˆÕr   c                 óŒ   — | j                   j                  |«      }t        t        g|f¢­Ž } |«       }| j	                  ||«      S )z, Parse a string of SVG <path> data.
        )rE   r-   r   ÚnextÚrule_svg_path)r   r)   ÚgenÚnext_val_fnÚtokens        r   ÚparsezSVGPathParser.parseš   sA   € ð �j‰j�n‰n˜TÓ"ˆÜœdÐ, c VÒ,ˆÙ“ˆØ×!Ñ! +¨uÓ5Ð5r   c                 óÂ   — g }|d   t         urQ|d   dk7  rt        d|›�«      ‚| j                  |d      } |||«      \  }}|j                  |«       |d   t         urŒQ|S )Nr   r   zexpecting a command; got é   )r
   ÚSyntaxErrorrM   r   )r   rT   rU   ÚcommandsÚruleÚcommand_groups         r   rR   zSVGPathParser.rule_svg_path¢   ss   € ØˆØ�A‰hœcÑ!Ø�Q‰x˜9Ò$Ý!Á5Ð"JÓKÐKØ×(Ñ(¨¨q©Ñ2ˆDÙ#'¨°UÓ#;Ñ ˆM˜5Ø�O‰O˜MÔ*ð �A‰hœcÒ!ð ˆr   c                 ó&   — |d   } |«       }|g f|fS )NrX   r   )r   rT   rU   r   s       r   rF   zSVGPathParser.rule_closepath¬   s!   € Ø˜‘(ˆÙ“ˆØ˜ˆ}˜eÐ#Ð#r   c                 ó¼   — |d   } |«       }g }|d   | j                   v r8| j                  ||«      \  }}|j                  |«       |d   | j                   v rŒ8||f|fS ©NrX   r   ©rO   Úrule_coordinate_pairÚextend)r   rT   rU   r   ÚcoordinatesÚpairs         r   rG   z#SVGPathParser.rule_moveto_or_lineto±   ss   € Ø˜‘(ˆÙ“ˆØˆØ�A‰h˜$×,Ñ,Ñ,Ø×3Ñ3°KÀÓG‰KˆD�%Ø×Ñ˜tÔ$ð �A‰h˜$×,Ñ,Ò,ð ˜Ð% uÐ,Ð,r   c                 ó¼   — |d   } |«       }g }|d   | j                   v r8| j                  ||«      \  }}|j                  |«       |d   | j                   v rŒ8||f|fS r_   )rO   Úrule_coordinater   )r   rT   rU   r   rc   Úcoords         r   rH   z$SVGPathParser.rule_orthogonal_linetoº   ss   € Ø˜‘(ˆÙ“ˆØˆØ�A‰h˜$×,Ñ,Ñ,Ø×/Ñ/°¸UÓC‰LˆE�5Ø×Ñ˜uÔ%ð �A‰h˜$×,Ñ,Ò,ð ˜Ð% uÐ,Ð,r   c                 óT  — |d   } |«       }g }|d   | j                   v r„| j                  ||«      \  }}| j                  ||«      \  }}| j                  ||«      \  }}|j                  |«       |j                  |«       |j                  |«       |d   | j                   v rŒ„||f|fS r_   r`   )r   rT   rU   r   rc   Úpair1Úpair2Úpair3s           r   rI   zSVGPathParser.rule_curveto3Ã   s»   € Ø˜‘(ˆÙ“ˆØˆØ�A‰h˜$×,Ñ,Ñ,Ø×4Ñ4°[À%ÓH‰LˆE�5Ø×4Ñ4°[À%ÓH‰LˆE�5Ø×4Ñ4°[À%ÓH‰LˆE�5Ø×Ñ˜uÔ%Ø×Ñ˜uÔ%Ø×Ñ˜uÔ%ð �A‰h˜$×,Ñ,Ò,ð ˜Ð% uÐ,Ð,r   c                 ó  — |d   } |«       }g }|d   | j                   v r^| j                  ||«      \  }}| j                  ||«      \  }}|j                  |«       |j                  |«       |d   | j                   v rŒ^||f|fS r_   r`   )r   rT   rU   r   rc   ri   rj   s          r   rJ   zSVGPathParser.rule_curveto2Ð   s—   € Ø˜‘(ˆÙ“ˆØˆØ�A‰h˜$×,Ñ,Ñ,Ø×4Ñ4°[À%ÓH‰LˆE�5Ø×4Ñ4°[À%ÓH‰LˆE�5Ø×Ñ˜uÔ%Ø×Ñ˜uÔ%ð	 �A‰h˜$×,Ñ,Ò,ð
 ˜Ð% uÐ,Ð,r   c                 ó¼   — |d   } |«       }g }|d   | j                   v r8| j                  ||«      \  }}|j                  |«       |d   | j                   v rŒ8||f|fS r_   r`   )r   rT   rU   r   rc   ri   s         r   rK   zSVGPathParser.rule_curveto1Û   ss   € Ø˜‘(ˆÙ“ˆØˆØ�A‰h˜$×,Ñ,Ñ,Ø×4Ñ4°[À%ÓH‰LˆE�5Ø×Ñ˜uÔ%ð �A‰h˜$×,Ñ,Ò,ð ˜Ð% uÐ,Ð,r   c           	      óh  — |d   } |«       }g }|d   | j                   v �rt        |d   «      dz  }|t        d«      k  rt        d|›�«      ‚ |«       }|d   | j                   vrt        d|›�«      ‚t        |d   «      dz  }|t        d«      k  rt        d|›�«      ‚ |«       }|d   | j                   vrt        d|›�«      ‚t        |d   «      dz  } |«       }|d   d   dvrt        d|›�«      ‚t        |d   d   «      dz  }t        |d   «      dkD  rt	        |«      }|d   dd  |d<   n |«       }|d   d   dvrt        d|›�«      ‚t        |d   d   «      dz  }	t        |d   «      dkD  rt	        |«      }|d   dd  |d<   n |«       }|d   | j                   vrt        d|›�«      ‚t        |d   «      dz  }
 |«       }|d   | j                   vrt        d|›�«      ‚t        |d   «      dz  } |«       }|j                  |||||	|
|g«       |d   | j                   v r�Œ||f|fS )NrX   r   z0.0z$expecting a nonnegative number; got úexpecting a number; got )Ú0Ú1zexpecting a boolean flag; got )rO   r   rY   ÚlenrN   rb   )r   rT   rU   r   Ú	argumentsÚrxÚryÚaxis_rotationÚlarge_arc_flagÚ
sweep_flagÚxÚys               r   rL   z!SVGPathParser.rule_elliptical_arcä   sv  € Ø˜‘(ˆÙ“ˆØˆ	Ø�A‰h˜$×,Ñ,Ò,Ü˜˜q™Ó" QÑ&ˆBØ”G˜E“NÒ"Ý!ÉeÐ"UÓVÐVá“MˆEØ�Q‰x˜t×1Ñ1Ñ1Ý!Á%Ð"IÓJÐJÜ˜˜q™Ó" QÑ&ˆBØ”G˜E“NÒ"Ý!ÉeÐ"UÓVÐVá“MˆEØ�Q‰x˜t×1Ñ1Ñ1Ý!Á%Ð"IÓJÐJÜ# E¨!¡HÓ-°Ñ1ˆMá“MˆEØ�Q‰x˜‰{ *Ñ,Ý!ÉÐ"OÓPÐPÜ$ U¨1¡X¨a¡[Ó1°AÑ5ˆNä�5˜‘8‹}˜qÒ Ü˜U›�Ø  ™8 A B˜<��a’á#›�Ø�Q‰x˜‰{ *Ñ,Ý!ÉÐ"OÓPÐPÜ   q¡¨!¡Ó-°Ñ1ˆJä�5˜‘8‹}˜qÒ Ü˜U›�Ø  ™8 A B˜<��a’á#›�Ø�Q‰x˜t×1Ñ1Ñ1Ý!Á%Ð"IÓJÐJÜ˜˜a™Ó! AÑ%ˆAá“MˆEØ�Q‰x˜t×1Ñ1Ñ1Ý!Á%Ð"IÓJÐJÜ˜˜a™Ó! AÑ%ˆAá“MˆEØ×Ñ˜b " m°^ÀZÐQRÐTUÐVÔWð] �A‰h˜$×,Ñ,Ó,ð` ˜Ð# UÐ*Ð*r   c                 óŽ   — |d   | j                   vrt        d|›�«      ‚t        «       j                  |d   «      } |«       }||fS ©Nr   ro   rX   ©rO   rY   r   Úcreate_decimal)r   rT   rU   ry   s       r   rf   zSVGPathParser.rule_coordinate  sH   € Ø�‰8˜4×-Ñ-Ñ-Ý¹eÐEÓFÐFÜ‹L×'Ñ'¨¨a©Ó1ˆÙ“ˆØ�%ˆxˆr   c                 ó  — |d   | j                   vrt        d|›�«      ‚t        «       j                  |d   «      } |«       }|d   | j                   vrt        d|›�«      ‚t        «       j                  |d   «      } |«       }||g|fS r|   r}   )r   rT   rU   ry   rz   s        r   ra   z"SVGPathParser.rule_coordinate_pair!  sŠ   € à�‰8˜4×-Ñ-Ñ-Ý¹eÐEÓFÐFÜ‹L×'Ñ'¨¨a©Ó1ˆÙ“ˆØ�‰8˜4×-Ñ-Ñ-Ý¹eÐEÓFÐFÜ‹L×'Ñ'¨¨a©Ó1ˆÙ“ˆØ�1ˆv�uˆ}Ðr   N)r   r   r   r.   Ú	svg_lexerr%   rV   rR   rF   rG   rH   rI   rJ   rK   rL   rf   ra   r   r   r   r0   r0   j   sI   „ ñð$ 'ó 4ò:6òò$ò
-ò-ò-ò	-ò-ò4+òló
r   r0   )r.   Ú
__future__r   r    Údecimalr   r   Ú	functoolsr   Úobjectr   r
   r   r   r€   r0   Ú
svg_parserr   r   r   ú<module>r†      sd   ðñ<õ 'ã 	ß 'Ý ôˆ6ô ñ ƒf€ò€ôˆFô ñD �'‹N€	ôA�Fô AñH ‹_�
r   