σ
ίΘ[c           @` s,  d  Z  d d l m Z m Z m Z m Z d d l m Z d d l Z d d l	 Z	 d d d d	 d
 g Z
 d   Z e	 j d  d k r d d l m Z n	 d   Z d   Z y d d l m Z Wn0 e k
 rμ d d l m Z e d    Z n Xe	 j d d k re	 j d  d k  rd   Z n	 d   Z d S(   u  
Simple utility functions and bug fixes for compatibility with all supported
versions of Python.  This module should generally not be used directly, as
everything in `__all__` will be imported into `astropy.utils.compat` and can
be accessed from there.

Includes the following fixes:

* The `contextlib.suppress` context manager, which is only available in Python
  3.4 or greater.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   sixNu   invalidate_cachesu   override__dir__u   suppressu   possible_filenameu   namedtuple_asdictc         C` sM   t  |  t j  r t St  |  t j  rI t j d k oG t j d  d k St S(   u  
    Determine if the ``filename`` argument is an allowable type for a filename.

    In Python 3.3 use of non-unicode filenames on system calls such as
    `os.stat` and others that accept a filename argument was deprecated (and
    may be removed outright in the future).

    Therefore this returns `True` in all cases except for `bytes` strings in
    Windows on Python >= 3.3.
    u   win32i   i   (   i   i   (	   t
   isinstanceR   t	   text_typet   Truet   binary_typet   syst   platformt   version_infot   False(   t   filename(    (    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyt   possible_filename   s    i   (   t   invalidate_cachesc           C` s   d  S(   N(   t   None(    (    (    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyt   <lambda>5   s    c         ` sV   t  j d  d k  r4 t j      f d    } n t j      f d    } | S(   uΔ  
    When overriding a __dir__ method on an object, you often want to
    include the "standard" members on the object as well.  This
    decorator takes care of that automatically, and all the wrapped
    function needs to do is return a list of the "special" members
    that wouldn't be found by the normal Python means.

    Example
    -------

    @override__dir__
    def __dir__(self):
        return ['special_method1', 'special_method2']
    i   i   c         ` sl   t    } x* |  j j   D] } | j t |   q W| j t j |  j   | j   |    t |  S(   N(	   t   sett	   __class__t   mrot   updatet   dirR   t   iterkeyst   __dict__t   sorted(   t   selft   memberst   cls(   t   f(    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyt   override__dir__wrapperJ   s    	c         ` s2   t  t j |    } | j   |    t |  S(   N(   R   t   objectt   __dir__R   R   (   R   R   (   R   (    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyR   U   s    (   i   i   (   R	   R   t	   functoolst   wraps(   R   R   (    (   R   s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyt   override__dir__8   s    !(   t   suppress(   t   contextmanagerc          g` s!   y	 d VWn |  k
 r n Xd S(   u2  A context manager for ignoring exceptions.  Equivalent to::

            try:
                <body>
            except exceptions:
                pass

        Example::

            >>> import os
            >>> with suppress(OSError):
            ...     os.remove('file-that-does-not-exist')

        N(    (   t
   exceptions(    (    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyR$   c   s    	i   c         ` s     f d     j  D S(   u  
        The same as ``namedtuple._adict()``, but fixed to work even when
        namedtuple is a subclass of another namedtuple

        Parameters
        ----------
        namedtuple : collections.namedtuple
            The named tuple to get the dict of
        c         ` s"   i  |  ] } t    |  |  q S(    (   t   getattr(   t   .0t   fi(   t
   namedtuple(    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pys
   <dictcomp>   s   	 (   t   _fields(   R*   (    (   R*   s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyt   namedtuple_asdict   s    
c         C` s
   |  j    S(   uΈ   
        The same as ``namedtuple._adict()``.

        Parameters
        ----------
        namedtuple : collections.namedtuple
            The named tuple to get the dict of
        (   t   _asdict(   R*   (    (    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyR,      s    	(   i   i   (   i   i   i   (   t   __doc__t
   __future__R    R   R   R   t   externR   R!   R	   t   __all__R   R   t	   importlibR   R#   t
   contextlibR$   t   ImportErrorR%   R,   (    (    (    s8   lib/python2.7/site-packages/astropy/utils/compat/misc.pyt   <module>   s&   "				&&