bgdZddlZddlmZddlmZdZddZdZdd Z d Z d Z d Z d dZ GddeZd!dZdddddddZdZdZdZdS)"z .. autofunction:: rgb .. autofunction:: iterflatlist .. autofunction:: strlist .. autofunction:: get_unit .. autofunction:: split_coordinate .. autofunction:: split_angle .. autofunction:: rect_top_left_corner .. autofunction:: pretty_xml N)Path)patternc,t|tSN) isinstancestrvalues _/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/svgwrite/utils.py is_stringr s eS ! !!RGBcd}|dkr8dt|dzt|dzt|dzfzS|dkr#d||||||fzStd|z)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%)'`` ========= ============================================================= cDt|}|dkrd}|dkrd}|S)Nrd)floatr s r percentzrgb..percent8s.e  199E 3;;E r rz rgb(%d,%d,%d)%zrgb(%d%%,%d%%,%d%%)zInvalid mode '%s')upperint ValueError)rgbmoders r rgbr$s( zz||u#a&&3,A c!ffsl!KKK % GGAJJ 'KKK,t3444r c#K|D]<}t|dr&t|st|D]}|V8|V=dS)z: Flatten nested *values*, returns an `iterator`. __iter__N)hasattrr iterflatlist)valueselementitems r r!r!Jsv  7J ' '  '0B0B $W--    MMMM r ,c|t|r|S|dt|DS)z Concatenate **values** with **sepertator**, `None` values will be excluded. :param values: `iterable` object :returns: `string` c0g|]}|t|Sr)r).0r s r zstrlist..bs#aaaeuO`s5zzO`O`O`r )r joinr!)r" seperators r strlistr,WsCc ~~aa|F7K7Kaaabbbr ct|ttfrdStj|}|r|dStd|z)z Get the `unit` identifier of **coordinate**, if **coordinate** has a valid `unit` identifier appended, else returns `None`. NInvalid format: '%s'rrrr coordinatematchgrouprr1results r get_unitr6esa *sEl++t   % %j 1 1F >||A/*<===r c0t|ttfrt|dfStj|}|r7t|d|dfStd|z)z Split coordinate into `` 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.r/r0r4s r split_coordinater9ts*sEl++)j!!4((   % %j 1 1F >fll1oo&& Q88/*<===r c0t|ttfrt|dfStj|}|r7t|d|dfStd|z)z Split angle into `` and `` identifier. :returns: <2-tuple> (number, angle-identifier) or (number, None) if no angle-identifier is present or angle is an int or float. Nr8r.r/)rrrrangler2r3r)r;r5s r split_angler<s%#u&&$e d## ]  ' 'F 9fll1oo&& Q88/%7888r top-leftc^|d\}}t|d\}}t|d\}}t|d\} } t|d\} } || krtd|| krtd|dkr || dz z }n$|dkr|| z }n|d krtd |z|d kr || dz z }n$|d kr|| z }n|d krtd|z|r||}|r||}||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'`` ========== ============================== -rr8z0x-coordinate and width has to have the same unitz1y-coordinate and height has to have the same unitcenterg@rightleftz!Invalid horizontal position: '%s'middlebottomtopzInvalid vertical position: '%s')lowersplitr9r) insertsizeposverthorizxxunityyunitwidthwunitheighthunits r rect_top_left_cornerrUsv&))++##C((KD%q **HAuq **HAu#DG,,LE5$T!W--MFE ~~KLLL ~~LMMM   N '   I &rsc& !!!!!!"""#5#5#5#5L    c c c c > > >>>>"999$0000fV&    * $ ( # % * # 999^^^ r