³ò
C3IHc        	   @   s   d  d k  l Z d  d k l Z d  d k l Z d  d k l Z l Z d  d k	 Td  d k
 Z
 d e f d „  ƒ  YZ d	 „  Z d
 „  Z d „  Z d Z e
 i d e ƒ Z e
 i d e ƒ Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d „  Z d Z d „  Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   Check(   t   BaseVisitor(   t   Warning(   t   astt   walk(   t   *Nt   UnknownErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR      s    c         C   sÎ   t  |  t i ƒ o | |  i ƒ | |  i ƒ Sn” t  |  t i ƒ o | |  i ƒ | |  i ƒ Snc t  |  t i ƒ o | |  i ƒ | |  i ƒ Sn2 t  |  t i ƒ o | |  i ƒ | |  i ƒ Sn t ‚ d  S(   N(	   t
   isinstanceR   t   Addt   leftt   rightt   Mult   Subt   DivR   (   t   nodet   recurse(    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyt   _compute_node
   s    c         C   s+   t  |  t i ƒ o |  i Sn t |  t ƒ S(   sB   Compute a simple forms of constant strings from an expression node(   R	   R   t   Constt   valueR   t   _compute_constant(   R   (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR      s    c         C   sn   t  |  t i ƒ o d t |  i ƒ Sn t  |  t i ƒ o |  i Sn t  |  t i ƒ o d Sn t	 |  t
 ƒ S(   sD   Compute the length of simple forms of tuples from an expression nodet    N(   N(   R	   R   t   Tuplet   Nonet   lent   nodesR   R   t	   BackquoteR   t   _compute_tuple_size(   R   (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR      s    s   ([hlL])?([diouxXeEfFgGcrs%])s,   %(())?[ #+-]*([0-9]*|[*])(|[.](|[*]|[0-9]*))s4   %([(]([a-zA-Z_]+)[)])?[ #+-]*([0-9]*)(|[.](|[0-9]*))t   FormatErrorc           B   s   e  Z d  „  Z RS(   c         C   s   t  i |  ƒ | |  _ d  S(   N(   t	   Exceptiont   __init__t   position(   t   selfR    (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR   .   s    (   R   R   R   (    (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR   -   s   c         C   s  d } g  } x|  i  d | ƒ } | d j  o | Sn t i |  | ƒ } | p | i d ƒ | j oD t i |  | ƒ } | p | i d ƒ | j o t | ƒ ‚ qª n | i d ƒ d j oA | i | i d ƒ | i d ƒ | i d ƒ | i d ƒ f ƒ n | i d ƒ } q | S(   Ni    t   %i   i   i   i   i   (	   t   findt   _TUP_FORMAT_REGEXt   searcht   startt   _DICT_FORMAT_REGEXR   t   groupt   appendt   end(   t   st   post   specst   match(    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyt   _check_format2   s     *t   _GetModc           B   s/   e  Z d  „  Z d „  Z d „  Z e Z e Z RS(   c         C   s   g  |  _  d  S(   N(   t   mods(   R!   (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR   G   s    c         C   s!   |  i  i | ƒ |  i | ƒ d  S(   N(   R1   R)   t   visitChildren(   R!   R   (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyt   visitModI   s    c         C   s   d  S(   N(    (   R!   R   (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyt   visitFunctionM   s    (   R   R   R   R3   R4   t
   visitClasst   visitLambda(    (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR0   F   s
   			c         C   sJ   y t  |  i t ƒ  ƒ i SWn) t j
 o t  |  i t ƒ  ƒ i Sn Xd  S(   N(   R   t   codeR0   R1   t   AttributeErrorR   (   R   (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyt   get_modsQ   s    i
   c         C   s7   |  | | t  !} | t |  ƒ | t  j o d p d S(   Ns   ...R   (   t   _BAD_FORMAT_MAXR   (   R+   R,   t   result(    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyt   _bad_format_strX   s    t   FormatStringCheckc           B   sq   e  Z d  Z e d d ƒ Z e d d ƒ Z e d d ƒ Z e d d ƒ Z e d	 d
 ƒ Z e d d ƒ Z	 d „  Z
 RS(   s#   Look for warnings in format stringss6   Report illegal format specifications in format stringss(   Bad format specifier at position %d (%s)s4   Report unused modifiers for format strings (l, h, L)s   Modifier %s is not necessarysA   Report format strings which use both positional and named formatss.   Cannot mix positional and named formats (%%%s)sB   Report positional format string with the wrong number of argumentssC   Wrong number of arguments supplied for format: %d given %d requiredsI   Report unknown names if locals() or globals() are used for format stringss"   The name "%s" is not defined in %ss2   Report bad constant expressions for format stringss   Error computing constant: %sc         C   s¶  | i  p d  Sn x| i i ƒ  D]Œ} xƒt | i ƒ D]r} g  } y t | i ƒ } t | ƒ } Wn t j
 o1 } | i	 | |  i
 | i t | | i ƒ ƒ nD t j
 o% } | i	 | |  i t | ƒ ƒ n t j
 o n X| p q8 n t | ƒ } xq | D]i \ }	 }
 } } | o | i	 | |  i | ƒ n |
 d j o | d 7} n | d j o | d 7} qqWg  } | D]  } | d o | | d q~q~~ } t | ƒ d j o° yf t | i ƒ } d } t | ƒ t j o t | ƒ } n | | j o | i	 | |  i | | ƒ n Wqªt j
 o qªt j
 o% } | i	 | |  i t | ƒ ƒ qªXq8 t | ƒ t | ƒ j o	d  } t | i t i ƒ o{ t | i i t i ƒ ob | i i i d j o | i } | i } n | i i i d j o | i  i } | i  i } qn | d  j	 oa x^ | D]R } | i! | ƒ p& | i	 | |  i" | | i i i ƒ q.| i# | | ƒ | | <q.Wqªq8 | i	 | |  i$ d | d ƒ q8 Wq" Wd  S(	   NR   i   i    t   localst   varst   globalss   (%s)(   s   localss   vars(%   t	   parseTreet   scopest   valuesR9   R   R   R   R/   R   t   warningt	   badFormatR    R<   t	   TypeErrort   badConstantt   strR   R   t   uselessModifierR   R   t   typet	   TupleTypet   formatCountR   R	   R   t   CallFunct   Namet   namet   defst   usest
   root_scopet   has_keyt   unknownFormatNamet   gett   mixedFormat(   R!   t   filet   unused_checkert   scopet   modt   formatsR+   t   detailt   countRO   t   widtht	   precisiont	   lmodifiert   _[1]t   ft   namest   tt   nt   definesRQ   (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyt   checky   sv    
    4!%	 "(   R   R   t   __doc__R   RE   RI   RV   RL   RT   RG   Rg   (    (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pyR=   \   s   						(   t   pychecker2.CheckR    t   pychecker2.utilR   t   pychecker2.WarningR   t   compilerR   R   t   typest   reR   R   R   R   R   t   _MOD_AND_TYPEt   compileR$   R'   R   R/   R0   R9   R:   R<   R=   (    (    (    s3   C:\py\_spe\plugins\pychecker2\FormatStringChecks.pys   <module>   s*   
				
	
			