| Server IP : 93.86.61.54 / Your IP : 216.73.216.156 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/python3/dist-packages/scour/__pycache__/ |
Upload File : |
o
p�_$, � @ s� d Z ddlmZ ddlZddlmZmZ ddlmZ G dd� de �Z
e
� Zg d�ZG d d
� d
e �Z
e
e�ZG dd� de �Ze� ZdS )
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 @ s e Zd Zdd� ZdS )�_EOFc C s dS )N�EOF� )�selfr r �1/usr/lib/python3/dist-packages/scour/svg_regex.py�__repr__8 s z
_EOF.__repr__N)�__name__�
__module__�__qualname__r r r r r
r 6 s r ))�floatz=[-+]?(?:(?:[0-9]*\.[0-9]+)|(?:[0-9]+\.?))(?:[Ee][-+]?[0-9]+)?)�intz[-+]?[0-9]+)�commandz[AaCcHhLlMmQqSsTtVvZz]c @ s e Zd ZdZdd� Zdd� ZdS )�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 C sH || _ g }|D ]
\}}|�d||f � qd�|�| _t�| j�| _d S )Nz
(?P<%s>%s)�|)�lexicon�append�join�regex_string�re�compile�regex)r r �parts�namer r r r
�__init__P s zLexer.__init__c c sR � | j �|�D ]}| jD ]\}}|�|�}|dur ||fV nqqtdfV dS )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 �_�mr r r
�lexX s �
��z Lexer.lexN)r r
r �__doc__r r$ r r r r
r E s
r c @ st e Zd ZdZefdd�Zdd� Zdd� Zdd � Zd
d� Z dd
� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� ZdS )�
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 C s� || _ 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| jd��| _t ddg�| _
d S )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 r: r r r
r } sR �������� �
���
�����
�zSVGPathParser.__init__c C s0 | j �|�}ttg|f�R � }|� }| �||�S )z, Parse a string of SVG <path> data.
)r: r$ r �next�
rule_svg_path)r r �gen�next_val_fn�tokenr r r
�parse� s zSVGPathParser.parsec C s` g }|d t ur.|d dkrtd|f ��| j|d }|||�\}}|�|� |d t us|S )Nr r zexpecting a command; got %r� )r �SyntaxErrorrB r )r rH rI �commands�rule�
command_groupr r r
rF � s
�zSVGPathParser.rule_svg_pathc C s |d }|� }|g f|fS )NrK r )r rH rI r r r r
r; � s zSVGPathParser.rule_closepathc C �T |d }|� }g }|d | j v r$| �||�\}}|�|� |d | j v s||f|fS �NrK r �rD �rule_coordinate_pair�extend)r rH rI r �coordinates�pairr r r
r<