o
    pf4                     @   s  d Z ddlmZmZmZ ddlZddlmZ ddlZddlm	Z	 ddl
mZ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 ejruddlmZmZmZmZmZmZ ddlmZ eeeeef f Z ee!gef Z"e#dZ$ej%G dd deZ&dS )z0Container for filesystem resource informations.
    )absolute_importprint_functionunicode_literalsN)cast)deepcopy   )Textoverload)ResourceType)MissingInfoNamespace)join)Permissions)epoch_to_datetime)AnyCallableListMappingOptionalUnion)datetimeTc                   @   s  e Zd ZdZg dZefddZdd ZeZdd Z	e
d	d
 Ze
dd
 Zdd
 Ze
dd Ze
dd ZdBddZdd Zdd Zdd ZdBddZdd Zedd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Zed6d7 Z ed8d9 Z!ed:d; Z"ed<d= Z#ed>d? Z$ed@dA Z%dS )CInfoa  Container for :ref:`info`.

    Resource information is returned by the following methods:

         * `~fs.base.FS.getinfo`
         * `~fs.base.FS.scandir`
         * `~fs.base.FS.filterdir`

    Arguments:
        raw_info (dict): A dict containing resource info.
        to_datetime (callable): A callable that converts an
            epoch time to a datetime object. The default uses
            `~fs.time.epoch_to_datetime`.

    )raw_to_datetime
namespacesc                 C   s    || _ || _t| j  | _dS )z3Create a resource info object from a raw info dict.N)r   r   	frozensetkeysr   )selfraw_infoto_datetime r    @/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/info.py__init__1   s   zInfo.__init__c                 C   s   | j r	d| jS d| jS )Nz
<dir '{}'>z<file '{}'>)is_dirformatnamer   r    r    r!   __str__8   s   zInfo.__str__c                 C   s   | j t|dd kS )Nr   )r   getattr)r   otherr    r    r!   __eq__A   s   zInfo.__eq__c                 C      d S Nr    r   tr    r    r!   _make_datetimeE      zInfo._make_datetimec                 C   r+   r,   r    r-   r    r    r!   r/   J   r0   c                 C   s   |d ur	|  |S d S r,   )r   r-   r    r    r!   r/   O   s   
c                 C   r+   r,   r    )r   	namespacekeyr    r    r!   getV   r0   zInfo.getc                 C   r+   r,   r    r   r1   r2   defaultr    r    r!   r3   [   r0   Nc                 C   s,   z
| j | ||W S  ty   | Y S w )a  Get a raw info value.

        Arguments:
            namespace (str): A namespace identifier.
            key (str): A key within the namespace.
            default (object, optional): A default value to return
                if either the namespace or the key within the namespace
                is not found.

        Example:
            >>> info = my_fs.getinfo("foo.py", namespaces=["details"])
            >>> info.get('details', 'type')
            2

        )r   r3   KeyErrorr4   r    r    r!   r3   `   s
   c                 C   s   || j vr	t|dS )zCheck if the given namespace is present in the info.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the given namespace is not
                present in the info.

        N)r   r   r   r1   r    r    r!   _require_namespacev   s   
	zInfo._require_namespacec                 C   s   |  |dd}||v S )a  Check if a given key in a namespace is writable.

        When creating an `Info` object, you can add a ``_write`` key to
        each raw namespace that lists which keys are writable or not.

        In general, this means they are compatible with the `setinfo`
        function of filesystem objects.

        Arguments:
            namespace (str): A namespace identifier.
            key (str): A key within the namespace.

        Returns:
            bool: `True` if the key can be modified, `False` otherwise.

        Example:
            Create an `Info` object that marks only the ``modified`` key
            as writable in the ``details`` namespace::

                >>> now = time.time()
                >>> info = Info({
                ...     "basic": {"name": "foo", "is_dir": False},
                ...     "details": {
                ...         "modified": now,
                ...         "created": now,
                ...         "_write": ["modified"],
                ...     }
                ... })
                >>> info.is_writeable("details", "created")
                False
                >>> info.is_writeable("details", "modified")
                True

        _writer    )r3   )r   r1   r2   
_writeabler    r    r!   is_writeable   s   $zInfo.is_writeablec                 C   s
   || j v S )zCheck if the resource info contains a given namespace.

        Arguments:
            namespace (str): A namespace identifier.

        Returns:
            bool: `True` if the namespace was found, `False` otherwise.

        )r   r7   r    r    r!   has_namespace   s   
zInfo.has_namespacec                 C   s   t t| j|p	| jdS )z+Create a copy of this resource info object.)r   )r   r   r   r   )r   r   r    r    r!   copy   s   z	Info.copyc                 C   s   t || jS )zMake a path by joining ``dir_path`` with the resource name.

        Arguments:
            dir_path (str): A path to a directory.

        Returns:
            str: A path to the resource.

        )r   r%   )r   dir_pathr    r    r!   	make_path   s   zInfo.make_pathc                 C      t t| ddS )z`str`: the resource name.basicr%   )r   r   r3   r&   r    r    r!   r%         z	Info.namec                 C   sH   |  dd}|dr|ddkrdS |d\}}}|r"d| S dS )aE  `str`: the last component of the name (with dot).

        In case there is no suffix, an empty string is returned.

        Example:
            >>> info = my_fs.getinfo("foo.py")
            >>> info.suffix
            '.py'
            >>> info2 = my_fs.getinfo("bar")
            >>> info2.suffix
            ''

        rA   r%   .r    )r3   
startswithcount
rpartition)r   r%   basenamedotextr    r    r!   suffix   s
   zInfo.suffixc                 C   sD   |  dd}|dr|ddkrg S dd |ddd D S )z`List`: a list of any suffixes in the name.

        Example:
            >>> info = my_fs.getinfo("foo.tar.gz")
            >>> info.suffixes
            ['.tar', '.gz']

        rA   r%   rC   r   c                 S   s   g | ]}d | qS )rC   r    ).0rK   r    r    r!   
<listcomp>   s    z!Info.suffixes.<locals>.<listcomp>N)r3   rE   rF   splitr   r%   r    r    r!   suffixes   s   zInfo.suffixesc                 C   s(   |  dd}|dr|S |dd S )z`str`: the name minus any suffixes.

        Example:
            >>> info = my_fs.getinfo("foo.tar.gz")
            >>> info.stem
            'foo'

        rA   r%   rC   r   )r3   rE   rN   rO   r    r    r!   stem   s   
z	Info.stemc                 C   r@   )z6`bool`: `True` if the resource references a directory.rA   r#   r   boolr3   r&   r    r    r!   r#     rB   zInfo.is_dirc                 C   s   t t| dd S )z1`bool`: `True` if the resource references a file.rA   r#   rR   r&   r    r    r!   is_file
  s   zInfo.is_filec                 C   s   |  d | dddduS )z,`bool`: `True` if the resource is a symlink.linktargetNr8   r3   r&   r    r    r!   is_link  s   
zInfo.is_linkc                 C   s   |  d t| dddS )z`~fs.enums.ResourceType`: the type of the resource.

        Requires the ``"details"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the 'details'
                namespace is not in the Info.

        detailstyper   )r8   r
   r3   r&   r    r    r!   rZ        
z	Info.typec                 C       |  d | | dd}|S )z`~datetime.datetime`: the resource last access time, or `None`.

        Requires the ``"details"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"details"``
                namespace is not in the Info.

        rY   accessedr8   r/   r3   r   _timer    r    r!   r]   &     
zInfo.accessedc                 C   r\   )z`~datetime.datetime`: the resource last modification time, or `None`.

        Requires the ``"details"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"details"``
                namespace is not in the Info.

        rY   modifiedr^   r_   r    r    r!   rb   6  ra   zInfo.modifiedc                 C   r\   )z`~datetime.datetime`: the resource creation time, or `None`.

        Requires the ``"details"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"details"``
                namespace is not in the Info.

        rY   createdr^   r_   r    r    r!   rc   F  ra   zInfo.createdc                 C   r\   )z`~datetime.datetime`: the resource metadata change time, or `None`.

        Requires the ``"details"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"details"``
                namespace is not in the Info.

        rY   metadata_changedr^   r_   r    r    r!   rd   V  ra   zInfo.metadata_changedc                 C   s.   |  d | dd}|du rdS t|}|S )z`Permissions`: the permissions of the resource, or `None`.

        Requires the ``"access"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"access"``
                namespace is not in the Info.

        accesspermissionsN)r8   r3   r   )r   _perm_namesrf   r    r    r!   rf   f  s   
zInfo.permissionsc                 C   s   |  d tt| ddS )z`int`: the size of the resource, in bytes.

        Requires the ``"details"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"details"``
                namespace is not in the Info.

        rY   size)r8   r   intr3   r&   r    r    r!   rh   y  r[   z	Info.sizec                 C      |  d | ddS )z`str`: the owner of the resource, or `None`.

        Requires the ``"access"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"access"``
                namespace is not in the Info.

        re   userrW   r&   r    r    r!   rk        
z	Info.userc                 C   rj   )z`int`: the user id of the resource, or `None`.

        Requires the ``"access"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"access"``
                namespace is not in the Info.

        re   uidrW   r&   r    r    r!   rm     rl   zInfo.uidc                 C   rj   )z`str`: the group of the resource owner, or `None`.

        Requires the ``"access"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"access"``
                namespace is not in the Info.

        re   grouprW   r&   r    r    r!   rn     rl   z
Info.groupc                 C   rj   )z`int`: the group id of the resource, or `None`.

        Requires the ``"access"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"access"``
                namespace is not in the Info.

        re   gidrW   r&   r    r    r!   ro     rl   zInfo.gidc                 C   rj   )z`str`: the link target (if resource is a symlink), or `None`.

        Requires the ``"link"`` namespace.

        Raises:
            ~fs.errors.MissingInfoNamespace: if the ``"link"``
                namespace is not in the Info.

        rU   rV   rW   r&   r    r    r!   rV     rl   zInfo.targetr,   )&__name__
__module____qualname____doc__	__slots__r   r"   r'   __repr__r*   r	   r/   r3   r8   r;   r<   r=   r?   propertyr%   rK   rP   rQ   r#   rT   rX   rZ   r]   rb   rc   rd   rf   rh   rk   rm   rn   ro   rV   r    r    r    r!   r      sx    




'


















r   )'rs   
__future__r   r   r   typingr   sixr=   r   _typingr   r	   enumsr
   errorsr   pathr   rf   r   timer   TYPE_CHECKINGr   r   r   r   r   r   r   objectRawInfori   
ToDatetimeTypeVarr   python_2_unicode_compatibler   r    r    r    r!   <module>   s(     
