CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
sftp.cpython-310.pyc71 linesDownload Raw Back to __pycache__
1o

2��Yi#�@s�ddlZddlZddlZddlZddlZddlmZmZddlZddl	m3Z4ddlmZe�
d�ZGdd�de5�Zd	d6�Zdd�ZdS)
�N)�S_ISDIR�S_ISLNK�)�AbstractFileSystem��infer_storage_optionszfsspec.sftpcs�eZdZdZdZ�fdd�Zdd�Zedd��Ze	d	d7��Z8d&d
d�Zd'dd�Zdd�Z
dd�Ze	d(dd��Zd)dd�Zd(dd�Zdd�Zd*d d!�Zd"d#�Zd$d%�Z�ZS)+�SFTPFileSystemz�Files over SFTP/SSH9 10    Peer-to-peer filesystem over SSH using paramiko.11 12    Note: if using this with the ``open`` or ``open_files``, with full URLs,13    there is no way to tell if a path is relative, so all paths are assumed14    to be absolute.15    )�sftp�sshcsB|jrdSt�jdi|��|�dd�|_||_||_|��dS)a�16 17        Parameters18        ----------19        host: str20            Hostname or IP as a string21        temppath: str22            Location on the server to put files, when within a transaction23        ssh_kwargs: dict24            Parameters passed on to connection. See details in25            https://docs.paramiko.org/en/3.3/api/client.html#paramiko.client.SSHClient.connect26            May include port, username, password...27        N�temppathz/tmp�)�_cached�super�__init__�popr�host�28ssh_kwargs�_connect)�selfrr��	__class__r��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\fsspec/implementations/sftp.pyrszSFTPFileSystem.__init__cCsPt�d|j�t��|_|j�t���|jj|jfi|j	��|j�29�|_dS)NzConnecting to SFTP server %s)�logger�debugr�paramikoZ	SSHClient�clientZset_missing_host_key_policyZ
AutoAddPolicy�connectrZ	open_sftp�ftp�rrrrr2s3031zSFTPFileSystem._connectcCst|�dS)N�pathr)�clsrrrr�_strip_protocol9szSFTPFileSystem._strip_protocolcCs$t|�}|�dd�|�dd�|S)Nr�protocol)rr)Zurlpath�outrrr�_get_kwargs_from_urls=sz$SFTPFileSystem._get_kwargs_from_urlsT��cCsR|�|�}t�d|�|�|�rtd|����|r |�|�dS|j�||�dS)NzCreating folder %s�
File exists: )r!rr�exists�FileExistsError�makedirsr�mkdir)rrZcreate_parents�moderrrr*Ds3233zSFTPFileSystem.mkdirFcCs~|�|�r|std|����|�d�}|dd�dkrdnd}|D]}|r<|r.|�d|��n|}|�|�s<|j�||�q!dS)Nr&�/��)r'r(�splitrr*)rr�exist_okr+�parts�new_path�partrrrr)Os3435��zSFTPFileSystem.makedirscCs&|�|�}t�d|�|j�|�dS)NzRemoving folder %s)r!rrr�rmdir�rrrrrr4\s36zSFTPFileSystem.rmdircCs(|�|�}|�|j�|��}||d<|S)N�name)r!�_decode_statr�stat)rrr8rrr�infoas37zSFTPFileSystem.infoNc38Cs�t|j�rd}n39t|j�rd}nd}d|j||j|jtjj|jtj	j40d�tjj|jtj	j41d�d�}|r@d�|�
d�|jg�|d<|S)	N�	directory�link�filer.)�tz)r6�size�type�uid�gid�time�mtimer,r6)r�st_moder�st_size�st_uid�st_gid�datetime�
fromtimestamp�st_atime�timezone�utc�st_mtime�join�rstrip�filename)r8�parent_path�tr#rrrr7gs(424344�45��
zSFTPFileSystem._decode_statcsP�����t�d����fdd��j���D�}|r|Sdd�|D�}t|�S)NzListing folder %scsg|]}��|���qSr)r7��.0r8�rrrr�46<listcomp>�sz%SFTPFileSystem.ls.<locals>.<listcomp>cSsg|]}|d�qS)r6rrSrrrrV�s)r!rrrZlistdir_iter�sorted)rr�detail�stats�pathsrrUr�ls�s47zSFTPFileSystem.lscKs*|�|�}t�d||�|j�||�dS)NzPut file %s into %s)r!rrr�put)r�lpath�rpath�callback�kwargsrrrr\�s48zSFTPFileSystem.putcKs4|�|�rtj|dd�dS|j�|�|�|�dS)NT)r0)�isdir�osr)r�getr!)rr^r]r`rrr�get_file�s49zSFTPFileSystem.get_file�rbcKs�t�d|�|�dd�dur@d�|jtt���g�}|jj	|||r#|ndd�}||_||_50||_t�
t|�|_t�
t|�|_|S|jj	|||rI|ndd�}|S)z�51        block_size: int or None52            If 0, no buffering, if 1, line buffering, if >1, buffer that many53            bytes, if None use default from paramiko.54        zOpening file %sZ55autocommitTFr,�����)�bufsize)rrrcrNr�str�uuid�uuid4r�open�56targetpath�fs�types�57MethodType�
commit_a_file�commit�discard_a_file�discard)rrr+�58block_sizer`Zpath2�frrr�_open�s�zSFTPFileSystem._opencCs*|�|�r
|j�|�dS|j�|�dS�N)rarr4�remover5rrr�_rm�s59zSFTPFileSystem._rmcCs4|�|�}|�|�}t�d||�|j�||�dS)NzRenaming %s into %s)r!rrrZposix_rename)r�old�newrrr�mv�s6061zSFTPFileSystem.mv)Tr%)Fr%rw)F)reN)�__name__�62__module__�__qualname__�__doc__r"rr�classmethodr!�staticmethodr$r*r)r4r9r7r[r\rdrvryr|�
__classcell__rrrrrs*	63646566
6768 6970rcCs|j�|j|j�dSrw)rmr|rrlrrrrrp�srpcCs|j�|j�dSrw)rmryrrrrrrr�srr)rH�loggingrbrnrir8rrrr.r�utilsr�	getLoggerrrrprrrrrr�<module>s71'
Aluode/PerceptionLabPortable · CoolFace