ó
™‚Mc           @   sL  d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l	 Z	 d d l
 Z
 d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z m Z m Z m Z m Z m Z d d d g Z d Z e	 j d ƒ Z d e f d „  ƒ  YZ  d e! f d „  ƒ  YZ" d Z# d e f d „  ƒ  YZ$ d S(   s%   Data structures for message catalogs.iÿÿÿÿ(   t   parse_header(   t   datetime(   t   get_close_matches(   t   message_from_string(   t   copyN(   t   __version__(   t   Locale(   t   format_datetime(   t
   get_plural(   t   odictt   distinctt   sett   LOCALTZt   UTCt   FixedOffsetTimezonet   Messaget   Catalogt   TranslationErrors   restructuredtext ens¬   (?x)
    \%
        (?:\(([\w]*)\))?
        (
            [-#0\ +]?(?:\*|[\d]+)?
            (?:\.(?:\*|[\d]+))?
            [hlL]?
        )
        ([diouxXeEfFgGcrs%])
c           B   s¤   e  Z d  Z d d d d d d d d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z	 e
 e	 d d	 ƒZ	 d
 „  Z e
 e d d ƒZ d „  Z e
 e d d ƒZ RS(   s0   Representation of a single message in a catalog.u    c	   	      C   så   | |  _  | r" |  j r" d } n  | |  _ t t | ƒ ƒ |  _ t | ƒ |  _ | rq |  j rq |  j j	 d ƒ n |  j j
 d ƒ t t | ƒ ƒ |  _ t t | ƒ ƒ |  _ t | t ƒ rÉ | g |  _ n t | ƒ |  _ | |  _ d S(   s4  Create the message object.

        :param id: the message ID, or a ``(singular, plural)`` tuple for
                   pluralizable messages
        :param string: the translated message string, or a
                       ``(singular, plural)`` tuple for pluralizable messages
        :param locations: a sequence of ``(filenname, lineno)`` tuples
        :param flags: a set or sequence of flags
        :param auto_comments: a sequence of automatic comments for the message
        :param user_comments: a sequence of user comments for the message
        :param previous_id: the previous message ID, or a ``(singular, plural)``
                            tuple for pluralizable messages
        :param lineno: the line number on which the msgid line was found in the
                       PO file, if any
        u    s   python-formatN(   u    u    (   t   idt   pluralizablet   stringt   listR
   t	   locationsR   t   flagst   python_formatt   addt   discardt   auto_commentst   user_commentst
   isinstancet
   basestringt   previous_idt   lineno(	   t   selfR   R   R   R   R   R   R   R    (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __init__1   s    			c         C   s&   d t  |  ƒ j |  j t |  j ƒ f S(   Ns   <%s %r (flags: %r)>(   t   typet   __name__R   R   R   (   R!   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __repr__T   s    c         C   s˜   t  | t ƒ r… |  j } | j } | rH | rH t |  j d | j d ƒ S| re t |  j d | j ƒ S| r… t |  j | j d ƒ Sn  t |  j | j ƒ S(   s0   Compare Messages, taking into account plural idsi    (   R   R   R   t   cmpR   (   R!   t   objt   pluralt
   obj_plural(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __cmp__X   s    		c         C   sC   t  t t |  j |  j |  j |  j |  j |  j |  j	 |  j
 f ƒ Œ  S(   N(   R   t   mapR   R   R   R   R   R   R   R   R    (   R!   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   clonee   s    c         C   s_   d d l  m } g  } xB | D]: } y | | |  ƒ Wq t k
 rV } | j | ƒ q Xq W| S(   s•  Run various validation checks on the message.  Some validations
        are only performed if the catalog is provided.  This method returns
        a sequence of `TranslationError` objects.

        :rtype: ``iterator``
        :param catalog: A catalog instance that is passed to the checkers
        :see: `Catalog.check` for a way to perform checks for all messages
              in a catalog.
        iÿÿÿÿ(   t   checkers(   t   babel.messages.checkersR-   R   t   append(   R!   t   catalogR-   t   errorst   checkert   e(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   checkk   s    
c         C   s   d |  j  k S(   Nt   fuzzy(   R   (   R!   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR5   ~   s    t   docs          Whether the translation is fuzzy.

        >>> Message('foo').fuzzy
        False
        >>> msg = Message('foo', 'foo', flags=['fuzzy'])
        >>> msg.fuzzy
        True
        >>> msg
        <Message 'foo' (flags: ['fuzzy'])>

        :type:  `bool`
        c         C   s   t  |  j t t f ƒ S(   N(   R   R   R   t   tuple(   R!   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR   Ž   s    sÀ           Whether the message is plurizable.

        >>> Message('foo').pluralizable
        False
        >>> Message(('foo', 'bar')).pluralizable
        True

        :type:  `bool`
        c         C   sY   |  j  } t | t t f ƒ s* | g } n  t t d  g  | D] } t j | ƒ ^ q: ƒ ƒ S(   N(	   R   R   R   R7   t   boolt   filtert   Nonet   PYTHON_FORMATt   search(   R!   t   idsR   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR   ›   s    	só           Whether the message contains Python-style parameters.

        >>> Message('foo %(name)s bar').python_format
        True
        >>> Message(('foo %(name)s', 'foo %(name)s')).python_format
        True

        :type:  `bool`
        (    (    (    (    (    N(   R$   t
   __module__t   __doc__R:   R"   R%   R*   R,   R4   R5   t   propertyR   R   (    (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR   .   s    "													c           B   s   e  Z d  Z RS(   s_   Exception thrown by translation checkers when invalid message
    translations are encountered.(   R$   R>   R?   (    (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR   ¬   s   u¸   # Translations template for PROJECT.
# Copyright (C) YEAR ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#c           B   sX  e  Z d  Z d d e d d d d d d d d d e d „ Z d „  Z d „  Z e	 e e d d ƒZ
 d „  Z d „  Z e	 e e d d	 ƒZ d
 „  Z e	 e d d ƒZ d „  Z e	 e d d ƒZ d „  Z e	 e d d ƒZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d d d d  d d „ Z d „  Z e d „ Z d „  Z RS(!   s$   Representation of a message catalog.s   utf-8c         C   s}  | |  _  | r! t j | ƒ } n  | |  _ | |  _ t ƒ  |  _ | pH d |  _ | pW d |  _ | pf d |  _	 | pu d |  _
 |
 p„ d |  _ | p“ d |  _ | p¢ d |  _ | d	 k rÆ t j t ƒ } n. t | t ƒ rô | j rô | j d t ƒ } n  | |  _ |	 d	 k rt j t ƒ }	 n. t |	 t ƒ rI|	 j rI|	 j d t ƒ }	 n  |	 |  _ | |  _ t ƒ  |  _ d	 |  _ d	 |  _ d	 S(
   s0  Initialize the catalog object.

        :param locale: the locale identifier or `Locale` object, or `None`
                       if the catalog is not bound to a locale (which basically
                       means it's a template)
        :param domain: the message domain
        :param header_comment: the header comment as string, or `None` for the
                               default header
        :param project: the project's name
        :param version: the project's version
        :param copyright_holder: the copyright holder of the catalog
        :param msgid_bugs_address: the email address or URL to submit bug
                                   reports to
        :param creation_date: the date the catalog was created
        :param revision_date: the date the catalog was revised
        :param last_translator: the name and email of the last translator
        :param language_team: the name and email of the language team
        :param charset: the encoding to use in the output
        :param fuzzy: the fuzzy bit on the catalog header
        t   PROJECTt   VERSIONt   ORGANIZATIONs   EMAIL@ADDRESSs   FULL NAME <EMAIL@ADDRESS>s   LANGUAGE <LL@li.org>s   utf-8t   tzinfoN(   t   domainR   t   parset   localet   _header_commentR	   t	   _messagest   projectt   versiont   copyright_holdert   msgid_bugs_addresst   last_translatort   language_teamt   charsetR:   R   t   nowR   R   RD   t   replacet   creation_datet   revision_dateR5   t   obsoletet   _num_pluralst   _plural_expr(   R!   RG   RE   t   header_commentRJ   RK   RL   RM   RS   RT   RN   RO   RP   R5   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR"   ¼   s6    							c         C   s€   |  j  } | j d |  j ƒ j d |  j ƒ j d |  j j d ƒ ƒ j d |  j ƒ } |  j r| | j d d |  j j ƒ } n  | S(   NRA   RB   t   YEARs   %YRC   s   Translations templates   %s translations(	   RH   RR   RJ   RK   RT   t   strftimeRL   RG   t   english_name(   R!   t   comment(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   _get_header_commentø   s    		c         C   s   | |  _  d  S(   N(   RH   (   R!   R   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   _set_header_comment  s    R6   sƒ      The header comment for the catalog.

    >>> catalog = Catalog(project='Foobar', version='1.0',
    ...                   copyright_holder='Foo Company')
    >>> print catalog.header_comment #doctest: +ELLIPSIS
    # Translations template for Foobar.
    # Copyright (C) ... Foo Company
    # This file is distributed under the same license as the Foobar project.
    # FIRST AUTHOR <EMAIL@ADDRESS>, ....
    #

    The header can also be set from a string. Any known upper-case variables
    will be replaced when the header is retrieved again:

    >>> catalog = Catalog(project='Foobar', version='1.0',
    ...                   copyright_holder='Foo Company')
    >>> catalog.header_comment = '''\
    ... # The POT for my really cool PROJECT project.
    ... # Copyright (C) 1990-2003 ORGANIZATION
    ... # This file is distributed under the same license as the PROJECT
    ... # project.
    ... #'''
    >>> print catalog.header_comment
    # The POT for my really cool Foobar project.
    # Copyright (C) 1990-2003 Foo Company
    # This file is distributed under the same license as the Foobar
    # project.
    #

    :type: `unicode`
    c         C   sh  g  } | j  d d |  j |  j f f ƒ | j  d |  j f ƒ | j  d t |  j d d d ƒf ƒ |  j d  k r | j  d ƒ | j  d ƒ | j  d ƒ n| | j  d t |  j d d d ƒf ƒ | j  d
 |  j	 f ƒ | j  d |  j
 j d t |  j ƒ ƒ f ƒ | j  d |  j f ƒ | j  d ƒ | j  d d |  j f ƒ | j  d ƒ | j  d d t f ƒ | S(   Ns   Project-Id-Versions   %s %ss   Report-Msgid-Bugs-Tos   POT-Creation-Dates   yyyy-MM-dd HH:mmZRG   t   ens   PO-Revision-Dates   YEAR-MO-DA HO:MI+ZONEs   Last-Translators   FULL NAME <EMAIL@ADDRESS>s   Language-Teams   LANGUAGE <LL@li.org>t   LANGUAGEs   Plural-Formss   MIME-Versions   1.0s   Content-Types   text/plain; charset=%ss   Content-Transfer-Encodingt   8bits   Generated-Bys	   Babel %s
(   s   PO-Revision-Dates   YEAR-MO-DA HO:MI+ZONE(   s   Last-Translators   FULL NAME <EMAIL@ADDRESS>(   s   Language-Teams   LANGUAGE <LL@li.org>(   s   MIME-Versions   1.0(   s   Content-Transfer-EncodingRa   (   R/   RJ   RK   RM   R   RS   RG   R:   RT   RN   RO   RR   t   strt   plural_formsRP   RB   (   R!   t   headers(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   _get_mime_headers'  s2    						c         C   so  x^ | D]V \ } } | j  ƒ  d k r t | ƒ \ } } d | k rY | d j  ƒ  |  _ n  Pq q Wx| D]ÿ\ } } | j  ƒ  j |  j ƒ } | j |  j ƒ } | d k rß | j d ƒ } d j | d  ƒ |  _ | d |  _ qh | d k r÷ | |  _ qh | d k r| |  _	 qh | d	 k r'| |  _
 qh | d
 k r|t d | ƒ \ } } t | j d d ƒ ƒ |  _ | j d d ƒ |  _ qh | d k rjt j d | d ƒ \ } } } t j | d ƒ }	 t j |	 ƒ }
 | d | d } } | d  | d } } t | d ƒ } t | ƒ } t | ƒ } | d } | | 7} | | 9} t | ƒ } t j |
 ƒ } | j d | ƒ |  _ qh | d k rh d | k rgt j d | d ƒ \ } } } t j | d ƒ }	 t j |	 ƒ }
 | d | d } } | d  | d } } t | d ƒ } t | ƒ } t | ƒ } | d } | | 7} | | 9} t | ƒ } t j |
 ƒ } | j d | ƒ |  _ qgqh qh Wd  S(   Ns   content-typeRP   s   project-id-versiont    u    iÿÿÿÿs   report-msgid-bugs-tos   last-translators   language-teams   plural-formss    ;t   npluralsi   R(   s   (n != 1)s   pot-creation-dates   ([+-]\d{4})$i   s   %Y-%m-%d %H:%Mi    t   1i<   RD   s   po-revision-dateRY   (   t   lowerR    RP   t   decodet   splitt   joinRJ   RK   RM   RN   RO   t   intt   getRV   RW   t   ret   timet   strptimet   mktimeR   R   t   fromtimestampRR   RS   RT   (   R!   Rd   t   namet   valuet   mimetypet   paramst   partst   _t   tzoffsett   ttt   tst   plus_minus_st   restt   hours_offset_st   mins_offset_st
   plus_minust   hours_offsett   mins_offsett   net_mins_offsett   dt(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   _set_mime_headersC  sl    





s‰      The MIME headers of the catalog, used for the special ``msgid ""`` entry.

    The behavior of this property changes slightly depending on whether a locale
    is set or not, the latter indicating that the catalog is actually a template
    for actual translations.

    Here's an example of the output for such a catalog template:

    >>> created = datetime(1990, 4, 1, 15, 30, tzinfo=UTC)
    >>> catalog = Catalog(project='Foobar', version='1.0',
    ...                   creation_date=created)
    >>> for name, value in catalog.mime_headers:
    ...     print '%s: %s' % (name, value)
    Project-Id-Version: Foobar 1.0
    Report-Msgid-Bugs-To: EMAIL@ADDRESS
    POT-Creation-Date: 1990-04-01 15:30+0000
    PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
    Last-Translator: FULL NAME <EMAIL@ADDRESS>
    Language-Team: LANGUAGE <LL@li.org>
    MIME-Version: 1.0
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: 8bit
    Generated-By: Babel ...

    And here's an example of the output when the locale is set:

    >>> revised = datetime(1990, 8, 3, 12, 0, tzinfo=UTC)
    >>> catalog = Catalog(locale='de_DE', project='Foobar', version='1.0',
    ...                   creation_date=created, revision_date=revised,
    ...                   last_translator='John Doe <jd@example.com>',
    ...                   language_team='de_DE <de@example.com>')
    >>> for name, value in catalog.mime_headers:
    ...     print '%s: %s' % (name, value)
    Project-Id-Version: Foobar 1.0
    Report-Msgid-Bugs-To: EMAIL@ADDRESS
    POT-Creation-Date: 1990-04-01 15:30+0000
    PO-Revision-Date: 1990-08-03 12:00+0000
    Last-Translator: John Doe <jd@example.com>
    Language-Team: de_DE <de@example.com>
    Plural-Forms: nplurals=2; plural=(n != 1)
    MIME-Version: 1.0
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: 8bit
    Generated-By: Babel ...

    :type: `list`
    c         C   sG   |  j  d  k r@ d } |  j r4 t |  j ƒ d } n  | |  _  n  |  j  S(   Ni   i    (   RV   R:   RG   R   (   R!   t   num(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   num_pluralsÇ  s    	s®       The number of plurals used by the catalog or locale.

    >>> Catalog(locale='en').num_plurals
    2
    >>> Catalog(locale='ga').num_plurals
    3

    :type: `int`
    c         C   sG   |  j  d  k r@ d } |  j r4 t |  j ƒ d } n  | |  _  n  |  j  S(   Ns   (n != 1)i   (   RW   R:   RG   R   (   R!   t   expr(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   plural_exprÙ  s    	sØ       The plural expression used by the catalog or locale.

    >>> Catalog(locale='en').plural_expr
    '(n != 1)'
    >>> Catalog(locale='ga').plural_expr
    '(n==1 ? 0 : n==2 ? 1 : 2)'

    :type: `basestring`
    c         C   s   d |  j  |  j f S(   Ns   nplurals=%s; plural=%s(   Rˆ   RŠ   (   R!   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyRc   ë  s    sé       Return the plural forms declaration for the locale.

    >>> Catalog(locale='en').plural_forms
    'nplurals=2; plural=(n != 1)'
    >>> Catalog(locale='pt_BR').plural_forms
    'nplurals=2; plural=(n > 1)'

    :type: `str`
    c         C   s   |  j  | ƒ |  j k S(   s?   Return whether the catalog has a message with the specified ID.(   t   _key_forRI   (   R!   R   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __contains__ø  s    c         C   s   t  |  j ƒ S(   sn   The number of messages in the catalog.

        This does not include the special ``msgid ""`` entry.
        (   t   lenRI   (   R!   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __len__ü  s    c         c   s    g  } x. |  j  D]# \ } } | j d | | f ƒ q Wt ƒ  } |  j r_ | t d g ƒ O} n  t d d j | ƒ d | ƒVx |  j D] } |  j | Vq† Wd S(   sª   Iterates through all the entries in the catalog, in the order they
        were added, yielding a `Message` object for every entry.

        :rtype: ``iterator``
        s   %s: %sR5   u    s   
R   N(   t   mime_headersR/   R   R5   R   Rl   RI   (   R!   t   bufRt   Ru   R   t   key(    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __iter__  s    		c         C   s<   d } |  j  r d |  j  } n  d t |  ƒ j |  j | f S(   Nt    s    %ss	   <%s %r%s>(   RG   R#   R$   RE   (   R!   RG   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR%     s    	c         C   s/   |  j  | ƒ } | |  j k r+ |  j | =n  d S(   s)   Delete the message with the specified ID.N(   R‹   RI   (   R!   R   R‘   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __delitem__  s    c         C   s   |  j  j |  j | ƒ ƒ S(   sã   Return the message with the specified ID.

        :param id: the message ID
        :return: the message with the specified ID, or `None` if no such message
                 is in the catalog
        :rtype: `Message`
        (   RI   Rn   R‹   (   R!   R   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __getitem__  s    c         C   s³  t  | t ƒ s t d ƒ ‚ |  j | ƒ } |  j j | ƒ } | rè | j rp | j rp | j | _ | j | _ n  t	 t
 | j | j ƒ ƒ | _ t	 t
 | j | j ƒ ƒ | _ t	 t
 | j | j ƒ ƒ | _ | j | j O_ | } nÇ | d k rYt | j j |  j ƒ ƒ } | j ƒ  |  _ d j g  | j D] } d | ^ q.ƒ |  _ | j |  _ nV t  | t	 t f ƒ r¢t  | j t	 t f ƒ s¢t d t | j ƒ ƒ ‚ n  | |  j | <d S(   sé  Add or update the message with the specified ID.

        >>> catalog = Catalog()
        >>> catalog[u'foo'] = Message(u'foo')
        >>> catalog[u'foo']
        <Message u'foo' (flags: [])>

        If a message with that ID is already in the catalog, it is updated
        to include the locations and flags of the new message.

        >>> catalog = Catalog()
        >>> catalog[u'foo'] = Message(u'foo', locations=[('main.py', 1)])
        >>> catalog[u'foo'].locations
        [('main.py', 1)]
        >>> catalog[u'foo'] = Message(u'foo', locations=[('utils.py', 5)])
        >>> catalog[u'foo'].locations
        [('main.py', 1), ('utils.py', 5)]

        :param id: the message ID
        :param message: the `Message` object
        s   expected a Message objectR“   s   
s   # %ss   Expected sequence but got %sN(   R   R   t   AssertionErrorR‹   RI   Rn   R   R   R   R   R
   R   R   R   R   R   t   encodeRP   t   itemsR   Rl   RX   R5   R7   R#   (   R!   R   t   messageR‘   t   currentRd   R\   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   __setitem__)  s2    		#c	   	   
   C   s2   t  | | t | ƒ | | | | d | ƒ|  | <d S(   s3  Add or update the message with the specified ID.

        >>> catalog = Catalog()
        >>> catalog.add(u'foo')
        >>> catalog[u'foo']
        <Message u'foo' (flags: [])>

        This method simply constructs a `Message` object with the given
        arguments and invokes `__setitem__` with that object.

        :param id: the message ID, or a ``(singular, plural)`` tuple for
                   pluralizable messages
        :param string: the translated message string, or a
                       ``(singular, plural)`` tuple for pluralizable messages
        :param locations: a sequence of ``(filenname, lineno)`` tuples
        :param flags: a set or sequence of flags
        :param auto_comments: a sequence of automatic comments
        :param user_comments: a sequence of user comments
        :param previous_id: the previous message ID, or a ``(singular, plural)``
                            tuple for pluralizable messages
        :param lineno: the line number on which the msgid line was found in the
                       PO file, if any
        R    N(   R   R   (	   R!   R   R   R   R   R   R   R   R    (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR   \  s    c         c   sD   x= |  j  j ƒ  D], } | j d |  ƒ } | r | | f Vq q Wd S(   sB  Run various validation checks on the translations in the catalog.

        For every message which fails validation, this method yield a
        ``(message, errors)`` tuple, where ``message`` is the `Message` object
        and ``errors`` is a sequence of `TranslationError` objects.

        :rtype: ``iterator``
        R0   N(   RI   t   valuesR4   (   R!   R™   R1   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR4   x  s    	c   	         s  ˆ j  ‰ ˆ j ƒ  ‰ t ƒ  ˆ _  g  } | se g  ˆ D]( } | r4 ˆ | j r4 ˆ j | ƒ ^ q4 } n  t ƒ  ‰  ‡  ‡ ‡ ‡ f d †  } x¥ | D] } | j r ˆ j | j ƒ } | ˆ k rÍ | | | | ƒ q*| t k rt | j	 ƒ  j
 ƒ  | d ƒ } | r| | | d | ƒ q qn  | ˆ | j <q q Wt ƒ  ˆ _ x4 ˆ D], } | sY| ˆ  k rAˆ | ˆ j | <qAqAW| j ˆ _ d S(   s  Update the catalog based on the given template catalog.

        >>> from babel.messages import Catalog
        >>> template = Catalog()
        >>> template.add('green', locations=[('main.py', 99)])
        >>> template.add('blue', locations=[('main.py', 100)])
        >>> template.add(('salad', 'salads'), locations=[('util.py', 42)])
        >>> catalog = Catalog(locale='de_DE')
        >>> catalog.add('blue', u'blau', locations=[('main.py', 98)])
        >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)])
        >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'),
        ...             locations=[('util.py', 38)])

        >>> catalog.update(template)
        >>> len(catalog)
        3

        >>> msg1 = catalog['green']
        >>> msg1.string
        >>> msg1.locations
        [('main.py', 99)]

        >>> msg2 = catalog['blue']
        >>> msg2.string
        u'blau'
        >>> msg2.locations
        [('main.py', 100)]

        >>> msg3 = catalog['salad']
        >>> msg3.string
        (u'Salat', u'Salate')
        >>> msg3.locations
        [('util.py', 42)]

        Messages that are in the catalog but not in the template are removed
        from the main collection, but can still be accessed via the `obsolete`
        member:

        >>> 'head' in catalog
        False
        >>> catalog.obsolete.values()
        [<Message 'head' (flags: [])>]

        :param template: the reference catalog, usually read from a POT file
        :param no_fuzzy_matching: whether to use fuzzy matching of message IDs
        c            sµ  |  j  ƒ  }  t } | | k ry t } ˆ  j | ƒ ˆ j | ƒ } t | j t ƒ rd | j g |  _ q‹ t	 | j ƒ |  _ n ˆ j
 | d  ƒ } | j |  _ t |  j t	 t f ƒ r@t |  j t	 t f ƒ sý t } t |  j g d g t |  j ƒ d ƒ |  _ qqt |  j ƒ ˆ j k rqt } t |  j t | j ƒ  ƒ |  _ qqn1 t |  j t	 t f ƒ rqt } |  j d |  _ n  |  j | j O_ | r¤|  j t d g ƒ O_ n  |  ˆ |  j <d  S(   Nu    i   i    u   fuzzy(   R,   t   Falset   TrueR   Rn   R   R   R   R   R   t   popR:   R   R7   R   Rˆ   R   R   (   R™   t   oldkeyt   newkeyR5   t   oldmsg(   t   fuzzy_matchest   messagest	   remainingR!   (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   _mergeÂ  s4    -%i   i    N(   RI   R   R	   R   R‹   R   R   R   R   Ri   t   stripRU   RS   (	   R!   t   templatet   no_fuzzy_matchingt   fuzzy_candidatest   msgidR¦   R™   R‘   t   matches(    (   R£   R¤   R¥   R!   s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   update†  s4    /	+			c         C   s,   | } t  | t t f ƒ r( | d } n  | S(   s^   The key for a message is just the singular ID even for pluralizable
        messages.
        i    (   R   R   R7   (   R!   R   R‘   (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR‹   ù  s    N(    (    (    (    (    (   R$   R>   R?   R:   t   DEFAULT_HEADERRž   R"   R]   R^   R@   RX   Re   R†   R   Rˆ   RŠ   Rc   RŒ   RŽ   R’   R%   R”   R•   R›   R   R4   R   R­   R‹   (    (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyR   ¹   sF   			8					S/																			
	3	s(%   R?   t   cgiR    R   t   difflibR   t   emailR   R   Ro   Rp   t   babelR   RB   t
   babel.coreR   t   babel.datesR   t   babel.messages.pluralsR   t
   babel.utilR	   R
   R   R   R   R   t   __all__t   __docformat__t   compileR;   t   objectR   t	   ExceptionR   R®   R   (    (    (    s:   /usr/lib/python2.7/site-packages/babel/messages/catalog.pyt   <module>   s(   .		~
