
    ob4                     T   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.                  r<d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jF                  d      Z$ejJ                   G d de             Z&y)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                      e Zd ZdZg dZefdZd ZeZd Z	e
d        Ze
d        Zd Ze
d	        Ze
d
        Zd%dZd Zd Zd Zd%dZd Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Z ed         Z!ed!        Z"ed"        Z#ed#        Z$ed$        Z%y)&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                 p    || _         || _        t        | j                   j                               | _        y)z3Create a resource info object from a raw info dict.N)r   r   	frozensetkeysr   )selfraw_infoto_datetimes      )/usr/lib/python3/dist-packages/fs/info.py__init__zInfo.__init__1   s)     '#DHHMMO4    c                     | j                   rdj                  | j                        S dj                  | j                        S )Nz
<dir '{}'>z<file '{}'>)is_dirformatnamer    s    r#   __str__zInfo.__str__8   s3    ;;&&tyy11 ''		22r%   c                 6    | j                   t        |dd       k(  S )Nr   )r   getattr)r    others     r#   __eq__zInfo.__eq__A   s    xx75%666r%   c                      y N r    ts     r#   _make_datetimezInfo._make_datetimeE        	r%   c                      y r1   r2   r3   s     r#   r5   zInfo._make_datetimeJ   r6   r%   c                 *    || j                  |      S y r1   )r   r3   s     r#   r5   zInfo._make_datetimeO   s    =$$Q''r%   c                      y r1   r2   )r    	namespacekeys      r#   getzInfo.getV   r6   r%   c                      y r1   r2   r    r:   r;   defaults       r#   r<   zInfo.get[   r6   r%   Nc                 d    	 | j                   |   j                  ||      S # t        $ r |cY S w xY 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   r<   KeyErrorr>   s       r#   r<   zInfo.get`   s7    "	88I&**388 	N	s   ! //c                 6    || j                   vrt        |      y)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    r:   s     r#   _require_namespacezInfo._require_namespacev   s      DHH$&y11 %r%   c                 0    | j                  |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

        _writer2   )r<   )r    r:   r;   
_writeables       r#   is_writeablezInfo.is_writeable   s"    H XXi26
j  r%   c                     || 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   rC   s     r#   has_namespacezInfo.has_namespace   s     DHH$$r%   c                 ^    t        t        | j                        |xs | j                        S )z+Create a copy of this resource info object.)r"   )r   r   r   r   )r    r"   s     r#   copyz	Info.copy   s%     HTXX&K4T4CTCTUUr%   c                 .    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_paths     r#   	make_pathzInfo.make_path   s     Hdii((r%   c                 B    t        t        | j                  dd            S )z`str`: the resource name.basicr)   )r   r	   r<   r*   s    r#   r)   z	Info.name   s     D$((7F344r%   c                     | j                  dd      }|j                  d      r|j                  d      dk(  ry|j                  d      \  }}}|rd|z   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
            ''

        rQ   r)   .r    )r<   
startswithcount
rpartition)r    r)   basenamedotexts        r#   suffixzInfo.suffix   sX      xx(??3DJJsOq$8!__S1#ssSy'R'r%   c                     | j                  dd      }|j                  d      r|j                  d      dk(  rg S |j                  d      dd D cg c]  }d|z   	 c}S c c}w )z`List`: a list of any suffixes in the name.

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

        rQ   r)   rS   r   N)r<   rU   rV   split)r    r)   r[   s      r#   suffixeszInfo.suffixes   s[     xx(??3DJJsOq$8I+/::c?12+>?f???s   Ac                 t    | j                  dd      }|j                  d      r|S |j                  d      d   S )z`str`: the name minus any suffixes.

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

        rQ   r)   rS   r   )r<   rU   r]   )r    r)   s     r#   stemz	Info.stem   s8     xx(??3Kzz#q!!r%   c                 B    t        t        | j                  dd            S )z6`bool`: `True` if the resource references a directory.rQ   r'   r   boolr<   r*   s    r#   r'   zInfo.is_dir  s     D$((7H566r%   c                 D    t        t        | j                  dd             S )z1`bool`: `True` if the resource references a file.rQ   r'   rb   r*   s    r#   is_filezInfo.is_file
  s     dhhw9:::r%   c                 N    | j                  d       | j                  ddd      duS )z,`bool`: `True` if the resource is a symlink.linktargetNrD   r<   r*   s    r#   is_linkzInfo.is_link  s*     	'xx$/t;;r%   c                 \    | j                  d       t        | j                  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   )rD   r   r<   r*   s    r#   rm   z	Info.type  s*     		*DHHY:;;r%   c                 j    | j                  d       | j                  | j                  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.

        rl   accessedrD   r5   r<   r    _times     r#   ro   zInfo.accessed&  2     		*##DHHY
$CDr%   c                 j    | j                  d       | j                  | j                  dd            }|S )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.

        rl   modifiedrp   rq   s     r#   ru   zInfo.modified6  rs   r%   c                 j    | j                  d       | j                  | j                  dd            }|S )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.

        rl   createdrp   rq   s     r#   rw   zInfo.createdF  s2     		*##DHHY	$BCr%   c                 j    | j                  d       | j                  | j                  dd            }|S )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.

        rl   metadata_changedrp   rq   s     r#   ry   zInfo.metadata_changedV  s3     		*##DHHY8J$KLr%   c                 h    | j                  d       | j                  dd      }|y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)rD   r<   r   )r    _perm_namesr|   s      r#   r|   zInfo.permissionsf  s;     	)hhx7!+.r%   c                 d    | j                  d       t        t        | j                  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.

        rl   size)rD   r   intr<   r*   s    r#   r   z	Info.sizey  s*     		*C)V455r%   c                 H    | j                  d       | j                  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{   userri   r*   s    r#   r   z	Info.user  s#     	)xx&))r%   c                 H    | j                  d       | j                  dd      S )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{   uidri   r*   s    r#   r   zInfo.uid  #     	)xx%((r%   c                 H    | j                  d       | j                  dd      S )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{   groupri   r*   s    r#   r   z
Info.group  s#     	)xx'**r%   c                 H    | j                  d       | j                  dd      S )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{   gidri   r*   s    r#   r   zInfo.gid  r   r%   c                 H    | j                  d       | j                  dd      S )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.

        rg   rh   ri   r*   s    r#   rh   zInfo.target  s#     	'xx))r%   r1   )&__name__
__module____qualname____doc__	__slots__r   r$   r+   __repr__r/   r
   r5   r<   rD   rH   rJ   rL   rO   propertyr)   r[   r^   r`   r'   re   rj   rm   ro   ru   rw   ry   r|   r   r   r   r   r   rh   r2   r%   r#   r   r      s     6I-> 53 H7        ,
2%!N%V
) 5 5
 ( (* @ @ " " 7 7
 ; ;
 < < < <          $ 6 6 * * ) ) + + ) ) * *r%   r   )'r   
__future__r   r   r   typingr   sixrL   r   _typingr	   r
   enumsr   errorsr   pathr   r|   r   timer   TYPE_CHECKINGr   r   r   r   r   r   r   objectRawInfor   
ToDatetimeTypeVarr   python_2_unicode_compatibler   r2   r%   r#   <module>r      s    I H   
  #  (  $ #	DD!dGD&L112G3%/*JsA   s*6 s* !s*r%   