
     h!                         d Z ddlmZ ddlZddlmZ ddlmZ  G d de      Z	 G d d	e      Z
 G d
 de
      Z G d de
      Zy)z7
The **BaseElement** is the root for all SVG elements.
    )etreeN)	Parameter)AutoIDc                       e Zd ZdZdZd Zd Zd Zed        Z	ed        Z
ed        Zej                  d	        Zed
        Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zy)BaseElementz
    The **BaseElement** is the root for all SVG elements. The SVG attributes
    are stored in **attribs**, and the SVG subelements are stored in
    **elements**.

    baseElementc                 `   |j                  dd      }||j                  | _        nt               | _        |j                  dd      }||| j                  _        |j                  dd      }||| j                  _        t               | _        | j                  |       t               | _	        y)a  
        :param extra: extra SVG attributes (keyword arguments)

          * add trailing '_' to reserved keywords: ``'class_'``, ``'from_'``
          * replace inner '-' by '_': ``'stroke_width'``


        SVG attribute names will be checked, if **debug** is `True`.

        workaround for removed **attribs** parameter in Version 0.2.2::

            # replace
            element = BaseElement(attribs=adict)

            #by
            element = BaseElement()
            element.update(adict)

        factoryNdebugprofile)
pop
_parameterr   r   r   dictattribsupdatelistelements)selfextrar
   r   r   s        i/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/svgwrite/base.py__init__zBaseElement.__init__   s    * ))It,%00DO (kDO 		'4($)DOO! ))It,&-DOO#vE    c                     |j                         D ]8  \  }}|j                  d      j                  dd      }| j                  ||       : y)z Update SVG Attributes from `dict` attribs.

        Rules for keys:

        1. trailing '_' will be removed (``'class_'`` -> ``'class'``)
        2. inner '_' will be replaced by '-' (``'stroke_width'`` -> ``'stroke-width'``)

        _-N)itemsrstripreplace__setitem__)r   r   keyvalues       r   r   zBaseElement.updateH   sI     "--/ 	)JC **S/))#s3CS%(		)r   c                    t        j                   |       }t        j                   | j                        |_        t        j                   | j                        |_        d|j                  v r|j                         |d<   |S )Nid)copyr   r   next_id)r   newobjs     r   r$   zBaseElement.copyW   sX    44<<0))DMM26>>!!>>+F4Lr   c                 .    | j                   j                  S N)r   r   r   s    r   r   zBaseElement.debug_   s    $$$r   c                 .    | j                   j                  S r(   )r   r   r)   s    r   r   zBaseElement.profilec   s    &&&r   c                 .    | j                   j                  S r(   r   	validatorr)   s    r   r-   zBaseElement.validatorg   s    (((r   c                 &    || j                   _        y r(   r,   r   r!   s     r   r-   zBaseElement.validatork   s    $)!r   c                 6    | j                   j                         S r(   )r   get_versionr)   s    r   versionzBaseElement.versiono   s    **,,r   c                     || _         y r(   )r   )r   	parameters     r   set_parameterzBaseElement.set_parameters   s	    #r   Nc                 ,    t        j                  |      S r(   )r   r%   r/   s     r   r%   zBaseElement.next_idv   s    ~~e$$r   c                 v    d| j                   vr| j                         | j                   d<   | j                   d   S )z Get the object `id` string, if the object does not have an `id`,
        a new `id` will be created.

        :returns: `string`
        r#   )r   r%   r)   s    r   get_idzBaseElement.get_idy   s3     t||#!%DLL||D!!r   c                 (    d| j                         z  S )zn
        Get the `IRI` reference string of the object. (i.e., ``'#id'``).

        :returns: `string`
        z#%s)r8   r)   s    r   get_irizBaseElement.get_iri   s     t{{}$$r   c                 (    d| j                         z  S )zv
        Get the `FuncIRI` reference string of the object. (i.e. ``'url(#id)'``).

        :returns: `string`
        zurl(%s))r:   r)   s    r   get_funcirizBaseElement.get_funciri   s     4<<>))r   c                      | j                   |   S )zz Get SVG attribute by `key`.

        :param string key: SVG attribute name
        :return: SVG attribute value

        )r   )r   r    s     r   __getitem__zBaseElement.__getitem__   s     ||C  r   c                     | j                   r'| j                  j                  | j                  ||       || j                  |<   y)z Set SVG attribute by `key` to `value`.

        :param string key: SVG attribute name
        :param object value: SVG attribute value

        N)r   r-   check_svg_attribute_valueelementnamer   )r   r    r!   s      r   r   zBaseElement.__setitem__   s5     ::NN44T5E5EsER!Sr   c                     | j                   r0| j                  j                  | j                  |j                         | j                  j                  |       |S )z Add an SVG element as subelement.

        :param element: append this SVG element
        :returns: the added element

        )r   r-   check_valid_childrenrA   r   append)r   elements     r   addzBaseElement.add   sB     ::NN//0@0@'BUBUVW%r   c                 r    | j                         }t        j                  |d      }|j                  d      S )z Get the XML representation as unicode `string`.

        :return: unicode XML string of this object and all its subelements

        zutf-8)encoding)get_xmlr   tostringdecode)r   xmlxml_utf8_strs      r   rJ   zBaseElement.tostring   s0     lln~~cG<""7++r   c                 "    | j                         S )z Show SVG in IPython, Jupyter Notebook, and Jupyter Lab

        :return: unicode XML string of this object and all its subelements

        )rJ   r)   s    r   
_repr_svg_zBaseElement._repr_svg_   s     }}r   c                    t        j                  | j                        }| j                  r0| j                  j                  | j                  | j                         t        | j                  j                               D ].  \  }}|	| j                  |      }|s|j                  ||       0 | j                  D ]!  }|j                  |j                                # |S )z Get the XML representation as `ElementTree` object.

        :return: XML `ElementTree` of this object and all its subelements

        )r   ElementrA   r   r-   check_all_svg_attribute_valuesr   sortedr   value_to_stringsetr   rD   rI   )r   rL   	attributer!   rE   s        r   rI   zBaseElement.get_xml   s     mmD,,-::NN99$:J:JDLLY &t||'9'9'; < 	.Iu ,,U3GGIu-	. }} 	*GJJw()	*
r   c                     t        |t        t        f      rS| j                  r| j                  j                  |d       t        |t              r| j                  dk(  rt        |d      }t        |      S )z
        Converts *value* into a <string> includes a value check, depending
        on :attr:`self.debug` and :attr:`self.profile`.

        numbertiny   )	
isinstanceintfloatr   r-   check_svg_typer   roundstrr/   s     r   rT   zBaseElement.value_to_string   sW     ec5\*zz--eX>%'DLLF,BeQ5zr   c                     |%| j                   j                  dt        |             |&| j                   j                  dt        |             yy)zK Insert a **title** and/or a **desc** element as first subelement.
        Nr   )r   insertDescTitle)r   titledescs      r   set_desczBaseElement.set_desc   sE     MM  DJ/MM  E%L1 r   c                 (   t        |      }t        | j                        dk(  r| j                  j                  |       yd}| j                  |   j                  dv rU|dz  }|t        | j                        k(  r| j                  j                  |       y| j                  |   j                  dv rU| j                  |   j                  dk(  r)| j                  |   j
                  j                  |       y| j                  j                  ||       y)N
        :param xmldata: an xml.etree.ElementTree - Element() object.
        r   )re   rf      Nmetadata)Metadatalenr   rD   rA   rL   rb   )r   xmldatark   poss       r   set_metadatazBaseElement.set_metadata   s     G$t}}"MM  *C--$004EEq#dmm,,MM((2	 --$004EE
 }}S!--;c"&&--g6$$S(3r   r(   )NN)__name__
__module____qualname____doc__rA   r   r   r$   propertyr   r   r-   setterr2   r5   r%   r8   r:   r<   r>   r   rF   rJ   rO   rI   rT   rg   rp    r   r   r   r      s      K)V) % % ' ' ) ) * * - -$%"%*!"
	,(24r   r   c                       e Zd ZdZd Zd Zy)rd   re   c                     t        j                  | j                        | _        t	        |      | j                  _        y r(   )r   rQ   rA   rL   r`   text)r   rz   s     r   r   zTitle.__init__	  s'    ==!1!12D	r   c                     | j                   S r(   )rL   r)   s    r   rI   zTitle.get_xml  s    xxr   N)rq   rr   rs   rA   r   rI   rw   r   r   rd   rd     s    K"r   rd   c                       e Zd ZdZy)rc   rf   N)rq   rr   rs   rA   rw   r   r   rc   rc     s    Kr   rc   c                       e Zd ZdZd Zy)rl   rk   c                 n    t        j                  d      | _        | j                  j                  |       y)ri   rk   N)r   rQ   rL   rD   )r   rn   s     r   r   zMetadata.__init__  s$     ==, r   N)rq   rr   rs   rA   r   rw   r   r   rl   rl     s    K!r   rl   )rt   svgwrite.etreer   r$   svgwrite.paramsr   svgwrite.utilsr   objectr   rd   rc   rl   rw   r   r   <module>r      sK    !  % !o4& o4dF 5 !u !r   