a
    ©ˆc¯  ã                   @   sx   d Z zddlmZ W n ey2   ddlmZ Y n0 ddlmZmZ ddlm	Z	 ddl
mZ ee	ƒG dd„ deƒƒZd	S )
z, A resource protocol for package resources. é    )Úfiles)Ú	HasTraitsÚprovidesé   )ÚIResourceProtocol)ÚNoSuchResourceErrorc                   @   s   e Zd ZdZdd„ ZdS )ÚPackageResourceProtocola   A resource protocol for package resources.

    This protocol uses 'importlib.resources' to find and access resources.

    An address for this protocol is a string in the form::

        'package/resource'

    e.g::

        'acme.ui.workbench/preferences.ini'
    c                 C   s`   |  d¡^}}|r|st|ƒ‚zt|ƒj|Ž  d¡}W n$ ttttt	fyZ   t|ƒ‚Y n0 |S )z? Return a readable file-like object for the specified address. ú/Úrb)
Úsplitr   r   ÚjoinpathÚopenÚModuleNotFoundErrorÚ	TypeErrorÚFileNotFoundErrorÚIsADirectoryErrorÚPermissionError)ÚselfÚaddressÚpackageÚresource_pathÚf© r   ún/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/envisage/resource/package_resource_protocol.pyÚfile.   s    û
zPackageResourceProtocol.fileN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   N)r   Úimportlib.resourcesr   ÚImportErrorZimportlib_resourcesZ
traits.apir   r   Zi_resource_protocolr   Zno_such_resource_errorr   r   r   r   r   r   Ú<module>
   s   