
5	Pc           @   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.

iN(   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   replt   expr(    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(   NiR7   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								