ó
;Ò\c           @  s‘   d  d l  m Z d  d l Z d  d l Z d  d l Z d e j k Z d e j f d „  ƒ  YZ e ƒ  Z d e	 f d „  ƒ  YZ
 d e e d „ Z d S(	   iÿÿÿÿ(   t   print_functionNt   RENPY_UPDATE_TRANSLATIONSt	   Formatterc           B  s    e  Z d  Z d „  Z d „  Z RS(   sË   
    A string formatter that uses Ren'Py's formatting rules. Ren'Py uses
    square brackets to introduce formatting, and it supports a q conversion
    that quotes the text being shown to the user.
    c         c  sÀ  d } d } d } d } d } d } d } d }	 d }
 d } | } x9| D]1} | | k rƒ | d k rs | } qI qz| | 7} qI qI | | k rÉ | d k r± | | 7} | } qI qz| }	 | } d } qI qI | | k r¢| d k rû | d 7} |	 | 7}	 qI qz| d k r\| r'| d 8} |	 | 7}	 qI qŸ| |	 |
 | f V| } d } d }	 d }
 d } qI qz| d	 k rt| } qI qz| d
 k r’| } d } qI qz|	 | 7}	 qI qI | | k r| d k rï| |	 |
 | f V| } d } d }	 d }
 d } qI qz| d
 k r| } d } qI qz|
 | 7}
 qI qI | | k rI | d k rj| |	 |
 | f V| } d } d }	 d }
 d } qI qz| | 7} qI qI qI W| | k r¢t d j | ƒ ƒ ‚ n  | r¼| d d d f Vn  d S(   sÈ   
        Parses s according to Ren'Py string formatting rules. Returns a list
        of (literal_text, field_name, format, replacement) tuples, just like
        the method we're overriding.
        i    i   i   i   i   t    t   [t   ]t   :t   !s0   String {0!r} ends with an open format operation.N(   t   Nonet	   Exceptiont   format(   t   selft   st   LITERALt   OPEN_BRACKETt   VALUEt   FORMATt
   CONVERSIONt   bracket_deptht   literalt   valueR
   t
   conversiont   statet   c(    (    s   renpy/substitutions.pyt   parse)   s¦    









c         C  s%  | s
 | Sd | k r% t  | ƒ } n d | k r@ t | ƒ } n  d | k r t | t ƒ sj t | ƒ } n  t j j | ƒ } n  d | k r¾ t | t ƒ s© t | ƒ } n  | j d d ƒ } n  d | k rÙ | j ƒ  } n  d | k rô | j	 ƒ  } n  d	 | k r!| r!| d
 j ƒ  | d } n  | S(   Nt   rR   t   tt   qt   {s   {{t   ut   lR   i    i   (
   t   reprt   unicodet
   isinstancet
   basestringt   renpyt   translationt   translate_stringt   replacet   uppert   lower(   R   R   R   (    (    s   renpy/substitutions.pyt   convert_field¤   s*    (   t   __name__t
   __module__t   __doc__R   R)   (    (    (    s   renpy/substitutions.pyR   "   s   	{t   MultipleDictc           B  s   e  Z d  „  Z d „  Z RS(   c         G  s   | |  _  d  S(   N(   t   dicts(   R   R.   (    (    s   renpy/substitutions.pyt   __init__Ì   s    c         C  sA   x% |  j  D] } | | k r
 | | Sq
 Wt d j | ƒ ƒ ‚ d  S(   Ns   Name '{}' is not defined.(   R.   t	   NameErrorR
   (   R   t   keyt   d(    (    s   renpy/substitutions.pyt   __getitem__Ï   s    (   R*   R+   R/   R3   (    (    (    s   renpy/substitutions.pyR-   Ê   s   	c         C  sÈ   t  |  t ƒ s t |  ƒ }  n  | r9 t j j |  ƒ }  n  t j j rW | rW |  t f Sd |  k rm |  t f S|  } | d k	 r— t
 | t j j ƒ } n t j j } t j |  d | ƒ }  |  |  | k f S(   s¼  
    Performs translation and formatting on `s`, as necessary.

    `scope`
        The scope which is used in formatting, in addition to the default
        store.

    `force`
        Force substitution to occur, even if it's disabled in the config.

    `translate`
        Determines if translation occurs.

    Returns the substituted string, and a flag that is True if substitution
    occurred, or False if no substitution occurred.
    R   N(    (   R!   R"   R    R#   R$   R%   t   configt   new_substitutionst   FalseR   R-   t   storet   __dict__t	   formattert   vformat(   R   t   scopet   forcet	   translatet   old_st   kwargs(    (    s   renpy/substitutions.pyt
   substitute×   s    

(   t
   __future__R    R#   t   stringt   ost   environt   update_translationsR   R9   t   objectR-   R   R6   t   TrueR@   (    (    (    s   renpy/substitutions.pyt   <module>   s   ¥	