403Webshell
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 :  /usr/lib/python3/dist-packages/scour/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/scour/__pycache__/scour.cpython-310.pyc
o

p�_���@s�ddlmZddlmZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Zddlm
Z
mZddlmZmZddlmZmZmZmZddlZddlmZmZdd	lmZdd
lmZddlm Z ddl!m"Z"d
Z#e"Z$dZ%dddd�Z&e&�'�Z(de(d<e&�'�Z)de)d<e�*d�Z+ddddddddd d!d"d#d$d%d&d'�Z,e,d(e,d)e,d*e,d+e,d,e,d-e,d.e,d/e,d0e,d1e,d2e,d3e,d4g
Z-gd5�Z.id6d7�d8d9�d:d;�d<d=�d>d?�d@dA�dBdC�dDdE�dFdG�dHdI�dJdK�dLdM�dNdO�dPdQ�dRdS�dTdU�dVdW�idXdY�dZd[�d\d]�d^d;�d_d`�dadb�dcdd�dedf�dgdh�didf�djdk�dldm�dndo�dpdq�drds�dtdu�dvdw��idxdy�dzd{�d|d}�d~d}�dd��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���id�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���id�d��d�d��d�d��d�d��d�d“d�d��d�dœd�dǓd�dɓd�d˓d�d͓d�d͓d�dГd�dғd�dԓd�d֓d�dؓ�id�d��d�dۓd�dݓd�dߓd�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d��d�d��d�d���id�d��d�d��d�d���d�d��d�d��d�d��d�d��d�d	��d
�d��d�d
��d�d��d�d��d�d��d�d��d�d��d�d��d�d��i�d�d��d�d��d �d!��d"�d#��d$�d%��d&�d'��d(�d)��d*�d+��d,�d-��d.�d/��d0�d1��d2�d3��d4�d5��d6�d5��d7�d8��d9�d:��d;�d<���d=�d>�d?�d@�dA�dB�dC�dD�dE�dF�dG�dH��Z/i�dI�dJ��dK�dL��dM�dN��dO�dP��dQ�dR��dS�dT��dU�dV��dW�dX��dY�dZ��d[�dP��d\�d]��d^�dN��d_�dL��d`�dP��da�d]��db�dL��dc�dd�i�de�df��dg�df��dh�df��di�df��dj�dk��dl�df��dm�dn��do�dL��dp�dL��dq�dL��dr�dL��ds�dL��dt�d]��du�dv��dw�dP��dx�d]��dy�dL��i�dz�dL��d{�d|��d}�d~��d�d���d��d���d��d]��d��d]��d��d���d��dL��d��df��d��d���d��df��d��d���d��d]��d��dP��d��d]��d��d����dL�dL�d]�d���Z0�d��d��Z1�d��d��Z2e�*�d��Z3e�*�d��Z4e�*�d��Z5e�*�d��Z6G�d��d���d�e7�Z8G�d��d���d�e7�Z9�d�d��d��Z:g�d��a;�d�d��d��Z<�d��d��Z=�dF�d��d��Z>�d��d��Z?�d��d��Z@�d��d��ZA�d��d��ZB�d��d��ZC�d��d��ZD�d��d��ZE�d��d��ZF�d��d��ZG�d��d��ZH�d��d��ZI�d��d��ZJ�d��d��ZK�ddÄZL�dĐdńZM�dƐdDŽZN�dȐdɄZO�dʐd˄ZP�d̐d̈́ZQ�dΐdτZR�dАdфZS�dҐdӄZT�dԐdՄZU�d֐dׄZV�dؐdلZW�dڐdۄZX�dG�dݐdބZY�dߐd�ZZe�d�g�d��Z[�d�e\e[j]�e[j^__ge[�d�d�d�g�d��e[�d�d�d_g�d��e[�d�d�d�d�g�d��e[�d�d�dsg�d��e[�d�d�dsg�d��e[�d�d�d�g�d��e[�d�d�d�g�d��e[�d�d�d_g�d��e[�d�d�g�d���d��e[�d��d�e8j`�d�g�d��e[�d��d�e8j`�d�g�d��e[�d��dL�d�g�d��e[�d��d�g�d���d��e[�d�dg�d���d��e[�ddg�d���d��e[�dd�d�dg�d��e[�dd�dg�d��e[�dd�dg�d��e[�dd�dg�d��e[�dd�dg�d��e[�d	d�d
�dg�d��e[�dd�d
�dg�d��e[�d
�d�dog�d��e[�dd�dog�d��e[�dd�dog�d��e[�d�d�dog�d��e[�d�d�dog�d��e[�dd�dog�d��e[�d�dg�d��d��e[�dd�dg�d��e[�d�d�dg�d��e[�d�d�dg�d��e[�d��de8j`�d_�dsg��e[�d��de8ja�d_�dsg�d�d ��d!��e[�d�de8j`�d_�dsg��e[�d�de8ja�d_�dsg�d"�d ��d!��e[�d��d#e8j`�d_�dsg��e[�d��d$e8ja�d_�dsg�d%�d ��d!��e[�d��d#e8j`�d_�dsg��e[�d��d$e8ja�d_�dsg�d&�d ��d!��e[�dd�d�g�d��e[�dd�d�g�d��e[�dd�d�g�d��e[�d�d�e8j`�d�g�d��e[�d�d'e8ja�d�g�d(�d ��d)��e[�d*�d�g�d+�d ��d)��e[�d,�d�g�d-�d ��d)��e[�d.�d/e8j`�d�g�d��e[�d.�d0e8ja�d�g�d1�d ��d)��e[�d	�d/e8j`�d�g�d��e[�d	�d0e8ja�d�g�d2�d ��d)��e[�d�d/e8j`�d�g�d��e[�d�d0e8ja�d�g�d3�d ��d)��e[�d4�d5�d�d�g�d��e[�d6�d'g�d7��d��e[�d8d�d9g�d��e[�d:�d|g�d7��d��e[�d;�d'�d<g�d��e[�d=�d'�d>g�d��e[�d?�d@�d<g�d��e[�dAd�d9g�d��e[�dB�d'g�d7��d��e[�dCdg�d7��d��e[�dDd�dEg�d��e[�dFd�dEg�d��e[�dGd�dEg�d��e[�dHd�dEg�d��e[�dI�df�dJg�d��e[�dK�d'�dLg�d��e[�dMdg�d7��d��e[�dN�dO�dEg�d��e[�dN�dP�dQg�d��e[�dR�dS�d<g�d��e[�dTd�dg�d��e[�dUd�dg�d��e[�dVd�dg�d��e[�dW�d�d<g�d��e[�dX�d|�dQg�d��e[�dYd�dZg�d��e[�d[d�dLg�d��e[�d\�d'�d]g�d��e[�d^�d'�d]�dg�d��e[�d_�d|�d`g�d��e[�da�db�dLg�d��e[�dc�d'�d>�d]g�d��e[�dd�de�dfg�d��e[�dd�dg�dLg�d��e[�dh�di�dZg�d��e[�dj�di�dZg�d��ZbgZceed�ZeebD]Zfefjgdu�	r�ec�hef��	q�efjgD]
Zieeei�hef��	q��	q��dk�dl�Zj�dm�dn�Zkel�f�do�dp�Zme�*�dq�Zne�*�dr�Zo�ds�dt�Zp�du�dv�Zq�dw�dx�Zr�dy�dz�Zs�d{�d|�Zt�d}�d~�Zu�d�d��Zv�d��d��Zw�d��d��Zx�d��d��Zy�d�ggf�d��d��Zz�d��d��Z{�dH�d��d��Z|�d��d��Z}�d��d��Z~�d��d��Z�d��d��Z��d��d��Z��d��d��Z��d��d��Z��d��d��Z��d�d��d��Z��d��d��Z�g�d��Z�g�d��e�e.��d�gZ�e�d��d ��d��d��e�e��D��Z��d��d��Z��d��d��Z��dI�d��d��Z��d�d��d��Z��d�d��d��Z�G�d��d���d�ej��Z�ej��d��d�e��d��d��e$�d��Z�e�j��d��d�e��d�ej��d��e�j��d��d��d��d��dܐd��d��e�j��ddÐd��dĐdܐdŐd��e�j��dƐd��dǐdȐdɐdʍe�j��dːd��d̐d͐dΐdʍe��e��dϡZ�e�j��dАd�e��d��dѐdҐdӐdԍe�j��dՐd�e��d֐dאdҐdؐdԍe�j��dِdڐdېdܐdݐd��e�j��dސdڐdߐdܐd�d��e�j��d�dڐd�dܐd�d��e�j��d�d��d�dܐd�d��e�j��d�d��d�dܐd�d��e�j��d�d��d�dܐd�d��e�j��d�d��d�dܐd�d��e�j��d�dڐd�dܐd�d��e���e��e��e��d�Z�e�j��d�d��d�dܐd��d��e�j��d��d��d��dܐd��d��e�j��d��d��d��dܐd��d��e�j��d��d��d��dܐd��d��e�j��d��d��d�dܐd�d��e�j��d�d��d�dܐd�d��e�j��d�dڐd�dܐd�d��e�j��d�d��d	�dܐd
�d��e���e��e��e��d�Z�e�j��d�d��d
�d�d�d�d�dԍe�j��d�d�e��d�d'�dҐd�dԍe�j��d�dڐd�dܐd�d��e�j��d�d��d�dܐd�d��e���e��e��e��d�Z�e�j��d�d��d�dܐd�d��e�j��d�d��d �dܐd!�d��e�j��d"�d��d
�d#�d$�d%�d&�dԍe�j��d'�d��d(�dܐd)�d��e�j��d*�d��d
�d+�d,�d-�d.�e�j��d/�d��d
�d0�d%�d1�d.�e���e��e��e��d2�Z�e�j��d3�d��d4�dܐd5�d��e���e���dJ�d6�d7�Z��d8�d9�Z��d�d:�d;�Z��dK�d<�d=�Z��d>�d?�Z��d@�dA�Z��dB�d��Z��dC�dD�Z�e��dEk�
roe��dSdS(L�)�division)�print_function)�absolute_importN)�Node�NotFoundErr)�
namedtuple�defaultdict)�Context�Decimal�InvalidOperation�
getcontext)�range�urllib)�
svg_parser)�svg_transform_parser)�parseCssString)�__version__�scourz+Copyright Jeff Schiller, Louis Simard, 2010z&lt;z&gt;z&amp;)�<�>�&z&apos;�'z&quot;�"z\s*[\s,]\s*�http://www.w3.org/2000/svg�http://www.w3.org/1999/xlinkz2http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtdz+http://www.inkscape.org/namespaces/inkscapez*http://ns.adobe.com/AdobeIllustrator/10.0/zhttp://ns.adobe.com/Graphs/1.0/z1http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/z"http://ns.adobe.com/Variables/1.0/z#http://ns.adobe.com/SaveForWeb/1.0/z&http://ns.adobe.com/Extensibility/1.0/zhttp://ns.adobe.com/Flows/1.0/z)http://ns.adobe.com/ImageReplacement/1.0/z/http://ns.adobe.com/GenericCustomNamespace/1.0/zhttp://ns.adobe.com/XPath/1.0/z'http://www.bohemiancoding.com/sketch/ns)�SVG�XLINK�SODIPODI�INKSCAPE�ADOBE_ILLUSTRATOR�ADOBE_GRAPHS�ADOBE_SVG_VIEWER�ADOBE_VARIABLES�	ADOBE_SFW�ADOBE_EXTENSIBILITY�ADOBE_FLOWS�ADOBE_IMAGE_REPLACEMENT�ADOBE_CUSTOM�ADOBE_XPATH�SKETCHrrrr r!r"r#r$r%r&r'r(r))Gzalignment-baseline�baseline-shift�clip�	clip-path�	clip-rule�color�color-interpolation�color-interpolation-filters�
color-profilezcolor-rendering�cursor�	direction�displayzdominant-baseline�enable-background�fill�fill-opacity�	fill-rule�filter�flood-color�
flood-opacity�font�font-family�	font-size�font-size-adjust�font-stretch�
font-style�font-variant�font-weight�glyph-orientation-horizontalzglyph-orientation-verticalzimage-rendering�kerning�letter-spacing�lighting-color�marker�
marker-end�
marker-mid�marker-start�mask�opacity�overflow�pointer-events�shape-rendering�
stop-color�stop-opacity�stroke�stroke-dasharray�stroke-dashoffset�stroke-linecap�stroke-linejoin�stroke-miterlimit�stroke-opacity�stroke-width�text-anchor�text-decoration�text-rendering�unicode-bidi�
visibility�word-spacing�writing-mode�audio-levelzbuffered-rendering�
display-alignzline-increment�solid-color�
solid-opacity�
text-align�
vector-effect�
viewport-fill�viewport-fill-opacity�	alicebluezrgb(240, 248, 255)�antiquewhitezrgb(250, 235, 215)�aquazrgb( 0, 255, 255)�
aquamarinezrgb(127, 255, 212)�azurezrgb(240, 255, 255)�beigezrgb(245, 245, 220)�bisquezrgb(255, 228, 196)�blackz
rgb( 0, 0, 0)�blanchedalmondzrgb(255, 235, 205)�bluezrgb( 0, 0, 255)�
bluevioletzrgb(138, 43, 226)�brownzrgb(165, 42, 42)�	burlywoodzrgb(222, 184, 135)�	cadetbluezrgb( 95, 158, 160)�
chartreusezrgb(127, 255, 0)�	chocolatezrgb(210, 105, 30)�coralzrgb(255, 127, 80)�cornflowerbluezrgb(100, 149, 237)�cornsilkzrgb(255, 248, 220)�crimsonzrgb(220, 20, 60)�cyan�darkbluezrgb( 0, 0, 139)�darkcyanzrgb( 0, 139, 139)�
darkgoldenrodzrgb(184, 134, 11)�darkgrayzrgb(169, 169, 169)�	darkgreenzrgb( 0, 100, 0)�darkgrey�	darkkhakizrgb(189, 183, 107)�darkmagentazrgb(139, 0, 139)�darkolivegreenzrgb( 85, 107, 47)�
darkorangezrgb(255, 140, 0)�
darkorchidzrgb(153, 50, 204)�darkredzrgb(139, 0, 0)�
darksalmonzrgb(233, 150, 122)�darkseagreenzrgb(143, 188, 143)�
darkslatebluezrgb( 72, 61, 139)�
darkslategrayzrgb( 47, 79, 79)�
darkslategrey�
darkturquoisezrgb( 0, 206, 209)�
darkvioletzrgb(148, 0, 211)�deeppinkzrgb(255, 20, 147)�deepskybluezrgb( 0, 191, 255)�dimgrayzrgb(105, 105, 105)�dimgrey�
dodgerbluezrgb( 30, 144, 255)�	firebrickzrgb(178, 34, 34)�floralwhitezrgb(255, 250, 240)�forestgreenzrgb( 34, 139, 34)�fuchsiazrgb(255, 0, 255)�	gainsborozrgb(220, 220, 220)�
ghostwhitezrgb(248, 248, 255)�goldzrgb(255, 215, 0)�	goldenrodzrgb(218, 165, 32)�grayzrgb(128, 128, 128)�grey�greenzrgb( 0, 128, 0)�greenyellowzrgb(173, 255, 47)�honeydewzrgb(240, 255, 240)�hotpinkzrgb(255, 105, 180)�	indianredzrgb(205, 92, 92)�indigozrgb( 75, 0, 130)�ivoryzrgb(255, 255, 240)�khakizrgb(240, 230, 140)�lavenderzrgb(230, 230, 250)�
lavenderblushzrgb(255, 240, 245)�	lawngreenzrgb(124, 252, 0)�lemonchiffonzrgb(255, 250, 205)�	lightbluezrgb(173, 216, 230)�
lightcoralzrgb(240, 128, 128)�	lightcyanzrgb(224, 255, 255)�lightgoldenrodyellowzrgb(250, 250, 210)�	lightgrayzrgb(211, 211, 211)�
lightgreenzrgb(144, 238, 144)�	lightgrey�	lightpinkzrgb(255, 182, 193)�lightsalmonzrgb(255, 160, 122)�
lightseagreenzrgb( 32, 178, 170)�lightskybluezrgb(135, 206, 250)�lightslategrayzrgb(119, 136, 153)�lightslategrey�lightsteelbluezrgb(176, 196, 222)�lightyellowzrgb(255, 255, 224)�limezrgb( 0, 255, 0)�	limegreenzrgb( 50, 205, 50)�linenzrgb(250, 240, 230)�magenta�maroonzrgb(128, 0, 0)�mediumaquamarinezrgb(102, 205, 170)�
mediumbluezrgb( 0, 0, 205)�mediumorchidzrgb(186, 85, 211)�mediumpurplezrgb(147, 112, 219)�mediumseagreenzrgb( 60, 179, 113)�mediumslatebluezrgb(123, 104, 238)�mediumspringgreenzrgb( 0, 250, 154)�mediumturquoisezrgb( 72, 209, 204)�mediumvioletredzrgb(199, 21, 133)�midnightbluezrgb( 25, 25, 112)�	mintcreamzrgb(245, 255, 250)�	mistyrosezrgb(255, 228, 225)�moccasinzrgb(255, 228, 181)�navajowhitezrgb(255, 222, 173)�navyzrgb( 0, 0, 128)�oldlacezrgb(253, 245, 230)�olivezrgb(128, 128, 0)�	olivedrabzrgb(107, 142, 35)�orangezrgb(255, 165, 0)�	orangeredzrgb(255, 69, 0)�orchidzrgb(218, 112, 214)�
palegoldenrodzrgb(238, 232, 170)�	palegreenzrgb(152, 251, 152)�
paleturquoisezrgb(175, 238, 238)�
palevioletredzrgb(219, 112, 147)�
papayawhipzrgb(255, 239, 213)�	peachpuffzrgb(255, 218, 185)�peruzrgb(205, 133, 63)�pinkzrgb(255, 192, 203)�plumzrgb(221, 160, 221)�
powderbluezrgb(176, 224, 230)�purplezrgb(128, 0, 128)�redzrgb(255, 0, 0)�	rosybrownzrgb(188, 143, 143)�	royalbluezrgb( 65, 105, 225)�saddlebrownzrgb(139, 69, 19)�salmonzrgb(250, 128, 114)�
sandybrownzrgb(244, 164, 96)�seagreenzrgb( 46, 139, 87)�seashellzrgb(255, 245, 238)�siennazrgb(160, 82, 45)�silverzrgb(192, 192, 192)�skybluezrgb(135, 206, 235)�	slatebluezrgb(106, 90, 205)�	slategrayzrgb(112, 128, 144)�	slategrey�snowzrgb(255, 250, 250)�springgreenzrgb( 0, 255, 127)�	steelbluezrgb( 70, 130, 180)zrgb(210, 180, 140)zrgb( 0, 128, 128)zrgb(216, 191, 216)zrgb(255, 99, 71)zrgb( 64, 224, 208)zrgb(238, 130, 238)zrgb(245, 222, 179)zrgb(255, 255, 255)zrgb(245, 245, 245)zrgb(255, 255, 0)zrgb(154, 205, 50))�tan�teal�thistle�tomato�	turquoise�violet�wheat�white�
whitesmoke�yellow�yellowgreenr*�baseliner,�noner-�nonzeror.z#000r0�	linearRGBr/�sRGBr3�ltrr4�inliner5�
accumulater6r7�1r8r9r:r;r?r>�mediumr@�normalrArBrCrD�0degrFrGz#fffrHrKrJrIrLrMrO�visiblePaintedrQrRrSrTrU�0rV�buttrW�miterrX�4rYrZr[�startr\r^r_�visibler`razlr-tbrbrdrerf)rgrhricCs |dkr|dkp|dko|dkS�Nr�)�a�brr�-/usr/lib/python3/dist-packages/scour/scour.py�is_same_sign�s rcCs:t||�rt||�r||||}t�d|�dkSdS)N�F)r�scouringContext�plus)�x1�y1�x2�y2�diffrrr�is_same_direction�srz[-+]?(\d*\.?)?\d+[eE][-+]?\d+z[-+]?(\d*\.?)?\d+z[eE]([-+]?\d+)z!(em|ex|px|pt|pc|cm|mm|in|%){1,1}$c@s�eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
eeeeee	e
eee
d�
Zed
edededede	de
dedede
di
Zdd�Zdd�Zee�Zee�ZdS)�Unit���rr��������	)
��%�px�pt�pc�em�ex�cm�mm�inr)r*r+r,r-r.r/r0r1r2cCs4|durtjSztj|WStytjYSw�N)r�NONE�s2u�KeyError�INVALID)�unitstrrrr�get�s
�zUnit.getcCs"ztj|WStyYdSw)Nr7)r�u2sr6)�unitintrrr�str�s
�zUnit.strN)�__name__�
__module__�__qualname__r7r4�PCT�PX�PT�PC�EM�EX�CM�MM�INr5r:r9r<�staticmethodrrrrr�sL��	rc@seZdZdd�ZdS)�	SVGLengthc	Cs@zt|�|_t|j�|jkrt|j�|_tj|_WdSty�d|_d}t�|�}|durTt	�|�}t
�||�d��}t|�
d��dt|�
d��|_|�d�}nt	�|�}|durjt|�
d��|_|�d�}t|j�|jkrxt|j�|_|dkr�t�||�}|dur�t�|�
d��|_YdSYdSd|_tj|_YdSw)Nr�
r)�float�value�intrr4�units�
ValueError�	scinumber�match�number�sciExponent�searchr�group�end�unitr9r7)�selfr<�	unitBegin�scinum�numMatch�expMatch�	unitMatchrrr�__init__�s<


�

��zSVGLength.__init__N)r=r>r?r_rrrrrJ�srJcCsT|duri}|�d�}|dkr|||<|��r(|jD]
}|jtjkr't||�q|S)z1
    Returns all elements with id attributes
    N�idr))�getAttribute�
hasChildNodes�
childNodes�nodeTyper�ELEMENT_NODE�findElementsWithId)�node�elemsr`�childrrrrfs


�rf)r6rSr9r,rLrKrIrJcCs�|duri}|jdkr@|jtdkr@d�dd�|jD��}|dkr>t|�}|D]}|dD]}|d|}t||||�q-q'|S|�tdd	�}|dkrot|�d
kro|ddkro|d
d�}||vrj||�	|�n|h||<|�
d��d
�}	|	D] }
|
�d�}t|�dkr�|d��}|d
��}t||||�qyt
D]}
|�
|
���}|s�q�t||
||�q�|��r�|jD]
}|jtjkr�t||�q�|S)a	
    Returns IDs of all referenced elements
    - node is the node at which to start the search.
    - returns a map which has the id as key and
      each value is is a set of nodes

    Currently looks at 'xlink:href' and all attributes in 'referencingProps'
    N�stylerr)cs��|]}|jVqdSr3��	nodeValue��.0rirrr�	<genexpr>>��z)findReferencedElements.<locals>.<genexpr>�
propertiesr�hrefrr�#�;�:r!)�nodeName�namespaceURI�NS�joinrcr�findReferencingProperty�getAttributeNS�len�addra�split�strip�referencingPropsrbrdrre�findReferencedElements)rg�ids�
stylesheet�cssRules�rule�propname�propvalrsr`�stylesrj�prop�val�attrrirrrr�*sJ
� 

�

�r�cCs�|tvrv|dkrxt|�dkr3|dd�dkr3|d|�d��}||vr,||�|�dS|h||<dSt|�dkrzd}|dd�d	krM|d|�d
��}n|dd�dkr^|d|�d��}|dur|||vro||�|�dS|h||<dSdSdSdSdS)
Nr)r&rr$�url(#�)r'r%�url("#�")�url('#�'))r�r}�findr~)rgr�r�r�r`rrrr{hs&�r{cCs�|durg}|durt|j�}gd�}|jD]5}|jtjkrq|�d�}|dks,||vrK|jdkrA|jt	dkrAt
||||d�}q|j|vrK|�|�q|S)N)r<rj�metadata�script�title�descr`r)�gr��
referencedIDs)r��documentElementrcrdrrerarwrxry�removeUnusedDefs�append)�doc�defElem�
elemsToRemover��keepTags�elem�elem_idrrrr��s 




�r�cCs�d}gd�}t|j�}t|j�}|s7|j�d�}|D]}t|||d�}|D]}	|	j�|	�td7a|d7}q%q|D],}
|
|vre||
}|dure|j|vre|jdure|jj	dkre|j�|�|d7}td7aq9|S)z�
    Removes all unreferenced elements except for <svg>, <font>, <metadata>, <title>, and <desc>.
    Also vacuums the defs of any non-referenced renderable elements.

    Returns the number of unreferenced elements removed from the document.
    r)�linearGradient�radialGradient�pattern�defsr�rN)
rfr�r��getElementsByTagNamer��
parentNode�removeChild�_num_elements_removedrw�tagName)r��keepDefs�num�
removeTags�identifiedElementsr�r��aDefr�r�r`�gonerrrr�removeUnreferencedElements�s0


�
�r�c	sLd}t|j��t|j����fdd��D���jdd�dd��D�����fdd��D��t�|�}t�}g}ttt	��d��}|�
�d	\}}	�D]!}
|	dkrY|��\}}	|	d8}	t	|
�|kri|�|
�qM|�
|
�qMd}|D]0}t||�}
|
|vs�|
|vr�|d7}t||�}
|
|vs�|
|vs�|t||
���|��7}|d7}qs|S)
z�
    Shortens ID names used in the document. ID names referenced the most often are assigned the
    shortest ID names.

    Returns the number of bytes saved by shortening ID names in the document.
    rcs$g|]}|�vrt�|�|f�qSr�r}�ro�rid)r�r�rr�
<listcomp>�s�zshortenIDs.<locals>.<listcomp>T)�reversecSsg|]\}}|�qSrr)ro�countr�rrrr���csg|]}|�vr|�qSrrr�)�idListrrr���r�rr)rfr�r��sort�extend�
protected_ids�set�list�compute_id_lengthsr}r��popr~r��intToID�renameIDr9)r��prefix�optionsr��protectedIDs�consumedIDs�need_new_id�id_allocations�optimal_id_length�id_use_limit�
current_id�curIdNum�old_id�new_idr)r�r�r�r�
shortenIDs�s<




�
r�ccsH�d}d}d}|r"|d7}||9}||fVt|d|�}|s	dSdS)a�Compute how many IDs are available of a given size

    Example:
        >>> lengths = list(compute_id_lengths(512))
        >>> lengths
        [(1, 26), (2, 676)]
        >>> total_limit = sum(x[1] for x in lengths)
        >>> total_limit
        702
        >>> intToID(total_limit, '')
        'zz'

    Which tells us that we got 26 IDs of length 1 and up to 676 IDs of length two
    if we need to allocate 512 IDs.

    :param highest: Highest ID that need to be allocated
    :return: An iterator that returns tuples of (id-length, use-limit).  The
     use-limit applies only to the given id-length (i.e. it is excluding IDs
     of shorter length).  Note that the sum of the use-limit values is always
     equal to or greater than the highest param.
    �rrN)rN)�highest�step�	id_length�	use_limitrrrr�s�
�r�cCsHd}|dkr |d8}t|dtd��|}t|d�}|dks||S)z�
    Returns the ID name for the given ID number, spreadsheet-style, i.e. from a to z,
    then from aa to az, ba to bz, etc., until zz.
    r)rrr�r)�chr�ordrN)�idnumr�r�rrrr�5s�r�cCs\d}||}|�d|�|t|�t|�7}|du�r,|D�]
}|jdkr||jtdkr||jdur|d�dd�|jD��}|�d	|d
d	|d
�}|�d|dd	|d
�}|�d
|dd	|d
�}|j	�
|�g|jdd�<|t|�t|�7}|�tdd�}	|	d|kr�|�tddd|�|t|�t|�7}|�
d�}
|
dkr�|
�d	|d
d	|d
�}|�d|dd	|d
�}|�d|dd	|d
�}|�d|�|t|
�t|�7}tD]F}|�
|�}|dk�r*|�d	|d
d	|d
�}|�d|dd	|d
�}|�d|dd	|d
�}|�||�|t|�t|�7}q�q|S)z�
    Changes the ID name from idFrom to idTo, on the declaring element
    as well as all nodes in referringNodes.

    Updates identifiedElements.

    Returns the number of bytes saved by this replacement.
    rr`Nrjrr)csrkr3rlrnrrrrpdrqzrenameID.<locals>.<genexpr>r�r�zurl(#'r�zurl(#"r�rrsrtr�r�)�setAttributer}rwrxry�
firstChildrzrc�replace�
ownerDocument�createTextNoder|�setAttributeNSrar�)�idFrom�idTor��referringNodesr��definingNoderg�oldValue�newValuersr�r�rrrr�DsH






��	r�cs�g}|js|js|jrSg}g}|jr|j�d�}|jr!|j�d�}|D]/�d}|jr3�d��s3d}n|r<�|vr<d}n|rKt�fdd�|D��rKd}|rR|���q#|S)z1Return a list of protected IDs out of the seenIDs�,Fr Tc3��|]}��|�VqdSr3)�
startswith)ror��r`rrrp���z protected_ids.<locals>.<genexpr>)�protect_ids_prefix�protect_ids_noninkscape�protect_ids_listr�isdigit�anyr�)�seenIDsr�r��protect_ids_prefixesr��	protectedrr�rr��s*
�r�cCs,t|j�}t||�}|r|D]}||=q|S)z:Returns a list of unprotected IDs within the document doc.)rfr�r�)r�r�r�r�r`rrr�unprotected_ids�s

r�cCsLdg}d}|D]}||}||vr#|j|vr#|�d�td7a|d7}q|S)zb
    Removes the unreferenced ID attributes.

    Returns the number of ID attributes removed
    r<rr`r)rw�removeAttribute�_num_ids_removed)r�r�r�r�r`rgrrr�removeUnreferencedIDs�s
�r�c	Cs�d}|jtjkrF|j}g}t|j�D]}|�|�}|dur(|j|vr(|�|j	�q|D]}|�
|�q+|t|�7}|jD]	}|t
||�7}q<|Sr)rdrre�
attributesr
�length�itemrxr�rwr�r}rc�removeNamespacedAttributes)	rg�
namespacesr��attrList�
attrsToRemove�attrNumr��attrNamerirrrr��s
�
r�cCs~d}|jtjkr=|j}g}|D]}|dur|j|vr|�|�q|D]}|�|�q"|t|�7}|jD]	}|t||�7}q3|Sr)	rdrrercrxr�r�r}�removeNamespacedElements)rgr�r��	childList�childrenToRemoverirrrr�s
�
rcCs�g}|jr|�d�n|jr|�d�|jr|�d�|jr#|�d�|s'dSd}g}|D]}|�|j�|��q-|D]}|j�	|�|d7}t
d7a
q;|S)N)r�r�r�r�r�r�rr)�remove_descriptive_elementsr��
remove_titlesr��remove_descriptions�remove_metadatar�r�r�r�r�)r�r��elementTypesr��elementsToRemove�elementType�elementrrr�removeDescriptiveElements�s(



r
cCsd}g}|jtjkr|jdksG|jD]4}|jdkrF|jtdkrFt|j�dkrF|jD]}|jtjkr@|jtdkr@|jdvr@nq*|�	|�q|D]$}|jj
dkr_|j�|j
|�|jj
dksQ|j�|�td7a|d7}qI|jD]}|jtjkr|t|�7}qq|S)z�
    This walks further and further down the tree, removing groups
    which do not have any attributes or a title/desc child and
    promoting their children up one level
    r�switchr�r�r�r�r)rdrrerwrcrxryr}r�r�r�r��insertBeforer�r�r��removeNestedGroups)rgr��groupsToRemoveri�
grandchildr�rrrrs0
&

�
��

�rcCshd}g}|jD]+}|jtjkr#|�d�|vr"|�|�|t||�7}q|jtjkr2|j�	�r2|Sqt
|�dkr;|Si}|dj}t|j
�D]}|�|�}|jdvrY|j||j<qGtt
|��D].}	|	dkrgq`||	}|jdvrqq`g}
|D]}|�|�||kr�|
�|�qu|
D]}||=q�q`|D]}|D]}|�|�q�|�|||�q�|t
|�dt
|�7}|S)a�
    This recursively calls this function on all children of the passed in element
    and then iterates over all child elements and removes common inheritable attributes
    from the children and places them in the parent group.  But only if the parent contains
    nothing but element children and whitespace.  The attributes are only removed from the
    children if the children are not referenced by other elements in the document.
    rr`r�r-rcr6r7r8r<r=r>r?r@rArBrCrFrOrPrSrTrUrVrWrXrYrZr[r\r]r_r`ra)r��animate�animateColor�animateTransform�
animateMotion)rcrdrrerar��!moveCommonAttributesToParentGroup�	TEXT_NODErmr�r}r�r
r�r�rw�	localNamer�r�)r��referencedElementsr��
childElementsri�commonAttrsr��indexr��childNum�
distinctAttrs�namerrrr&sP

��


�

��rcCs(d}|jjd}|dkr�|j�|�}|jtjks$|jdks$|jtdkr)|d8}qdd�|j	�
�D�}|s:|d8}q||}}d}|dkr�|j�|d�}|jtjkr�|jdks_|jtdkr`n,dd�|j	�
�D�}	dd	�|jD�}
||	kszt|
�r{n|d7}|d8}n|d8}|dksE|d}|d
kr�q	|j�|�}|jtjkr�|jdkr�|jtdkr�n|d7}q�|j�|�}|d7}|j||d�}
|
D]0}|jtjkr�|jdkr�|jtdkr�|jdd�D]}|�|�q�|�
|���q�|�|�q�|dks|jD]}|jtjk�r|t|�7}�q|S)
z�
    Merge two or more sibling <g> elements with the identical attributes.

    This function acts recursively on the given element.
    rrr�rcS�i|]}|j|j�qSr�rwrm�rorrrr�
<dictcomp>��z:mergeSiblingGroupsWithCommonAttributes.<locals>.<dictcomp>cSr#rr$r%rrrr&�r'css8�|]}|jtjkr|jdvr|jtdkrdVqdS)rrTN)rdrrerwrxry)ro�nrrrrp�s�
��z9mergeSiblingGroupsWithCommonAttributes.<locals>.<genexpr>r!TN)rcr�r�rdrrerwrxryr��valuesr��appendChildr��unlink�&mergeSiblingGroupsWithCommonAttributes)r�r��i�currentNoder��runStart�runEnd�runElements�nextNode�nextAttributes�hasNoMergeTagsrg�primaryGroup�nodesri�	childNoderrrr,ysf

�$�$�
8�r,cCsd}dD]�}|jjd}|dkr�|j�|�}|jtjkr�|�|�dkr�|jdvr�|�|�}||}}d}|dkr_|j�|d�}	|	jtjkrW|	�|�|krNn|d7}|d8}n|d8}|dks8|dkr�||jjdkr�|j�|d�jtjkrxn|d7}||jjdksk||d}
|
|jjkr�|jdkr�|jt	dkr�d	}q|j
}|�t	dd�}|j||d�|jd
d
�<|jD]}
||
_q�g|j||d�<|j�
||�||_|d7}|d}td8an	|d8}n|d8}|dksq|jD]}|jtjk�r|t|�7}q�|S)a�
    Creates <g> elements to contain runs of 3 or more
    consecutive child elements having at least one common attribute.

    Common attributes are not promoted to the <g> by this function.
    This is handled by moveCommonAttributesToParentGroup.

    If all children have a common attribute, an extra <g> is not created.

    This function acts recursively on the given element.
    rrrr))1rrrrr�r�r�r��circle�ellipse�line�path�polygon�polyline�rectr�r��svg�symbol�user�r�r�altGlyphDef�clipPathr1r2r9r<z	font-face�
foreignObject�imagerHrLr�r�rjr�text�view�	animation�audio�discard�handler�listener�prefetch�
solidColor�textArea�videor"r�rr N)rcr�r�rdrrerarwrxryr��createElementNSr��insertr��createGroupsForCommonAttributes)r�r��curAttr�curChildr7rMr/r0r1r2�	runLength�documentrVrirrrrS�sf




��	


��
Z�rSc
Csd}g}|jD]}|jtjkr|�|�|t|�7}qt|�dkr#|S|j}i}t|j	�D]}|�
|�}|jdvr?|j||j<q-tt|��D]+}||}g}	|D]}
|�
|
�}|dksc|dusc|dkrh|	�|
�qP|	D]}||=qkqF|D]}
|�|
�|d7}qt|S)z�
    This recursively calls this function on all children of the element passed in,
    then removes any unused attributes on this elem if none of the children inherit it
    rrrr)N�inherit)rcrdrrer��removeUnusedAttributesOnParentr}r�r
r�r�rwrmrar�)
r�r�rrir��unusedAttrsrr�r �inheritedAttrsr"r�rrrrrYBs>

�

�

��

rYc
	Cs:d}dD]�}|�|�D]�}i}g}|�d�D]o}t|�d��}|jtjkr+|jd}n|jtjkr5|j}nd}t|�|krH|�	dt
t|���n|�	dt
|��|�d�}	|�d�}
|�d�}||vr~||}|d|	kr~|d	|
kr~|d
|kr~|�|�|	|
|g||<q|D]}|j�
|�|d	7}td	7aq�qq|S)Nr�r�r��stop�offset�Y@rQrRrjrr!)r�rJrarOrr@rMr4rNr�r<r�r�r�r�)
r�r��gradType�grad�stops�
stopsToRemover]�offsetUr^r.rMrj�oldStoprrr�removeDuplicateGradientStopsys<


$

��!rfc	Cs�d}t|j�}t�t|j��D]�\}}t|�dkr�||vr�||}|dur�|jtjkr�|j	dvr�|j
tdkr�|��}|jtjkr�|j	dvr�|j
tdkr�t|�
d��dkre|�
d�}|D]}|�|�q]dD]}	|�|	�dkr�|�|	�dks�|�d|	|�|	��qg|j	dkr�|j	dkr�d	D]}	|�|	�dkr�|�|	�dks�|�d|	|�|	��q�|j	d
kr�|j	d
kr�dD]}	|�|	�dkr�|�|	�dks�|�d|	|�|	��q�|�tdd
�}
|
r�|�tdd
|
�n|�tdd
�|j�|�td7a|d7}q|S)Nrrr\rr])�
gradientUnits�spreadMethod�gradientTransformr)r�)�fx�fy�cx�cy�rr�)rrrrrrs)rfr��six�	iteritemsr�r}rdrrerwrxryr�r�r*rar�r|�removeAttributeNSr�r�r�)r�r�r�r�r6r��refElem�
stopsToAddr]r��target_hrefrrr�!collapseSinglyReferencedGradients�sN


����ruc	s�gd�}gd�}�fdd�|D�}|���tdd����d�}|jr@t|j�D]}|�|�}|D]}|�|�}|�|�q2q)d�|�S)	N)rgrhrirrrrrlrmrjrkrn)r^rQrRrjcsg|]}��|��qSr�rar%�rarrr��r'z,computeGradientBucketKey.<locals>.<listcomp>rrsr]�)	r�r|ryr�r�r
r�rarz)	ra�gradBucketAttr�gradStopBucketsAttr�subKeysrbr-r]r��stopKeyrrwr�computeGradientBucketKey�s


�
r}cgs��|D]`}tt�}|D]
}t|�}||�|�qt�|�D]D}t|�dkr'q|d}|dd�}dd�|D�}|�d�}	|	s\tt|��D]}
||
}|r[||
}	|||
<d||
<nqE|	||fVqqdS)	a�Detects duplicate gradients from each iterable/generator given as argument

    Yields (master, master_id, duplicates_id, duplicates) tuples where:
      * master_id: The ID attribute of the master element.  This will always be non-empty
        and not None as long at least one of the gradients have a valid ID.
      * duplicates_id: List of ID attributes of the duplicate gradients elements (can be
        empty where the gradient had no ID attribute)
      * duplicates: List of elements that are duplicates of the `master` element.  Will
        never include the `master` element.  Has the same order as `duplicates_id` - i.e.
        `duplicates[X].getAttribute("id") == duplicates_id[X]`.
    r!rrNcSsg|]}|�d��qSr�rv)ro�drrrr�r'z.detect_duplicate_gradients.<locals>.<listcomp>r`r))	rr�r}r�ro�
itervaluesr}rar
)�
grad_lists�grads�grad_bucketsra�key�bucket�master�
duplicates�duplicates_ids�	master_idr-�dup_idrrr�detect_duplicate_gradientss2�
�	��r�cCs�d}t||�D]�\}}|jsq||vr�|dur%d�|�}t�d|d�}||D]_}dD]}	|�|	�}
|�d|d|
�\}}|dkrJ|�|	|�q-|�t	dd	�d
|krb|�
t	dd	d
|�t|�}
|
D]}|
|}
|�d|d|
�\}}|dkr�||
|<qht||
�q)|j�
|�q|r�z||}Wnty�t�}Ynw|D]}|�|d�}|dur�q�|�|�q�|||<dSdS)N�|zurl\(['"]?#(?:z)['"]?\)�r6rSr�r�rrrsrt)�zipr�rz�re�compilera�subnr�r|ryr��	_getStyle�	_setStyler�r6r�r��update)r�r�r��referenced_ids�func_irir��dup_grad�dup_id_regexr�r��v�v_newr(r�rj�master_references�
referencesrrr�dedup_gradient/sN

��
��r�c	Csnd}d}t|j�}||kr5|}|�d�}|�d�}t||�D]\}}}t||||�|t|�7}q||ks
|S)Nr rr�r�)r�r�r�r�r�r})	r��prev_numr�r��linear_gradients�radial_gradientsr�r�r�rrr�removeDuplicateGradientsgs


�
r�cCsl|jtjkriS|�d�}|r4i}|�d�}|D]}|�d�}t|�dkr1|d��||d��<q|SiS)z6Returns the style attribute of a node as a dictionary.rjrurvr!rr)rdrrerarr}r�)rg�style_attribute�styleMap�	rawStylesrjr�rrrr�{s


�r�csHd��fdd��D��}|dkr|�d|�|S|�d�r"|�d�|S)zBSets the style attribute of a node to the dictionary ``styleMap``.ruc3s �|]}|d�|VqdS)rvNr)ror��r�rrrp�s�z_setStyle.<locals>.<genexpr>r)rj)rzr�rar�)rgr��
fixedStylerr�rr��s
�
r�cCs�d}t|�}|�r�dD]C}||vrN||�d�}t|�dkrN|ddd�dks<|ddd�dks<|ddd�d	krN|d
dkrN|dd||<|d
7}qd
|vrrt|d
�}|dkrrdD]}||vrqt||�sq||=|d
7}q_d|vr�|ddkr�dD]}||vr�t||�s�||=|d
7}q~t|d�s�t|d�dvr�|d=|d
7}d|vr�|ddkr�dD]}	|	|vr�t||	�s�||	=|d
7}q�d|vr�t|d�}
|
dkr�dD]}||vr�t||�s�||=|d
7}q�d|v�r
t|d�}|dk�r
dD]}
|
|v�rt||
��s||
=|d
7}q�d|v�r6t|d�}|jdk�r6dD]}
|
|v�r4t||
��s4||
=|d
7}�q t|��sMdD]}||v�rK||=|d
7}�q=dD]}||v�r]||=|d
7}�qOd|v�r�|j	dv�rr|d=|d
7}n$||j
jk�r�|dd k�r�|d=|d
7}n|dd!k�r�|d=|d
7}|j�r�t
|�D]}|tv�r�|�|||�||=�q�t||�|jD]
}|t||�7}�q�|S)"Nrr�z) r!r$r�r%r�r�rzrgb(0, 0, 0)r�rMg)r6r7r8rSrWrYrXrVrTrUrYrSr�)rZrWrXrVrTrUrY)Nr�r6)r8r7r7)r6r8rY)rSrZrWrVrTrUrZ)rSrWrVrTrUrY)r=r>r@r?rArBrCrFzline-heightrErfr[r\r]r^r`ra)z-inkscape-font-specificationrN)r?r@rErDrHr��hiddenr)r�rr}rL�styleInheritedByChild�styleInheritedFromParentrJrM�mayContainTextNodesrwr�r��style_to_xmlr��
svgAttributesr�r�rc�repairStyle)rgr�r�r�r��chunkrM�uselessStyle�strokestyle�	fillstyle�fillOpacity�uselessFillStyle�
strokeOpacity�uselessStrokeStyle�strokeWidth�	fontstyle�
inkscapeStyle�propNamerirrrr��s�<���
��

�
�

�
�

�
�

r�cCs`|j}|jtjkrdSt|�}||vr||}|dks|S|�|�}|dvr+|�|�St||�S)z�
    Returns the value of 'style' that is inherited from the parents of the passed-in node

    Warning: This method only considers presentation attributes and inline styles,
             any style sheets are ignored!
    NrX�r)rX)r�rdr�
DOCUMENT_NODEr�rar�)rgrjr�r�rMrrrr�s


r�FcCs�|jtjkrdS|r$|�|�dvrdSt|�}||vr#||dks#dSn|js)dS|jr;|jD]}t||d�r:dSq/|jdvrBdSdS)a�
    Returns whether 'style' is inherited by any children of the passed-in node

    If False is returned, it is guaranteed that 'style' can safely be removed
    from the passed-in node without influencing visual output of it's children

    If True is returned, the passed-in node should not have its text-based
    attributes removed.

    Warning: This method only considers presentation attributes and inline styles,
             any style sheets are ignored!
    Fr�rXT)rr��glyphr�rHrLz
missing-glyphr�r?rr@)rdrrerar�rcr�rw)rgrj�nodeIsChildr�rirrrr�9s&�
�
r�cCs�z|jWSty
Ynwd}|jtjkrd}n%|jtdkr#d}n|jdvr+d}n|jdvr>d}|jD]}t|�r=d}q5||_|S)ae
    Returns True if the passed-in node is probably a text element, or at least
    one of its descendants is probably a text element.

    If False is returned, it is guaranteed that the passed-in node has no
    business having text-based attributes.

    If True is returned, the passed-in node should not have its text-based
    attributes removed.
    TFr)	r>r8r9r:r<r=r;rEr])r�rCrHrLr�r�r�r@)	r��AttributeErrorrdrrerxryrwrc)rg�resultrirrrr�ks(�


�r��DefaultAttribute)r"rMrO�elements�
conditionsr3�
clipPathUnits�userSpaceOnUserC)r��filterUnits�objectBoundingBoxrgr�r��	maskUnits�maskContentUnits�patternUnitsr��patternContentUnits�primitiveUnits�externalResourcesRequired�false)'r�altGlyphrrrrr8rCr2r�r9�feImager9r<rDr�rEr:r�rHrL�mpathr;r�r<r=r�r>r�r�r?rr@rF�textPath�tref�tspanrArG�width�dr?�height�baseProfile�preserveAspectRatioz
xMidYMid meet)r�rErHr�r?r@rG�x)
r2�fePointLight�feSpotLightrDrEr�r>r?rFrA�y�zr�r�rr:rrrrlr8r9rm�markerUnitsr��refX�refY�markerHeightr"�markerWidth�orient�lengthAdjust�spacing)rFr�r�r��startOffsetr��method�align�exacti����g��������cC�|�d�dkS�Nrgr�rv�rgrrr�<lambda>��r�)r�cCr�r�rvr�rrrr��r��xg333333�?cCr�r�rvr�rrrr��r�cCr�r�rvr�rrrr��r�rcCr�r�rvr�rrrr��r�)r�r�rjcC�|�d�|�d�kS)Nrjrlrvr�rrrr��r�rkcCr�)Nrkrmrvr�rrrr��r�rn�2g�?cCr�r�rvr�rrrr��r�cCr�r�rvr�rrrr��r�cCr�r�rvr�rrrr�r�rh�pad�	amplitude)�feFuncA�feFuncB�feFuncG�feFuncR�azimuth�feDistantLight�
baseFrequency�bias�feConvolveMatrix�diffuseConstant�feDiffuseLighting�edgeMode�	duplicate�	elevation�exponent�	intercept�k1�feComposite�k2�k3�k4�mode�feBlend�
numOctaves�feTurbulencer^�operator�over�erode�feMorphology�order�3�	pointsAtX�	pointsAtY�	pointsAtZ�
preserveAlpha�radius�scale�feDisplacementMap�seed�specularConstant�feSpecularLighting�specularExponent�stdDeviation�feGaussianBlur�stitchTiles�noStitch�surfaceScale�type�matrix�
feColorMatrix�
turbulence�xChannelSelector�A�yChannelSelectorcCs8|�|�|dkr|tgd��O}|dvr|�d�|S)zTAdds an attribute to a set of attributes.

    Related attributes are also included.rH)rKrJrI)r~r�)�
taintedSet�taintedAttributerrr�taint8s

r+cCs�|�|j�sdSt|jt�r+|�|j�|jkr)|jdus!|�|�r)|�|j�dSdSt|�|j��}|jdusD|j|jkrm|j	t
jksm|j	dus[|j	|j	ks[t|j	t�rm|j	|j	vrm|jduse|�|�rm|�|j�dSdS)z�
    Removes the DefaultAttribute 'attribute' from 'node' if specified conditions are fulfilled

    Warning: Does NOT check if the attribute is actually valid for the passed element type for increased preformance!
    rNr)
�hasAttributer"�
isinstancerMr<rar�r�rJrOrr7r�)rg�	attributermrrr�removeDefaultAttributeValueDs(�


�r/cs6d}�jtjkr
dStD]	}|t�|�7}q�jtvr*t�jD]	}|t�|�7}q �fdd�t�jj	�D�}|D]"}||vr[|t
vr[��|�t
|krV��|�|d7}q9t
||�}q9t��}t|�D]}||vr�|t
vr�||t
|kr~||=|d7}qdt
||�}qdt�|��jD]}|t|||���7}q�|S)z�'tainted' keeps a set of attributes defined in parent nodes.

    For such attributes, we don't delete attributes with default values.rcsg|]	}�j�|�j�qSr)r�r�rw�ror-r�rrr�usz0removeDefaultAttributeValues.<locals>.<listcomp>r)rdrre�default_attributes_universalr/rw�default_attributes_per_elementr
r�r��default_propertiesrar�r+r�r�r�rc�removeDefaultAttributeValues�copy)rgr��taintedr�r.r�r�rirr�rr4as<



�

�

r4z0\s*rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*zE\s*rgb\(\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*\)\s*cCs>|}|tvr
t|}t�|�}|durBtt|�d��dd�}tt|�d��dd�}tt|�d��dd�}d|||f}n%t�|�}|durgt|�d��}t|�d��}t|�d��}d|||f}|dd	kr�|��}t|�d
kr�|d|dkr�|d|dkr�|d|d
kr�d	|d|d|d}|S)z_
       Converts the input color string and returns a #RRGGBB (or #RGB if possible) string
    Nrg�o@r_r!r"z
#%02x%02x%02xrrtr&r#r$r%)	�colors�rgbprRrNrLrV�rgb�lowerr})rM�s�	rgbpMatchrnr�r�rgbMatchrrr�convertColor�s(

<r>c
Csd}|jtjkr
dSg}|jdvrddg}n|jdvrdg}n|jdvr'dg}t|�}|D]N}|�|�}|d	krYt|�}t|�}t|�}||krY|�||�||t|�|��7}||vr{||}t|�}t|�}t|�}||kr{|||<|||7}q-t	||�|j
D]}	|t|	�7}q�|S)
zU
       Recursively converts all color properties into #RRGGBB format if shorter
    r)	r>r8r9r<r:r=r;r�rr6rS)r]rQ)rNrdr))rdrrerwr�rar>r}r�r�rc�
convertColors)
r�numBytes�attrsToConvertr�r��
oldColorValue�
newColorValue�oldBytes�newBytesrirrrr?�sB




�

r?c&
CsN|�d�}t�|�}t|�}|�d�dvpd|vo|ddv}|�d�p0|�d�p0d|vp0d|v}d}}tt|��D�]�}	||	\}
}d}|
dkr�t|t|�d�D]&}||d	|8<||d
|8<|||d	7}|||d
7}qRd|f||	<q;|
dkr�|t|d	dd��7}|t|d
dd��7}q;|
d
kr�t|t|��D]}|||8<|||7}q�d|f||	<q;|
dkr�|t|�7}q;|
dkr�t|t|��D]}|||8<|||7}q�d|f||	<q;|
dkr�|t|�7}q;|
dk�rT|d|d}
}|	dk�r|d|8<|d|8<|
|}}d}t|t|�d�D]#}|||8<||d|8<|||7}|||d7}�q)d|f||	<q;|
dv�r�t|t|�d�D]#}|||8<||d|8<|||7}|||d7}�qa|
��|f||	<q;|
dv�r�|	dk�r�|d|d}
}|
|}}d}n||d}
||d}t|t|�d�D]}|||7}|||d7}�q�q;|
dv�r�|t|ddd��7}|t|ddd��7}q;|
dv�r<t|t|�d�D]9}|||8<||d|8<||d|8<||d|8<|||d7}|||d7}�q�|
��|f||	<q;|
dv�rX|t|ddd��7}|t|ddd��7}q;|
dk�r�t|t|�d
�D]M}|||8<||d|8<||d|8<||d|8<||d|8<||d	|8<|||d7}|||d	7}�qed|f||	<q;|
dk�r�|t|ddd
��7}|t|d	dd
��7}q;|
dv�r�|
|}}d|f||	<q;|�s�tt|��D�]T}	||	\}
}d}|
d v�r;|
dk�rd}|t|�k�r9||||dk�r dk�r.nn|||d�=t	d7a	n|d7}|t|�k�s�q�|
dk�r�|t|�k�r�||||dk�r�||dk�r�||dk�r�||dk�r�||d	k�r�dk�r�nn|||d
�=t	d7a	n|d
7}|t|�k�sG�q�|
dk�r�|t|�k�r�||d	||d
k�r�dk�r�nn|||d�=t	d7a	n|d7}|t|�k�s��q�|
d!k�r$|t|�k�r"||||dk�r	||dk�r	||dk�r	dk�rnn|||d�=t	d7a	n|d7}|t|�k�s�q�|
d"v�rDt|�}|
d#d$�|D�f||	<t	t||	d�|7a	�q�t|�}	d%}|	dk�r�|	d8}	||	\}
}|
dk�r||	d\}}|dk�r|t|�dk�r|||	=t	d7a	nGd&}nD|
dk�r�t|�d|	k�r�t|�dk�r�||	=t	d7a	�qL|�r�d%}n |d|dk�r�dk�r�nnd'|dd�f||	<t	d7a	|	dk�sQd(d$�|D�}|dg}|dd�D]�\}
}d}|}|
dk�rkg}|t|�k�rk||||d}}||d||d}}||d}||d	}d%}|dk�r(|dk�r'|dk�r'd&}n||}|||k�r<|||k�r<d&}|�rU|�rK|�
|
|f�g}|�
d'||gf�n|�|||d
��|d
7}|t|�k�s�|�sx|
dk�sx|
d)k�r|�
|
|f��q�|}d*}g}g}|D]6\}
}|d*k�r�|
}|}�q�|
dk�r�|
|k�s�|
d'k�r�|dk�r�|�|��q�|�
||f�|
}|}�q�|�
||f�|}g}|D�]R\}
}|
d'k�rNd}g}|t|�k�rB||dk�r|�r�|�
d'|f�g}|�
d||dgf�t	d7a	n/||ddk�r,|�r|�
d'|f�g}|�
d||gf�t	d7a	n|�|||d��|d7}|t|�k�s�|�rL|�
d'|f��q�|
dk�r�d}|d|dg}|t|�k�r�||dk�r�|�ry|�
|
|f�g}d'}
|�
d||dgf�t	d7a	n1||ddk�r�|�r�|�
|
|f�g}d'}
|�
d||gf�t	d7a	n|�|||d��|d7}|t|�k�sd|�r�|�
|
|f��q�|
dk�r�d+} t|��r�|d,\}}|d-k�r�|d.|d/|d,|d0f} d}g}!|t|�k�r�| d||k�rD| d||dk�rD|!�r$|�
d|!f�g}!|�
d-||d||d||d||d	gf�t	d7a	nd}"|"d	k�r]|!�
|||"�|"d7}"|"d	k�sK||d||d||d	||df} |d
7}|t|�k�s|!�r�|�
d|!f��q�|
d!k�rd+}#d}g}!|t|�k�r|#d||k�r�|#d||dk�r�|!�r�|�
d!|!f�g}!|�
d1||d||dgf�t	d7a	nd}"|"dk�r�|!�
|||"�|"d7}"|"dk�s�||d||||d||df}#|d7}|t|�k�s�|!�r|�
d!|!f��q�|�
|
|f��q�|}|�	s3tt|��D�]}	||	\}
}|
d"v�rt|�dk�rd}$|$dt|�k�r}t||$||$d��rp||$||$d7<||$d=t	d7a	n|$d7}$|$dt|�k�sN�q.|
d'k�r�t|�dk�r�d}$|$dt|�k�r�t
||$|$d���r�||$||$d7<||$d||$d7<||$d=||$d=t	d7a	n|$d7}$|$dt|�k�s��q.|
dk�	r1t|�d
k�	r1d}$|$dt|�k�	r1t
||$|$d���	r$||$||$d7<||$d||$d7<||$d=||$d=t	d7a	n|$d7}$|$dt|�k�s�q.d*}g}|dg}|dd�D]4\}
}|d*k�	r`|
|k�	sU|
dk�	r`|�
||f�d*}g}|
|k�	rq|
dk�	rq|�|��	qB|
}|}�	qB|d*k�	r�|�
||f�|}t||�}%t|%�t|�k�	r�tt|�t|%�7a|�d|%�dSdS)2z@
       Cleans the path string (d attribute) of the element
    r~rV)�round�squarerHrJrr'r&r$r%rN�H�h�Vr��Mrr!�m)�L�T)rL)�l�t)�S�Qr#r"�r;�q�C�c)r��Zr�)rLrOrPrT)rIr�cSsg|]}|dkr|�qS)rr)ro�coordrrrr��	r�zcleanPath.<locals>.<listcomp>FTrOcSs,g|]}t|d�dks|ddkr|�qS)rrr�r�)ror�rrrr��	s,rWr)r�r r;���������rP)rar�parser�r,r
r}�sumr:�_num_path_segments_removedr�r�rr�
serializePath�_num_bytes_saved_in_path_datar�)&rr��
oldPathStrr;rj�has_round_or_square_linecaps�has_intermediate_markersr�r��	pathIndex�cmd�datar-�startx�starty�oldLen�subpath_needs_anchor�next_cmd�	next_data�newPath�newData�p1x�p1y�p2x�p2y�dx�dy�foundStraightCurverL�prevCmd�prevData�
lineTuples�
bez_ctl_pt�curveTuples�j�quad_ctl_pt�
coordIndex�
newPathStrrrr�	cleanPath�s�

�
���






�






�

	(
��
x
��
,
��
P
��
�



 $
�#


���
(


��


��


 (6


�0��
("


�,��

��	


��


��



�rcCstd}t�|���}g}tt|��D]d}||�d�}t|�dkr(|�|d�qtt|��D]F}|dkrB|ddkrA|�|d�q.d}t|�rP|t|�d}|rk|t|�ddvrk|d|||t|�d<q.|�d||�q.qt|�ddkr�gSd}|t|�kr�zt��||�||<t��||d�||d<Wnty�gYSw|d7}|t|�ks�|S)zw
       Parse string into a list of points.

       Returns a list containing an even number of coordinate strings
    r�-rr))�e�Er!)	�RE_COMMA_WSPrr�r
r}r�r�create_decimalr)r;r-�ws_nums�nums�	negcoordsr{�prevrrr�parseListOfPoints�
s@�� ��	r�cCs|t|�d��}t|�d}|dkr2|dd�\}}|dd�\}}||kr2||kr2|dd�=td7a|�dt||d��dS)zI
       Remove unnecessary closing point of polygon points attribute
    �pointsr!NrYrT)r�rar}� _num_points_removed_from_polygonr��scourCoordinates)r�r��pts�Nrgrh�endx�endyrrr�cleanPolygons
r�cCs&t|�d��}|�dt||d��dS)z0
       Scour the polyline points attribute
    r�TN)r�rar�r�)r�r�r�rrr�
cleanPolyline&sr�cCsL|��}|dvr$tt|��}|dkrdd�|D�S|dvr$dd�|D�SgS)z�
       Checks if there are control points in the path data

       Returns the indices of all values in the path data which are control points
    )rVr;rTrVcS�g|]
}|ddkr|�qS)r%r#r�rorrrrr�8�z!controlPoints.<locals>.<listcomp>rScSr�)r#r!rr�rrrr�:r��r:r
r}�rerf�indicesrrr�
controlPoints.sr�cCs*|��dkrtt|��}dd�|D�SgS)z�
       Checks if there are flags in the path data

       Returns the indices of all values in the path data which are flags
    rcSsg|]
}|ddvr|�qS)r&)r"r#rr�rrrr�Gr�zflags.<locals>.<listcomp>r�r�rrr�flags?sr�csd��fdd�|D��S)z;
       Reserializes the path data with some cleanups.
    r)c	3s4�|]\}}|t|�t||�t||�d�VqdS))�control_pointsr�N)r�r�r�)rorerf�r�rrrpRs���z serializePath.<locals>.<genexpr>�rz)�pathObjr�rr�rr_Ls�r_cCsd�dd�|D��S)z@
       Reserializes the transform data with some cleanups.
    � css4�|]\}}|dd�dd�|D��dVqdS)�(r�css�|]}t|�VqdSr3��scourUnitlessLength)rorSrrrrp\��z/serializeTransform.<locals>.<genexpr>.<genexpr>r�Nr�)ro�command�numbersrrrrp\s�(�z%serializeTransform.<locals>.<genexpr>r�)�transformObjrrr�serializeTransformXs
�r�cCs|dur�g}d}d}|D]A}||v}	t||j|	d�}
|dkrB|s4|
d��s4|
ddkrBd|vsBd|vsB|d|vs=|jrB|�d�|�|
�|
}|d7}q|jr�t|�dkr�tdt|��D]}||dd	krzd||dvrz||dd7<q^d�|�SdSd�|�SdS)
a1
       Serializes coordinate data with some cleanups:
          - removes all trailing zeros after the decimal
          - integerize coordinates if possible
          - removes extraneous whitespace
          - adds spaces between values in a subcommand if required (or if force_whitespace is True)
    Nrr))�renderer_workaround�is_control_point�.r�rr�r�)r�r�r�r�r}r
rz)rfr��force_whitespacer�r�rnrV�
previousCoordrXr��scouredCoordr-rrrr�`s>�	�
�


 �

�r�cCst|�}t|j�t�|j�S)z)
    Scours a length. Accepts units.
    )rJr�rMrr<rO)r�rrr�scourLength�sr�c	Cs*t|t�s
t��t|��}|}|rt�|�}nt�|�}|��}||kr)t|�}n|�	�}d�
|�}d�
|�t|���}|sit|�dkrS|dd�dkrS|dd�}nt|�dkri|dd�dkrid|dd�}|}t|�dkr�|�
�}|�|��	�}t�|�d	t�|�}t|�t|�kr�|}|S)
z�
    Scours the numeric part of a length only. Does not accept units.

    This is faster than scourLength on elements guaranteed not to
    contain units.
    z{0:f}r!Nz0.rr"z-0.r�r�)r-r
rr�r<�scouringContextCrr�to_integral_value�	normalize�format�quantizer}�adjusted�scalebro�	text_type)	r�r�r��initial_length�	intLength�nonsci�return_valuer�scirrrr��s2



r�cCs�d}t|�}dD]]}|�|�}|dkr9t|�}|jtjkr9t|�}t|�t|�kr9|t|�t|�7}|�||�||vre||}t|�}|jtjkret|�}t|�t|�kre|t|�t|�7}|||<qt	||�|j
D]}|jtj
kr||t|�7}qn|S)a�
    Because opacities, letter spacings, stroke widths and all that don't need
    to be preserved in SVG files with 9 digits of precision.

    Takes all of these attributes, in the given element node and its children,
    and reduces their precision to the current Decimal context's precision.
    Also checks for the attributes actually being lengths, not 'inherit', 'none'
    or anything that isn't an SVGLength.

    Returns the number of bytes saved after performing these reductions.
    r)
rMr;r7rYrRrXrUrFr`rEr?r>rZr))r�rarJrOrr7r�r}r�r�rcrdrre�reducePrecision)rr�r��
lengthAttrr��valLen�newValrirrrr��s4
�

�r�cCsB|dkr	|d;}n|d;}|dkr|d8}|S|dkr|d7}|S)z�
    Because any rotation can be expressed within 360 degrees
    of any given number, and since negative angles sometimes
    are one character longer than corresponding positive angle,
    we shorten the number to one in the range to [-90, 270[.
    ri����ihii����r)�anglerrr�
optimizeAngles
�r�cCs2t|�dkr�|dddkr�|dd}\}}}}}}|gd�kr&|d=n�|dkr?|dkr?|dkr?|dkr?d||gf|d<n}|dkrX|dkrX|dkrX|dkrXd||gf|d<nd||kr�d|krfdkr�nnT|dkr�||kr�d|kr{dkr�nn?|dkr�t|d|dd�td	�kr�||}}	ttt�t�t|�����}
|	dkr�|dkr�d
|
}
nd|
}
d|
gf|d<|D]X\}}|dkr�t|�dkr�|ddkr�|d=q�|dkr�t|d�|d<t|�d
kr�|d|dkr�dkr�nq�|dd�=q�|dk�rt|�dk�r|d|dk�r|d=q�d}
|
t|�k�rH||
\}}||
d\}}||k�r:dk�r�nnN|d|d7<t|�dk�rmt|�dk�r_|d|d7<nt|�dk�rm|�	|d�||
=|d|dk�r�dk�r�nn�|
d8}
||
=n�||k�r�dk�r�nn"t|�t|�k�r�dk�r�nnt|d|d�|d<||
=n�||k�r�dk�r=nnu|d|d9<t|�dk�r�t|�dk�r�|d|d9<n2t|�dk�rt|�dk�r|�	|d|d�nt|�dk�rt|�dk�r|d|d9<||
=|ddk�r<t|�dk�s5|ddk�r<|
d8}
||
=n|
d7}
|
t|�k�s d}
|
t|�k�r�||
\}}|dk�sa|dk�rst|�dk�rs|ddk�rs||
=n|dk�r�t|�dk�r�|ddk�r�||
=n|
d7}
|
t|�k�sQdSdS)z�
    Optimises a series of transformations parsed from a single
    transform="" attribute.

    The transformation list is modified in-place.
    rrr#)rrrrrr�	translaterr r!z1e-15iL�����rotater"N�skewX�skewY)
r}�absr
r<�math�degrees�asinrLr�r�)�	transformr#�A1�B1�A2�B2�A3�B3�sin_A�cos_Ar'r"�argsr-�currType�currArgs�prevType�prevArgsrrr�optimizeTransforms�(* 

�,
�
 �$�$*��.
�r�cCs�d}dD]:}|�|�}|dkr>t�|�}t|�t|�}t|�t|�kr>t|�r/|�||�n|�|�|t|�t|�7}q|jD]}|j	t
jkrQ|t||�7}qB|S)z�
    Attempts to optimise transform specifications on the given node and its children.

    Returns the number of bytes saved after performing these reductions.
    r)r��patternTransformrir))
rarr\r�r�r}r�r�rcrdrre�optimizeTransforms)rr�r��
transformAttrr�r�r�rirrrr��s$


�
�r�cCs^d}t|tjjj�rtt|j�7a|j�	|�|d7}|S|j
dd�D]}|t|�7}q$|S)z@
       Removes comments from the element and its children.
    rrN)r-�xml�dom�minidom�Comment�_num_bytes_saved_in_commentsr}rfr�r�rc�removeComments)rr��
subelementrrrr��s�r�c

Csddl}	|�tdd�}|dkr�t|�dk�rtj�tj�|��d��dd�}|dv�r|�	dd�}t
�d	d
|�}tj
�|�}|jdkr\|jdd�}|ddkrXd
|}nd|}d}|jdkr�|jddkr�|jr�t��}tj�tj�|j��}t�|�zEztj�|�}	|	��}
|	��Wn)ty�}ztd|dt|�d|�dtj�d�d}
WYd}~nd}~wwW|dur�t�|�n|dur�t�|�ww|
dk�r|� |
�}|dk�r|dkr�d}|�!tddd|d|�"��t#d7a#~dSdSdSdSdSdS)Nrrrsr)r)�png�jpg�gif�\�/zfile:/+zfile:///�file)�schemezfile://zfile:zWARNING: Could not open file 'zh' for embedding. The raster image will be kept as a reference but might be invalid. (Exception details: r��stdout�r�r��jpegzdata:image/z;base64,)$�base64r|ryr}�osr;�splitext�basenamer:r�r��subrr\�urlparser��_replace�
infilename�getcwd�abspath�dirname�chdir�request�urlopen�read�close�	Exception�printr<�ensure_value�sysr��	b64encoder��decode�_num_rasters_embedded)
rr�r�rs�ext�
href_fixed�parsed_href�working_dir_old�working_dir_newr��
rasterdatar��
b64eRasterrrr�embedRasters�sp$



������
���


��.rc	Cs"t|�d��}t|�d��}|jr+|jtjkr|jtjks)|jtjkr+|jtjkr+dSt�|�d��}d\}}t	|�dkryz2t
|d�}t
|d�}|dksR|dkrUWdSt
|d�}t
|d	�}||jksk||jkrnWdSWn	tyxYnw|�
dd
|j|jf�|�d�|�d�dS)Nr�r��viewBoxr�r#rrr!r"z	0 0 %s %s)rJrar�rOrr4rAr�rr}rLrMrPr�r�)	�
docElementr��wrI�vbSep�vbWidth�vbHeight�vbX�vbYrrr�properlySizeDoc;
s2��
rcCs�|dus
|jtjkrdS|j|krc|j}|j}|j}|j}d}|dkr.|�||d|�}n|�	|�}|j
}t|j�D]}	|�
|	�}
|�|
j|
j|
j�q;|jD]
}|�|�d��qP|�||�|}|jD]}t|||�qfdS)Nr)rvT)rdrrer�rrxr�r�rQ�
createElementr�r
r�r�r�r"rmrcr*�	cloneNode�replaceChild�remapNamespacePrefix)rg�	oldprefix�	newprefixr�	namespacer��parent�newNoder�r-r�rirrrrd
s,




�rcs>�durt�t�fdd��D��s�Sd��fdd��D��S)Nc3s�|]}|�vVqdSr3r�rorV)rFrrrp�
r�z#make_well_formed.<locals>.<genexpr>r)c3s$�|]
}|�vr�|n|VqdSr3rr)�
quote_dictrrrp�
s�")�XML_ENTS_NO_QUOTESr�rz)rFr r)r rFr�make_well_formed�
s
r"cCs@|�d�}|dks||�d�krd}t}||fSd}t}||fS)Nrrr)r��XML_ENTS_ESCAPE_QUOT�XML_ENTS_ESCAPE_APOS)rM�
quot_count�quote�xml_entrrr�choose_quote_character�
s
�r()
rFr�r�r�r��flowDiv�flowPara�flowSpan�flowTref�flowLine)r`zxml:id�classr�r�r�r�r�r�rrrrrsrtr�r�r�r�rlrmrn�rx�ryrjrkr~r�rjcCstt�Sr3)r}�KNOWN_ATTRSrrrrr��
scCsi|]\}}||�qSrr)rorr"rrrr&�
r'r&cCs|j}t|}||fSr3)r"�KNOWN_ATTRS_ORDER_BY_NAME)r.r"�order_valuerrr�_attribute_sort_key_function�
sr4cs2|��sgS|j�t�fdd�t�j�D�td�S)Nc3r�r3)r�r0�r.rrrp�
r�z0attributes_ordered_for_output.<locals>.<genexpr>)r�)�
hasAttributesr��sortedr
r�r4)rrr5r�attributes_ordered_for_output�
s�r8c	Cs�g}d}d}|jr|jdkrd}n|jdkrd}||j9}d}|�||d|jg�t|�}|D]q}|j}	t|	�\}
}t|	|�}	|jdkrOd	�	t
|	�d	���}	|�d�|j
durb|�|j
d
g�n"|jdur�|jdkrz|j�d�d
krz|�d�n
|jdkr�|�d�|�|jd|
|	|
g�|jdkr�|	dkr�d}q0|	dkr�d}q0|j}|jdkr�|�d�n�|�d�d}
|jD]�}|jtjkr�|s�|jtvr�|�t||d|��q�|�|t|||d|�g�d}
q�|jtjk�r6|j}|�s.|jtv�r*|�dd�}|�dd�}||jk�r|��}n
||jk�r|��}d|v�r)|�dd�}d|v�sn|��}|�t|��q�|jtjk�rG|�d|jdg�q�|jtj k�r^|�|||dd|jdg�q�	q�|
�ro|�|�|�||�|�d |jdg�d�	|�S)!Nr)�tab�	�spacer��
rrjrurvzhttp://www.w3.org/2000/xmlns/�xmlnsr �xmlns:rzxlink:�=�	xml:space�preserveT�defaultFrz/>rrz  z	<![CDATA[z]]>z<!--z-->z</)!�newlines�indent_type�indent_depthr�rwr8rmr(r"rzr7rr�r�rxr�rrcr�rdrre�TEXT_CONTENT_ELEMENTS�serializeXMLrr�r��lstrip�	lastChild�rstripr��CDATA_SECTION_NODE�COMMENT_NODE)rr�rE�preserveWhitespace�outPartsrD�newline�attrsr��	attrValuer&r'�children�	onNewLineri�text_contentrrrrG�
s�










�





�� 

rGc
s:t|�}|jdkr
|j|_t|jd�at|jd�adadadada	da
dadada
dadadadadadatjj�|��t��d��}|r[d�|�}|jrQt|��td�|�tjd�t �|�|j!dur�tt"�j#t$�7att%�j#t$�7ag}�j#j&}t'|j(�D]}|�)|�j*t$vr�|�+|�)|�j,�q�|D]}�j#�-|�td7aq��j#�.d	�d
kr��j#�/d	d
��fdd�}�j#j&}g}g}	t'|j(�D]6}
|�)|
�}|j,}|j*}|dd
�dkr�|d
kr�|	�+|d
d��|�+|�q�||d
d�|�r�|�+|�q�|D]}
�j#�-|
�td7aq�|	D]
}t0�j#|d��q
|j1�r t2��a	|j3�r5�j#�4d��r5�j#�-d�td7at5�j#|�a
|j6�rDt7�j#�at8�|j9�dk�rW	t8�|j9�dk�sMdD]J}�j#�|�D]@}|�:�}|du�r�|j;D] }|j<t=j>t=j?t=j@fv�r�n|j<t=jAk�r�|j*�B��s�n�qpd}|�r�|jC�D|�td7a�qa�qY|jE�r�tF�j#�}tG�|�}tH||�tI��dk�r�	tI��dk�s�tJ��dk�r�	tJ��dk�s�ttK��7a|jL�r�ttM�j#�7a|jN�r�tO�j#�tF�j#�}�j#j;D]
}ttP||�7a�q�ttQ�j#�7a|jL�rtR�j#�dk�r	tR�j#�dk�s�j#�d�D]}tS||��q%�j#�d�D]}tT||��q4�j#�d�D]}|�.d�dk�rU|jC�D|��qCtU||��qC|jV�rittW�|jX|�7adD]%}��|�D]}dD]}|�.|�dk�r�|�/|tY|�.|����qv�qr�qk�j#�.d�}|�r�tZ�[|�}dd�|D�}�j#�/dd�\|��t]�j#�att^�j#|�7at_�j#|�a|j`�rֈj#�d�D]}ta||��q�|jb�r�tc�j#|�td�j#|�d}|jedu�r�d}�jf�r�|d 7}|d!7}nd}�j;D]}|j<t=j>k�r||7}�q||�g�d7}�q|S)"Nr)�prec�flowRootzNSVG input document uses {} flow text elements, which won't render on browsers!zWARNING: {}r�Frr=rcsH��|d�rdS��d�D]}|j��D]}|j�|�r dSqq
dS)N�*FT)�getElementsByTagNameNSr�r�r)r"r�)r�rrr.�r�rr�xmlnsUnused�s��z scourString.<locals>.xmlnsUnusedr%r>r)r@)r�r�r�r�r�Tr<r=r;r~)
r?rEr>r8r9r:r�r�r]r9)r�r�r�r�rlrmrnr/r0rrrrrjrkr^r
cSsg|]}t|��qSrr�)ror�rrrr�r�zscourString.<locals>.<listcomp>r�rEr<z$<?xml version="1.0" encoding="UTF-8"z standalone="yes"z?>
)h�sanitizeOptions�cdigits�digitsr	rr�r��_num_attributes_removedr��_num_comments_removed�_num_style_properties_fixedrr^r�r`�_num_bytes_saved_in_colorsr��_num_bytes_saved_in_ids�_num_bytes_saved_in_lengths�_num_bytes_saved_in_transformsr�r�r��parseStringr}r�r��error_on_flowtextr�r�r�stderrr
�keep_editor_datarr��unwanted_nsr�r�r
r�r�rmr�rwr�rar�r�strip_commentsr��strip_xml_space_attributer,r��
simple_colorsr?r��	keep_defsrbrcrdrrerKrLr�isspacer�r��	strip_idsr�r�r�rfrur��group_collapser,�group_createrSrrYrr�r�r�shorten_idsr��shorten_ids_prefixr�r�rrzr�r4r��
embed_rastersr�enable_viewboxingrrG�strip_xml_prolog�
standalone�toxml)�	in_stringr��cnt_flowText_el�errmsg�xmlnsDeclsToRemover�rr�rZ�redundantPrefixesr-r"r�rr��tagr��
removeElemrir�r��
referencedIdsr<r=r"r
�lengths�
out_string�total_outputrrYr�scourString2s@
�

���



�

�


���


��

����



r�c	Cs�t|�}|�d|�t|d��}|��}Wd�n1swYt||�}tjj�|�	d��}|�
d�}|D]}z|�d�Wq9tyKYq9w|S)Nr��rbzutf-8rWr`)
r[r�openr�r�r�r�r�re�encoder��setIdAttributer)�filenamer��fryr�r��	all_nodesrgrrr�scourXmlFileDs
�

�r�c@seZdZdZdd�ZdS)�HeaderedFormatterzk
       Show application name, version number, and copyright statement
       above usage information.
    cCsdttttj�||�fS)Nz%s %s
%s
%s)�APP�VER�	COPYRIGHT�optparse�IndentedHelpFormatter�format_usage)rY�usagerrrr�fs�zHeaderedFormatter.format_usageN)r=r>r?�__doc__r�rrrrr�`sr�z(%prog [INPUT.SVG [OUTPUT.SVG]] [OPTIONS]z�If the input/output files are not specified, stdin/stdout are used. If the input/output files are specified with a svgz extension, then compressed SVG is assumed.�!)�max_help_position)r��description�	formatter�versionz-p�storer])�actionr"�dest�helpz-qz--quiet�
store_true�quietzsuppress non-error output)r�r�rBr�z-vz	--verbose�verbosez!verbose output (statistics, etc.)z-ir�z	INPUT.SVGz)alternative way to specify input filename)r�r��metavarr�z-o�outfilenamez
OUTPUT.SVGz*alternative way to specify output filename�Optimizationz--set-precisionr$�NUMz4set number of significant digits (default: %default))r�r"r�rBr�r�z--set-c-precisionr\r zXset number of significant digits for control points (default: same as '--set-precision')z--disable-simplify-colors�store_falserlTz&won't convert colors to #RRGGBB formatz--disable-style-to-xmlr�z(won't convert styles into XML attributesz--disable-group-collapsingrpzwon't collapse <g> elementsz--create-groupsrqzBcreate <g> elements for runs of elements with identical attributesz--keep-editor-datarhzTwon't remove Inkscape, Sodipodi, Adobe Illustrator or Sketch elements and attributesz--keep-unreferenced-defsrmzEwon't remove elements within the defs container that are unreferencedz--renderer-workaroundr�zDwork around various renderer bugs (currently only librsvg) (default)z--no-renderer-workaroundzAdo not work around various renderer bugs (currently only librsvg)zSVG documentz--strip-xml-prologrvz&won't output the XML prolog (<?xml ?>)z--remove-titlesrzremove <title> elementsz--remove-descriptionsrzremove <desc> elementsz--remove-metadatarzNremove <metadata> elements (which may contain license/author information etc.)z--remove-descriptive-elementsrz.remove <title>, <desc> and <metadata> elementsz--enable-comment-strippingrjzremove all comments (<!-- -->)z--disable-embed-rastersrtz*won't embed rasters as base64-encoded dataz--enable-viewboxingruzJchanges document width/height to 100%/100% and creates viewbox coordinateszOutput formattingz--indent�stringrDr;�TYPEz?indentation of the output: none, space, tab (default: %default)z	--nindentrEzIdepth of the indentation, i.e. number of spaces/tabs: (default: %default)z--no-line-breaksrCzkdo not create line breaks in output(also disables indentation; might be overridden by xml:space="preserve")z--strip-xml-spacerkzBstrip the xml:space="preserve" attribute from the root SVG elementz
ID attributesz--enable-id-strippingrozremove all unreferenced IDsz
--shorten-idsrrz7shorten all IDs to the least number of letters possiblez--shorten-ids-prefixrsr)�PREFIXz"add custom prefix to shortened IDsz--protect-ids-noninkscaper�z(don't remove IDs not ending with a digitz--protect-ids-listr��LISTz3don't remove IDs given in this comma-separated list)r�r"r�r�r�z--protect-ids-prefixr�z/don't remove IDs starting with the given prefixzSVG compatibility checksz--error-on-flowtextrfzVexit with error if the input SVG uses non-standard flowing text (only warn by default)cCs�t�|�\}}|r(|js|�d�|_|js|r|�d�|_|s(|r(t�d|�|jdkr2t�d�|j|jkrBd|_tdt	j
d�|jdvrLt�d	�|jdkrVt�d
�|jrg|jrg|j|jkrgt�d�|S)Nrz0Additional arguments not handled: %r, see --helprzCNumber of significant digits has to be larger than zero, see --helpr z�WARNING: The value for '--set-c-precision' should be lower than the value for '--set-precision'. Number of significant digits for control points reset to default value, see --helpr�)r9r;r�z&Invalid value for --indent, see --helpz<Value for --nindent should be positive (or zero), see --helpz-Input filename is the same as output filename)
�_options_parser�
parse_argsr�r�r��errorr]r\r�rrgrDrE)r��ignore_additional_argsr��rargsrrrr��s,


�




r�cCst�Sr3)r[rrrr�generateDefaultOptionssr�cs0t�fdd�t��D��}t��}|�|�|S)Nc3s(�|]}|�d�s|t�|�fVqdS)�__N)r��getattr)ror�r�rrrps�&z"sanitizeOptions.<locals>.<genexpr>)�dict�dirr��get_default_values�_update_careful)r��optionsDict�sanitizedOptionsrr�rr[s
r[cCs6tj�|�d��dvrddl}|�||�St||�S)Nr)z.svgzz.gzr)r�r;r�r:�gzip�GzipFiler�)r�rr�rrr�maybe_gziped_files
r�cCs�|jr
t|jd�}nztjj}Wntytj}Ynwtj��r't�d�|j	r4t|j	d�}||gSztj
j}WntyFtj
}Ynwtj|_
||gS)Nr�zBNo input file specified, see --help for detailed usage information�wb)r�r�r�stdin�bufferr��isattyr�r�r�r�rg)r��infile�outfilerrr�getInOut#s&
�


�
�r�cCs�dtt�tjdtt�tjdtt�tjdtt�tjdtt�tjdtt�tjdtt	�tjdtt
�tjd	tt�tjd
tt�tjdtt
�tjdtt�tjd
tt�tjdtt�S)Nz  Number of elements removed: z   Number of attributes removed: z&  Number of unreferenced IDs removed: z  Number of comments removed: z$  Number of style properties fixed: z$  Number of raster images embedded: z+  Number of path segments reduced/removed: z*  Number of points removed from polygons: z&  Number of bytes saved in path data: z#  Number of bytes saved in colors: z%  Number of bytes saved in comments: z   Number of bytes saved in IDs: z$  Number of bytes saved in lengths: z,  Number of bytes saved in transformations: )r<r�r��linesepr^r�r_r`rr^r�r`rar�rbrcrdrrrr�	getReportAs�������������������������	�	�	�
�
�
�������
�
��r�cCst|�}t��}|��}t||��d�}|�|�|tjus.ttjd�r*|tjj	us.|�
�|tjusCttjd�r?|tjj	usC|�
�t��}tt
||d��}t|�}t|�}	|	|d}
|js�td�|j||	||
�|�dtj�d�|jr�tt�|�dtj�d�dSdSdS)NzUTF-8r�g@�@r_zCScour processed file "{}" in {} ms: {}/{} bytes new/orig -> {:.1f}%r�r�)r[�timer�r�r��writerr��hasattrr�r�r�rNrFr}r�r�r�r"rr�r�)r��input�outputrryr�rW�duration�oldsize�newsize�sizediffrrrrTs8
""���cCs"t�}t|�\}}t|||�dSr3)r�r�r)r�r�r�rrr�runysr��__main__)NN)F)FF)rF)NF)rn)��
__future__rrrr�r�r�r�rr��xml.dom.minidomr��xml.domrr�collectionsrr�decimalr	r
rrro�	six.movesr
r�scour.svg_regexr�scour.svg_transformr�scour.yocto_cssrrrr�r�r�r!r5r$r#r�r�ryrir�r7r3rrrQrSrTrX�objectrrJrfr�r�r{r�r�r�r�r�r�r�r�r�r�rr
rrr,rSrYrfrur}r�r�r�r�r�r�r�r�r�r�r}�_fields�__new__�__defaults__r@r4�default_attributesr1r�r2�default_attributer�r�rr+r/r�r4r9r8r>r?rr�r�r�r�r�r_r�r�r�r�r�r�r�r�r�rrrr"r(rFr7r1�	enumerater2r4r8rGr�r�r�r��OptionParserr��
add_optionrN�
SUPPRESS_HELP�OptionGroup�_option_group_optimization�add_option_group�_option_group_document�_option_group_formatting�_option_group_ids�_option_group_compatibilityr�r�r[r�r�r�rr�r=rrrr�<module>sJ/
��
L��������	�
���
������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�1�2�3�4�5�6�7�8�9�:�;�<�=�>�?�@�A�B�C�D�E�F�G�H�I�J�K�L�M�N�O�P�Q�R�S�T�U�V�W�X�Y�Z�[�\�]�^�_�`�a�b�c�d�e�f�g�h�i�j�k�l�m�n�o�p�q�r�s�t�u�v�w�x�y�z�{�|�}�~������������������	��
�
��������	�
���
������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�2�3�4�5�6
�<>,
>&R F
%SH7)D/8
2<�������	�
�����
����� �!�"�#�$�%�(�)�*�+�,�-�0�1�2�3�6�7
��9�:
��<�=
��?�@
��D�E�F�G�H
��K
��M
��O�P
��R�S
��U�V
��X�^�_�`�a�b�c�d�e�f�g�h�i�j�k�l�m�n�o�p�q�r�s�t�u�v�w�x�y�z�{�|�}�~����
�04t<
4	5.#N)%

	�
��
�e
�	��������������
��������
����
������
�
	%
�

Youez - 2016 - github.com/yon3zu
LinuXploit