ó
™‚Mc           @   s  d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l m Z m	 Z	 m
 Z
 m Z d d l m Z m Z m Z m Z m Z m Z d d l m Z m Z d d	 d
 g Z d Z d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d
 e j e f d „  ƒ  YZ d S(   s˜   Several classes and functions that help with integrating and using Babel
in applications.

.. note: the code in this module is not used by Babel itself
iÿÿÿÿ(   t   datet   datetimet   timeN(   t   Locale(   t   format_datet   format_datetimet   format_timet   LC_TIME(   t   format_numbert   format_decimalt   format_currencyt   format_percentt   format_scientifict
   LC_NUMERIC(   t   sett   UTCt   Formatt	   LazyProxyt   Translationss   restructuredtext enc           B   sz   e  Z d  Z d d „ Z d d d „ Z d d d „ Z d d d „ Z d „  Z d d „ Z	 d „  Z
 d d	 „ Z d
 „  Z RS(   s  Wrapper class providing the various date and number formatting functions
    bound to a specific locale and time-zone.
    
    >>> fmt = Format('en_US', UTC)
    >>> fmt.date(date(2007, 4, 1))
    u'Apr 1, 2007'
    >>> fmt.decimal(1.2345)
    u'1.234'
    c         C   s   t  j | ƒ |  _ | |  _ d S(   s·   Initialize the formatter.
        
        :param locale: the locale identifier or `Locale` instance
        :param tzinfo: the time-zone info (a `tzinfo` instance or `None`)
        N(   R   t   parset   localet   tzinfo(   t   selfR   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __init__,   s    t   mediumc         C   s   t  | | d |  j ƒS(   sÚ   Return a date formatted according to the given pattern.
        
        >>> fmt = Format('en_US')
        >>> fmt.date(date(2007, 4, 1))
        u'Apr 1, 2007'
        
        :see: `babel.dates.format_date`
        R   (   R   R   (   R   R    t   format(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR    5   s    	c         C   s   t  | | d |  j d |  j ƒS(   sH  Return a date and time formatted according to the given pattern.
        
        >>> from pytz import timezone
        >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
        >>> fmt.datetime(datetime(2007, 4, 1, 15, 30))
        u'Apr 1, 2007 11:30:00 AM'
        
        :see: `babel.dates.format_datetime`
        R   R   (   R   R   R   (   R   R   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR   @   s    
c         C   s   t  | | d |  j d |  j ƒS(   s+  Return a time formatted according to the given pattern.
        
        >>> from pytz import timezone
        >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
        >>> fmt.time(datetime(2007, 4, 1, 15, 30))
        u'11:30:00 AM'
        
        :see: `babel.dates.format_time`
        R   R   (   R   R   R   (   R   R   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR   M   s    
c         C   s   t  | d |  j ƒS(   sÉ   Return an integer number formatted for the locale.
        
        >>> fmt = Format('en_US')
        >>> fmt.number(1099)
        u'1,099'
        
        :see: `babel.numbers.format_number`
        R   (   R   R   (   R   t   number(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR   Y   s    	c         C   s   t  | | d |  j ƒS(   sÌ   Return a decimal number formatted for the locale.
        
        >>> fmt = Format('en_US')
        >>> fmt.decimal(1.2345)
        u'1.234'
        
        :see: `babel.numbers.format_decimal`
        R   (   R	   R   (   R   R   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   decimald   s    	c         C   s   t  | | d |  j ƒS(   s   Return a number in the given currency formatted for the locale.
        
        :see: `babel.numbers.format_currency`
        R   (   R
   R   (   R   R   t   currency(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR   o   s    c         C   s   t  | | d |  j ƒS(   sÎ   Return a number formatted as percentage for the locale.
        
        >>> fmt = Format('en_US')
        >>> fmt.percent(0.34)
        u'34%'
        
        :see: `babel.numbers.format_percent`
        R   (   R   R   (   R   R   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   percentv   s    	c         C   s   t  | d |  j ƒS(   s…   Return a number formatted using scientific notation for the locale.
        
        :see: `babel.numbers.format_scientific`
        R   (   R   R   (   R   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt
   scientific   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R    R   R   R   R   R   R   R   (    (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR   !   s   				c           B   s(  e  Z d  Z d d d d g Z d „  Z d „  Z e e ƒ 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 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 d  „  Z  RS(!   s  Class for proxy objects that delegate to a specified function to evaluate
    the actual object.
    
    >>> def greeting(name='world'):
    ...     return 'Hello, %s!' % name
    >>> lazy_greeting = LazyProxy(greeting, name='Joe')
    >>> print lazy_greeting
    Hello, Joe!
    >>> u'  ' + lazy_greeting
    u'  Hello, Joe!'
    >>> u'(%s)' % lazy_greeting
    u'(Hello, Joe!)'
    
    This can be used, for example, to implement lazy translation functions that
    delay the actual translation until the string is actually used. The
    rationale for such behavior is that the locale of the user may not always
    be available. In web applications, you only know the locale when processing
    a request.
    
    The proxy implementation attempts to be as complete as possible, so that
    the lazy objects should mostly work as expected, for example for sorting:
    
    >>> greetings = [
    ...     LazyProxy(greeting, 'world'),
    ...     LazyProxy(greeting, 'Joe'),
    ...     LazyProxy(greeting, 'universe'),
    ... ]
    >>> greetings.sort()
    >>> for greeting in greetings:
    ...     print greeting
    Hello, Joe!
    Hello, universe!
    Hello, world!
    t   _funct   _argst   _kwargst   _valuec         O   sP   t  j |  d | ƒ t  j |  d | ƒ t  j |  d | ƒ t  j |  d d  ƒ d  S(   NR#   R$   R%   R&   (   t   objectt   __setattr__R"   (   R   t   funct   argst   kwargs(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR   ®   s    c         C   sD   |  j  d  k r= |  j |  j |  j Ž  } t j |  d | ƒ n  |  j  S(   NR&   (   R&   R"   R#   R$   R%   R'   R(   (   R   t   value(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR,   µ   s    c         C   s   | |  j  k S(   N(   R,   (   R   t   key(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __contains__¼   s    c         C   s   t  |  j ƒ S(   N(   t   boolR,   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __nonzero__¿   s    c         C   s   t  |  j ƒ S(   N(   t   dirR,   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __dir__Â   s    c         C   s   t  |  j ƒ S(   N(   t   iterR,   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __iter__Å   s    c         C   s   t  |  j ƒ S(   N(   t   lenR,   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __len__È   s    c         C   s   t  |  j ƒ S(   N(   t   strR,   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __str__Ë   s    c         C   s   t  |  j ƒ S(   N(   t   unicodeR,   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __unicode__Î   s    c         C   s   |  j  | S(   N(   R,   (   R   t   other(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __add__Ñ   s    c         C   s   | |  j  S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __radd__Ô   s    c         C   s   |  j  | S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __mod__×   s    c         C   s   | |  j  S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __rmod__Ú   s    c         C   s   |  j  | S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __mul__Ý   s    c         C   s   | |  j  S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __rmul__à   s    c         O   s   |  j  | | Ž  S(   N(   R,   (   R   R*   R+   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __call__ã   s    c         C   s   |  j  | k  S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __lt__æ   s    c         C   s   |  j  | k S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __le__é   s    c         C   s   |  j  | k S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __eq__ì   s    c         C   s   |  j  | k S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __ne__ï   s    c         C   s   |  j  | k S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __gt__ò   s    c         C   s   |  j  | k S(   N(   R,   (   R   R;   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __ge__õ   s    c         C   s   t  |  j | ƒ d  S(   N(   t   delattrR,   (   R   t   name(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __delattr__ø   s    c         C   s   t  |  j | ƒ S(   N(   t   getattrR,   (   R   RJ   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __getattr__û   s    c         C   s   t  |  j | | ƒ d  S(   N(   t   setattrR,   (   R   RJ   R,   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR(   þ   s    c         C   s   |  j  | =d  S(   N(   R,   (   R   R-   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __delitem__  s    c         C   s   |  j  | S(   N(   R,   (   R   R-   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __getitem__  s    c         C   s   | |  j  | <d  S(   N(   R,   (   R   R-   R,   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __setitem__  s    (!   R   R    R!   t	   __slots__R   R,   t   propertyR.   R0   R2   R4   R6   R8   R:   R<   R=   R>   R?   R@   RA   RB   RC   RD   RE   RF   RG   RH   RK   RM   R(   RO   RP   RQ   (    (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR   ‰   s>   "																											c           B   s•   e  Z d  Z d Z d e d „ Z d d e d „ Z e e ƒ Z d „  Z e	 d „ Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   s&   An extended translation catalog class.t   messagesc         C   sM   t  j j |  d | ƒt d t | d d ƒ g ƒ |  _ | |  _ i  |  _ d S(   s—   Initialize the translations catalog.

        :param fileobj: the file-like object the translation should be read
                        from
        t   fpRJ   N(	   t   gettextt   GNUTranslationsR   t   filterR"   RL   t   filest   domaint   _domains(   R   t   fileobjRZ   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR     s    !	c         C   s¢   | d k	 rO t | t t f ƒ s- | g } n  g  | D] } t | ƒ ^ q4 } n  | sa |  j } n  t j | | | ƒ } | s† t j ƒ  S|  d t	 | d ƒ d | ƒ S(   sù  Load translations from the given directory.

        :param dirname: the directory containing the ``MO`` files
        :param locales: the list of locales in order of preference (items in
                        this list can be either `Locale` objects or locale
                        strings)
        :param domain: the message domain
        :return: the loaded catalog, or a ``NullTranslations`` instance if no
                 matching translations were found
        :rtype: `Translations`
        R\   t   rbRZ   N(
   R"   t
   isinstancet   listt   tupleR7   t   DEFAULT_DOMAINRV   t   findt   NullTranslationst   open(   t   clst   dirnamet   localesRZ   R   t   filename(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   load  s    "
c         C   s#   d t  |  ƒ j |  j j d ƒ f S(   Ns
   <%s: "%s">s   project-id-version(   t   typeR   t   _infot   get(   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   __repr__3  s    c         C   s‰   t  | d |  j ƒ } | r7 | |  j k r7 |  j | ƒ S|  j j | ƒ } | rk | d k	 rk | j | ƒ n | j |  ƒ | |  j | <|  S(   sµ  Add the given translations to the catalog.

        If the domain of the translations is different than that of the
        current catalog, they are added as a catalog that is only accessible
        by the various ``d*gettext`` functions.

        :param translations: the `Translations` instance with the messages to
                             add
        :param merge: whether translations for message domains that have
                      already been added should be merged with the existing
                      translations
        :return: the `Translations` instance (``self``) so that `merge` calls
                 can be easily chained
        :rtype: `Translations`
        RZ   N(   RL   Ra   RZ   t   mergeR[   Rl   R"   t   add_fallback(   R   t   translationsRn   RZ   t   existing(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   add7  s    c         C   sQ   t  | t j ƒ rM |  j j | j ƒ t  | t ƒ rM |  j j | j ƒ qM n  |  S(   sÄ  Merge the given translations into the catalog.

        Message translations in the specified catalog override any messages
        with the same identifier in the existing catalog.

        :param translations: the `Translations` instance with the messages to
                             merge
        :return: the `Translations` instance (``self``) so that `merge` calls
                 can be easily chained
        :rtype: `Translations`
        (   R^   RV   RW   t   _catalogt   updateR   RY   t   extend(   R   Rp   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyRn   T  s
    c         C   s   |  j  j | |  ƒ j | ƒ S(   sU   Like ``gettext()``, but look the message up in the specified
        domain.
        (   R[   Rl   RV   (   R   RZ   t   message(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   dgettextg  s    c         C   s   |  j  j | |  ƒ j | ƒ S(   sW   Like ``lgettext()``, but look the message up in the specified 
        domain.
        (   R[   Rl   t   lgettext(   R   RZ   Rv   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt	   ldgettextm  s    c         C   s   |  j  j | |  ƒ j | ƒ S(   sV   Like ``ugettext()``, but look the message up in the specified
        domain.
        (   R[   Rl   t   ugettext(   R   RZ   Rv   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt	   dugettexts  s    c         C   s"   |  j  j | |  ƒ j | | | ƒ S(   sV   Like ``ngettext()``, but look the message up in the specified
        domain.
        (   R[   Rl   t   ngettext(   R   RZ   t   singulart   pluralt   num(    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt	   dngettexty  s    c         C   s"   |  j  j | |  ƒ j | | | ƒ S(   sW   Like ``lngettext()``, but look the message up in the specified
        domain.
        (   R[   Rl   t	   lngettext(   R   RZ   R}   R~   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt
   ldngettext  s    c         C   s"   |  j  j | |  ƒ j | | | ƒ S(   sV   Like ``ungettext()`` but look the message up in the specified
        domain.
        (   R[   Rl   t	   ungettext(   R   RZ   R}   R~   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt
   dungettext…  s    N(   R   R    R!   Ra   R"   R   Ri   t   classmethodRm   t   TrueRr   Rn   Rw   Ry   R{   R€   R‚   R„   (    (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyR     s   							(   R!   R   R    R   RV   t
   babel.coreR   t   babel.datesR   R   R   R   t   babel.numbersR   R	   R
   R   R   R   t
   babel.utilR   R   t   __all__t   __docformat__R'   R   R   RW   R   (    (    (    s1   /usr/lib/python2.7/site-packages/babel/support.pyt   <module>   s   ".h‚