
    O|b                     H    d Z ddlZddlZddlZddlZddlZg Z G d d      Zy)z3
ftputil.path - simulate `os.path` for FTP servers
    Nc                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)_Pathz
    Support class resembling `os.path`, accessible from the `FTPHost` object,
    e. g. as `FTPHost().path.abspath(path)`.

    Hint: substitute `os` with the `FTPHost` object.
    c                    || _         |j                  | _        t        }|j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  | _	        |j                  | _
        |j                  | _        |j                  | _        y )N)_host	_encoding	posixpathbasenamecommonprefixdirnameisabsjoinnormcasenormpathsplit
splitdrivesplitext)selfhostpps      ,lib/python3.12/site-packages/ftputil/path.py__init__z_Path.__init__!   s    

 OOzzXX
GG	XX
--    c                 l   |}t         j                  j                  || j                        }| j	                  |      s*| j                  | j                  j                         |      }t         j                  j                  t        j                  |      | j                  |      | j                        S )z*
        Return an absolute path.
        encoding)ftputiltoolas_str_pathr   r   r   r   getcwdsame_string_type_asosfspathr   )r   pathoriginal_paths      r   abspathz_Path.abspath4   s     ||''t~~'Fzz$99TZZ..0$7D||//IIm$dmmD&94>>
 	
r   c                     |dv ry	 | j                   j                  |d      }|duS # t        j                  j                  $ r Y yw xY w)z1
        Return true if the path exists.
         r   F_exception_for_missing_pathNT)r   lstatr   errorRootDirErrorr   r#   lstat_results      r   existsz_Path.existsB   sT     9	::++De+TLt++}})) 		s    ( AAc                     t         j                  j                  |       | j                  j	                  |      j
                  S )z
        Return the timestamp for the last modification for `path` as a float.

        This will raise `PermanentError` if the path doesn't exist, but maybe
        other exceptions depending on the state of the server (e. g. timeout).
        )r   r   raise_for_empty_pathr   statst_mtimer   r#   s     r   getmtimez_Path.getmtimeN   s/     	))$/zzt$---r   c                     t         j                  j                  |       | j                  j	                  |      j
                  S )z
        Return the size of the `path` item as an integer.

        This will raise `PermanentError` if the path doesn't exist, but maybe
        raise other exceptions depending on the state of the server (e. g.
        timeout).
        )r   r   r2   r   r3   st_sizer5   s     r   getsizez_Path.getsizeX   s/     	))$/zzt$,,,r   c                     |dv sJ |dk(  rd}t         j                  }nd}t         j                  }t        j                  j                  || j                        }| j                  |      | j                  j                         k(  r|S 	 | j                  j                  |d      }|y ||j                        S # t        j                  j                  $ r Y yt        j                  j                  $ r |cY S w xY w)a  
        Return `True` if `path` represents the file system entity described by
        `dir_or_file` ("dir" or "file").

        Return `False` if `path` isn't a directory or file, respectively or if
        `path` leads to an infinite chain of links.
        )dirfiler;   TFr   r)   )r3   S_ISDIRS_ISREGr   r   r   r   r   r   r   st_moder,   RecursiveLinksErrorr-   )r   r#   dir_or_fileshould_look_for_dirstat_functionstat_results         r   _is_file_system_entityz_Path._is_file_system_entitym   s     o--%"& LLM"' LLM||''t~~'F ==$**"3"3"55&&	:**//$E/RK "$[%8%899 }}00 	}})) 	'&&	's   B= =C=C=<C=c                 0    |dv ry| j                  |d      S )z
        Return true if the `path` exists and corresponds to a directory (no
        link).

        A non-existing path does _not_ cause a `PermanentError`, instead return
        `False`.
        r'   Fr;   rE   r5   s     r   isdirz_Path.isdir   s"     9**477r   c                 0    |dv ry| j                  |d      S )z
        Return true if the `path` exists and corresponds to a regular file (no
        link).

        A non-existing path does _not_ cause a `PermanentError`, instead return
        `False`.
        r'   Fr<   rG   r5   s     r   isfilez_Path.isfile   s"     9**488r   c                 *   t         j                  j                  || j                        }|dk(  ry	 | j                  j                  |d      }|yt        j                  |j                        S # t         j                  j                  $ r Y yw xY w)z
        Return true if the `path` exists and is a link.

        A non-existing path does _not_ cause a `PermanentError`, instead return
        `False`.
        r   r(   Fr)   )r   r   r   r   r   r+   r3   S_ISLNKr?   r,   r-   r.   s      r   islinkz_Path.islink   s     ||''t~~'F2:		:::++De+TL #||L$8$899 }})) 		s   A2 2BBc                    t         j                  j                  |d       t         j                  j                  || j                        }	 | j
                  j                  |      } ||||       |D ]j  }| j                  ||      }	 | j
                  j                  |      }t        j                  |t        j                           sX| j                  |||       l y# t        $ r Y yw xY w# t        $ r Y w xY w)a  
        Directory tree walk with callback function.

        For each directory in the directory tree rooted at top
        (including top itself, but excluding "." and ".."), call
        func(arg, dirname, fnames). dirname is the name of the
        directory, and fnames a list of the names of the files and
        subdirectories in dirname (excluding "." and "..").  func may
        modify the fnames list in-place (e.g. via del or slice
        assignment), and walk will only recurse into the
        subdirectories whose names remain in fnames; this can be used
        to implement a filter, or to impose a specific order of
        visiting.  No semantics are defined for, or required of, arg,
        beyond that arg is always passed to func.  It can be used,
        e.g., to pass a filename pattern, or a mutable object designed
        to accumulate statistics.  Passing None for arg is common.
        top)path_argument_namer   N)r   r   r2   r   r   r   listdirOSErrorr   r+   r3   r=   ST_MODEwalk)r   rO   funcargnamesnamerD   s          r   rT   z
_Path.walk   s    $ 	))#%)Hll&&sT^^&D	JJ&&s+E 	S#u 	+D99S$'D"jj..t4 ||K56		$c*	+  		  s$   C# C2#	C/.C/2	C>=C>N)__name__
__module____qualname____doc__r   r%   r0   r6   r9   rE   rH   rJ   rM   rT    r   r   r   r      s:    $&

.	-*!:F
8
9:*"+r   r   )	r\   r!   r   r3   ftputil.errorr   ftputil.tool__all__r   r]   r   r   <module>ra      s.   
 
    
 I+ I+r   