m
fIc           @   s  d  Z  d k Z d k Z d k Z d k Z d k Z d k Z d k l Z d d d d d d d	 d
 d d d d g Z	 e i
 i e i d d  Z d   Z d   Z d   Z d f  d     YZ d e f d     YZ d d d d  Z h  Z d d d e d d  Z d e d d  Z h  a h  a d a d d  Z d d  Z d d  Z d   Z d   Z  d    Z! d!   Z" d"   Z# d#   Z$ d$   Z% d%   Z& e Z' d S(&   s  Internationalization and localization support.

This module provides internationalization (I18N) and localization (L10N)
support for your Python programs by providing an interface to the GNU gettext
message catalog library.

I18N refers to the operation by which a program is made aware of multiple
languages.  L10N refers to the adaptation of your program, once
internationalized, to the local language and cultural habits.

N(   s   ENOENTt   NullTranslationst   GNUTranslationst   Catalogt   findt   translationt   installt
   textdomaint   bindtextdomaint   dgettextt	   dngettextt   gettextt   ngettextt   sharet   localec         C   s   |  o | Sn | Sd S(   sy   
    Implements the C expression:

      condition ? true : false

    Required to correctly interpret plural forms.
    N(   t	   conditiont   truet   false(   R   R   R   (    (    t$   /mit/python/lib/python2.4/gettext.pyt   test=   s     c            s  d k  l  } d k }	 d k } | i | |   i  } yN g  } | D]6 } | d |	 i	 j o | d d j o | | qE qE ~ } Wn | i j
 o t d  n X| o t d  n |  i d d	  }  |  i d
 d  }  t i d      i d |   }  t i d       d    d g } x |  D] } | d j o | i d  q.| d j oP t |  d j o t d  n   i  | i    } | d c d | 7<q.| d c | 7<q.W  i  | i    }  t d |   S(   s   Gets a C expression as used in PO files for plural forms and returns a
    Python lambda function that implements an equivalent expression.
    (   s   StringIONi    i   t   ns;   plural forms expression error, maybe unbalanced parenthesiss*   plural forms expression could be dangerouss   &&s    and s   ||s    or s   \!([^=])s    not \1s   (.*?)\?(.*?):(.*)c            s8   d |  i d  |  i d   i   |  i d   f S(   Ns   test(%s, %s, %s)i   i   i   (   t   xt   groupt   exprt   subt   repl(   R   (   R   R   (    R   R   f   s    t    t   (t   )s%   unbalanced parenthesis in plural formis   (%s)s   lambda n: int(%s)(   t   StringIOt   tokent   tokenizet   generate_tokenst   pluralt   readlinet   tokenst   _[1]R   t   NAMEt   dangert
   TokenErrort
   ValueErrort   replacet   ret   compileR   R   R   t   stackt   ct   appendt   lent   popt   st   eval(   R    R#   R,   R%   R   R   R0   R+   R"   R   R   R   R   (    (   R   R   R   t   c2pyK   s:     N	 c         C   s  d k  l } | |   }  d d >}	 d d >} d d >}
 d } |  i d  } | d j o" |  | } |  |  }  | |
 O} n d } |  i d  } | d j o" |  | } |  |  }  | |	 O} n d } |  i d  } | d j o" |  | } |  |  }  | | O} n d } |  } g  } x t | d  D]t } | | @pb | } | | @o | | 7} n | |	 @o | | 7} n | |
 @o | | 7} n | i |  q&q&W| i   | S(	   N(   s	   normalizei   i    i   t   @R   t   .t   _(   R   t	   normalizet   COMPONENT_CODESETt   COMPONENT_TERRITORYt   COMPONENT_MODIFIERt   maskR   t   post   modifiert   codesett	   territoryt   languaget   rett   ranget   it   valR-   t   reverse(   R   R6   R>   RB   R?   R8   R:   R;   R@   R7   R9   RC   R=   R<   (    (    R   t   _expand_lang   sN    








    
c           B   s   t  Z d  d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z e d  Z RS(   Nc         C   sF   h  |  _ d  |  _ d  |  _ d  |  _ | d  j	 o |  i |  n d  S(   N(   t   selft   _infot   Nonet   _charsett   _output_charsett	   _fallbackt   fpt   _parse(   RF   RL   (    (    R   t   __init__   s    				c         C   s   d  S(   N(    (   RF   RL   (    (    R   RM      s    c         C   s+   |  i o |  i i |  n
 | |  _ d  S(   N(   RF   RK   t   add_fallbackt   fallback(   RF   RP   (    (    R   RO      s    
c         C   s"   |  i o |  i i |  Sn | S(   N(   RF   RK   R
   t   message(   RF   RQ   (    (    R   R
      s    
c         C   s"   |  i o |  i i |  Sn | S(   N(   RF   RK   t   lgettextRQ   (   RF   RQ   (    (    R   RR      s    
c         C   sA   |  i o |  i i | | |  Sn | d j o | Sn | Sd  S(   Ni   (   RF   RK   R   t   msgid1t   msgid2R   (   RF   RS   RT   R   (    (    R   R      s
    
c         C   sA   |  i o |  i i | | |  Sn | d j o | Sn | Sd  S(   Ni   (   RF   RK   t	   lngettextRS   RT   R   (   RF   RS   RT   R   (    (    R   RU      s
    
c         C   s(   |  i o |  i i |  Sn t |  S(   N(   RF   RK   t   ugettextRQ   t   unicode(   RF   RQ   (    (    R   RV      s    
c         C   sM   |  i o |  i i | | |  Sn | d j o t |  Sn t |  Sd  S(   Ni   (   RF   RK   t	   ungettextRS   RT   R   RW   (   RF   RS   RT   R   (    (    R   RX      s
    
c         C   s   |  i S(   N(   RF   RG   (   RF   (    (    R   t   info   s    c         C   s   |  i S(   N(   RF   RI   (   RF   (    (    R   t   charset   s    c         C   s   |  i S(   N(   RF   RJ   (   RF   (    (    R   t   output_charset   s    c         C   s   | |  _ d  S(   N(   RZ   RF   RJ   (   RF   RZ   (    (    R   t   set_output_charset   s    c         C   s.   d  k  } | o
 |  i p |  i | i d <d  S(   NR5   (   t   __builtin__RW   RF   RV   R
   t   __dict__(   RF   RW   R]   (    (    R   R      s    	(   t   __name__t
   __module__RH   RN   RM   RO   R
   RR   R   RU   RV   RX   RY   RZ   R[   R\   t   FalseR   (    (    (    R   R       s   												c           B   sS   t  Z d Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 RS(
   Nl   * l   $< c         C   s  t  i } t | d d  }	 h  |  _ } d   |  _ | i	   } t |  } | d | d   d } | |  i j o, | d | d d ! \ } } } } d	 } nO | |  i j o, | d
 | d d ! \ } } } } d } n t d d |	   xt d |  D]} | | | | | d ! \ } } | | } | | | | | d ! \ } } | | } | | j  o+ | | j  o | | | !} | | | !} n t d d |	   | d j o(d } } x| i#   D]	} | i%   } | p qn d | j oM | i& d d  \ } } | i%   i(   } | i%   } | |  i) | <| } n# | o |  i) | c d | 7<n | d j o | i& d  d |  _* q| d j o9 | i& d  } | d i& d  d } t+ |  |  _ qqWn d | j o | i& d  \ } }
 | i& d  } |  i* oC t. | |  i*  } g  } | D] } | t. | |  i*  q.~ } n xn t1 t |   D] } | | | | | f <qgWn= |  i* o( t. | |  i*  } t. | |  i*  } n | | | <| d 7} | d 7} q Wd S(   s8   Override this method to support alternative .mo formats.t   nameR   c         C   s   t  |  d j  S(   Ni   (   t   intR   (   R   (    (    R   t   <lambda>   s    s   <Ii   i    s   <4Ii   s   <IIs   >4Is   >IIs   Bad magic numberi   s   File is corruptt   :i   s   
s   content-types   charset=s   plural-formst   ;s   plural=t    N(2   t   structt   unpackt   getattrRL   t   filenameRF   t   _catalogt   catalogR    t   readt   bufR.   t   buflent   magict   LE_MAGICt   versiont   msgcountt	   masteridxt   transidxt   iit   BE_MAGICt   IOErrort   xrangeRB   t   mlent   mofft   mendt   tlent   tofft   tendt   msgt   tmsgRH   t   lastkt   kt
   splitlinest   itemt   stript   splitt   vt   lowerRG   RI   R2   RS   RT   RW   R#   R   RA   (   RF   RL   Rt   R   Rw   R   R   Ri   RS   Rk   RT   Rs   R}   Ru   R    R{   Rp   R   Rm   R   Ro   Rq   Rv   RB   R   R#   R   R~   R   R|   R   (    (    R   RM      sz     	"
"
  
 

 


1 


c         C   s   t    } |  i i | |  } | | j o& |  i o |  i i |  Sn | Sn |  i	 o | i
 |  i	  Sn |  i o | i
 |  i  Sn | S(   N(   t   objectt   missingRF   Rl   t   getRQ   R   RK   R
   RJ   t   encodeRI   (   RF   RQ   R   R   (    (    R   R
   J  s    	


c         C   s   t    } |  i i | |  } | | j o& |  i o |  i i |  Sn | Sn |  i	 o | i
 |  i	  Sn | i
 t i    S(   N(   R   R   RF   Rl   R   RQ   R   RK   RR   RJ   R   R   t   getpreferredencoding(   RF   RQ   R   R   (    (    R   RR   X  s    	

c         C   s   y` |  i | |  i |  f } |  i o | i |  i  Sn |  i o | i |  i  Sn | SWnP t	 j
 oD |  i
 o |  i
 i | | |  Sn | d j o | Sq | Sn Xd  S(   Ni   (   RF   Rl   RS   R    R   R   RJ   R   RI   t   KeyErrorRK   R   RT   (   RF   RS   RT   R   R   (    (    R   R   c  s    


c         C   s   yQ |  i | |  i |  f } |  i o | i |  i  Sn | i t i	    SWnP t
 j
 oD |  i o |  i i | | |  Sn | d j o | Sq | Sn Xd  S(   Ni   (   RF   Rl   RS   R    R   R   RJ   R   R   R   R   RK   RU   RT   (   RF   RS   RT   R   R   (    (    R   RU   s  s    

c         C   s[   t    } |  i i | |  } | | j o, |  i o |  i i |  Sn t	 |  Sn | S(   N(
   R   R   RF   Rl   R   RQ   R   RK   RV   RW   (   RF   RQ   R   R   (    (    R   RV     s    	
c         C   s   y  |  i | |  i |  f } Wn` t j
 oT |  i o |  i i | | |  Sn | d j o t
 |  } q t
 |  } n X| S(   Ni   (   RF   Rl   RS   R    R   R   R   RK   RX   RT   RW   (   RF   RS   RT   R   R   (    (    R   RX     s     
(   R_   R`   Rr   Rx   RM   R
   RR   R   RU   RV   RX   (    (    (    R   R      s   	Q						i    c         C   sf  | d  j o
 t } n | d  j of g  } x; d D]3 } t i i |  } | o | i	 d  } Pq1 q1 Wd | j o | i
 d  q n g  } xC | D]; } x2 t |  D]$ }
 |
 | j o | i
 |
  q q Wq W| o
 g  }	 n d  }	 xr | D]j } | d j o Pn t i i | | d d |   } t i i |  o  | o |	 i
 |  q^| Sq q W|	 S(	   Nt   LANGUAGEt   LC_ALLt   LC_MESSAGESt   LANGRe   t   Cs   %s.mo(   R   R   R   R   (   t	   localedirRH   t   _default_localedirt	   languagest   envart   ost   environR   RC   R   R-   t   nelangst   langRE   t   nelangt   allt   resultt   patht   joint   domaint   mofilet   exists(   R   R   R   R   R   RC   R   R   R   R   R   (    (    R   R     s@    
 	  
 c         C   s  | d  j o
 t } n t |  | | d d }	 |	 p( | o t	   Sn t
 t d |    n d  }
 x |	 D] } t i i |  } t i |  } | d  j o% t i | | t | d    } n t i |  } | o | i |  n |
 d  j o
 | }
 qk |
 i |  qk W|
 S(   NR   i   s$   No translation file found for domaint   rb(   t   class_RH   R   R   R   R   R   t   mofilesRP   R    Ry   t   ENOENTR   R   R   R   t   abspatht   keyt   _translationsR   t   tt
   setdefaultt   opent   copyR=   R\   RO   (   R   R   R   R   RP   R=   R   R   R   R   R   (    (    R   R     s*    
 %
c         C   s,   t  |  | d t d | } | i |  d  S(   NRP   R=   (   R   R   R   t   TrueR=   R   R   RW   (   R   R   RW   R=   R   (    (    R   R     s    t   messagesc         C   s   |  d  j	 o
 |  a n t S(   N(   R   RH   t   _current_domain(   R   (    (    R   R     s     
c         C   s+   | d  j	 o | t |  <n t i |  t  S(   N(   R   RH   t   _localedirsR   R   R   (   R   R   (    (    R   R     s     c         C   s(   | d  j	 o | t |  <n t i |   S(   N(   R=   RH   t   _localecodesetsR   R   (   R   R=   (    (    R   t   bind_textdomain_codeset  s     c         C   sU   y. t  |  t i |  d   d t i |   } Wn t j
 o | Sn X| i	 |  S(   NR=   (
   R   R   R   R   RH   R   R   Ry   RQ   R
   (   R   RQ   R   (    (    R   R     s    	c         C   sU   y. t  |  t i |  d   d t i |   } Wn t j
 o | Sn X| i	 |  S(   NR=   (
   R   R   R   R   RH   R   R   Ry   RQ   RR   (   R   RQ   R   (    (    R   t	   ldgettext
  s    	c         C   sp   y. t  |  t i |  d   d t i |   } Wn, t j
 o  | d j o | Sq] | Sn X| i | | |  S(   NR=   i   (   R   R   R   R   RH   R   R   Ry   R   RS   RT   R   (   R   RS   RT   R   R   (    (    R   R	     s    	c         C   sp   y. t  |  t i |  d   d t i |   } Wn, t j
 o  | d j o | Sq] | Sn X| i | | |  S(   NR=   i   (   R   R   R   R   RH   R   R   Ry   R   RS   RT   RU   (   R   RS   RT   R   R   (    (    R   t
   ldngettext  s    	c         C   s   t  t |   S(   N(   R   R   RQ   (   RQ   (    (    R   R
   (  s    c         C   s   t  t |   S(   N(   R   R   RQ   (   RQ   (    (    R   RR   +  s    c         C   s   t  t |  | |  S(   N(   R	   R   RS   RT   R   (   RS   RT   R   (    (    R   R   .  s    c         C   s   t  t |  | |  S(   N(   R   R   RS   RT   R   (   RS   RT   R   (    (    R   RU   1  s    ((   t   __doc__R   R   R   R)   Rh   t   syst   errnoR   t   __all__R   R   t   prefixR   R   R2   RE   R    R   RH   R   R   Ra   R   R   R   R   R   R   R   R   R   R   R	   R   R
   RR   R   RU   R   (   RU   R   R   R   Rh   R   R	   R   R
   R)   R   R    R   R   R   R   R   R   R   R   R2   RE   R   R   R   RR   R   R   R   R   (    (    R   t   ?   s8   &6*		4	+J&								