
    7Th]                       S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
JrJrJrJrJrJr  S SKJr  S SKJr  S SKJrJr  S S	KJrJrJrJr  \R:                  " S
5      r " S S5      r " S S\ 5      r!          SS jr"S r#S r$\RJ                  " SS5      r&       SS jr' S        S!S jjr(S r)S r*S r+S r,      S"S jr-S r. " S S\R^                  5      r0g)#    )annotationsN)	has_magic)Path)	BaseCache
BlockCache
BytesCache	MMapCacheReadAheadCachecaches)compr)conf)
filesystemget_filesystem_class)_unstrip_protocolbuild_name_functioninfer_compressionstringify_pathfsspecc                  `    \ rS rSrSr     SS jrS rS rS rS r	\
S	 5       rS
 rS rSrg)OpenFile    a  
File-like object to be used in a context

Can layer (buffered) text-mode and compression over any file-system, which
are typically binary-only.

These instances are safe to serialize, as the low-level file object
is not created until invoked using ``with``.

Parameters
----------
fs: FileSystem
    The file system to use for opening the file. Should be a subclass or duck-type
    with ``fsspec.spec.AbstractFileSystem``
path: str
    Location to open
mode: str like 'rb', optional
    Mode of the opened file
compression: str or None, optional
    Compression to apply
encoding: str or None, optional
    The encoding to use if opened in text mode.
errors: str or None, optional
    How to handle encoding errors if opened in text mode.
newline: None or str
    Passed to TextIOWrapper in text mode, how to handle line endings.
autoopen: bool
    If True, calls open() immediately. Mostly used by pickle
pos: int
    If given and autoopen is True, seek to this location immediately
Nc                z    Xl         X l        X0l        [        X$5      U l        XPl        X`l        Xpl        / U l        g N)	fspathmodeget_compressioncompressionencodingerrorsnewlinefobjects)selfr   r   r   r   r   r    r!   s           C/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/core.py__init__OpenFile.__init__A   s6     		*4=     c                    [         U R                  U R                  U R                  U R                  U R
                  U R                  U R                  44$ r   )r   r   r   r   r   r   r    r!   r#   s    r$   
__reduce__OpenFile.__reduce__T   sG    				  
 	
r'   c                "    SU R                    S3$ )Nz<OpenFile 'z'>)r   r)   s    r$   __repr__OpenFile.__repr__b   s    TYYKr**r'   c                   U R                   R                  SS5      R                  SS5      S-   n U R                  R                  U R                  US9nU/U l        U R                  b7  [        U R                     nU" X!S   S9nU R                  R                  U5        SU R                   ;  aD  [        X R                  U R                  U R                  S9nU R                  R                  U5        U R                  S   $ ! [
         a7  n[        U R                  5      (       a  [        SU R                  5      Uee S nAff = f)	Nt b)r   a   %s not found. The URL contains glob characters: you maybe needed
to pass expand=True in fsspec.open() or the storage_options of 
your library. You can also set the config value 'open_expand'
before import, or fsspec.core.DEFAULT_EXPAND at runtime, to True.r   )r   r    r!   )r   replacer   openr   FileNotFoundErrorr   r"   r   r   appendPickleableTextIOWrapperr   r    r!   )r#   r   fecompresss        r$   	__enter__OpenFile.__enter__e   s#   yy  b)11#r:S@	TYYT2A 'T--.Ha)AMM  #dii'MM$++t||A MM  #}}R  3 ! 		##'X II  		s   $D 
E2E  Ec                $    U R                  5         g r   )close)r#   argss     r$   __exit__OpenFile.__exit__   s    

r'   c                B    [        U R                  U R                  5      $ r   )r   r   r   r)   s    r$   	full_nameOpenFile.full_name   s     DGG44r'   c                "    U R                  5       $ )zMaterialise this as a real open file without context

The OpenFile object should be explicitly closed to avoid enclosed file
instances persisting. You must, therefore, keep a reference to the OpenFile
during the life of the file-like it generates.
)r<   r)   s    r$   r5   OpenFile.open   s     ~~r'   c                    [        U R                  5       HD  nSU R                  ;  a!  UR                  (       d  UR	                  5         UR                  5         MF     U R                  R                  5         g)z#Close all encapsulated file objectsrN)reversedr"   r   closedflushr?   clear)r#   r9   s     r$   r?   OpenFile.close   sK    $--(A$))#AHH	GGI ) 	r'   )r   r   r    r"   r   r   r!   r   )rbNNNN)__name__
__module____qualname____firstlineno____doc__r%   r*   r-   r<   rA   propertyrD   r5   r?   __static_attributes__ r'   r$   r   r       sQ    H &
+!@ 5 5 r'   r   c                  T   ^  \ rS rSrSrSSS.U 4S jjrS rS rU 4S	 jrS
 r	Sr
U =r$ )	OpenFiles   ao  List of OpenFile instances

Can be used in a single context, which opens and closes all of the
contained files. Normal list access to get the elements works as
normal.

A special case is made for caching filesystems - the files will
be down/uploaded together at the start or end of the context, and
this may happen concurrently, if the target filesystem supports it.
rO   Nr   r   c               F   > Xl         X l        / U l        [        TU ]  " U6   g r   )r   r   filessuperr%   )r#   r   r   r@   	__class__s       r$   r%   OpenFiles.__init__   s!    	
$r'   c                X   U R                   c  [        S5      eU R                   n [        US5      (       a"  UR                  U 5      U l        U R                  $ [        US5      (       a  UR                   b  UR                   nOOMa  U  Vs/ s H  o"R                  5       PM     sn$ s  snf )NzContext has already been used	open_manyr   )r   
ValueErrorhasattrrb   r]   r<   )r#   r   ss      r$   r<   OpenFiles.__enter__   s    77?<==WWr;''\\$/
zz!r4  RUU%6UU  (,,t!t,,,s   B'c                :   U R                   nU  Vs/ s H  o3R                  " U6 PM       nSU R                  ;  a\   [        US5      (       a  UR	                  U R
                  5        g [        US5      (       a  UR                   b  UR                   nOg M[  g s  snf )NrI   rb   r   )r   rA   r   rd   commit_manyr]   )r#   r@   r   re   s       r$   rA   OpenFiles.__exit__   s    WW$()DqT	D)dii2{++NN4::.2t$$):B    	*s   Bc                   > [         TU ]  U5      n[        U[        5      (       a  [	        X R
                  U R                  S9$ U$ )Nr[   )r^   __getitem__
isinstanceslicerY   r   r   )r#   itemoutr_   s      r$   rk   OpenFiles.__getitem__   s9    g!$'dE""SyyTWW==
r'   c                     S[        U 5       S3$ )Nz	<List of z OpenFile instances>)lenr)   s    r$   r-   OpenFiles.__repr__   s    3t9+%9::r'   )r]   r   r   )rP   rQ   rR   rS   rT   r%   r<   rA   rk   r-   rV   __classcell__r_   s   @r$   rY   rY      s2    	 $(D    - ; ;r'   rY   c                j   [        U UUUUUU
S9u  pnUR                  S:X  a  Xl        OGSU;  aA  U	(       a:  U Vs1 s H  oR                  U5      iM     nnU H  n UR	                  USS9  M     [        U Vs/ s H  n[        UUUUUUUS9PM     snUUS9$ s  snf ! [
         a     MS  f = fs  snf )a	  Given a path or paths, return a list of ``OpenFile`` objects.

For writing, a str path must contain the "*" character, which will be filled
in by increasing numbers, e.g., "part*" ->  "part1", "part2" if num=2.

For either reading or writing, can instead provide explicit list of paths.

Parameters
----------
urlpath: string or list
    Absolute or relative filepath(s). Prefix with a protocol like ``s3://``
    to read from alternative filesystems. To read from multiple files you
    can pass a globstring or a list of paths, with the caveat that they
    must all have the same protocol.
mode: 'rb', 'wt', etc.
compression: string or None
    If given, open file using compression codec. Can either be a compression
    name (a key in ``fsspec.compression.compr``) or "infer" to guess the
    compression from the filename suffix.
encoding: str
    For text mode only
errors: None or str
    Passed to TextIOWrapper in text mode
name_function: function or None
    if opening a set of files for writing, those files do not yet exist,
    so we need to generate their names by formatting the urlpath for
    each sequence number
num: int [1]
    if writing mode, number of files we expect to create (passed to
    name+function)
protocol: str or None
    If given, overrides the protocol found in the URL.
newline: bytes or None
    Used for line terminator in text mode. If None, uses system default;
    if blank, uses no translation.
auto_mkdir: bool (True)
    If in write mode, this will ensure the target directory exists before
    writing, by calling ``fs.mkdirs(exist_ok=True)``.
expand: bool
**kwargs: dict
    Extra options that make sense to a particular storage connection, e.g.
    host, port, username, password, etc.

Examples
--------
>>> files = open_files('2015-*-*.csv')  # doctest: +SKIP
>>> files = open_files(
...     's3://bucket/2015-*-*.csv.gz', compression='gzip'
... )  # doctest: +SKIP

Returns
-------
An ``OpenFiles`` instance, which is a list of ``OpenFile`` objects that can
be used as a single context

Notes
-----
For a full list of the available protocols and the implementations that
they map across to see the latest online documentation:

- For implementations built into ``fsspec`` see
  https://filesystem-spec.readthedocs.io/en/latest/api.html#built-in-implementations
- For implementations in separate packages see
  https://filesystem-spec.readthedocs.io/en/latest/api.html#other-known-implementations
)numname_functionstorage_optionsprotocolexpandfilerI   T)exist_ok)r   r   r   r    r!   r[   )get_fs_token_pathsrz   
auto_mkdir_parentmakedirsPermissionErrorrY   r   )urlpathr   r   r   r    rx   rw   rz   r!   r   r{   kwargsr   fs_tokenpathsr   parentsparents                     r$   
open_filesr      s    ^ -#B% 
{{f"	DZ056::d#6FFT2 
  	
  '! 	
   7 # 	
s   BB:B0
B-,B-c                j   SSK Jn  SU ;   at  [        R                  " S5      n/ nU R	                  S5       HF  nSU;   d  UR                  U5      (       a  UR                  U5        M2  UR                  US-   5        MH     OU /n/ nS nUR                  5       n[        U5       H  nUR                  SS 5      =(       d    [        U5      S   =(       d    Sn	[        U	5      n
U
R                  U5      nUR                  U	0 5      nXS   L a  UR                  U5        [        S	0 UR                  5        VVs0 s H  u  pX;  d
  XU   :w  d  M  X_M     snnDUD6nU
R!                  U5      nSU;  a  [#        X5      (       a  UnUR                  XU45        UnM     UR%                  5         U$ s  snnf )
Nr   )CachingFileSystemz::z.*[^a-z]+.*://rz   r|   target_protocolrW   )fsspec.implementations.cachedr   recompilesplitmatchr7   copyrJ   popsplit_protocolr   _get_kwargs_from_urlsupdatedictitems_strip_protocol
issubclassreverse)r   r   r   xbitspro   previous_bitbitrz   clsextra_kwargskwskvkws                   r$   	_un_chainr   K  s   ?t|JJ}%D!AzQWWQZZAAI&	 " v
CL[[]F~::j$/S>#3Fq3ISV"8,005jj2&q'>JJv 
 , 2 2 4T 4QRVtqt 4T

 !!#&B&:c+M+MC

C2&'   KKMJ Us   6F/F/c                   [        U 5      n 1 SknUR                  5        VVs0 s H  u  p4X2;  d  M  X4_M     nnn[        X5      n0 n[        [	        U5      5       HC  u  pxUu  pnU[        U5      S-
  :X  a  [        S0 UDUD6nM+  [        S0 UDUD6US'   XS'   XS'   ME     US   u  pn[        U
40 UD6nX4$ s  snnf )a  
Turn fully-qualified and potentially chained URL into filesystem instance

Parameters
----------
url : str
    The fsspec-compatible URL
**kwargs: dict
    Extra options that make sense to a particular storage connection, e.g.
    host, port, username, password, etc.

Returns
-------
filesystem : FileSystem
    The new filesystem discovered from ``url`` and created with
    ``**kwargs``.
urlpath : str
    The file-systems-specific URL for ``url``.
>   rw   r   r    r{   r!   r   r   rx      target_optionsr   for   rW   )r   r   r   	enumeraterJ   rr   r   r   )urlr   known_kwargsr   r   chaininkwargsichurlsrz   r   r   _r   s                  r$   	url_to_fsr   q  s    ( 
C	L  &||~G~tq1Fdad~FGc"EH8E?+E
Q-b-H-H%)%;B%;(%;!"&."# , !8Gq	H	)	)B; Hs
   B:B:open_expandFc                p    Uc  [         OUn[        SU /UUUUUUUS.UD6n	U	(       d  [        U 5      eU	S   $ )a  Given a path or paths, return one ``OpenFile`` object.

Parameters
----------
urlpath: string or list
    Absolute or relative filepath. Prefix with a protocol like ``s3://``
    to read from alternative filesystems. Should not include glob
    character(s).
mode: 'rb', 'wt', etc.
compression: string or None
    If given, open file using compression codec. Can either be a compression
    name (a key in ``fsspec.compression.compr``) or "infer" to guess the
    compression from the filename suffix.
encoding: str
    For text mode only
errors: None or str
    Passed to TextIOWrapper in text mode
protocol: str or None
    If given, overrides the protocol found in the URL.
newline: bytes or None
    Used for line terminator in text mode. If None, uses system default;
    if blank, uses no translation.
expand: bool or None
    Whether to regard file paths containing special glob characters as needing
    expansion (finding the first match) or absolute. Setting False allows using
    paths which do embed such characters. If None (default), this argument
    takes its value from the DEFAULT_EXPAND module variable, which takes
    its initial value from the "open_expand" config value at startup, which will
    be False if not set.
**kwargs: dict
    Extra options that make sense to a particular storage connection, e.g.
    host, port, username, password, etc.

Examples
--------
>>> openfile = open('2015-01-01.csv')  # doctest: +SKIP
>>> openfile = open(
...     's3://bucket/2015-01-01.csv.gz', compression='gzip'
... )  # doctest: +SKIP
>>> with openfile as f:
...     df = pd.read_csv(f)  # doctest: +SKIP
...

Returns
-------
``OpenFile`` object.

Notes
-----
For a full list of the available protocols and the implementations that
they map across to see the latest online documentation:

- For implementations built into ``fsspec`` see
  https://filesystem-spec.readthedocs.io/en/latest/api.html#built-in-implementations
- For implementations in separate packages see
  https://filesystem-spec.readthedocs.io/en/latest/api.html#other-known-implementations
)r   r   r   r   r    rz   r!   r{   r   rW   )DEFAULT_EXPANDr   r6   )
r   r   r   r   r    rz   r!   r{   r   ro   s
             r$   r5   r5     s\    H  &~^6F
 
	
 
C ((q6Mr'   c                   SU;  a  [        S5      e[        U 4SU0UD6n[        US   R                  SS5      (       d  [        S5      eU nU Vs/ s H  oUR                  PM     nnSSS5        [        U [        5      (       a  [        U 5      (       a  [        U [        5      (       a  WS   $ W$ s  snf ! , (       d  f       NT= f)	a#  Open file(s) which can be resolved to local

For files which either are local, or get downloaded upon open
(e.g., by file caching)

Parameters
----------
url: str or list(str)
mode: str
    Must be read mode
storage_options:
    passed on to FS for or used by open_files (e.g., compression)
rI   z(Can only ensure local files when readingr   r   
local_fileFzOopen_local can only be used on a filesystem which has attribute local_file=TrueN)	rc   r   getattrr   namerl   strr   r   )r   r   ry   ofr]   r9   r   s          r$   
open_localr     s    $ $CDD	C	6d	6o	6B2a588\511-
 	
 
u!&'A' 
3Ys^^
38M8MQxL ( 
s   B6B1&B61B66
Cc                `    US:X  a  [        U 5      nUb  U[        ;  a  [        SU S35      eU$ )NinferzCompression type z not supported)r   r   rc   )r   r   s     r$   r   r     s<    g'0;e#;,[MHIIr'   c                    [        U 5      n SU ;   a&  U R                  SS5      u  p[        U5      S:  a  X4$ U R                  S5      (       a  U R                  SS5      $ SU 4$ )zReturn protocol, path pairr   r   zdata::N)r   r   rr   
startswith)r   rz   r   s      r$   r   r   $  sf    W%G ua0x=1>!'""}}S!$$=r'   c                T    [        U 5      u  p[        U5      nUR                  U 5      $ )zCReturn only path part of full URL, according to appropriate backend)r   r   r   )r   rz   r   r   s       r$   strip_protocolr   1  s)     )KH
x
(Cw''r'   c                   / n[        U 5      n SU;   a  [        S U  5       5      S:  a  [        S5      e[        U[	        U 5      5      nU  H7  nSU;   a  UR                  [        XdU5      5        M&  UR                  U5        M9     [	        U5      U:  a  USU nU$ U  HF  n[        U5      (       a"  UR                  UR                  U5      5        M5  UR                  U5        MH     U$ )a  Expand paths if they have a ``*`` in them (write mode) or any of ``*?[]``
in them (read mode).

:param paths: list of paths
mode: str
    Mode in which to open files.
num: int
    If opening in writing mode, number of files we expect to create.
fs: filesystem object
name_function: callable
    If opening in writing mode, this callable is used to generate path
    names. Names are generated for each partition by
    ``urlpath.replace('*', name_function(partition_index))``.
:return: list of paths
wc              3  6   #    U  H  nS U;   d  M  Sv   M     g7f)*r   NrW   ).0r   s     r$   	<genexpr>)expand_paths_if_needed.<locals>.<genexpr>L  s     ,%Q3!8qq%s   
	r   z;When writing data, only one filename mask can be specified.r   N)
listsumrc   maxrr   extend_expand_pathsr7   r   glob)r   r   rw   r   rx   expanded_paths	curr_paths          r$   expand_paths_if_neededr   8  s      NKE
d{,%,,q0M  #s5z"Ii%%mIc&RS%%i0  ~$+DS1N  I##%%bggi&89%%i0  r'   c                   [        U [        [        [        45      (       a0  U (       d  [	        S5      e[        [        [        U 5      5      5      nO[        U 5      nU=(       d    0 nU(       a  XTS'   [        Xt=(       d    0 5      n0 n	[        [        U5      5       HC  u  pUu  pnU
[        U5      S-
  :X  a  [        S0 UDU	D6n	M+  [        S0 UDU	D6U	S'   XS'   XS'   ME     US   u  pn[        U40 U	D6n[        U [        [        [        45      (       av  U  Vs/ s H$  n[        [        U5      U=(       d    0 5      S   PM&     nn[        U Vs1 s H  nUS   iM
     sn5      S:  a  [	        SU 5      eU Vs/ s H  nUS   PM
     nnOUR                  U5      n[        U[        [        [        45      (       a7  U(       a  [        XUUU5      nO[        U[        5      (       d  [        U5      nOlS	U;   d  S
U;   a  U(       a  [!        XU5      nOLSU;   aC  [#        UR%                  U5      5       Vs/ s H  nUR'                  U5      (       a  M  UPM     nnOU/nUUR(                  U4$ s  snf s  snf s  snf s  snf )aJ  Filesystem, deterministic token, and paths from a urlpath and options.

Parameters
----------
urlpath: string or iterable
    Absolute or relative filepath, URL (may include protocols like
    ``s3://``), or globstring pointing to data.
mode: str, optional
    Mode in which to open files.
num: int, optional
    If opening in writing mode, number of files we expect to create.
name_function: callable, optional
    If opening in writing mode, this callable is used to generate path
    names. Names are generated for each partition by
    ``urlpath.replace('*', name_function(partition_index))``.
storage_options: dict, optional
    Additional keywords to pass to the filesystem class.
protocol: str or None
    To override the protocol specifier in the URL
expand: bool
    Expand string paths for writing, assuming the path is a directory
zempty urlpath sequencerz   r   r   r   r   r   z$Protocol mismatch getting fs from %sr   r   r   rW   )rl   r   tuplesetrc   r   nextiterr   r   rJ   rr   r   r   r   r   r   sortedr   isdir	_fs_token)r   r   rw   rx   ry   rz   r{   urlpath0r   r   r   r   r   nested_protocolr   r   r   r   upchainspcr9   s                         r$   r~   r~   g  sR   > 'D%-..566!$tG}"56!'*%+O&.
#h 526EH8E?+$&!rE
Q-b-H-H%)%;B%;(%;!"&5"# , qEQ	H	)	)B'D%-..LS
LSqInQ')>B?BG 	 
 ("1()A-CWMM!()2A)""5)%$s+,,*5ROEE4((KE4K3$;F!%<EE\ &rwwu~ 6J 61bhhqkQ 6EJEGEr||U""+
 )) Ks   +I0I5;I:7I?I?c           	        [        U [        5      (       a  U R                  S5      S:  a  [        S5      eSU ;  a   [        R
                  R                  U S5      n Uc  [        US-
  5      n[        U5       Vs/ s H  o0R                  SU" U5      5      PM     nnU[        U5      :w  a  [        R                  S5        U$ [        U [        [        45      (       a  [        U 5      U:X  d   e[        U 5      nU$ [        S5      es  snf )Nr   r   z.Output path spec must contain exactly one '*'.z*.partzqIn order to preserve order between partitions paths created with ``name_function`` should sort to partition orderzPath should be either
1. A list of paths: ['foo.json', 'bar.json', ...]
2. A directory: 'foo/
3. A path with a '*' in it: 'foo.*.json')rl   r   countrc   osr   joinr   ranger4   r   loggerwarningr   r   rr   )r   rx   rw   r   r   s        r$   r   r     s    $::c?QMNN_77<<h/D /a8M>CCjIjc=#34jIF5M!NN* L 
D5$-	(	(4yCT
 L 7
 	
 Js   :!Dc                  @   ^  \ rS rSrSr     SU 4S jjrS rSrU =r$ )r8   i  zTextIOWrapper cannot be pickled. This solves it.

Requires that ``buffer`` be pickleable, which all instances of
AbstractBufferedFile are.
c                H   > XX4XV4U l         [        TU ]  " U R                   6   g r   )r@   r^   r%   )r#   bufferr   r    r!   line_bufferingwrite_throughr_   s          r$   r%    PickleableTextIOWrapper.__init__  s$     f~T	$))$r'   c                &    [         U R                  4$ r   )r8   r@   r)   s    r$   r*   "PickleableTextIOWrapper.__reduce__  s    &		11r'   )r@   )NNNFF)	rP   rQ   rR   rS   rT   r%   r*   rV   rt   ru   s   @r$   r8   r8     s(     
%2 2r'   r8   )
rO   Nutf8NNr   NNTT)rO   Nr   NNNN)rO   )r   z#str | list[str] | Path | list[Path]r   r   ry   r   returnzstr | list[str])rO   r   NNNT)1
__future__r   iologgingr   r   r   r   pathlibr   fsspec.cachingr   r   r   r	   r
   r   fsspec.compressionr   fsspec.configr   fsspec.registryr   r   fsspec.utilsr   r   r   r   	getLoggerr   r   r   rY   r   r   r   getr   r5   r   r   r   r   r   r~   r   TextIOWrapperr8   rW   r'   r$   <module>r     s>   " 	  	 	    %  <  
		8	${ {|7; 7;x 
	pf#L/d -/
 
Rn 	,
  	B
(,b 
	K#\<2b.. 2r'   