ó
—êé[c           @   s´  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d d d d d	 d
 d d d d d g Z	 e j
 j e j d d ƒ Z d „  Z d „  Z d „  Z d d' d „  ƒ  YZ d e f d „  ƒ  YZ d d d d „ Z i  Z d d d e d d „ Z d e d d d „ Z i  a i  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.

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

      condition ? true : false

    Required to correctly interpret plural forms.
    N(    (   t	   conditiont   truet   false(    (    s   /usr/lib/python2.7/gettext.pyt   test=   s    c   
         s  y d d l  m } Wn! t k
 r7 d d l m } n Xd d l } d d l } | j | |  ƒ j ƒ } y@ g  | D]/ } | d | j k rr | d d k rr | ^ qr } Wn | j k
 rÇ t	 d ‚ n X| rÚ t	 d ‚ n  |  j
 d	 d
 ƒ }  |  j
 d d ƒ }  t j d ƒ ‰  ˆ  j d |  ƒ }  t j d ƒ ‰  ‡  ‡ f d †  ‰ d g } x“ |  D]‹ } | d k rr| j d ƒ qP| d k rËt | ƒ d k rœt	 d ‚ n  ˆ  j ˆ | j ƒ  ƒ }	 | d c d |	 7<qP| d c | 7<qPWˆ  j ˆ | j ƒ  ƒ }  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.
    iÿÿÿÿ(   t   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 |  j  d ƒ |  j  d ƒ ˆ  j ˆ |  j  d ƒ ƒ f S(   Ns   test(%s, %s, %s)i   i   i   (   t   groupt   sub(   t   x(   t   exprt   repl(    s   /usr/lib/python2.7/gettext.pyR   i   s    t    t   (t   )s%   unbalanced parenthesis in plural forms   (%s)s   lambda n: int(%s)(   t	   cStringIOR   t   ImportErrort   tokent   tokenizet   generate_tokenst   readlinet   NAMEt
   TokenErrort
   ValueErrort   replacet   ret   compileR   t   appendt   lent   popt   eval(
   t   pluralR   R   R    t   tokensR   t   dangert   stackt   ct   s(    (   R   R   s   /usr/lib/python2.7/gettext.pyt   c2pyK   s>    @
	c         C   s•  d d l  m } | |  ƒ }  d
 } d } d } d } |  j d ƒ } | d k rp |  | } |  |  }  | | O} n d } |  j d ƒ } | d k r² |  | } |  |  }  | | O} n d } |  j d	 ƒ } | d k rô |  | }	 |  |  }  | | O} n d }	 |  }
 g  } x~ t | d ƒ D]l } | | @s|
 } | | @rE| |	 7} n  | | @r\| | 7} n  | | @rs| | 7} n  | j | ƒ qqW| j ƒ  | S(   Niÿÿÿÿ(   t	   normalizei   i    i   t   @R   t   .t   _i   i   i   (   R   R4   R   t   rangeR)   t   reverse(   R   R4   t   COMPONENT_CODESETt   COMPONENT_TERRITORYt   COMPONENT_MODIFIERt   maskt   post   modifiert   codesett	   territoryt   languaget   rett   it   val(    (    s   /usr/lib/python2.7/gettext.pyt   _expand_lang‚   sL    






 
 
 
c           B   s�   e  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 d „ Z RS(   c         C   sD   i  |  _  d  |  _ d  |  _ d  |  _ | d  k	 r@ |  j | ƒ n  d  S(   N(   t   _infot   Nonet   _charsett   _output_charsett	   _fallbackt   _parse(   t   selft   fp(    (    s   /usr/lib/python2.7/gettext.pyt   __init__®   s    				c         C   s   d  S(   N(    (   RM   RN   (    (    s   /usr/lib/python2.7/gettext.pyRL   ¶   s    c         C   s)   |  j  r |  j  j | ƒ n	 | |  _  d  S(   N(   RK   t   add_fallback(   RM   t   fallback(    (    s   /usr/lib/python2.7/gettext.pyRP   ¹   s    	c         C   s   |  j  r |  j  j | ƒ S| S(   N(   RK   R   (   RM   t   message(    (    s   /usr/lib/python2.7/gettext.pyR   ¿   s    	c         C   s   |  j  r |  j  j | ƒ S| S(   N(   RK   t   lgettext(   RM   RR   (    (    s   /usr/lib/python2.7/gettext.pyRS   Ä   s    	c         C   s7   |  j  r |  j  j | | | ƒ S| d k r/ | S| Sd  S(   Ni   (   RK   R   (   RM   t   msgid1t   msgid2R   (    (    s   /usr/lib/python2.7/gettext.pyR   É   s
    	c         C   s7   |  j  r |  j  j | | | ƒ S| d k r/ | S| Sd  S(   Ni   (   RK   t	   lngettext(   RM   RT   RU   R   (    (    s   /usr/lib/python2.7/gettext.pyRV   Ñ   s
    	c         C   s#   |  j  r |  j  j | ƒ St | ƒ S(   N(   RK   t   ugettextt   unicode(   RM   RR   (    (    s   /usr/lib/python2.7/gettext.pyRW   Ù   s    	c         C   sC   |  j  r |  j  j | | | ƒ S| d k r5 t | ƒ St | ƒ Sd  S(   Ni   (   RK   t	   ungettextRX   (   RM   RT   RU   R   (    (    s   /usr/lib/python2.7/gettext.pyRY   Þ   s
    	
c         C   s   |  j  S(   N(   RG   (   RM   (    (    s   /usr/lib/python2.7/gettext.pyt   infoæ   s    c         C   s   |  j  S(   N(   RI   (   RM   (    (    s   /usr/lib/python2.7/gettext.pyt   charseté   s    c         C   s   |  j  S(   N(   RJ   (   RM   (    (    s   /usr/lib/python2.7/gettext.pyt   output_charsetì   s    c         C   s   | |  _  d  S(   N(   RJ   (   RM   R[   (    (    s   /usr/lib/python2.7/gettext.pyt   set_output_charsetï   s    c         C   sÐ   d d  l  } | r |  j p! |  j | j d <t | d ƒ rÌ d | k r] | j d | j d <n  d | k r‹ | rx |  j p~ |  j | j d <n  d | k rª |  j | j d <n  d | k rÌ |  j | j d <qÌ n  d  S(   NiÿÿÿÿR7   t   __contains__R   R   RS   RV   (	   t   __builtin__RW   R   t   __dict__t   hasattrRY   R   RS   RV   (   RM   RX   t   namesR_   (    (    s   /usr/lib/python2.7/gettext.pyR   ò   s    N(   t   __name__t
   __module__RH   RO   RL   RP   R   RS   R   RV   RW   RY   RZ   R[   R\   R]   t   FalseR   (    (    (    s   /usr/lib/python2.7/gettext.pyR   ­   s   												c           B   sS   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   l   Þ* l   •$< c         C   sÀ  t  j } t | d d ƒ } i  |  _ } d „  |  _ | j ƒ  } t | ƒ } | d | d  ƒ d } | |  j k r� | d | d d !ƒ \ } }	 }
 } d	 } nL | |  j k r× | d
 | d d !ƒ \ } }	 }
 } d } n t	 d d | ƒ ‚ xÐt
 d |	 ƒ D]¿} | | | |
 |
 d !ƒ \ } } | | } | | | | | d !ƒ \ } } | | } | | k  rˆ| | k  rˆ| | | !} | | | !} n t	 d d | ƒ ‚ | d k rÃd } } x| j ƒ  D]ÿ } | j ƒ  } | sÛq½n  d | k r3| j d d ƒ \ } } | j ƒ  j ƒ  } | j ƒ  } | |  j | <| } n  | rS|  j | c d | 7<n  | d k rx| j d ƒ d |  _ q½| d k r½| j d ƒ } | d j d ƒ d } t | ƒ |  _ q½q½Wn  d | k rj| j d ƒ \ } } | j d ƒ } |  j r6t | |  j ƒ } g  | D] } t | |  j ƒ ^ q} n  xk t t | ƒ ƒ D] } | | | | | f <qIWn: |  j ršt | |  j ƒ } t | |  j ƒ } n  | | | <|
 d 7}
 | d 7} qù Wd S(   s8   Override this method to support alternative .mo formats.t   nameR   c         S   s   t  |  d k ƒ S(   Ni   (   t   int(   R   (    (    s   /usr/lib/python2.7/gettext.pyt   <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(   t   structt   unpackt   getattrt   _catalogR-   t   readR*   t   LE_MAGICt   BE_MAGICt   IOErrort   xrangeRH   t
   splitlinest   stript   splitt   lowerRG   RI   R3   RX   R8   (   RM   RN   Rm   t   filenamet   catalogt   buft   buflent   magict   versiont   msgcountt	   masteridxt   transidxt   iiRD   t   mlent   mofft   mendt   tlent   tofft   tendt   msgt   tmsgt   lastkt   kt   itemt   vR-   RT   RU   R   (    (    s   /usr/lib/python2.7/gettext.pyRL     sr    	"	"	 
 

	
	(	

c         C   s}   t  ƒ  } |  j j | | ƒ } | | k rG |  j rC |  j j | ƒ S| S|  j r` | j |  j ƒ S|  j ry | j |  j ƒ S| S(   N(   t   objectRo   t   getRK   R   RJ   t   encodeRI   (   RM   RR   t   missingRŠ   (    (    s   /usr/lib/python2.7/gettext.pyR   W  s    				c         C   ss   t  ƒ  } |  j j | | ƒ } | | k rG |  j rC |  j j | ƒ S| S|  j r` | j |  j ƒ S| j t j ƒ  ƒ S(   N(	   R�   Ro   R�   RK   RS   RJ   R‘   R   t   getpreferredencoding(   RM   RR   R’   RŠ   (    (    s   /usr/lib/python2.7/gettext.pyRS   e  s    			c         C   s¡   yV |  j  | |  j | ƒ f } |  j r8 | j |  j ƒ S|  j rQ | j |  j ƒ S| SWnD t k
 rœ |  j r… |  j j | | | ƒ S| d k r• | S| Sn Xd  S(   Ni   (   Ro   R-   RJ   R‘   RI   t   KeyErrorRK   R   (   RM   RT   RU   R   RŠ   (    (    s   /usr/lib/python2.7/gettext.pyR   p  s    			c         C   s—   yL |  j  | |  j | ƒ f } |  j r8 | j |  j ƒ S| j t j ƒ  ƒ SWnD t k
 r’ |  j r{ |  j j | | | ƒ S| d k r‹ | S| Sn Xd  S(   Ni   (	   Ro   R-   RJ   R‘   R   R“   R”   RK   RV   (   RM   RT   RU   R   RŠ   (    (    s   /usr/lib/python2.7/gettext.pyRV   €  s    		c         C   sQ   t  ƒ  } |  j j | | ƒ } | | k rM |  j rC |  j j | ƒ St | ƒ S| S(   N(   R�   Ro   R�   RK   RW   RX   (   RM   RR   R’   RŠ   (    (    s   /usr/lib/python2.7/gettext.pyRW   Ž  s    		
c         C   s~   y  |  j  | |  j | ƒ f } WnW t k
 ry |  j rO |  j j | | | ƒ S| d k rj t | ƒ } qz t | ƒ } n X| S(   Ni   (   Ro   R-   R”   RK   RY   RX   (   RM   RT   RU   R   RŠ   (    (    s   /usr/lib/python2.7/gettext.pyRY   —  s     	(   Rc   Rd   Rq   Rr   RL   R   RS   R   RV   RW   RY   (    (    (    s   /usr/lib/python2.7/gettext.pyR     s   	Q						i    c         C   s¢  | d  k r t } n  | d  k r‚ g  } x9 d	 D]1 } t j j | ƒ } | r. | j d ƒ } Pq. q. Wd | k r‚ | j d ƒ q‚ n  g  } xA | D]9 } x0 t | ƒ D]" } | | k r¢ | j | ƒ q¢ q¢ Wq� W| rÛ g  }	 n d  }	 xº | D]² } | d k rþ Pn  t j j	 | | d d |  ƒ }
 t j j	 d | d d |  ƒ } t j j
 |
 ƒ rk| rd|	 j |
 ƒ qk|
 Sn  t j j
 | ƒ rè | r“|	 j | ƒ qš| Sqè qè W|	 S(
   Nt   LANGUAGEt   LC_ALLt   LC_MESSAGESt   LANGRi   t   Cs   %s.mos   /usr/share/locale-langpack(   R•   R–   R—   R˜   (   RH   t   _default_localedirt   ost   environR�   Rw   R)   RF   t   patht   joint   exists(   t   domaint	   localedirt	   languagest   allt   envarRE   t   nelangst   langt   nelangt   resultt   mofilet	   mofile_lp(    (    s   /usr/lib/python2.7/gettext.pyR   ¥  sD    		c      	   C   s  | d  k r t } n  t |  | | d d ƒ} | sU | r@ t ƒ  St t d |  ƒ ‚ n  d  } x» | D]³ } | t j j | ƒ f }	 t	 j
 |	 ƒ }
 |
 d  k rÎ t | d ƒ � } t	 j |	 | | ƒ ƒ }
 Wd  QXn  t j |
 ƒ }
 | ró |
 j | ƒ n  | d  k r|
 } qb | j |
 ƒ qb W| S(   NR£   i   s$   No translation file found for domaint   rb(   RH   R   R   R   Rs   R    R›   R�   t   abspatht   _translationsR�   t   opent
   setdefaultt   copyR]   RP   (   R    R¡   R¢   t   class_RQ   R@   t   mofilesR¨   R©   t   keyt   tRN   (    (    s   /usr/lib/python2.7/gettext.pyR   Ü  s*    	!	c         C   s/   t  |  | d t d | ƒ} | j | | ƒ d  S(   NRQ   R@   (   R   t   TrueR   (   R    R¡   RX   R@   Rb   R´   (    (    s   /usr/lib/python2.7/gettext.pyR   û  s    t   messagesc         C   s   |  d  k	 r |  a n  t S(   N(   RH   t   _current_domain(   R    (    (    s   /usr/lib/python2.7/gettext.pyR   	  s    	c         C   s)   | d  k	 r | t |  <n  t j |  t ƒ S(   N(   RH   t   _localedirsR�   Rš   (   R    R¡   (    (    s   /usr/lib/python2.7/gettext.pyR     s    c         C   s&   | d  k	 r | t |  <n  t j |  ƒ S(   N(   RH   t   _localecodesetsR�   (   R    R@   (    (    s   /usr/lib/python2.7/gettext.pyt   bind_textdomain_codeset  s    c         C   sP   y. t  |  t j |  d  ƒ d t j |  ƒ ƒ} Wn t k
 rB | SX| j | ƒ S(   NR@   (   R   R¸   R�   RH   R¹   Rs   R   (   R    RR   R´   (    (    s   /usr/lib/python2.7/gettext.pyR	     s    c         C   sP   y. t  |  t j |  d  ƒ d t j |  ƒ ƒ} Wn t k
 rB | SX| j | ƒ S(   NR@   (   R   R¸   R�   RH   R¹   Rs   RS   (   R    RR   R´   (    (    s   /usr/lib/python2.7/gettext.pyt	   ldgettext&  s    c         C   si   y. t  |  t j |  d  ƒ d t j |  ƒ ƒ} Wn% t k
 rU | d k rN | S| Sn X| j | | | ƒ S(   NR@   i   (   R   R¸   R�   RH   R¹   Rs   R   (   R    RT   RU   R   R´   (    (    s   /usr/lib/python2.7/gettext.pyR
   .  s    c         C   si   y. t  |  t j |  d  ƒ d t j |  ƒ ƒ} Wn% t k
 rU | d k rN | S| Sn X| j | | | ƒ S(   NR@   i   (   R   R¸   R�   RH   R¹   Rs   RV   (   R    RT   RU   R   R´   (    (    s   /usr/lib/python2.7/gettext.pyt
   ldngettext9  s    c         C   s   t  t |  ƒ S(   N(   R	   R·   (   RR   (    (    s   /usr/lib/python2.7/gettext.pyR   D  s    c         C   s   t  t |  ƒ S(   N(   R»   R·   (   RR   (    (    s   /usr/lib/python2.7/gettext.pyRS   G  s    c         C   s   t  t |  | | ƒ S(   N(   R
   R·   (   RT   RU   R   (    (    s   /usr/lib/python2.7/gettext.pyR   J  s    c         C   s   t  t |  | | ƒ S(   N(   R¼   R·   (   RT   RU   R   (    (    s   /usr/lib/python2.7/gettext.pyRV   M  s    (    ((   t   __doc__R   R°   R›   R'   Rl   t   syst   errnoR    t   __all__R�   Rž   t   prefixRš   R   R3   RF   R   R   RH   R   R­   Re   R   R   R¸   R¹   R·   R   R   Rº   R	   R»   R
   R¼   R   RS   R   RV   R   (    (    (    s   /usr/lib/python2.7/gettext.pyt   <module>   s>   &H			7	+T¤5								