
    Kwg                         d Z dZddlmZmZ ddlmZ ddlmZ  G d d      Z	 G d d	      Z
 G d
 de      Zd ZddZd Zd ZddZy)z3.3.0a  Framework for objects whose assignments are checked. Used by graphics.

We developed reportlab/graphics prior to Python 2 and metaclasses. For the
graphics, we wanted to be able to declare the attributes of a class, check
them on assignment, and convert from string arguments.  Examples of
attrmap-based objects can be found in reportlab/graphics/shapes.  It lets
us defined structures like the one below, which are seen more modern form in
Django models and other frameworks.

We'll probably replace this one day soon, hopefully with no impact on client
code.

class Rect(SolidShape):
    """Rectangle, possibly with rounded corners."""

    _attrMap = AttrMap(BASE=SolidShape,
        x = AttrMapValue(isNumber),
        y = AttrMapValue(isNumber),
        width = AttrMapValue(isNumber),
        height = AttrMapValue(isNumber),
        rx = AttrMapValue(isNumber),
        ry = AttrMapValue(isNumber),
        )


    )
isAnythingDerivedValue)isSeq)	rl_configc                       e Zd ZdZd Zd Zy)CallableValuez(a class to allow callable initial valuesc                 .    || _         || _        || _        y Nfuncargskw)selfr   r   r   s       L/var/www/horilla/myenv/lib/python3.12/site-packages/reportlab/lib/attrmap.py__init__zCallableValue.__init__%   s    		    c                 N     | j                   | j                  i | j                  S r
   r   )r   s    r   __call__zCallableValue.__call__+   s     tyy$)).dgg..r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   #   s    2/r   r   c                   $    e Zd ZdZddZd Zd Zy)AttrMapValuez,Simple multi-value holder for attribute mapsNc                     |xs t         | _        || _        || _        || _        |j                         D ]  \  }}t        | ||        y r
   )r   validatedesc_initial_advancedUsageitemssetattr)r   r   r   initialadvancedUsager   kvs           r   r   zAttrMapValue.__init__0   sI     .J	+88: 	CAaD1	r   c                     |dk(  r6t        | j                  t              r| j                         S | j                  S |dk(  ryt        |      )Nr#   hiddenr   )
isinstancer   r   AttributeError)r   names     r   __getattr__zAttrMapValue.__getattr__8   sA    ?$--6t}}8N== 8^T""r   c                     ddj                  | j                  j                         D cg c]  }d|z  	 c}      z  S c c}w )NzAttrMapValue(%s)z, z%s=%r)join__dict__r!   )r   is     r   __repr__zAttrMapValue.__repr__A   s5    !DIIDMMDWDWDY.Zqw{.Z$[[[.Zs   >
)NNNr   )r   r   r   r   r   r,   r1   r   r   r   r   r   .   s    6#\r   r   c                   (    e Zd Zdg fdZd Zg fdZy)AttrMapNc                 D   i }|rdt        |t              r|}nQt        |      s|f}|D ]>  }t        |d|       }|| ur|s|j	                  |       )t        dt        |      z         t        j                  | |       | j                  |       | j	                  |       y )N_attrMapzBASE=%s has wrong kind of value)
r)   r3   r   getattrupdate
ValueErrorasciidictr   remove)r   BASEUNWANTEDr   dataBams          r   r   zAttrMap.__init__E   s    $w'T{D7D WA :d3B~t{{2()JUSTX)UVVW 	d4 HBr   c                 8    |D ]  }	 | |=  y # t         $ r Y w xY wr
   )KeyError)r   unwantedr%   s      r   r;   zAttrMap.removeW   s1     	AG	  s   	c                 B    t        | |      }|j                  |       |S )N)r<   r=   )r3   r7   )r   r=   r   cs       r   clonezAttrMap.clone^   s    x0	r   )r   r   r   r   r;   rF   r   r   r   r3   r3   D   s     $  r   r3   c                    t         j                  rh| j                  }|rZ|d   dk7  rRt        |t              rnA	 ||   j
                  } ||      s(t        d|d|d| j                  j                        	 t        | j                  |d      }t        |t              r	 |j                  | |       y|dk(  r6| j                  j                          | j                  j                  |       y|| j                  |<   y# t        $ r& t        d|d| j                  j                        w xY w# t        $ r Y yw xY w)	z validate setattr(obj,name,value)r   _zIllegal assignment of 'z' to 'z' in class zIllegal attribute 'Nr/   )r   shapeCheckingr5   r)   r   r   r*   	__class__r   rB   r6   property__set__r/   clearr7   )objr+   valuemapr   props         r   validateSetattrrR   c   s2   ll47S= %.p"4y11H#E?,afhlnqn{n{  oE  oE  .F  G  G + 3==d+D$x 	LLU# 
z	E""T   p(QUWZWdWdWmWm)noop  		s   ?C? !D1 ?/D.1	D=<D=c                     | j                   }t        | j                  dd      }|r||u r|j                         |fS |dfS ||u r|j                         | _         yy)zclone obj._attrMap if requiredr5   N)r5   r6   rJ   rF   )rN   retAoAs       r   _privateAttrMaprW      sY    A	z$	/B
7779b= d7N7779CL r   c                 |    |j                  d      }t        |      dk(  ry|dd D ]  }t        | |      }  | |d   fS )zPLocate the object src.P for P a string, return parent and name of attribute
    .r   )NN)splitlenr6   )srcPps      r   _findObjectAndAttrr`      sM     	
A
1v{1R 	"A#q/C	"AbEzr   c           
          t        | d      sW| j                  }dd l}|j                  |j                  |f|j
                  z   g t        | dd       t        fdd      | _        y y )N__attrproxy__r   __setattr__c                      || |||      S r
   r   )r   r%   r&   osahooks        r   <lambda>z!hook__setattr__.<locals>.<lambda>   s    Y]^bcdefgjYk r   )rb   rc   )hasattrrJ   newclassobjr   	__bases__r6   rf   )rN   Cri   s      r   hook__setattr__rm      s\    3'MMll1::qd1;;.>.5c-.MSWkmn (r   Nc                     t        | d      sJ d       t        | d      \  }}t        |      s|f}g }g }	|D ]6  }
t        |
      r
|
d   |
dd }}
t        | |
      \  }}|s*t	        |dd      }8 y)z>
    Add a proxy attribute 'name' to src with targets dst
    r5   zsrc object has no _attrMap   r   N)rh   rW   r   r`   r6   )r]   r+   r   r   r#   dstrU   rV   DDVderN   attrdAs                  r   addProxyAttributerw      s    
 3z"@$@@"C"EAr:STs
A	B .8Q412qA&s1-	TZ-B.r   )r   )NNNN)__version__r   reportlab.lib.validatorsr   r   reportlab.lib.utilsr   	reportlabr   r   r   r:   r3   rR   rW   r`   rm   rw   r   r   r   <module>r|      sZ    	4 > % 	/ 	/\ \,d >#:%	n.r   