ok

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/svgwrite/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/svgwrite/__pycache__/utils.cpython-37.pyc

B

s�]Q�@sdZddlmZddlZddlZddlZejddkZddlm	Z	er\ddl
mZeZ
eZn(ddlZe�de�ddlmZdd	�Z
d
d�ZddlmZd/dd�Zdd�Zd0dd�Zdd�Zdd�Zdd�Zd1dd�ZGdd�de�Zd2d d!�Zd"d#d$d%d&d'd(�Z d)d*�Z!d+d,�Z"d-d.�Z#dS)3z�

.. autofunction:: rgb

.. autofunction:: iterflatlist

.. autofunction:: strlist

.. autofunction:: get_unit

.. autofunction:: split_coordinate

.. autofunction:: split_angle

.. autofunction:: rect_top_left_corner

.. autofunction:: pretty_xml

�)�unicode_literalsN�)�partial)�urlopenz1Python 2 support will be dropped with version 1.4cCst|t�rt|dd�St|�S)N�utf8)�encoding)�
isinstance�strZunicode)�value�r�	/utils.py�
to_unicode+sr
cCs
t|t�S)N)r�
basestring)r
rrr�	is_string0sr)�pattern�RGBcCsldd�}|��dkr:dt|�d@t|�d@t|�d@fS|dkr\d||�||�||�fStd|��d	S)
aM
    Convert **r**, **g**, **b** values to a `string`.

    :param r: red part
    :param g: green part
    :param b: blue part
    :param string mode: ``'RGB | %'``

    :rtype: string

    ========= =============================================================
    mode      Description
    ========= =============================================================
    ``'RGB'`` returns a rgb-string format: ``'rgb(r, g, b)'``
    ``'%'``   returns percent-values as rgb-string format: ``'rgb(r%, g%, b%)'``
    ========= =============================================================

    cSs$t|�}|dkrd}|dkr d}|S)Nr�d)�float)r
rrr�percentIszrgb.<locals>.percentrz
rgb(%d,%d,%d)��%zrgb(%d%%,%d%%,%d%%)zInvalid mode '%s'N)�upper�int�
ValueError)�r�g�b�moderrrr�rgb6s&rccsDx>|D]6}t|d�r6t|�s6xt|�D]
}|Vq&Wq|VqWdS)z:
    Flatten nested *values*, returns an `iterator`.

    �__iter__N)�hasattrr�iterflatlist)�valuesZelement�itemrrrr![s

r!�,cCs(t|�r|S|�dd�t|�D��SdS)z�
    Concatenate **values** with **sepertator**, `None` values will be excluded.

    :param values: `iterable` object
    :returns: `string`

    cSsg|]}|dk	rt|��qS)N)r	)�.0r
rrr�
<listcomp>sszstrlist.<locals>.<listcomp>N)r�joinr!)r"Z	seperatorrrr�strlisthsr(cCs<t|ttf�rdStj�|�}|r,|�d�Std|��dS)z�
    Get the `unit` identifier of **coordinate**, if **coordinate** has a valid
    `unit` identifier appended, else returns `None`.

    N�zInvalid format: '%s')rrrr�
coordinate�match�groupr)r*�resultrrr�get_unitvs
r.cCsRt|ttf�rt|�dfStj�|�}|rBt|�d��|�d�fStd|��dS)z�
    Split coordinate into `<number>` and 'unit` identifier.

    :returns: <2-tuple> (number, unit-identifier) or (number, None) if no unit-identifier
      is present or coordinate is an int or float.

    N�r)zInvalid format: '%s')rrrrr*r+r,r)r*r-rrr�split_coordinate�sr0cCsRt|ttf�rt|�dfStj�|�}|rBt|�d��|�d�fStd|��dS)z�
    Split angle into `<number>` and `<angle>` identifier.

    :returns: <2-tuple> (number, angle-identifier) or (number, None) if no angle-identifier
      is present or angle is an int or float.

    Nr/r)zInvalid format: '%s')rrrr�angler+r,r)r1r-rrr�split_angle�s	r2�top-leftc
Cs|���d�\}}t|d�\}}t|d�\}}t|d�\}	}
t|d�\}}||
krbtd��||krrtd��|dkr�||	d}n&|dkr�||	}n|d	kr�td
|��|dkr�||d}n&|dkr�||}n|d
kr�td|��|r�d||f}|�rd||f}||fS)a4
    Calculate top-left corner of a rectangle.

    **insert** and **size** must have the same units.

    :param 2-tuple insert: insert point
    :param 2-tuple size: (width, height)
    :param string pos: insert position ``'vert-horiz'``
    :return: ``'top-left'`` corner of the rect
    :rtype: 2-tuple

    ========== ==============================
    pos        valid values
    ========== ==============================
    **vert**   ``'top | middle | bottom'``
    **horiz**  ``'left'|'center'|'right'``
    ========== ==============================
    �-rr/z0x-coordinate and width has to have the same unitz1y-coordinate and height has to have the same unit�centerg@�right�leftz!Invalid horizontal position: '%s'ZmiddleZbottom�topzInvalid vertical position: '%s'z%s%s)�lower�splitr0r)
�insert�size�posZvertZhoriz�xZxunit�yZyunit�widthZwunitZheightZhunitrrr�rect_top_left_corner�s4

rAc@s6eZdZdZd	dd�Zed
dd��Zeddd��ZdS)�AutoIDr/NcCs|�|�dS)N)�
_set_value)�selfr
rrr�__init__�szAutoID.__init__cCs|dk	r||_dS)N)�_nextid)�clsr
rrrrC�szAutoID._set_valuecCs&|�|�d|j}|jd7_|S)Nzid%dr/)rCrF)rGr
Zretvalrrr�next_id�s

zAutoID.next_id)N)N)N)�__name__�
__module__�__qualname__rFrE�classmethodrCrHrrrrrB�s
rBcCsvddlmm}t|�dkr.|��dkr.dStr>|�|�}n|�|�d��}|jd|d��	d�}d�
|d	d��S)
z�
    Create human readable XML string.

    :param xml_string: input xml string without line breaks and indentation
    :indent int: how much to indent, by default 2 spaces
    :return: xml_string with linebreaks and indentation

    rN��zutf-8� )�indent�
r/)Zxml.dom.minidomZdom�minidom�len�strip�PYTHON3ZparseString�encodeZtoprettyxmlr:r')Z
xml_stringrPrRZxml_tree�linesrrr�
pretty_xml�s	rXzapplication/x-font-ttfzapplication/x-font-opentypezapplication/font-woffzapplication/font-woff2zapplication/vnd.ms-fontobjectzapplication/font-sfnt)ZttfZotfZwoffZwoff2ZeotZsfntcCs$tj�|���\}}t|dd�S)Nr/)�os�path�splitextr9�FONT_MIMETYPES)�name�_Zextrrr�
font_mimetypesr_cCst�|���}dj||d�S)Nz+data:{mimetype};charset=utf-8;base64,{data})�mimetype�data)�base64Z	b64encode�decode�format)rar`rrr�base64_datasrecCs(ddl}|�d|�}|r |dSdSdS)Nrzurl\((.*?)\))�re�findall)�textrfr-rrr�find_first_urls
ri)rrrr)r$)r3)r)$�__doc__Z
__future__r�sysrYrb�version_inforU�	functoolsrZurllib.requestrr	r
r�warnings�warn�DeprecationWarningZurllibrZ
svgwrite.datarrr!r(r.r0r2rA�objectrBrXr\r_rerirrrr�<module>sD
%

3


Zerion Mini Shell 1.0