
    qi-                         S r SSKrSSKrSSKJr  SSKJr  Sr\R                  " S5      r	 " S S5      r
 " S	 S
\
5      rg)af  
Implements two property managers: one in-memory (dict-based), and one
persistent low performance variant using shelve.

The properties dictionaray is built like::

    { ref-url1: {propname1: value1,
                 propname2: value2,
                 },
      ref-url2: {propname1: value1,
                 propname2: value2,
                 },
      }

    N)util)ReadWriteLockreStructuredTextzwsgidav.prop_manc                       \ rS rSrSrS rS rS rS rS r	S r
SS	 jrSS
 jrSS jrSS jr SS jrSS jrSS jrSS jrSS jrSrg)PropertyManager.   z
An in-memory property manager implementation using a dictionary.

This is obviously not persistent, but should be enough in some cases.
For a persistent implementation, see property_manager.ShelvePropertyManager().
c                 L    S U l         SU l        [        5       U l        SU l        g )NF   )_dict_loadedr   _lock_verboseselfs    V/home/kali/flask_env/lib/python3.13/site-packages/wsgidav/prop_man/property_manager.py__init__PropertyManager.__init__6   s     
"_
    c                     g)Nr    r   s    r   __repr__PropertyManager.__repr__<   s     r   c                 d    U R                   S:  a  U R                  5         U R                  5         g )N   )r   _check_closer   s    r   __del__PropertyManager.__del__?   s     !+KKMr   c                     [         R                  S5        U R                  R                  5          0 U l        SU l        U R                  R                  5         g ! U R                  R                  5         f = f)Nz_lazy_open()T_loggerdebugr   acquire_writer   r   releaser   s    r   
_lazy_openPropertyManager._lazy_openD   sR    n%

  "	!DJDLJJ DJJ    A A6c                     g Nr   r   s    r   _syncPropertyManager._syncM   s    r   c                     [         R                  S5        U R                  R                  5          S U l        SU l        U R                  R                  5         g ! U R                  R                  5         f = fNz_close()Fr    r   s    r   r   PropertyManager._closeP   sR    j!

  "	!DJ DLJJ DJJ r'   c                      U R                   (       d  gU R                  R                  5        H  u  p#U SU 3nM     g! [         a1    [        R                  U R                  R                   SU 35         gf = f)NT, z _check: ERROR F)r   r   items	Exceptionr!   	exception	__class____name__)r   msgkv_dummys        r   r   PropertyManager._checkY   st    		<<

((*3b +  	!8!8 9NO	s   ? *? 8A:9A:c           	         [         R                  U R                  R                   SU R	                  5        SU 35        U R
                  (       d!  U R                  5         U R                  S:  a  g  U R                  R                  5        HS  u  p#[         R                  SU 35        UR                  5        H"  u  pE [         R                  SU SU< 35        M$     MU     g ! [         a&  n[         R                  SU SU 35         S nAMV  S nAff = f! [         a"  n[         R                  SU 35         S nAg S nAff = f)	N(z): r   z    z        z: z: ERROR z PropertyManager._dump()  ERROR: )r!   infor4   r5   r   r   r%   r   r   r1   r2   error)r   r6   r7   r8   k2v2es          r   _dumpPropertyManager._dumpe   s   //0$--/1B#cUKL||OO}}!
	B

((*tA3Z(ggiFBAxt2bV%<= ( +
 % Axt8A3%?@@A  	BMM<QC@AA	BsC   3AD  C%D %
D/D
D DD 
E"D??ENc                    [         R                  SU S35        U R                  R                  5          U R                  (       d  U R                  5         / nXR                  ;   a5  U R                  U   R                  5        H  nUR                  U5        M     UU R                  R                  5         $ ! U R                  R                  5         f = f)Nzget_properties())
r!   r"   r   acquire_readr   r%   r   keysappendr$   )r   norm_urlenviron
returnlistpropdatas        r   get_propertiesPropertyManager.get_propertiesw   s    z34

!		!<<!J::% $

8 4 9 9 ;H%%h/ !<JJ DJJ s   A(B8 8Cc           	         [         R                  SU SU S35        U R                  R                  5          U R                  (       d  U R                  5         XR                  ;  a   U R                  R                  5         g  U R                  U   nUR                  U5      U R                  R                  5         $ ! [         a$  n[         R                  SU SU SU 35        e S nAff = f! U R                  R                  5         f = f)Nzget_property(r0   rE   z) failed : )r!   r"   r   rF   r   r%   r   r$   r2   r3   get)r   rI   namerJ   resourcepropsrA   s         r   get_propertyPropertyManager.get_property   s    hZr$q9:

!	!<<!zz) JJ  $

8 4 !$$T*JJ   !!M(2dV;qc"RS
 JJ s/   0C0 B? C0 ?
C-	C((C--C0 0Dc           
      `   U(       a  UR                  S5      (       d   eU(       d   eUc   e[        R                  SU SU SU SU 35        U(       a  g U R                  R	                  5          U R
                  (       d  U R                  5         XR                  ;   a  U R                  U   nO0 nX6U'   X`R                  U'   U R                  5         U R                  S:  a  U R                  5         U R                  R                  5         g ! U R                  R                  5         f = f)N/zwrite_property(r0   
, dry_run=z):
	r   )
startswithr!   r"   r   r#   r   r%   r   r*   r   r   r$   )r   rI   rQ   property_valuedry_runrJ   locatordicts          r   write_propertyPropertyManager.write_property   s     H//4444t)))hZr$z'&HXY	
 

  "	!<<!::%"jj2  .#.JJx JJL!]]a/JJ DJJ s   2BD D-c           	         [         R                  SU SU SU S35        U(       a  gU R                  R                  5          U R                  (       d  U R                  5         XR                  ;   a4  U R                  U   nX%;   a   XR	 XPR                  U'   U R                  5         U R                  S:  a  U R                  5         U R                  R                  5         g! U R                  R                  5         f = f)zK
Specifying the removal of a property that does not exist is NOT an error.
zremove_property(r0   rW   rE   Nr   )r!   r"   r   r#   r   r%   r   r*   r   r   r$   )r   rI   rQ   rZ   rJ   r[   s         r   remove_propertyPropertyManager.remove_property   s     	(
"TF*WIQOP

  "	!<<!::%"jj2&#) ,7JJx(JJL!]]a/JJ DJJ s   BC" "C>c                 x   [         R                  SU S35        U R                  R                  5          U R                  (       d  U R                  5         XR                  ;   a  U R                  U	 U R                  5         U R                  R                  5         g ! U R                  R                  5         f = f)Nzremove_properties(rE   )	r!   r"   r   r#   r   r%   r   r*   r$   )r   rI   rJ   s      r   remove_properties!PropertyManager.remove_properties   s~    *8*A67

  "	!<<!::%JJx(

JJ DJJ s   AB B9c                 :   [         R                  SU SU S35        U R                  R                  5          U R                  S:  a  U R                  5         U R                  (       d  U R                  5         XR                  ;   a:  U R                  U   R                  5       U R                  U'   U R                  5         U R                  S:  a  U R                  S5        U R                  R                  5         g ! U R                  R                  5         f = f)Nzcopy_properties(r0   rE   r   z
after copy)r!   r"   r   r#   r   r   r   r%   r   copyr*   r$   )r   src_urldest_urlrJ   s       r   copy_propertiesPropertyManager.copy_properties   s    (	H:Q?@

  "	!!]]a/<<!**$'+zz'':'?'?'A

8$

!]]a/L)JJ DJJ s   B+C> >Dc           	      P   [         R                  SU SU SU S35        U R                  R                  5          U R                  S:  a  U R                  5         U R                  (       d  U R                  5         U(       a  [        U R                  R                  5       5       HZ  n[        R                  " X5      (       d  M   UR                  X5      nU R                  U   U R                  U'   U R                  U	 M\     O8XR                  ;   a)  U R                  U   U R                  U'   U R                  U	 U R                  5         U R                  S:  a  U R                  S5        U R                  R                  5         g ! U R                  R                  5         f = f)Nzmove_properties(r0   rE   r   z
after move)r!   r"   r   r#   r   r   r   r%   listr   rG   r   is_equal_or_child_urireplacer*   r$   )r   rf   rg   with_childrenrJ   urlds          r   move_propertiesPropertyManager.move_properties   s,   (	H:RaPQ

  "	!!]]a/<<!

 12C11'??KK:(,

3

1 JJsO	 3
 JJ&'+zz'':

8$JJw'JJL!]]a/L)JJ DJJ s   BF	 B(F	 	F%)r   r   r   r   ) r)   )FN)r5   
__module____qualname____firstlineno____doc__r   r   r   r%   r*   r   r   rB   rM   rS   r\   r_   rb   rh   rq   __static_attributes__r   r   r   r   r   .   sZ    !
!!
B$!!( FJ!<!2
!! !r   r   c                   J   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	rU =r$ )
ShelvePropertyManageri
  z@
A low performance property manager implementation using shelve
c                 j   > [         R                  R                  U5      U l        [        TU ]  5         g r)   )ospathabspath_storage_pathsuperr   )r   storage_pathr4   s     r   r   ShelvePropertyManager.__init__  s#    WW__\:r   c                 "    SU R                    S3$ )NzShelvePropertyManager(rE   )r   r   s    r   r   ShelvePropertyManager.__repr__  s    '(:(:';1==r   c                    [         R                  SU R                   S35        U R                  R	                  5          U R
                  (       a   U R                  R                  5         g[        R                  " U R                  SS9U l	        SU l        U R                  S:  a"  U R                  S5        U R                  S5        U R                  R                  5         g ! U R                  R                  5         f = f)Nz_lazy_open(rE   TF)	writebackr   zAfter shelve.open())r!   r"   r   r   r#   r   r$   shelveopenr   r   r   rB   r   s    r   r%    ShelvePropertyManager._lazy_open  s    D$6$6#7q9:

  "	!|| JJ   T%7%75IDJDL!]]a/12

01JJ DJJ s   C$ ,AC$ $D c                 ,   [         R                  S5        U R                  R                  5          U R                  (       a  U R
                  R                  5         U R                  R                  5         g! U R                  R                  5         f = f)z$Write persistent dictionary to disc.z_sync()N)r!   r"   r   r#   r   r   syncr$   r   s    r   r*   ShelvePropertyManager._sync'  sY    i 

  "	!||

!JJ DJJ s   +A7 7Bc                 H   [         R                  S5        U R                  R                  5          U R                  (       a(  U R
                  R                  5         S U l        SU l        U R                  R                  5         g ! U R                  R                  5         f = fr-   )r!   r"   r   r#   r   r   closer$   r   s    r   r   ShelvePropertyManager._close1  si    j!

  "	!||

  "!
$JJ DJJ s   9B B!c                    U R                   R                  5          U R                  SL nU(       a  U R                  5         [	        U R                  5      (       a4  U R                  R                  5         U R                  R                  5         U(       a  U R                  5         U R                   R                  5         g! U R                   R                  5         f = f)zDelete all entries.N)	r   r#   r   r   lenclearr   r   r$   )r   
was_closeds     r   r   ShelvePropertyManager.clear<  s    

  "
	!t+J		4::

  "

!

JJ DJJ s   B
C C)r   r   r   )r5   rt   ru   rv   rw   r   r   r%   r*   r   r   rx   __classcell__)r4   s   @r   rz   rz   
  s+    >!"!	!! !r   rz   )rw   r|   r   wsgidavr   wsgidav.rw_lockr   __docformat__get_module_loggerr!   r   rz   r   r   r   <module>r      sI   
 
   ) #

 
 !3
4T! T!x?!O ?!r   