ó
®â0_c           @  s!  d  d l  m Z d  d l Z d  d l Z d  d l m Z m Z m Z m Z m	 Z	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d d l m Z m Z e j d	 ƒ Z d
 „  Z e j d ƒ Z e j d ƒ Z e j d ƒ Z e j d ƒ Z e j d ƒ Z e j d ƒ Z d d d „ Z d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   TOKEN_BLOCKt   TOKEN_COMMENTt
   TOKEN_TEXTt	   TOKEN_VARt   TRANSLATOR_COMMENT_MARKt   Lexer(   t   six(   t
   force_text(   t   StringIOi   (   t   TranslatorCommentWarningt   trim_whitespaceu   \Sc         C  s   t  j | |  ƒ S(   ug   
    Change every non-whitespace character to the given char.
    Used in the templatize function.
    (   t   dot_ret   sub(   t   srct   char(    (    sC   /tmp/pip-unpacked-wheel-BAJOf3/django/utils/translation/template.pyt   blankout   s    u.   ^\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?'))\s*u˜   ^\s*trans\s+((?:"[^"]*?")|(?:'[^']*?'))(?:\s*\|\s*[^\s:]+(?::(?:[^\s'":]+|(?:"[^"]*?")|(?:'[^']*?')))?)*(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?\s*uD   ^\s*blocktrans(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?(?:\s+|$)u   ^\s*endblocktrans$u   ^\s*plural$u   _\(((?:".*?")|(?:'.*?'))\)u   utf-8c   &      C  s»  t  |  | ƒ }  t d ƒ } d& } t } t } t } g  } g  }	 t }
 g  } i  } d& } t j rf d n d } t d „ } x6t |  ƒ j ƒ  D]"} |
 r| j t	 k r|| j
 d k r|d j | ƒ } d& } xA t | j t ƒ ƒ D]* \ } } | j ƒ  j t ƒ rà | } qà qà Wx\ t | j t ƒ ƒ D]E \ } } | d& k	 r\| | k r\| j d | ƒ q$| j d ƒ q$Wt }
 g  } q­| j | j
 ƒ q‹ | r| j t	 k r{t j | j
 ƒ } t j | j
 ƒ } | r1| r“| r| j d j | | | | ƒ | |	 | ƒ d | ƒƒ n1 | j d	 j | | | ƒ | |	 | ƒ d | ƒƒ x$ | D] } | j t | d
 ƒ ƒ qIWx¤ |	 D] } | j t | d ƒ ƒ qpWn} | rÄ| j d j | | | | ƒ d | ƒƒ n% | j d j | | | ƒ d | ƒƒ x$ | D] } | j t | d
 ƒ ƒ qðWd& } t } t } g  } g  }	 q| r@t } qd } | rYd | } n  t d | j
 | | j f ƒ ‚ q­| j t k r¾| r§|	 j d | j
 ƒ q| j d | j
 ƒ q­| j t k r­| j
 j d d ƒ } | rø|	 j | ƒ q| j | ƒ q­q‹ | d& k	 rÓ| j | j
 j d ƒ } | | k r¬| j t k rÊxN | | D]B } d } | rud | } n  d | | | f } t  j! | t" ƒ qVWg  | | <qÊn | j d d j | | ƒ ƒ d& } n  | j t	 k rt# j | j
 ƒ } t$ j | j
 ƒ } t% j& | j
 ƒ } | rD| j' d ƒ }  |  d d k rO|  j( d ƒ }  n" |  d d k rq|  j( d ƒ }  n  |  j d d ƒ }  | j' d ƒ r%t) j | j' d ƒ ƒ }! |! j' d ƒ } | d d k rÛ| j( d ƒ } n" | d d k rý| j( d ƒ } n  | j d j | |  d | ƒƒ d& } q~| j d j |  d | ƒƒ q­| r"x+ t% j& | j
 ƒ D] }" | j d |" ƒ q]W| j' d ƒ rõt) j | j' d ƒ ƒ }! |! j' d ƒ } | d d k rÐ| j( d ƒ } qõ| d d k rõ| j( d ƒ } qõn  t } t } d | j* ƒ  k } g  } g  }	 q­| rMxS | D] }# | j d |# ƒ q/Wq­| j
 d k ret }
 q­| j t | j
 d ƒ ƒ q‹ | j t k r?| j
 j+ d  ƒ }$ t% j |$ d ƒ }# |# rØ| j d |# j' d ƒ ƒ n  xÒ |$ d D]U }% |% j, d! ƒ d k r"| j d" |% j+ d# d ƒ d ƒ qã| j t |% d$ ƒ ƒ qãWq‹ | j t k r”| j
 j ƒ  j t ƒ r­| j- | j g  ƒ j | j
 ƒ | j } q­q‹ | j t | j
 d% ƒ ƒ q‹ W| j. ƒ  S('   u¹   
    Turn a Django template into something that is understood by xgettext. It
    does so by translating the Django translation tags into standard gettext
    function invocations.
    u    u   uc         S  s(   d j  |  ƒ } | r$ t | ƒ } n  | S(   Nu    (   t   joinR   (   t   tokenst   trimt   message(    (    sC   /tmp/pip-unpacked-wheel-BAJOf3/django/utils/translation/template.pyt   join_tokens@   s    u
   endcommentu    # %su    #
u,    npgettext({p}{!r}, {p}{!r}, {p}{!r},count) t   pu#    ngettext({p}{!r}, {p}{!r}, count) u   Su   Pu    pgettext({p}{!r}, {p}{!r}) u    gettext({p}{!r}) u	   file %s, uD   Translation blocks must not include other block tags: %s (%sline %d)u   %%(%s)su   %u   %%u   
uj   The translator-targeted comment '%s' (%sline %d) was ignored, because it wasn't the last item on the line.u   # %su    | i   i    u   "u   'i   u    _(%s) u   trimmedu   commentu   Bu   |u   :_(u    %s u   :u   Fu   XN(/   R   R	   t   Nonet   FalseR   t   PY3R   t   tokenizet
   token_typeR   t   contentsR   t	   enumeratet
   splitlinest   Truet   lstript
   startswithR   t   writet   appendt   endblock_ret   matcht	   plural_ret   formatR   t   SyntaxErrort   linenoR   R   t   replacet   countR   t   warningst   warnR
   t	   inline_ret   block_ret   constant_ret   findallt   groupt   stript
   context_ret   split_contentst   splitt   findt
   setdefaultt   getvalue(&   R   t   origint   charsett   outt   message_contextt   intranst   inpluralt   trimmedt   singulart   pluralt	   incommentt   commentt   lineno_comment_mapt   comment_lineno_cachet
   raw_prefixR   t   tt   contentt   translators_comment_startR)   t   linet	   endbmatcht   pluralmatcht   partt   filemsgR   t
   cur_linenot   ct   warn_msgt   imatcht   bmatcht   cmatchest   gt   context_matcht   fmatcht   cmatcht   partsR   (    (    sC   /tmp/pip-unpacked-wheel-BAJOf3/django/utils/translation/template.pyt
   templatize*   s2   ""	

						$(   t
   __future__R    t   reR,   t   django.template.baseR   R   R   R   R   R   t   django.utilsR   t   django.utils.encodingR   t   django.utils.sixR	   t    R
   R   t   compileR   R   R4   R.   R/   R$   R&   R0   R   R[   (    (    (    sC   /tmp/pip-unpacked-wheel-BAJOf3/django/utils/translation/template.pyt   <module>   s"   .		