
    O|b                     d    d Z ddlZg Z	 ddlZej
                  Z G d d      Zy# e$ r dZY w xY w)z=
ftputil.file - support for file-like objects on FTP servers
    Nc                   Z    e Zd ZdZdZd Z	 	 	 	 ddddZd Zd Zd	 Z	d
 Z
d Zd Zd Zy)FTPFilez
    Represents a file-like object associated with an FTP host. File and socket
    are closed appropriately if the `close` method is called.
       c                 ^    || _         |j                  | _        d| _        d| _        d| _        y)z!Construct the file(-like) object.TN)_host_sessionclosed_conn_fobj)selfhosts     ,lib/python3.12/site-packages/ftputil/file.py__init__zFTPFile.__init__!   s)    


    N)restc                &   |t        d      d|v rt        j                  j                  d      |dvr.t        j                  j                  dj	                  |            d|v rd|v rt        d	      d|v }d
|v }	|s!|t        j                  j                  d      d}
dj	                  |
      }t        j                  j                  5  | j                  j                  |       ddd       |	rdnd}dj	                  ||      }t        j                  j                  5  | j                  j                  ||      | _        ddd       | j                  j                  |||||      | _        d| _        y# 1 sw Y   xY w# 1 sw Y   BxY w)z
        Open the remote file with given path name and mode.

        Contrary to the `open` builtin, this method returns `None`, instead
        this file object is modified in-place.
        Nz'open() argument 2 must be str, not Noneazappend mode not supported)rrbrtwwbwtzinvalid mode '{}'btz'can't have text and binary mode at oncer   z,`rest` argument can't be used for text filesIzTYPE {}RETRSTORz{} {})	bufferingencodingerrorsnewlineF)	TypeErrorftputilerror
FTPIOErrorformat
ValueErrorCommandNotImplementedErrorftplib_error_to_ftp_io_errorr   voidcmdtransfercmdr
   makefiler   r	   )r   pathmoder   r    r!   r"   r   is_binary_modeis_read_modetransfer_typecommandcommand_types                r   _openzFTPFile._open+   s}   , <EFF$;--**+FGG99--**+>+E+Ed+KLL$;3$;FGGd{T%5--::> 
 ""=1]]77 	+MM!!'*	+ ".v6..t4]]77 	B227DADJ	BZZ((IQX ) 


 	+ 	+	B 	Bs   E;$"F;FFc                     | S )z)
        Return a file iterator.
         r   s    r   __iter__zFTPFile.__iter__f   s	     r   c                 6    | j                         }|r|S t        )zV
        Return the next line or raise `StopIteration`, if there are no more.
        )readlineStopIteration)r   lines     r   __next__zFTPFile.__next__l   s    
 }}Kr   c                     | S )Nr7   r8   s    r   	__enter__zFTPFile.__enter__z   s	     r   c                 $    | j                          y)NF)close)r   exc_typeexc_valexc_tbs       r   __exit__zFTPFile.__exit__   s     	

r   c                     |dj                         v rt        | j                  |      S t        dj	                  |            )z
        Handle requests for attributes unknown to `FTPFile` objects: delegate
        the requests to the contained file object.
        zgencoding flush isatty fileno read readline readlines seek tell truncate name softspace write writelinesz&'FTPFile' object has no attribute '{}')splitgetattrr   AttributeErrorr'   )r   	attr_names     r   __getattr__zFTPFile.__getattr__   sB    
 77<uw
 4::y11ELLYWXXr   c                    | j                   ry| j                  j                  j                         }	 | j                  j                          d| _        t        j                  j                  5  t        4t        | j                  t              r| j                  j                          | j                  j                          ddd       | j                  j                  j                  | j                         	 t        j                  j                  5  | j                  j                          ddd       | j                  j                  j                  |       d| _         y# 1 sw Y   xY w# 1 sw Y   BxY w# t        j                  j                   $ r5}t#        |      }|dd }|j%                         d   dk7  r|dvr Y d}~d}~ww xY w# | j                  j                  j                  |       d| _         w xY w)z&
        Close the `FTPFile`.
        N   r   z	timed out)150426450451T)r	   r   sock
gettimeoutr   rB   r$   r%   r*   	SSLSocket
isinstancer
   unwrap
settimeout_close_timeoutvoidrespr&   str
splitlines)r   old_timeoutexc
error_codes       r   rB   zFTPFile.close   s    ;; mm((335!	JJDJ;; #)z$**i/PJJ%%'

  "# MM))$*=*=>]]?? -MM**,-$ MM))+6 DK=# #- -==++  #h !W
>>#A&+5* M ;   MM))+6 DKs`   ;G .AE%7G ;E= E10E= %E.*G 1E:6E= =G+G
G 
GG .H c                     t        d      )Nzcannot serialize FTPFile object)r#   r8   s    r   __getstate__zFTPFile.__getstate__   s    9::r   )NNNN)__name__
__module____qualname____doc__rY   r   r5   r9   r>   r@   rF   rL   rB   ra   r7   r   r   r   r      sV     N 9 9v	 

Y+Z;r   r   )re   ftputil.errorr$   __all__sslrU   ImportErrorr   r7   r   r   <module>rj      sK   
   In; n;  Is   % //