• File: utils.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/svgwrite/__pycache__/utils.cpython-37.pyc
  • Date Modified: 11/23/2019 5:57 PM
  • File size: 7.6 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

s]Q@sdZddlmZddlZddlZddlZejddkZddlm	Z	er\ddl
mZeZ
eZn(ddlZededdlmZdd	Z
d
dZddlmZd/ddZddZd0ddZddZddZddZd1ddZGdddeZd2d 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|trt|ddSt|S)Nutf8)encoding)
isinstancestrZunicode)valuer	/utils.py
to_unicode+sr
cCs
t|tS)N)r
basestring)r
rrr	is_string0sr)patternRGBcCsldd}|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)Nrd)float)r
rrrpercentIszrgb.<locals>.percentrz
rgb(%d,%d,%d)%zrgb(%d%%,%d%%,%d%%)zInvalid mode '%s'N)upperint
ValueError)rgbmoderrrrrgb6s&rccsDx>|D]6}t|dr6t|s6xt|D]
}|Vq&Wq|VqWdS)z:
    Flatten nested *values*, returns an `iterator`.

    __iter__N)hasattrriterflatlist)valuesZelementitemrrrr![s

r!,cCs(t|r|S|ddt|DSdS)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)rjoinr!)r"Z	seperatorrrrstrlisthsr(cCs<t|ttfrdStj|}|r,|dStd|dS)z
    Get the `unit` identifier of **coordinate**, if **coordinate** has a valid
    `unit` identifier appended, else returns `None`.

    NzInvalid format: '%s')rrrr
coordinatematchgroupr)r*resultrrrget_unitvs
r.cCsRt|ttfrt|dfStj|}|rBt|d|dfStd|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.

    Nr)zInvalid format: '%s')rrrrr*r+r,r)r*r-rrrsplit_coordinatesr0cCsRt|ttfrt|dfStj|}|rBt|d|dfStd|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')rrrrangler+r,r)r1r-rrrsplit_angles	r2top-leftc
Cs|d\}}t|d\}}t|d\}}t|d\}	}
t|d\}}||
krbtd||krrtd|dkr||	d}n&|dkr||	}n|d	krtd
||dkr||d}n&|dkr||}n|d
krtd||rd||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 unitcenterg@rightleftz!Invalid horizontal position: '%s'ZmiddleZbottomtopzInvalid vertical position: '%s'z%s%s)lowersplitr0r)
insertsizeposZvertZhorizxZxunityZyunitwidthZwunitZheightZhunitrrrrect_top_left_corners4

rAc@s6eZdZdZd	ddZed
ddZedddZdS)AutoIDr/NcCs||dS)N)
_set_value)selfr
rrr__init__szAutoID.__init__cCs|dk	r||_dS)N)_nextid)clsr
rrrrCszAutoID._set_valuecCs&||d|j}|jd7_|S)Nzid%dr/)rCrF)rGr
Zretvalrrrnext_ids

zAutoID.next_id)N)N)N)__name__
__module____qualname__rFrEclassmethodrCrHrrrrrBs
rBcCsvddlmm}t|dkr.|dkr.dStr>||}n||d}|jd|d	d}d
|d	dS)
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

    rNzutf-8 )indent
r/)Zxml.dom.minidomZdomminidomlenstripPYTHON3ZparseStringencodeZtoprettyxmlr:r')Z
xml_stringrPrRZxml_treelinesrrr
pretty_xmls	rXzapplication/x-font-ttfzapplication/x-font-opentypezapplication/font-woffzapplication/font-woff2zapplication/vnd.ms-fontobjectzapplication/font-sfnt)ZttfZotfZwoffZwoff2ZeotZsfntcCs$tj|\}}t|ddS)Nr/)ospathsplitextr9FONT_MIMETYPES)name_Zextrrr
font_mimetypesr_cCst|}dj||dS)Nz+data:{mimetype};charset=utf-8;base64,{data})mimetypedata)base64Z	b64encodedecodeformat)rar`rrrbase64_datasrecCs(ddl}|d|}|r |dSdSdS)Nrzurl\((.*?)\))refindall)textrfr-rrrfind_first_urls
ri)rrrr)r$)r3)r)$__doc__Z
__future__rsysrYrbversion_inforU	functoolsrZurllib.requestrr	r
rwarningswarnDeprecationWarningZurllibrZ
svgwrite.datarrr!r(r.r0r2rAobjectrBrXr\r_rerirrrr<module>sD
%

3