o
    ADi,                     @  s  d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlZg dZdZG dd deedf Ze Zddd'ddZddd(d!d"Ze
d#dd)d%d&Z dS )*a  upath.registry -- registry for file system specific implementations

Retrieve UPath implementations via `get_upath_class`.
Register custom UPath subclasses in one of two ways:

### directly from Python

>>> from upath import UPath
>>> from upath.registry import register_implementation
>>> my_protocol = "myproto"
>>> class MyPath(UPath):
...     pass
>>> register_implementation(my_protocol, MyPath)

### via entry points

```toml
# pyproject.toml
[project.entry-points."universal_pathlib.implementations"]
myproto = "my_module.submodule:MyPath"
```

```ini
# setup.cfg
[options.entry_points]
universal_pathlib.implementations =
    myproto = my_module.submodule:MyPath
```
    )annotationsN)ChainMap)	lru_cache)import_module)entry_points)TYPE_CHECKING)Iterator)MutableMapping)get_filesystem_class)known_implementations)get_upath_classavailable_implementationsregister_implementationz!universal_pathlib.implementationsc                   @  s   e Zd ZU dZi ddddddddddd	d
dd
ddddddddddddddddddddddddddZd ed!< erNd"ed#< d?d&d'Zd@d+d,ZdAd/d0Z	dBd3d4Z
dCd6d7ZdDd9d:ZdEd<d=Zd>S )F	_Registryz&internal registry for UPath subclassesabfsz%upath.implementations.cloud.AzurePathabfssadlazdataz#upath.implementations.data.DataPathfilez$upath.implementations.local.FilePathlocalgcsz#upath.implementations.cloud.GCSPathgshdfsz#upath.implementations.hdfs.HDFSPathhttpz#upath.implementations.http.HTTPPathhttpsmemoryz'upath.implementations.memory.MemoryPaths3z"upath.implementations.cloud.S3Paths3asftpz#upath.implementations.sftp.SFTPPathsshz'upath.implementations.webdav.WebdavPathz'upath.implementations.github.GitHubPathz!upath.implementations.smb.SMBPath)webdavzwebdav+httpzwebdav+httpsgithubsmbzdict[str, str]r   z,MutableMapping[str, str | type[upath.UPath]]_mreturnNonec                 C  sF   t jdkrttd}nt tg }dd |D | _ti | j| _d S )N)   
   )groupc                 S  s   i | ]}|j |qS  )name).0epr*   r*   G/var/www/Datamplify/venv/lib/python3.10/site-packages/upath/registry.py
<dictcomp>`   s    z&_Registry.__init__.<locals>.<dictcomp>)	sysversion_infor   _ENTRY_POINT_GROUPget_entriesr   r   r$   )selfepsr*   r*   r.   __init__[   s
   
z_Registry.__init__itemobjectboolc                 C  s   |t  | j| jv S N)setunionr$   r4   )r5   r8   r*   r*   r.   __contains__c      z_Registry.__contains__strtype[upath.UPath]c                 C  s   | j |}|d u r|| jv r| j|   }| j |< |d u r&t| dt|tr>|dd\}}t|}t	||}|S |}|S )Nz not in registry.   )
r$   r3   r4   loadKeyError
isinstancer@   rsplitr   getattr)r5   r8   fqnmodule_namer+   modclsr*   r*   r.   __getitem__f   s   


z_Registry.__getitem__valuetype[upath.UPath] | strc                 C  sX   t |trt|tjst |tstdt|j|r!|| jv r%t	
  || j|< d S )Nz,expected UPath subclass or FQN-string, got: )rF   type
issubclassupathUPathr@   
ValueError__name__r$   r   cache_clear)r5   r8   rN   r*   r*   r.   __setitem__u   s   
z_Registry.__setitem___Registry__vc                 C  s   t d)Nzremoval is unsupported)NotImplementedError)r5   rX   r*   r*   r.   __delitem__   s   z_Registry.__delitem__intc                 C     t t | j| jS r;   )lenr<   r=   r$   r4   r5   r*   r*   r.   __len__   r?   z_Registry.__len__Iterator[str]c                 C  r\   r;   )iterr<   r=   r$   r4   r^   r*   r*   r.   __iter__   r?   z_Registry.__iter__N)r%   r&   )r8   r9   r%   r:   )r8   r@   r%   rA   )r8   r@   rN   rO   r%   r&   )rX   r@   r%   r&   )r%   r[   )r%   r`   )rU   
__module____qualname____doc__r   __annotations__r   r7   r>   rM   rW   rZ   r_   rb   r*   r*   r*   r.   r   <   sh   
 	






r   rA   F)fallbackrg   r:   r%   	list[str]c                 C  s$   t t}| s|S t h |t tS )zreturn a list of protocols for available implementations

    Parameters
    ----------
    fallback:
        If True, also return protocols for fsspec filesystems without
        an implementation in universal_pathlib.
    )list	_registry_fsspec_known_implementations)rg   implr*   r*   r.   r      s   	r   )clobberprotocolr@   rL   rO   rm   r&   c                C  s@   t d| st| d|s| tv rt| d|t| < dS )a  register a UPath implementation with a protocol

    Parameters
    ----------
    protocol:
        Protocol name to associate with the class
    cls:
        The UPath subclass for the protocol or a str representing the
        full path to an implementation class like package.module.class.
    clobber:
        Whether to overwrite a protocol with the same name; if False,
        will raise instead.
    z^[a-z][a-z0-9+_.]+$z is not a valid URI schemez- is already in registry and clobber is False!N)rematchrT   rj   )rn   rL   rm   r*   r*   r.   r      s
   r   Ttype[upath.UPath] | Nonec                C  s   zt |  W S  tyO   | s'tjdkrddlm} | Y S ddlm} | Y S |s,Y dS zt| }W n ty=   Y Y dS w t	j
d| dtdd	 tj Y S w )
aJ  Return the upath cls for the given protocol.

    Returns `None` if no matching protocol can be found.

    Parameters
    ----------
    protocol:
        The protocol string
    fallback:
        If fallback is False, don't return UPath instances for fsspec
        filesystems that don't have an implementation registered.
    ntr   )WindowsUPath)
PosixUPathNzUPath zr filesystem not explicitly implemented. Falling back to default implementation. This filesystem may not be tested.   )
stacklevel)rj   rE   osr+   upath.implementations.localrs   rt   r
   rT   warningswarnUserWarningrR   rS   )rn   rg   rs   rt   _r*   r*   r.   r      s.   



r   )rg   r:   r%   rh   )rn   r@   rL   rO   rm   r:   r%   r&   )rn   r@   rg   r:   r%   rq   )!re   
__future__r   rw   ro   r0   ry   collectionsr   	functoolsr   	importlibr   importlib.metadatar   typingr   r   r	   fsspec.corer
   fsspec.registryr   rk   rR   __all__r2   r@   r   rj   r   r   r   r*   r*   r*   r.   <module>   s4    O