CoolFace
Apppublic

Aluode/PerceptionLabPortable

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

2��Yi��@s�ddlmZddlmZmZmZmZmZmZm	Z	ddl3Z4ddlmZddl
mZddlmZddlmZddlmZeeeeee�Ze�dejegeej�Zeed	�Zed5d6ejfdd��ZGd
d�de�ZdS)�)�contextmanager)�	CFUNCTYPE�POINTER�c_int�7c_longlong�c_void_p�cast�create_string_bufferN)�8open_files)�AbstractArchiveFileSystem)�9MemoryFile)�DEFAULT_BLOCK_SIZE�read_set_seek_callback�10NO_OPEN_CB�allc#s��t|��t�t�����fdd�}�fdd�}t�|�}t|�}tr*tj}tj}	nt	j11�tj�}t	j12�
tj�}	t	j13�||��}14t|15|�t�|16d|||	�t	j17�|18�VWd�dS1s`wYdS)z�Read an archive from a seekable file-like object.19 20    The `file` object must support the standard `readinto` and 'seek' methods.21    cs$����}t|tt��}�|d<|S)Nr)�readintorrr)�	archive_p�contextZptrptr�length��bufZbuf_p�file���E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\fsspec/implementations/libarchive.py�	read_func*s22z custom_reader.<locals>.read_funccs��||����S)N)�seek�tell)rr�offset�whence)rrr�	seek_func3sz custom_reader.<locals>.seek_funcN)r	rr�ffiZ
READ_CALLBACK�
SEEK_CALLBACK�new_apirZNO_CLOSE_CB�23libarchive�readZ
OPEN_CALLBACKZVOID_CBZCLOSE_CALLBACKZnew_archive_readrZ	read_openZArchiveRead)r�format_nameZfilter_name�24block_sizerrZread_cbZseek_cbZopen_cbZclose_cbrrrr�
custom_reader!s"�25	2627"�r'csneZdZdZdZdZdZddddef�fdd�	Ze	d	d28��Z29e�fdd��Zd
d�Z
				ddd�Z�ZS)�LibArchiveFileSystemayCompressed archives as a file-system (read-only)30 31    Supports the following formats:32    tar, pax , cpio, ISO9660, zip, mtree, shar, ar, raw, xar, lha/lzh, rar33    Microsoft CAB, 7-Zip, WARC34 35    See the libarchive documentation for further restrictions.36    https://www.libarchive.org/37 38    Keeps file object open while instance lives. It only works in seekable39    file-like objects. In case the filesystem does not support this kind of40    file object, it is recommended to cache locally.41 42    This class is pickleable, but not necessarily thread-safe (depends on the43    platform). See libarchive documentation for details.44    �r#F�rNcs�t�j|fi|��|dkrtd��t|t�r8t|fd|i|p i��}t|�dkr4td|�d|�d���|d}||_|��|_	||_45d	|_d	S)46aB47        Parameters48        ----------49        fo: str or file-like50            Contains ZIP, and must exist. If a str, will fetch file using51            :meth:`~fsspec.open_files`, which must return one file exactly.52        mode: str53            Currently, only 'r' accepted54        target_protocol: str (optional)55            If ``fo`` is a string, this value can be used to override the56            FS protocol inferred from a URL57        target_options: dict (optional)58            Kwargs passed when instantiating the target FS, if ``fo`` is59            a string.60        r*z%Only read from archive files accepted�protocol�zPath "z(" did not resolve to exactly one file: "�"rN)�super�__init__�61ValueError�62isinstance�strr63�lenZof�	__enter__�for&�	dir_cache)�selfr5�modeZtarget_protocolZtarget_optionsr&�kwargs�files��	__class__rrr/^s64�6566zLibArchiveFileSystem.__init__ccsJ�|j�d�t|j|jd��}|VWd�dS1swYdS)Nr)r&)r5rr'r&)r7�arcrrr�
_open_archive�s67�"�z"LibArchiveFileSystem._open_archivecst��|��d�S)N�/)r.�_strip_protocol�lstrip)�cls�pathr;rrr@�sz$LibArchiveFileSystem._strip_protocolc	s�dddddddd��|jdurdSi|_g}|���E}|D]:��js&�js&q|j�d	d68�|�t�j��D����fdd69��D�}�jrFdnd
|d<|��j�||j|d<qWd�n1sbwY|j�dd70�|�|�D��dS)N�pathname�size�ctimer8�uid�gid�mtime)�namerE�createdr8rGrHrIcS�i|]	}||ddd��qS�r�	directory)rJrE�typer��.0�dirnamerrr�71<dictcomp>����z2LibArchiveFileSystem._get_dirs.<locals>.<dictcomp>csi|]72}|t��|��qSr)�getattr)rQ�key��entry�fieldsrrrS�srNrrOrJcSrLrMrrPrrrrS�rT)	r6r>�isdir�isfile�updateZ
_all_dirnames�setrJ�append)r7Z73list_namesr=�frrWr�	_get_dirs�s@�74 7576������zLibArchiveFileSystem._get_dirs�rbTcKs�|�|�}|dkrt�d}|���(}|D]}	|	j|krq|	jdkr#n|	�|	j�D]}77|78}nt�qWd�n1s<wYt|||d�S)Nra�r)�fsrC�data)r@�NotImplementedErrorr>rDrEZ79get_blocksr0r)r7rCr8r&Z80autocommitZ
cache_optionsr9rdr=rX�blockrrr�_open�s$81	828384���zLibArchiveFileSystem._open)raNTN)�__name__�85__module__�__qualname__�__doc__Zroot_markerr+Zcachabler
r/rr>�classmethodr@r`rg�
__classcell__rrr;rr(Hs*�'86,�r()�87contextlibr�ctypesrrrrrrr	r#Zlibarchive.ffir Zfsspecr88Zfsspec.archiverZfsspec.implementations.memoryrZfsspec.utilsr
r!Zc_archive_pZ	check_intr�hasattrr"Z	page_sizer'r(rrrr�<module>s $89�90&
Aluode/PerceptionLabPortable · CoolFace