ó
ži‚Nc           @   s[   d  Z  d d l m Z d d l m Z d d l m Z m Z d „  Z d „  Z d „  Z	 d S(	   s@   gettext message extraction via Babel: http://babel.edgewall.org/iÿÿÿÿ(   t   StringIO(   t   extract_python(   t   lexert	   parsetreec         c   sn   | j  d | j  d d ƒ ƒ } t j |  j ƒ  d | ƒj ƒ  } x( t | j ƒ  | | | ƒ D] } | Vq[ Wd S(   s  Extract messages from Mako templates.

    :param fileobj: the file-like object the messages should be extracted from
    :param keywords: a list of keywords (i.e. function names) that should be
                     recognized as translation functions
    :param comment_tags: a list of translator tags to search for and include
                         in the results
    :param options: a dictionary of additional options (optional)
    :return: an iterator over ``(lineno, funcname, message, comments)`` tuples
    :rtype: ``iterator``
    t   input_encodingt   encodingN(   t   gett   NoneR   t   Lexert   readt   parset   extract_nodest   get_children(   t   fileobjt   keywordst   comment_tagst   optionsR   t   template_nodet	   extracted(    (    s8   /usr/lib/python2.7/dist-packages/mako/ext/babelplugin.pyt   extract   s    c      
   c   sx  g  } t  } xe|  D]]} d	 } | rM t | t j ƒ rM | j j ƒ  rM q n  t | t j ƒ rÛ | j j ƒ  } | r“ | j	 t
 | j | ƒ ƒ q n  x? | D]7 }	 | j |	 ƒ rš t } | j	 t
 | j | ƒ ƒ qš qš Wq n  t | t j ƒ r| j j }
 | j } nnt | t j ƒ r/| j j }
 | j } nDt | t j ƒ rY| j j }
 | j } nt | t j ƒ rz| j j }
 nù t | t j ƒ rÝd j g  | j j ƒ  D] \ } } d | | f ^ q¢ƒ } d | }
 | j } n– t | t j ƒ r| j r
g  } t  } q n  | j }
 n] t | t j ƒ rCg  } t  } | j j }
 n0 t | t j ƒ rd| j j }
 n g  } t  } q | r| d d | j d k  rg  } n g  | D] } | d ^ q¤} t |
 t ƒ rÞ|
 j d d ƒ }
 n  t  |
 ƒ }
 xI t! |
 | | | ƒ D]2 \ } } } } | j | d | | | | f Vq Wg  } t  } | r x% t" | | | | ƒ D] } | Vq^Wq q Wd	 S(
   s'  Extract messages from Mako's lexer node objects

    :param nodes: an iterable of Mako parsetree.Node objects to extract from
    :param keywords: a list of keywords (i.e. function names) that should be
                     recognized as translation functions
    :param comment_tags: a list of translator tags to search for and include
                         in the results
    :param options: a dictionary of additional options (optional)
    :return: an iterator over ``(lineno, funcname, message, comments)`` tuples
    :rtype: ``iterator``
    s   , s   %s=%ss   {%s}iÿÿÿÿi    i   t   asciit   backslashreplaceN(#   t   FalseR   t
   isinstanceR   t   Textt   contentt   stript   Commentt   textt   extendt   _split_commentt   linenot
   startswitht   Truet   DefTagt   function_declt   codet   nodest   BlockTagt	   body_declt   CallTagt   PageTagt   CallNamespaceTagt   joint
   attributest	   iteritemst   ControlLinet   isendt   Codet
   Expressiont   unicodet   encodeR    R   R   (   R%   R   R   R   t   translator_commentst   in_translator_commentst   nodet   child_nodest   valuet   comment_tagR$   t   keyt   valt   attribst   commentR   t   funcnamet   messagest   python_translator_commentsR   (    (    s8   /usr/lib/python2.7/dist-packages/mako/ext/babelplugin.pyR   "   s„    	2
		%c         C   s3   g  t  | j ƒ  ƒ D] \ } } |  | | f ^ q S(   sv   Return the multiline comment at lineno split into a list of comment line
    numbers and the accompanying comment line(   t	   enumeratet
   splitlines(   R   R=   t   indext   line(    (    s8   /usr/lib/python2.7/dist-packages/mako/ext/babelplugin.pyR   €   s    N(
   t   __doc__R    t   babel.messages.extractR   t   makoR   R   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/mako/ext/babelplugin.pyt   <module>   s   		^