ó
Ąź\c           @  sT   d  Z  d d l m Z m Z d d l Z d d l Z d d l m Z e	 d  Z
 d S(   sc  
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).
i˙˙˙˙(   t   print_functiont   divisionN(   t	   cStringIOc         C  sŐ   t  j | } t | d d  } | d k r: t d   n  t j j t j j |  |   } t | d d  } | d k	 rź y | j	 |  } Wn t t
 f k
 rĽ qź Xt | j d   Sn  t t j j |  d  S(   s?  
    Acquire a readable object for a given package name and identifier.
    An IOError will be raised if the resource can not 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.
    t   __file__s   %r has no __file__!t
   __loader__s   utf-8t   rbN(   t   syst   modulest   getattrt   Nonet   IOErrort   ost   patht   joint   dirnamet   get_datat   AttributeErrort   StringIOt   decodet   opent   normpath(   t
   identifiert   pkgnamet   modt   fnR   t   loadert   data(    (    s6   lib/python2.7/site-packages/sympy/utilities/pkgdata.pyt   get_resource   s    !(   t   __doc__t
   __future__R    R   R   R   t   sympy.core.compatibilityR   R   t   __name__R   (    (    (    s6   lib/python2.7/site-packages/sympy/utilities/pkgdata.pyt   <module>   s
   