ó
î%![c           @   sx   d  Z  d d l Z d d l m Z d Z y e j e j f Z Wn e k
 r] e j f Z n Xd e	 f d     YZ
 d S(   s   Small AST optimizations.iĸĸĸĸN(   t   nodest   ASTPeepholeOptimizerc           B   s   e  Z d  Z d d  Z RS(   s;   Class for applying small optimizations to generate new AST.c            s{  g  } | } xô t  | t j  rt  | j t j  s: d St  | j j t j  si t  | j t j  rm d St  | j t  s d S| j	 | j j
  | j } t  | t j  r t  | j t  r t  | j t  r | j	 | j j
  | j	 | j j
  Pq q W| sd St | d    t   f d   | d D  rAd S    j t |   } t j | | j | j |  } | S(   sŲ  Optimize BinOps with string Const nodes on the lhs.

        This fixes an infinite recursion crash, where multiple
        strings are joined using the addition operator. With a
        sufficient number of such strings, astroid will fail
        with a maximum recursion limit exceeded. The
        function will return a Const node with all the strings
        already joined.
        Return ``None`` if no AST node can be obtained
        through optimization.
        i    c         3   s   |  ] } t  |    Vq d  S(   N(   t
   isinstance(   t   .0t   element(   t   known(    s2   lib/python2.7/site-packages/astroid/astpeephole.pys	   <genexpr>D   s   i   N(   R   t   _astt   BinOpt   leftt   Nonet   opt   Addt   rightt   _TYPESt   appendt   st   typet   anyt   joint   reversedR    t   Constt   linenot
   col_offset(   t   selft   nodet   parentt	   ast_nodest   currentt   valuet   newnode(    (   R   s2   lib/python2.7/site-packages/astroid/astpeephole.pyt   optimize_binop   s6    	N(   t   __name__t
   __module__t   __doc__R	   R   (    (    (    s2   lib/python2.7/site-packages/astroid/astpeephole.pyR      s   (   R   (   R!   R   t   astroidR    t   __all__t   Strt   BytesR   t   AttributeErrort   objectR   (    (    (    s2   lib/python2.7/site-packages/astroid/astpeephole.pyt   <module>   s   