Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/ftputil/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/ftputil/__pycache__/host.cpython-38.pyc
U

O��g��@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlZddlZdgZejjr�Gdd�dej�ZnejZGdd�d�ZdS)z]
`FTPHost` is the central class of the `ftputil` library.

See `__init__.py` for an example.
�N�FTPHostcseZdZ�fdd�Z�ZS)�default_session_factorycsLd|kr(tjj}||d<t�j||�n t�j||�tj�||d�dS)N�encoding)�ftputil�
path_encoding�DEFAULT_ENCODING�super�__init__�sessionZ_maybe_send_opts_utf8_on)�self�args�kwargsr��	__class__��9/opt/cppython/lib/python3.8/site-packages/ftputil/host.pyr	,sz default_session_factory.__init__)�__name__�
__module__�__qualname__r	�
__classcell__rrrrr+src@s|eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdUd
d�dd�Z	dd�Z
dd�Zedd��Z
dd�Zdd�Zdd�Zdd�Zeejjd
fdd ��Zd!d"�ZdVd#d$�ZdWd%d&�Zd'd(�ZdXd)d*�ZdYd+d,�Zd-d.�ZdZd0d1�Zd2d3�Zd4d5�Zd[d6d7�Z d\d8d9�Z!d:d;�Z"d<d=�Z#e#Z$d]d>d?�Z%d@dA�Z&dBdC�Z'dDdE�Z(d^dGdH�Z)d_dIdJ�Z*d`dKdL�Z+dMdN�Z,dOdP�Z-dQdR�Z.dSdT�Z/d
S)arz
    FTP host class.
    c	Os�||_||_|��|_tj�|�|_tj�|�|_	|j	j
|_|j��tj
j�,|j��}|j�tjj||jd��|_W5QRXg|_d|_d|_d\|_|_|_d|_d|_dS)z>
        Abstract initialization of `FTPHost` object.
        �rNF)�.z..�/�)�_args�_kwargs�
_make_session�_sessionr�pathZ_Path�statZ_Stat�_statZ_lstat_cache�
stat_cache�enable�error�ftplib_error_to_ftp_os_error�pwd�normpath�tool�as_str_path�	_encoding�_cached_current_dir�	_children�_file�closed�curdir�pardir�sep�_time_shift�use_list_a_option)rrr
Zcurrent_dirrrrr	]s$




�zFTPHost.__init__c	Cs"tjj�|j��W5QRXdS)aX
        Try to keep the connection alive in order to avoid server timeouts.

        Note that this won't help if the connection has already timed out! In
        this case, `keep_alive` will raise an `TemporaryError`. (Actually, if
        you get a server timeout, the error - for a specific connection - will
        be permanent.)
        N)rr#r$rr%�rrrr�
keep_alive�s
zFTPHost.keep_alivec	Csl|jdd�}|j��}|�dt�}tjj�6|||�}t|d�sVtj�	d|�d���|j
|_W5QRX|S)zp
        Return a new session object according to the current state of this
        `FTPHost` instance.
        NZsession_factoryrzsession instance z" must have an `encoding` attribute)rr�copy�poprrr#r$�hasattrZNoEncodingErrorrr))rrr
�factoryr
rrrr�s




�zFTPHost._make_sessioncCs|j|j|j�S)z9
        Return a copy of this `FTPHost` object.
        )rrrr3rrr�_copy�sz
FTPHost._copyc	Cs�|jD]�}|jjrz|j��Wn^tjk
r:YqYqtjk
rRYqYqtk
rhYqYqt	k
r~YqYqX|SqdS)z�
        Return an available (i. e. one whose `_file` object is closed and
        doesn't have a timed-out server connection) child (`FTPHost` object)
        from the pool of children or `None` if there aren't any.
        N)
r+r,r-rr%�ftplibZerror_replyZ
error_temp�EOFError�OSError�r�hostrrr�_available_child�s



zFTPHost._available_child�rN)�restc
	Cs�tjj||jd�}|��}|dkrD|��}|j�|�tj�	|�|_
|��}	|j�
|�r^|}
n|j�|	|�}
|j�|
�\}}z|�|�Wn*tjjk
r�tj�d�|���YnX|j
j|||||||d�d|kr�|j�|
�|j
S)a
        Return an open file(-like) object which is associated with this
        `FTPHost` object.

        The arguments `path`, `mode`, `buffering`, `encoding`, `errors` and
        `newlines` have the same meaning as for `open`. If `rest` is given as
        an integer,

        - reading will start at the byte (zero-based) `rest`
        - writing will overwrite the remote file from byte `rest`

        This method tries to reuse a child but will generate a new one if none
        is available.
        rNzEremote directory '{}' doesn't exist or has insufficient access rights)�mode�	bufferingr�errors�newlinerA�w)rr'r(r)r?r9r+�append�fileZFTPFiler,�getcwdr�isabs�join�split�chdirr#�PermanentError�
FTPIOError�format�_openr!�
invalidate)
rrrBrCrrDrErAr>ZbasedirZeffective_pathZ
effective_dirZeffective_filerrr�open�s>��
�	zFTPHost.openc	Csh|jr
dS|jD]}|j��|��qz"tjj�|j	��W5QRXW5|j��g|_d|_XdS)z(
        Close host connection.
        NT)
r-r+r,�closer!�clearrr#r$rr=rrrrT%s




z
FTPHost.closecCs|j��||j_d|j_dS)a,
        Set the parser for extracting stat results from directory listings.

        The parser interface is described in the documentation, but here are
        the most important things:

        - A parser should derive from `ftputil.stat.Parser`.

        - The parser has to implement two methods, `parse_line` and
          `ignores_line`. For the latter, there's a probably useful default
          in the class `ftputil.stat.Parser`.

        - `parse_line` should try to parse a line of a directory listing and
          return a `ftputil.stat.StatResult` instance. If parsing isn't
          possible, raise `ftputil.error.ParserError` with a useful error
          message.

        - `ignores_line` should return a true value if the line isn't assumed
          to contain stat information.
        FN)r!rUr �_parserZ_allow_parser_switching)r�parserrrr�
set_parser?s
zFTPHost.set_parsercCsHd}|dkrdSt|�}||}t|d|d|�d|}||S)z�
        Return the given time shift in seconds, but rounded to 15-minute units.
        The argument is also assumed to be given in seconds.
        �N@rrg@g.@)�abs�int)�
time_shift�minuteZabsolute_time_shift�signum�absolute_rounded_time_shiftrrrZ__rounded_time_shift]s��zFTPHost.__rounded_time_shiftcCsrd}d|}t|�|��}|d|kr8tj�d�|���d|}t||�|��|krntj�d�|t|����dS)z�
        Perform sanity checks on the time shift value (given in seconds). If
        the value is invalid, raise a `TimeShiftError`, else simply return
        `None`.
        rY�z!time shift abs({0:.2f} s) > 1 day�zFtime shift ({0:.2f} s) deviates more than {1:d} s from 15-minute unitsN)rZ�_FTPHost__rounded_time_shiftrr#�TimeShiftErrorrPr[)rr\r]�hourr_Zmaximum_deviationrrrZ__assert_valid_time_shiftqs���z!FTPHost.__assert_valid_time_shiftcCs4|�|�|��}||kr0|j��|�|�|_dS)a\
        Set the time shift value.

        By (my) definition, the time shift value is the difference of
        the time zone used in server listings and UTC, i. e.

            time_shift =def= t_server - utc
        <=> t_server = utc + time_shift
        <=> utc = t_server - time_shift

        The time shift is measured in seconds.
        N)�!_FTPHost__assert_valid_time_shiftr\r!rUrbr1)rr\Zold_time_shiftrrr�set_time_shift�s


zFTPHost.set_time_shiftcCs|jS)z�
        Return the time shift between FTP server and client. See the
        docstring of `set_time_shift` for more on this value.
        )r1r3rrrr\�szFTPHost.time_shiftc	Cs�d}z|�|d�}|��Wn.tjjk
rJtj�d�|�����YnXz|j�	|�}|�
|�Wn$tjjk
r�tj�d��YnXt��}||}|dkr�t
j
j|t
jjd�}|j|jdd�}|��|}|�|�d	S)
ai
        Synchronize the local times of FTP client and server. This is necessary
        to let `upload_if_newer` and `download_if_newer` work correctly. If
        `synchronize_times` isn't applicable (see below), the time shift can
        still be set explicitly with `set_time_shift`.

        This implementation of `synchronize_times` requires _all_ of the
        following:

        - The connection between server and client is established.
        - The client has write access to the directory that is current when
          `synchronize_times` is called.

        The common usage pattern of `synchronize_times` is to call it directly
        after the connection is established. (As can be concluded from the
        points above, this requires write access to the login directory.)

        If `synchronize_times` fails, it raises a `TimeShiftError`.
        Z_ftputil_sync_rFz,couldn't write helper file in directory '{}'z)could write helper file but not unlink itid%�)�tz�)�yearN)rSrTrr#rOrcrPrIr�getmtime�unlink�
FTPOSError�time�datetime�
fromtimestamp�timezone�utc�replaceri�	timestamprf)rZhelper_file_name�file_Zserver_time�nowr\Zserver_datetimerrr�synchronize_times�s2�
�
�zFTPHost.synchronize_timescCstj�||||�dS)zX
        Copy data from file-like object `source` to file-like object `target`.
        N)r�
file_transfer�copyfileobj)�source�targetZmax_chunk_size�callbackrrrrx�s
zFTPHost.copyfileobjcCs&tj�|d�}tj�||d�}||fS)z�
        Return a `LocalFile` and `RemoteFile` as source and target,
        respectively.

        The strings `source_path` and `target_path` are the (absolute or
        relative) paths of the local and the remote file, respectively.
        �rb�wb)rrw�	LocalFile�
RemoteFile�r�source_path�target_path�source_file�target_filerrr�
_upload_files�szFTPHost._upload_filescCsZ|dkrtd��tjj|dd�tjj||jd�}|�||�\}}tjj||d|d�dS)	a�
        Upload a file from the local source (name) to the remote target (name).

        If a callable `callback` is given, it's called after every chunk of
        transferred data. The chunk size is a constant defined in
        `file_transfer`. The callback will be called with a single argument,
        the data chunk that was transferred before the callback was called.
        ����path argument `source` is emptyrz�Zpath_argument_namerF�Zconditionalr{N)	�IOErrorrr'�raise_for_empty_pathr(r)r�rw�	copy_file�rryrzr{r�r�rrr�uploads	�zFTPHost.uploadcCsVtjj|dd�|dkr td��tjj||jd�}|�||�\}}tjj||d|d�S)a7
        Upload a file only if it's newer than the target on the remote host or
        if the target file does not exist. See the method `upload` for the
        meaning of the parameters.

        If an upload was necessary, return `True`, else return `False`.

        If a callable `callback` is given, it's called after every chunk of
        transferred data. The chunk size is a constant defined in
        `file_transfer`. The callback will be called with a single argument,
        the data chunk that was transferred before the callback was called.
        ryr�r��path argument `target` is emptyrTr�)	rr'r�r�r(r)r�rwr�r�rrr�upload_if_newers
�zFTPHost.upload_if_newercCs&tj�||d�}tj�|d�}||fS)z�
        Return a `RemoteFile` and `LocalFile` as source and target,
        respectively.

        The strings `source_path` and `target_path` are the (absolute or
        relative) paths of the remote and the local file, respectively.
        r|r})rrwrr~r�rrr�_download_files/szFTPHost._download_filescCsZtjj|dd�|dkr td��tjj||jd�}|�||�\}}tjj||d|d�dS)	a�
        Download a file from the remote source (name) to the local target
        (name).

        If a callable `callback` is given, it's called after every chunk of
        transferred data. The chunk size is a constant defined in
        `file_transfer`. The callback will be called with a single argument,
        the data chunk that was transferred before the callback was called.
        ryr�r�r�rFr�N)	rr'r�r�r(r)r�rwr�r�rrr�download;s
�zFTPHost.downloadcCsV|dkrtd��tjj|dd�tjj||jd�}|�||�\}}tjj||d|d�S)a;
        Download a file only if it's newer than the target on the local host or
        if the target file does not exist. See the method `download` for the
        meaning of the parameters.

        If a download was necessary, return `True`, else return `False`.

        If a callable `callback` is given, it's called after every chunk of
        transferred data. The chunk size is a constant defined in
        `file_transfer`. The callback will be called with a single argument,
        the data chunk that was transferred before the callback was called.
        r�r�rzr�rTr�)	r�rr'r�r(r)r�rwr�r�rrr�download_if_newerNs
�zFTPHost.download_if_newercCsF|��}z|�|�Wn*tjjk
r@tj�d�|���YnXdS)z�
        Raise an `InaccessibleLoginDirError` exception if we can't change to
        the login directory. This test is only reliable if the current
        directory is the login directory.
        z directory '{}' is not accessibleN)rIrMrr#rNZInaccessibleLoginDirErrorrP)rZpresumable_login_dirrrr�#_check_inaccessible_login_directorygs�z+FTPHost._check_inaccessible_login_directoryFc	Csj|��|��}zH|r.|�|�||d�W�.S|j�|�\}}|�|�|||�W�SW5|�|�XdS)a
        Run an FTP command on a path. The return value of the method is the
        return value of the command.

        If `descend_deeply` is true (the default is false), descend deeply,
        i. e. change the directory to the end of the path.
        r�N)r�rIrMrrL)r�commandr�descend_deeply�old_dir�head�tailrrr�_robust_ftp_commandws

zFTPHost._robust_ftp_commandcCs|jS)z4
        Return the current directory path.
        )r*r3rrrrI�szFTPHost.getcwdc	CsPtjj||jd�}tjj�|j�|�W5QRX|j�	|j�
|j|��|_dS)z=
        Change the directory on the host to `path`.
        rN)rr'r(r)r#r$r�cwdrr&rKr*�rrrrrrM�s
�z
FTPHost.chdircCs6tj�|�tjj||jd�}dd�}|�||�dS)z�
        Make the directory path on the remote host. The argument `mode` is
        ignored and only "supported" for similarity with `os.mkdir`.
        rc	Ss$tjj�|j�|�W5QRXdS��Callback function.N)rr#r$rZmkdr�rrrr��s
zFTPHost.mkdir.<locals>.commandN)rr'r�r(r)r��rrrBr�rrr�mkdir�sz
FTPHost.mkdirc	Cstj�|�tjj||jd�}|j�|�}|�|j�}|�	�}z�tdt|��D]�}|j|jj
|d|d��}z|�
|�WnNtjjk
r�z|�|�Wn&tjjk
r�|j�|�s‚YnXYqNX|t|�dkrN|sNtj�d�|��}tj|_|�qNW5|�
|�XdS)at
        Make the directory `path`, but also make not yet existing intermediate
        directories, like `os.makedirs`.

        The value of `mode` is only accepted for compatibility with
        `os.makedirs` but otherwise ignored.

        If `exist_ok` is `False` (the default) and the leaf directory exists,
        raise a `PermanentError` with `errno` 17.
        rrhNzpath {!r} exists)rr'r�r(r)r�abspathrLr0rIrM�range�lenrKr#rNr��isdirrP�errno�EEXIST)	rrrB�exist_ok�directoriesr��indexZnext_directoryZftp_os_errorrrr�makedirs�s.�
zFTPHost.makedirsc	Csrtj�|�tjj||jd�}|j�|�}|�|�rFtj�	d�
|���dd�}z|�
||�W5|j�|�XdS)a

        Remove the _empty_ directory `path` on the remote host.

        Compatibility note:

        Previous versions of ftputil could possibly delete non-empty
        directories as well, - if the server allowed it. This is no longer
        supported.
        rzdirectory '{}' not emptyc	Ss$tjj�|j�|�W5QRXdSr�)rr#r$rZrmdr�rrrr�s
zFTPHost.rmdir.<locals>.commandN)rr'r�r(r)rr��listdirr#rNrPr!rRr��rrr�rrr�rmdir�s

z
FTPHost.rmdirc	Cs�tj�|�tjj||jd�}|j�|�}|j�|�sN|j�|�sN|j�	|�sxdd�}z|�||�W5|j
�|�Xntj
�d��dS)z�
        Remove the file or link given by `path`.

        Raise a `PermanentError` if the path doesn't exist, but maybe raise
        other exceptions depending on the state of the server (e. g. timeout).
        rc	Ss$tjj�|j�|�W5QRXdSr�)rr#r$r�deleter�rrrr�/s
zFTPHost.remove.<locals>.commandz>remove/unlink can only delete files and links, not directoriesN)rr'r�r(r)rr��isfile�islink�existsr!rRr�r#rNr�rrr�removes 
�
�
��zFTPHost.removec		Cs\tj�|�tjj||jd�}|r,dd�}n|dkr>dd�}n|}g}z|�|�}Wn*tjjk
r~||j|t�	��YnX|D]�}|j
�||�}z|�|�j
}Wntjjk
r�d}YnXt�|�r�|�|||�q�z|�|�Wq�tjjk
�r||j|t�	��Yq�Xq�z|�|�Wn,tjjk
�rV||j|t�	��YnXdS)a
        Remove the given remote, possibly non-empty, directory tree. The
        interface of this method is rather complex, in favor of compatibility
        with `shutil.rmtree`.

        If `ignore_errors` is set to a true value, errors are ignored. If
        `ignore_errors` is a false value _and_ `onerror` isn't set, all
        exceptions occurring during the tree iteration and processing are
        raised. These exceptions are all of type `PermanentError`.

        To distinguish between error situations, pass in a callable for
        `onerror`. This callable must accept three arguments: `func`, `path`
        and `exc_info`. `func` is a bound method object, _for example_
        `your_host_object.listdir`. `path` is the path that was the recent
        argument of the respective method (`listdir`, `remove`, `rmdir`).
        `exc_info` is the exception info as it's got from `sys.exc_info`.

        Implementation note: The code is copied from `shutil.rmtree` in
        Python 2.4 and adapted to ftputil.
        rcWsdS)zDo nothing.Nr�rrrr�new_onerror]sz#FTPHost.rmtree.<locals>.new_onerrorNcWs�dS)zRe-raise exception.Nrr�rrrr�dsr)rr'r�r(r)r�r#rN�sys�exc_inforrK�lstat�st_moder�S_ISDIR�rmtreer�r�rl)	rr�
ignore_errors�onerrorr��names�nameZ	full_namerBrrrr�Bs8



zFTPHost.rmtreec
	s�tjj|dd�tjj|dd�tjj|�jd�}tjj|�jd�}�j�|�\}}�j�|�\}}�fdd�}���d|kp�d|k}|r�||krĈ��}	z��	|�|||�W5��	|	�Xn
|||�dS)	zB
        Rename the `source` on the FTP host to `target`.
        ryr�rzrc	s^z&tjj��j�||�W5QRXW5�j�|�}�j�|�}�j�|��j�|�XdS�N)	rr�r!rRrr#r$r�rename)Z
source_argZ
target_argZsource_absolute_pathZtarget_absolute_pathr3rr�rename_with_cleanup�s
z+FTPHost.rename.<locals>.rename_with_cleanup� N)
rr'r�r(r)rrLr�rIrM)
rryrzZsource_headZsource_tailZtarget_headZtarget_tailr�Zpaths_contain_whitespacer�rr3rr��s 
zFTPHost.renamecCsdd�}|j||dd�}|S)zj
        Return a directory listing as made by FTP's `LIST` command as a list of
        strings.
        c	sPg���fdd�}tjj�,�jr4�j�d||�n�j�||�W5QRX�S)r�cs��tjj|�jd��dS)r�rN)rGrr'Zas_strr))�line��linesrrrr{�sz<FTPHost._dir.<locals>._FTPHost_dir_command.<locals>.callbackz-a)rr#r$r2r�dir)rrr{rr�r�_FTPHost_dir_command�s
z*FTPHost._dir.<locals>._FTPHost_dir_commandT)r�)r�)rrr�r�rrr�_dir�s�zFTPHost._dircsBtj�|�|�tjj|�jd�}�j�|�}��fdd�|D�S)z�
        Return a list of directories, files etc. in the directory named `path`.

        If the directory listing from the server can't be parsed with any of
        the available parsers raise a `ParserError`.
        rcsg|]}tj��|�j��qSr)rr'Zsame_string_type_asr))�.0�item�Z
original_pathrrr�
<listcomp>�s�z#FTPHost.listdir.<locals>.<listcomp>)rr'r�r(r)r �_listdir)rr�itemsrr�rr��s�zFTPHost.listdirTcCs,tj�|�tjj||jd�}|j�||�S)a�
        Return an object similar to that returned by `os.lstat`.

        If the directory listing from the server can't be parsed with any of
        the available parsers, raise a `ParserError`. If the directory _can_ be
        parsed and the `path` is _not_ found, raise a `PermanentError`.

        (`_exception_for_missing_path` is an implementation aid and _not_
        intended for use by ftputil clients.)
        r)rr'r�r(r)r Z_lstat�rrZ_exception_for_missing_pathrrrr��sz
FTPHost.lstatcCs,tj�|�tjj||jd�}|j�||�S)a�
        Return info from a "stat" call on `path`.

        If the directory containing `path` can't be parsed, raise a
        `ParserError`. If the directory containing `path` can be parsed but the
        `path` can't be found, raise a `PermanentError`. Also raise a
        `PermanentError` if there's an endless (cyclic) chain of symbolic links
        "behind" the `path`.

        (`_exception_for_missing_path` is an implementation aid and _not_
        intended for use by ftputil clients.)
        r)rr'r�r(r)r r�rrrr�s
zFTPHost.statc
cstjj|dd�tjj||jd�}z|�|�}Wn<tjjk
rl}z|dk	rV||�WY�dSd}~XYnXgg}}|D]0}	|j�	|j�
||	��r�|�|	�q||�|	�q||r�|||fV|D]8}	|j�
||	�}
|s�|j�|
�s�|�
|
|||�EdHq�|�s|||fVdS)z�
        Iterate over directory tree and return a tuple (dirpath, dirnames,
        filenames) on each iteration, like the `os.walk` function (see
        https://docs.python.org/library/os.html#os.walk ).
        �topr�rN)rr'r�r(r)r�r#rlrr�rKrGr��walk)rr��topdownr��followlinksr��err�dirs�nondirsr�rrrrr�s*
zFTPHost.walkcsRtj�|�tjj||jd�}|j�|�}�fdd�}|�||�|j�	|�dS)a�
        Change the mode of a remote `path` (a string) to the integer `mode`.
        This integer uses the same bits as the mode value returned by the
        `stat` and `lstat` commands.

        If something goes wrong, raise a `TemporaryError` or a
        `PermanentError`, according to the status code returned by the server.
        In particular, a non-existent path usually causes a `PermanentError`.
        rc	s,tjj�|j�d��|��W5QRXdS)r�zSITE CHMOD 0{0:o} {1}N)rr#r$r�voidcmdrPr��rBrrr�/s
zFTPHost.chmod.<locals>.commandN)
rr'r�r(r)rr�r�r!rRr�rr�r�chmod!s
z
FTPHost.chmodcCstd��dS)Nzcannot serialize FTPHost object)�	TypeErrorr3rrr�__getstate__7szFTPHost.__getstate__cCs|Sr�rr3rrr�	__enter__=szFTPHost.__enter__cCs|��dS)NF)rT)r�exc_type�exc_val�exc_tbrrr�__exit__BszFTPHost.__exit__)r@NNNN)N)N)N)N)F)N)NF)FN)T)T)TNF)0rrr�__doc__r	r4rr9r?rSrTrX�staticmethodrbrerfr\rvrrwZMAX_COPY_CHUNK_SIZErxr�r�r�r�r�r�r�r�rIrMr�r�r�r�rkr�r�r�r�r�rr�r�r�r�r�rrrrrEsh)2�	�A
H�




'

6$
@0 


)r�rnr�r:rr�rmZ
ftputil.errorrZftputil.fileZftputil.file_transferZftputil.pathZftputil.path_encodingZftputil.sessionZftputil.statZftputil.tool�__all__rZRUNNING_UNDER_PY39_AND_UP�FTPrrrrrr�<module>s&


F1le Man4ger