a
    SG5dü  ã                   @   s0   d Z ddlZddlZddlmZ efdd„ZdS )ac  
pkgdata is a simple, extensible way for a package to acquire data file
resources.

The getResource function is equivalent to the standard idioms, such as
the following minimal implementation::

    import sys, os

    def getResource(identifier, pkgname=__name__):
        pkgpath = os.path.dirname(sys.modules[pkgname].__file__)
        path = os.path.join(pkgpath, identifier)
        return open(os.path.normpath(path), mode='rb')

When a __loader__ is present on the module given by __name__, it will defer
getResource to its get_data implementation and return it as a file-like
object (such as StringIO).
é    N)ÚStringIOc              	   C   s–   t j| }t|ddƒ}|du r&tdƒ‚tj tj |¡| ¡}t|ddƒ}|dur„z| |¡}W n tt	fyt   Y n0 t
| d¡ƒS ttj |¡dƒS )a>  
    Acquire a readable object for a given package name and identifier.
    An IOError will be raised if the resource cannot be found.

    For example::

        mydata = get_resource('mypkgdata.jpg').read()

    Note that the package name must be fully qualified, if given, such
    that it would be found in sys.modules.

    In some cases, getResource will return a real file object.  In that
    case, it may be useful to use its name attribute to get the path
    rather than use it as a file-like object.  For example, you may
    be handing data off to a C API.
    Ú__file__Nz%r has no __file__!Ú
__loader__zutf-8Úrb)ÚsysÚmodulesÚgetattrÚOSErrorÚosÚpathÚjoinÚdirnameÚget_dataÚAttributeErrorr   ÚdecodeÚopenÚnormpath)Ú
identifierZpkgnameÚmodÚfnr   ÚloaderÚdata© r   úS/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/utilities/pkgdata.pyÚget_resource   s    
r   )Ú__doc__r   r
   Úior   Ú__name__r   r   r   r   r   Ú<module>   s   