o
    Q `0                     @   s  d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm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mZ ejr}ddlmZ ddlmZmZmZmZmZ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   )join)ResourceType)MissingInfoNamespace)Permissions)epoch_to_datetime)overloadText)datetime)AnyCallableListMappingOptionalUnion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
            :func:`~fs.time.epoch_to_datetime`.

    )raw_to_datetime
namespacesc                 C   s    || _ || _t| j  | _dS )z<Create a resource info object from a raw info dict.
        N)r   r   	frozensetkeysr   )selfZraw_infoto_datetime r   )/usr/lib/python3/dist-packages/fs/info.py__init__2   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__:   s   zInfo.__str__c                 C   s   | j t|dd kS )Nr   )r   getattr)r   otherr   r   r    __eq__C   s   zInfo.__eq__c                 C      d S Nr   r   tr   r   r    _make_datetimeG      zInfo._make_datetimec                 C   r*   r+   r   r,   r   r   r    r.   L   r/   c                 C   s   |d ur	|  |S d S r+   )r   r,   r   r   r    r.   Q   s   
c                 C   r*   r+   r   )r   	namespacekeyr   r   r    getX   r/   zInfo.getc                 C   r*   r+   r   r   r0   r1   defaultr   r   r    r2   ]   r/   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.get('access', 'permissions')
            ['u_r', 'u_w', '_wx']

        )r   r2   KeyErrorr3   r   r   r    r2   b   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   r0   r   r   r    _require_namespacew   s   
	zInfo._require_namespacec                 C   s   |  |dd}||v S )a5  Check if a given key in a namespace is writable.

        Uses `~fs.base.FS.setinfo`.

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

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

        Z_writer   )r2   )r   r0   r1   Z
_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   r6   r   r   r    has_namespace   s   
zInfo.has_namespacec                 C   s   t t| j|p	| jdS )z4Create 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   Z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   r2   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 )z`str`: the last component of the name (including dot), or an
        empty string if there is no suffix.

        Example:
            >>> info
            <info 'foo.py'>
            >>> info.suffix
            '.py'
        r=   r$   .r    )r2   
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
            <info 'foo.tar.gz'>
            >>> info.suffixes
            ['.tar', '.gz']
        r=   r$   r?   r   c                 S   s   g | ]}d | qS )r?   r   ).0rG   r   r   r    
<listcomp>   s    z!Info.suffixes.<locals>.<listcomp>N)r2   rA   rB   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
            <info 'foo.tar.gz'>
            >>> info.stem
            'foo'

        r=   r$   r?   r   )r2   rA   rJ   rK   r   r   r    stem   s   
z	Info.stemc                 C   r<   )z?`bool`: `True` if the resource references a directory.
        r=   r"   r   boolr2   r%   r   r   r    r"      r>   zInfo.is_dirc                 C   s   t t| dd S )z:`bool`: `True` if the resource references a file.
        r=   r"   rN   r%   r   r   r    is_file   s   zInfo.is_filec                 C   s   |  d | dddduS )z5`bool`: `True` if the resource is a symlink.
        linktargetNr7   r2   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   )r7   r	   r2   r%   r   r   r    rV        
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.

        rU   accessedr7   r.   r2   r   Z_timer   r   r    rY        
zInfo.accessedc                 C   rX   )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.

        rU   modifiedrZ   r[   r   r   r    r]   #  r\   zInfo.modifiedc                 C   rX   )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.

        rU   createdrZ   r[   r   r   r    r^   3  r\   zInfo.createdc                 C   rX   )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.

        rU   metadata_changedrZ   r[   r   r   r    r_   C  r\   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)r7   r2   r   )r   Z_perm_namesra   r   r   r    ra   S  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.

        rU   size)r7   r   intr2   r%   r   r   r    rb   f  rW   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.

        r`   userrS   r%   r   r   r    re   u     
z	Info.userc                 C   rd   )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.

        r`   uidrS   r%   r   r   r    rg     rf   zInfo.uidc                 C   rd   )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.

        r`   grouprS   r%   r   r   r    rh     rf   z
Info.groupc                 C   rd   )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.

        r`   gidrS   r%   r   r   r    ri     rf   zInfo.gidc                 C   rd   )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.

        rQ   rR   rS   r%   r   r   r    rR     rf   zInfo.targetr+   )&__name__
__module____qualname____doc__	__slots__r   r!   r&   __repr__r)   r   r.   r2   r7   r8   r9   r:   r;   propertyr$   rG   rL   rM   r"   rP   rT   rV   rY   r]   r^   r_   ra   rb   re   rg   rh   ri   rR   r   r   r   r    r      sx    























r   )'rm   Z
__future__r   r   r   typingr   r:   r   Zsixpathr   Zenumsr	   errorsr
   ra   r   timer   Z_typingr   r   ZTYPE_CHECKINGr   r   r   r   r   r   r   objectZRawInforc   Z
ToDatetimeTypeVarr   Zpython_2_unicode_compatibler   r   r   r   r    <module>   s,     
