ó
’›V]c           @   sä   d  Z  d d l Z d d l m Z e ƒ  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d	 k ry e	 Z e Z e
 Z nI d
 „  Z d d d „  ƒ  YZ e e ƒ  ƒ Z e e ƒ Z d „  Z d „  Z d „  Z d „  Z e d „ Z d S(   s   
A static version of getattr.
This is a backport of the Python 3 code with a little bit of additional
information returned to enable Jedi to make decisions.
iÿÿÿÿN(   t
   py_versionc         C   sC   i  } y t  j |  d ƒ } Wn t k
 r/ n Xt j | | t ƒ S(   Nt   __dict__(   t   objectt   __getattribute__t   AttributeErrort   dictt   gett	   _sentinel(   t   objt   attrt   instance_dict(    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   _check_instance   s    c         C   sY   xR t  |  ƒ D]D } t t | ƒ ƒ t k r y | j | SWqQ t k
 rM qQ Xq q Wt S(   N(   t   _static_getmrot   _shadowed_dictt   typeR   R   t   KeyError(   t   klassR	   t   entry(    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   _check_class   s    c         C   s'   y t  |  ƒ Wn t k
 r" t SXt S(   N(   R   t	   TypeErrort   Falset   True(   R   (    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   _is_type!   s
    c         C   sŠ   t  j d } xv t |  ƒ D]h } y | j | ƒ d } Wn t k
 rJ q Xt  | ƒ t j k o{ | j d k o{ | j | k s | Sq Wt	 S(   NR   (
   R   R   R   t   __get__R   t   typest   GetSetDescriptorTypet   __name__t   __objclass__R   (   R   t	   dict_attrR   t
   class_dict(    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   _shadowed_dict_newstyle)   s    c         C   s   t  j d j |  ƒ S(   Nt   __mro__(   R   R   R   (   R   (    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   _static_getmro_newstyle8   s    i   c         C   s,   t  |  ƒ t k r" t |  d t ƒ St |  ƒ S(   s<  
        In Python 2 __dict__ is not overwritable:

            class Foo(object): pass
            setattr(Foo, '__dict__', 4)

            Traceback (most recent call last):
              File "<stdin>", line 1, in <module>
            TypeError: __dict__ must be a dictionary object

        It applies to both newstyle and oldstyle classes:

            class Foo(object): pass
            setattr(Foo, '__dict__', 4)
            Traceback (most recent call last):
              File "<stdin>", line 1, in <module>
            AttributeError: attribute '__dict__' of 'type' objects is not writable

        It also applies to instances of those objects. However to keep things
        straight forward, newstyle classes always use the complicated way of
        accessing it while oldstyle classes just use getattr.
        R   (   R   t   _oldstyle_class_typet   getattrR   R   (   R   (    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyR   A   s    t   _OldStyleClassc           B   s   e  Z RS(    (   R   t
   __module__(    (    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyR#   \   s   c         C   s)   t  j |  d ƒ } | t k r% |  j S| S(   Nt	   __class__(   R   R   t   _oldstyle_instance_typeR%   (   R   t   type_(    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt	   _get_typeb   s    c            s5   t  |  ƒ t k r+ ‡  f d †  ‰  ˆ  |  ƒ St |  ƒ S(   Nc         3   s9   |  Vx- |  j  D]" } x ˆ  | ƒ D] } | Vq" Wq Wd S(   sÜ   
                Oldstyle mro is a really simplistic way of look up mro:
                https://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style-classes-in-python
                N(   t	   __bases__(   R   t   baset
   yield_from(   t   oldstyle_mro(    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyR,   k   s    (   R   R!   R    (   R   (    (   R,   sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyR   i   s    

c         C   s   t  t |  ƒ | ƒ t k	 S(   N(   R   R(   R   (   R   t   name(    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   _safe_hasattrz   s    c         C   s   t  |  d ƒ p t  |  d ƒ S(   Nt   __set__t
   __delete__(   R.   (   R   (    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   _safe_is_data_descriptor~   s    c         C   s€  t  } t |  ƒ s` t |  ƒ } t | ƒ } | t  k sK t | ƒ t j k rf t |  | ƒ } qf n |  } t | | ƒ } | t  k	 rµ | t  k	 rµ t	 | d ƒ rµ t
 | ƒ rµ | t f Sn  | t  k	 rË | t f S| t  k	 rê | t	 | d ƒ f S|  | k rZxa t t | ƒ ƒ D]J } t t | ƒ ƒ t  k r	y | j | t f SWqSt k
 rOqSXq	q	Wn  | t  k	 rp| t f St | ƒ ‚ d S(   s‹  Retrieve attributes without triggering dynamic lookup via the
       descriptor protocol,  __getattr__ or __getattribute__.

       Note: this function may not be able to retrieve all attributes
       that getattr can fetch (like dynamically created attributes)
       and may find attributes that getattr can't (like descriptors
       that raise AttributeError). It can also return descriptor objects
       instead of instance members in some cases. See the
       documentation for details.

       Returns a tuple `(attr, is_get_descriptor)`. is_get_descripter means that
       the attribute is a descriptor that has a `__get__` attribute.
    R   N(   R   R   R(   R   R   R   t   MemberDescriptorTypeR   R   R.   R1   R   R   R   R   R   R   (   R   R	   t   defaultt   instance_resultR   R   t   klass_resultR   (    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   getattr_static‚   s4    !

(    (   t   __doc__R   t   jedi._compatibilityR    R   R   R   R   R   R   R    R   R   R(   R   R#   R&   R!   R.   R1   R6   (    (    (    sD   lib/python2.7/site-packages/jedi/evaluate/compiled/getattr_static.pyt   <module>   s*   				
									