
    qi<H                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
Jr  SSKJrJrJr  Sr\R"                  " \5      rSr " S	 S
\5      r " S S\5      r " S S\5      rg)a  
Implementation of a DAV provider that serves resource from a file system.

:class:`~wsgidav.fs_dav_provider.FilesystemProvider` implements a DAV resource
provider that publishes a file system.

If ``readonly=True`` is passed, write attempts will raise HTTP_FORBIDDEN.

This provider creates instances of :class:`~wsgidav.fs_dav_provider.FileResource`
and :class:`~wsgidav.fs_dav_provider.FolderResource` to represent files and
directories respectively.
    N)List)util)HTTP_FORBIDDENDAVError)DAVCollectionDAVNonCollectionDAVProviderreStructuredTexti    c                      ^  \ rS rSrSrS\S\S\4U 4S jjrS rS r	S	 r
S
 rS rS rS rS rS rS rSS.S jrS rS rS rS rS rSrU =r$ )FileResource%   zvRepresents a single existing DAV resource instance.

See also _DAVResource, DAVNonCollection, and FilesystemProvider.
pathenviron	file_pathc                    > [         TU ]  X5        X0l        [        R                  " U R                  5      U l        [        R                  R                  U R                  5      U l        [        R                  " U R                  5      U l        g N)super__init__
_file_pathosstat	file_statr   basenamenamer   to_strselfr   r   r   	__class__s       L/home/kali/flask_env/lib/python3.13/site-packages/wsgidav/fs_dav_provider.pyr   FileResource.__init__+   sW    '()+)A))$//:	KK		*	    c                 <    U R                   [        R                     $ r   )r   r   ST_SIZEr   s    r   get_content_lengthFileResource.get_content_length4   s    ~~dll++r!   c                 B    [         R                  " U R                  5      $ r   )r   guess_mime_typer   r$   s    r   get_content_typeFileResource.get_content_type7   s    ##DII..r!   c                 <    U R                   [        R                     $ r   r   r   ST_CTIMEr$   s    r   get_creation_dateFileResource.get_creation_date:       ~~dmm,,r!   c                     U R                   $ r   r   r$   s    r   get_display_nameFileResource.get_display_name=       yyr!   c                 B    [         R                  " U R                  5      $ r   )r   get_file_etagr   r$   s    r   get_etagFileResource.get_etag@   s    !!$//22r!   c                 <    U R                   [        R                     $ r   r   r   ST_MTIMEr$   s    r   get_last_modifiedFileResource.get_last_modifiedC   r0   r!   c                 T    [         R                  R                  U R                  5      $ r   r   r   islinkr   r$   s    r   is_linkFileResource.is_linkF       ww~~doo..r!   c                     gNT r$   s    r   support_etagFileResource.support_etagI       r!   c                     grF   rG   r$   s    r   support_rangesFileResource.support_rangesL   rJ   r!   c                 ^    U R                   (       a   e[        U R                  S[        5      $ )zEOpen content as a stream for reading.

See DAVResource.get_content()
rb)is_collectionopenr   BUFFER_SIZEr$   s    r   get_contentFileResource.get_contentO   s(    
 %%%% DOOT;77r!   N)content_typec                    U R                   (       a   eU R                  R                  (       a  [        [        5      e[        U R                  S[        5      $ )zEOpen content as a stream for writing.

See DAVResource.begin_write()
wb)rP   providerreadonlyr   r   rQ   r   rR   )r   rU   s     r   begin_writeFileResource.begin_writeZ   s@    
 %%%%==!!>** DOOT;77r!   c                     U R                   R                  (       a  [        [        5      e[        R
                  " U R                  5        U R                  SS9  U R                  SS9  g)JRemove this resource or collection (recursive).

See DAVResource.delete()
T	recursiveN)	rX   rY   r   r   r   unlinkr   remove_all_propertiesremove_all_locksr$   s    r   deleteFileResource.deletef   sN    
 ==!!>**
		$//"""T"2-r!   c                   U R                   R                  (       a  [        [        5      eU R                   R	                  XR
                  5      n[        R                  " U R                  U5      (       a   e[        R                  " U R                  U5        U R                   R                  nU(       a  U R                   R                  XR
                  5      nU(       a9  UR                  U R                  5       UR                  5       SU R
                  S9  gUR!                  U R                  5       UR                  5       U R
                  5        gg)"See DAVResource.copy_move_single()Fwith_childrenr   N)rX   rY   r   r   _loc_to_file_pathr   r   is_equal_or_child_urir   shutilcopy2r   prop_managerget_resource_instmove_propertiesget_ref_urlcopy_propertiesr   	dest_pathis_movefpDestpropMandestRess         r   copy_move_singleFileResource.copy_move_singleq   s    ==!!>**00LLI--diiCCCCT__f- --,,mm55iNG''$$&'')"' LL	 (  ''$$&(;(;(=t|| r!   c                     gzCReturn True, if move_recursive() is available (see comments there).TrG   r   rs   s     r   support_recursive_move#FileResource.support_recursive_move       r!   c                    U R                   R                  (       a  [        [        5      eU R                   R	                  XR
                  5      n[        R                  " U R                  U5      (       a   e[        R                  R                  U5      (       a   e[        R                  SU R                   SU S35        [        R                  " U R                  U5        U R                   R                   (       ar  U R                   R#                  XR
                  5      nU R                   R                   R%                  U R'                  5       UR'                  5       SU R
                  S9  ggz See DAVResource.move_recursive()zmove_recursive(z, )Trg   NrX   rY   r   r   ri   r   r   rj   r   r   exists_loggerdebugr   rk   moverm   rn   ro   rp   r   rs   ru   rw   s       r   move_recursiveFileResource.move_recursive      ==!!>**00LLI--diiCCCC77>>&))))'86(!DEDOOV, ==%%mm55iNGMM&&66  "##%"	 7  &r!   c                    [         R                  " U5      nU(       d"  [        R                  " U R                  XD45        gz@Set last modified time for destPath to timeStamp on epoch-formatTr   parse_time_stringr   utimer   r   rs   
time_stampdry_runsecss        r   set_last_modifiedFileResource.set_last_modified   .     %%j1HHT__tl3r!   )r   r   r   )__name__
__module____qualname____firstlineno____doc__strdictr   r%   r)   r.   r3   r8   r=   rB   rH   rL   rS   rZ   rc   rx   r}   r   r   __static_attributes____classcell__r   s   @r   r   r   %   s|    
+S +4 +C +,/-3-/	8 +/ 
8	.2( r!   r   c                      ^  \ rS rSrSrS\S\4U 4S jjrS rS r	S r
S	 rS
 rS rS rS rS\\   4S jrS\S\4S jrS rS rS rS rS rS rS rSrU =r$ )FolderResource   z}Represents a single existing file system folder DAV resource.

See also _DAVResource, DAVCollection, and FilesystemProvider.
r   r   c                 B  > [         TU ]  X5        X0l        [        R                  " U R                  5      U l        U R                  U l        [        R                  R                  U R                  5      U l
        [        R                  " U R                  5      U l
        g r   )r   r   r   r   r   r   rX   fs_optsr   r   r   r   r   r   s       r   r   FolderResource.__init__   sb    '()+)A}}GG$$T__5	KK		*	r!   c                 <    U R                   [        R                     $ r   r,   r$   s    r   r.    FolderResource.get_creation_date   r0   r!   c                     U R                   $ r   r2   r$   s    r   r3   FolderResource.get_display_name   r5   r!   c                     g r   rG   r$   s    r   get_directory_info!FolderResource.get_directory_info   rJ   r!   c                     g r   rG   r$   s    r   r8   FolderResource.get_etag   rJ   r!   c                 V    [         R                  " U R                  5      R                  $ r   )rk   
disk_usager   usedr$   s    r   get_used_bytesFolderResource.get_used_bytes         1666r!   c                 V    [         R                  " U R                  5      R                  $ r   )rk   r   r   freer$   s    r   get_available_bytes"FolderResource.get_available_bytes   r   r!   c                 <    U R                   [        R                     $ r   r;   r$   s    r   r=    FolderResource.get_last_modified   r0   r!   c                 T    [         R                  R                  U R                  5      $ r   r@   r$   s    r   rB   FolderResource.is_link   rD   r!   returnc                    / n[         R                  " U R                  5      (       d   e[        R                  " U R                  5       GH  n[         R                  " U5      (       d$  UR                  [        R                  " 5       5      n[         R                  " U5      (       d   e[        R                  R                  U R                  U5      n[        R                  R                  U5      (       d?  [        R                  R                  U5      (       d  [        R                  SU< 35        M  [         R                  " U5      nUR                  U5        GM     U$ )zeReturn list of direct collection member names (utf-8 encoded).

See DAVCollection.get_member_names()
Skipping non-file )r   is_strr   r   listdirdecodesysgetfilesystemencodingr   joinisdirisfiler   infor   append)r   nameListr   fps       r   get_member_namesFolderResource.get_member_names   s     {{4??++++ JJt/D;;t$${{3#<#<#>?;;t$$$$doot4B 77==$$RWW^^B-?-?1"89;;t$DOOD! 0 r!   r   c                 0   [         R                  " U5      (       d	   U< 5       e[        R                  R	                  U R
                  [         R                  " U5      5      n[         R                  " U R                  U5      nSn[        R                  R                  U5      (       a  [        X0R                  U5      nU$ [        R                  R                  U5      (       a  [        X0R                  U5      nU$ [        R                  SU 35        U$ )zZReturn direct collection member (DAVResource or derived).

See DAVCollection.get_member()
Nr   )r   r   r   r   r   r   r   join_urir   r   r   r   r   r   r   )r   r   r   r   ress        r   
get_memberFolderResource.get_member   s    
 {{4  -TH- WW\\$//4;;t+<=}}TYY- 77== ||R8C
 
	 WW^^Bt\\26C 
 MM.tf56
r!   c                 t   SU;  d   eU R                   R                  (       a  [        [        5      e[        R
                  " U R                  U5      nU R                   R                  X R                  5      n[        US5      nUR                  5         U R                   R                  X R                  5      $ )zNCreate an empty (length-0) resource.

See DAVResource.create_empty_resource()
/rW   )rX   rY   r   r   r   r   r   ri   r   rQ   closern   )r   r   r   r   fs        r   create_empty_resource$FolderResource.create_empty_resource  s    
 $==!!>**}}TYY-]],,T<<@TN		}}..t\\BBr!   c                     SU;  d   eU R                   R                  (       a  [        [        5      e[        R
                  " U R                  U5      nU R                   R                  X R                  5      n[        R                  " U5        g)zPCreate a new collection as member of self.

See DAVResource.create_collection()
r   N)rX   rY   r   r   r   r   r   ri   r   r   mkdir)r   r   r   r   s       r   create_collection FolderResource.create_collection  s_    
 $==!!>**}}TYY-]],,T<<@
r!   c                     U R                   R                  (       a  [        [        5      e[        R
                  " U R                  SS9  U R                  SS9  U R                  SS9  g)r]   F)ignore_errorsTr^   N)	rX   rY   r   r   rk   rmtreer   ra   rb   r$   s    r   rc   FolderResource.delete)  sP    
 ==!!>**dooU;""T"2-r!   c                   U R                   R                  (       a  [        [        5      eU R                   R	                  XR
                  5      n[        R                  " U R                  U5      (       a   e[        R                  R                  U5      (       d  [        R                  " U5         [        R                  " U R                  U5        U R                   R$                  nU(       a  U R                   R'                  XR
                  5      nU(       a9  UR)                  U R+                  5       UR+                  5       SU R
                  S9  gUR-                  U R+                  5       UR+                  5       U R
                  5        gg! [         a%    [         R#                  SU R                   35         Nf = f)rf   zCould not copy folder stats: Frg   N)rX   rY   r   r   ri   r   r   rj   r   r   r   r   rk   copystatr   	Exceptionr   	exceptionrm   rn   ro   rp   rq   rr   s         r   rx   FolderResource.copy_move_single4  sL   ==!!>**00LLI--diiCCCCww~~f%%HHV	Q OODOOV4
 --,,mm55iNG''$$&'')"' LL	 (  ''$$&(;(;(=t||   	Q =doo=NOP	Qs   3!F ,G ?G c                     gr{   rG   r|   s     r   r}   %FolderResource.support_recursive_moveT  r   r!   c                    U R                   R                  (       a  [        [        5      eU R                   R	                  XR
                  5      n[        R                  " U R                  U5      (       a   e[        R                  R                  U5      (       a   e[        R                  SU R                   SU S35        [        R                  " U R                  U5        U R                   R                   (       ar  U R                   R#                  XR
                  5      nU R                   R                   R%                  U R'                  5       UR'                  5       SU R
                  S9  ggr   r   r   s       r   r   FolderResource.move_recursiveX  r   r!   c                    [         R                  " U5      nU(       d"  [        R                  " U R                  XD45        gr   r   r   s        r   r    FolderResource.set_last_modifiedl  r   r!   )r   r   r   r   )r   r   r   r   r   r   r   r   r.   r3   r   r8   r   r   r=   rB   r   r   r   r   r   r   rc   rx   r}   r   r   r   r   r   s   @r   r   r      s    
+S +4 +-77-/ $s)  Ds | .C
	.@( r!   r   c                   z   ^  \ rS rSrSrSSS.U 4S jjrS rS\S	\4S
 jr	SS\S	\4S jjr
S\S	\S\4S jrSrU =r$ )FilesystemProviderix  zDefault implementation of a filesystem DAVProvider.

Args:
    root_folder (str)
    readonly (bool)
    fs_opts (dict | None): defaults to `config.fs_dav_provider`
    shadow (dict):  @deprecated (Use option `fs_provider.shadow_map` instead)
FN)rY   r   c                8  > [         R                  R                  U5      nU(       a$  [         R                  R                  U5      (       d  [	        SU 35      e[
        TU ]  5         Xl        X l        Uc  [        R                  U  S35        0 nX0l        U R                  R                  S5      =(       d    0 U l        U R                  (       aD  U R                  R                  5        VVs0 s H  u  pEUR                  5       U_M     snnU l        g g s  snnf )NzInvalid root path: z/: no `fs_opts` parameter passed to constructor.
shadow_map)r   r   abspathr   
ValueErrorr   r   root_folder_pathrY   r   warningr   getr   itemslower)r   root_folderrY   r   kvr   s         r   r   FilesystemProvider.__init__  s     ggook2"''.."="=2;-@AA + ?OOtf$STUG,,**<8>B??8<8M8M8OP8Oqwwy!|8OPDO Ps   .Dc                     U R                   (       a  SOSnU R                  R                   SU R                  < SU S3$ )Nz	Read-Onlyz
Read-Writez
 for path z (r   )rY   r   r   r   )r   rws     r   __repr__FilesystemProvider.__repr__  s<     MM[|..))**T5J5J4MRPRtSTUUr!   r   r   c                    U R                   R                  UR                  5       5      nU(       d  SU4$ SnUS   R                  5       nUS;  a  SU SU SU< S3nO_[        R
                  R                  U5      (       a  SU SU S	U< S3nO-[        R
                  R                  U5      (       d	  SU SU S
3nU(       a  [        R                  U5        SU4$ [        R                  SU SU 35        SU4$ )z4File not found: See if there is a shadow configured.FNREQUEST_METHOD)GETHEADOPTIONSzShadow z -> z: ignored for method .z : ignored for existing resource z: does not exist.T)
r   r   r   upperr   r   r   r   r   r   )r   r   r   r   shadowerrmethods          r   _resolve_shadow_path'FilesystemProvider._resolve_shadow_path  s    $$TZZ\2)##)*00233D6fX-B6*ANCWW^^I&&D6fX-Mi]Z[\C''D6fX->?COOC )##wtfD12V|r!   c                    U R                   nUc   e[        R                  " U5      (       d   e[        R                  " U5      (       d   eUR                  S5      R	                  S5      n[
        R                  R                  [
        R                  R                  " U/UQ76 5      nU R                  XU5      u  peUR                  U5      (       d  U(       d  [        SU 35      e[        R                  " U5      nU$ )zConvert resource path to a unicode absolute file path.
Optional environ argument may be useful e.g. in relation to per-user
sub-folder chrooting inside root_folder_path.
r   z7Security exception: tried to access file outside root: )r   r   r   stripsplitr   r   r   r   r  
startswithRuntimeErrorto_unicode_safe)r   r   r   	root_path
path_partsr   	is_shadows          r   ri   $FilesystemProvider._loc_to_file_path  s    
 ))	$$${{9%%%%{{4    ZZ_**3/
GGOOBGGLL$HZ$HI	  $88	R	##I..yI)U 
 ((3	r!   r   c                    U =R                   S-  sl         U R                  X5      n[        R                  R	                  U5      (       d  gU R
                  R                  S5      (       d8  [        R                  R                  U5      (       a  [        [        SU< 35      e[        R                  R                  U5      (       a  [        XU5      $ [        XU5      $ )zFReturn info dictionary for path.

See DAVProvider.get_resource_inst()
   Nfollow_symlinkszSymlink support is disabled: )_count_get_resource_instri   r   r   r   r   r   rA   r   r   r   r   r   )r   r   r   r   s       r   rn   $FilesystemProvider.get_resource_inst  s    
 	%%*%##D2ww~~b!!|| 122rww~~b7I7I>-J2&+QRR77==!$44D2..r!   )r   rY   r   r   r   )r   r   r   r   r   r   r   r   r   r  ri   r   rn   r   r   r   s   @r   r   r   x  sf     16t Q Q(V t ,c D 2/c /D /\ / /r!   r   )r   r   rk   r   r   typingr   wsgidavr   wsgidav.dav_errorr   r   wsgidav.dav_providerr   r   r	   __docformat__get_module_loggerr   r   rR   r   r   r   rG   r!   r   <module>r"     sn   
 
   
   6 M M"

 
 
*C# CRD] DT_/ _/r!   