
\c           @   s  d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z 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 m Z m Z d d l m Z d d l m Z d d l m Z m Z m Z d d l m Z m Z m Z m  Z  m! Z! m" Z" d d d g Z# e j$ d e j%  Z& d   Z' d e( f d     YZ) d e* f d     YZ+ d Z, e rd   Z- n e Z- d e( f d     YZ. d S(   s   
    babel.messages.catalog
    ~~~~~~~~~~~~~~~~~~~~~~

    Data structures for message catalogs.

    :copyright: (c) 2013-2019 by the Babel Team.
    :license: BSD, see LICENSE for more details.
iN(   t   parse_header(   t   OrderedDict(   t   datetimet   time(   t   get_close_matches(   t   message_from_string(   t   copy(   t   __version__(   t   Localet   UnknownLocaleError(   t   format_datetime(   t
   get_plural(   t   distinctt   LOCALTZt   FixedOffsetTimezone(   t   string_typest   number_typest   PY2t   cmpt	   text_typet
   force_textt   Messaget   Catalogt   TranslationErrors   
    \%
        (?:\(([\w]*)\))?
        (
            [-#0\ +]?(?:\*|[\d]+)?
            (?:\.(?:\*|[\d]+))?
            [hlL]?
        )
        ([diouxXeEfFgGcrs%])
c         C   s   t  j d |   } t j | j d  d  } t j |  } t j |  } | j d  } | d  k	 r | d | d } } | d  | d } }	 t	 | d  }
 t	 |  } t	 |	  } | d	 } | | 7} | |
 9} t
 |  } | j d
 |  } n  | S(   Ns+   ^(?P<datetime>.*?)(?P<tzoffset>[+-]\d{4})?$R   s   %Y-%m-%d %H:%Mt   tzoffseti    i   i   t   1i<   t   tzinfo(   t   ret   matchR   t   strptimet   groupt   mktimeR   t   fromtimestampt   Nonet   intR   t   replace(   t   valueR   t   ttt   tst   dtR   t   plus_minus_st   restt   hours_offset_st   mins_offset_st
   plus_minust   hours_offsett   mins_offsett   net_mins_offset(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _parse_datetime_header,   s"    


c        	   B   s   e  Z d  Z d d d d d d d d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d d  Z e d    Z e d    Z e 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(   s_  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 ``(filename, 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
        :param context: the message context
        u    s   python-formatN(   u    u    (   t   idt   pluralizablet   stringt   listR   t	   locationst   sett   flagst   python_formatt   addt   discardt   auto_commentst   user_commentst
   isinstanceR   t   previous_idt   linenot   context(
   t   selfR1   R3   R5   R7   R;   R<   R>   R?   R@   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __init__O   s     				c         C   s&   d t  |   j |  j t |  j  f S(   Ns   <%s %r (flags: %r)>(   t   typet   __name__R1   R4   R7   (   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __repr__t   s    c         C   s"   d   } t  | |   | |   S(   s0   Compare Messages, taking into account plural idsc         S   sH   t  |  t  r2 |  j r2 |  j d |  j p. d f S|  j |  j pD d f S(   Ni    t    (   R=   R   R2   R1   R@   (   t   obj(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   values_to_comparez   s    (   R   (   RA   t   otherRH   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __cmp__x   s    	c         C   s   |  j  |  d k S(   Ni    (   RJ   (   RA   RI   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __gt__   s    c         C   s   |  j  |  d k  S(   Ni    (   RJ   (   RA   RI   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __lt__   s    c         C   s   |  j  |  d k S(   Ni    (   RJ   (   RA   RI   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __ge__   s    c         C   s   |  j  |  d k S(   Ni    (   RJ   (   RA   RI   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __le__   s    c         C   s   |  j  |  d k S(   Ni    (   RJ   (   RA   RI   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __eq__   s    c         C   s   |  j  |  d k S(   Ni    (   RJ   (   RA   RI   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __ne__   s    c         C   sI   t  t t |  j |  j |  j |  j |  j |  j |  j	 |  j
 |  j f	    S(   N(   R   t   mapR   R1   R3   R5   R7   R;   R<   R>   R?   R@   (   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   clone   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.checkersRS   R   t   append(   RA   t   catalogRS   t   errorst   checkert   e(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   check   s    
c         C   s   d |  j  k S(   s   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`t   fuzzy(   R7   (   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR[      s    c         C   s   t  |  j t t f  S(   s   Whether the message is plurizable.

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

        :type:  `bool`(   R=   R1   R4   t   tuple(   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR2      s    
c         C   s>   |  j  } t | t t f  s* | g } n  t d   | D  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`c         s   s   |  ] } t  j |  Vq d  S(   N(   t   PYTHON_FORMATt   search(   t   .0R1   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pys	   <genexpr>   s    (   R1   R=   R4   R\   t   any(   RA   t   ids(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR8      s    
	(    (    (    (    (    N(   RD   t
   __module__t   __doc__R!   RB   RE   RJ   RK   RL   RM   RN   RO   RP   RR   RZ   t   propertyR[   R2   R8   (    (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR   L   s    $									c           B   s   e  Z d  Z RS(   s_   Exception thrown by translation checkers when invalid message
    translations are encountered.(   RD   Rb   Rc   (    (    (    s5   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         C   sd   t  |  j d   } i  } xB | j   D]4 \ } } | j d  } | j d  } | | | <q( W| S(   Nt   utf8(   R   t   encodet   itemst   decode(   t   header_stringt   headerst   decoded_headerst   nameR$   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _parse_header   s    c           B   s  e  Z d  Z d d e d d d d d d d d d e d  Z d   Z d   Z d   Z	 e
 e e  Z e
 e	  Z d   Z d   Z e
 e e d d Z d	   Z d
   Z e
 e e d d Z e
 d    Z e
 d    Z e
 d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d d d d  d! d d d  Z d   Z d d  Z d d  Z  e! e! e d  Z" d d  Z# RS("   s$   Representation of a message catalog.c         C   s\  | |  _  | |  _ | |  _ t   |  _ | p0 d |  _ | p? d |  _ | pN d |  _ | p] d |  _ |
 pl d |  _	 | p{ d |  _
 | p d |  _ | d
 k r t j t  } n. t | t  r | j r | j d t  } n  | |  _ |	 d
 k r d	 }	 n. t |	 t  r(|	 j r(|	 j d t  }	 n  |	 |  _ | |  _ t   |  _ d
 |  _ d
 |  _ d
 S(   sD  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 (defaults to utf-8)
        :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-8R   s   YEAR-MO-DA HO:MI+ZONEN(   t   domaint   localet   _header_commentR   t	   _messagest   projectt   versiont   copyright_holdert   msgid_bugs_addresst   last_translatort   language_teamt   charsetR!   R   t   nowR   R=   R   R#   t   creation_datet   revision_dateR[   t   obsoletet   _num_pluralst   _plural_expr(   RA   Rr   Rq   t   header_commentRu   Rv   Rw   Rx   R}   R~   Ry   Rz   R{   R[   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyRB      s2    								c         C   s   | d  k r" d  |  _ d  |  _ d  St | t  rM t |  |  _ | |  _ d  St | t  r t |  |  _ y t j |  |  _ Wn t k
 r d  |  _ n Xd  St	 d |   d  S(   NsF   `locale` must be a Locale, a locale identifier string, or None; got %r(
   R!   t   _locale_identifiert   _localeR=   R   R   R   t   parseR	   t	   TypeError(   RA   Rr   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _set_locale/  s     			c         C   s   |  j  S(   N(   R   (   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _get_localeD  s    c         C   s   |  j  S(   N(   R   (   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _get_locale_identifierG  s    c         C   s   |  j  } t j t  j d  } t |  j d  rH |  j j d  } n  | j d |  j  j d |  j	  j d |  j d |  j
  } |  j r |  j j n |  j } | r | j d d |  } n  | S(	   Ns   %Yt   strftimeRn   Ro   t   YEARRp   s   Translations templates   %s translations(   Rs   R   R|   R   R   t   hasattrR~   R#   Ru   Rv   Rw   Rr   t   english_namet   locale_identifier(   RA   t   commentt   yeart   locale_name(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _get_header_commentM  s    	c         C   s   | |  _  d  S(   N(   Rs   (   RA   R3   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _set_header_comment[  s    t   docs      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   s  g  } | j  d d |  j |  j f f  | j  d |  j f  | j  d t |  j d d d f  t |  j t t	 f t
  r | j  d t |  j d d d f  n | j  d |  j f  | j  d	 |  j f  |  j r | j  d
 t |  j  f  n  |  j rBd |  j k rB| j  d |  j j d t |  j   f  n | j  d |  j f  |  j d  k	 r| j  d |  j f  n  | 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:mmZRr   t   ens   PO-Revision-Dates   Last-Translatort   Languaget   LANGUAGEs   Language-Teams   Plural-Formss   MIME-Versions   1.0s   Content-Types   text/plain; charset=%ss   Content-Transfer-Encodingt   8bits   Generated-Bys	   Babel %s
(   s   MIME-Versions   1.0(   s   Content-Transfer-EncodingR   (   RU   Ru   Rv   Rx   R
   R}   R=   R~   R   t   time_R   Ry   R   t   strRz   R#   Rr   R!   t   plural_formsR{   Ro   (   RA   Rj   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _get_mime_headers  s8    							c         C   s  x| D]\ } } t  | j   d |  j } t  | d |  j } | d k r | j d  } d j | d   |  _ | d |  _ q | d k r | |  _ q | d k r | |  _ q | d k r | j	 d	 d
  } |  j
 |  q | d k r | |  _ q | d k r=t |  \ } } d | k r| d j   |  _ qq | d k rt d |  \ } } t | j d d   |  _ | j d d  |  _ q | d k rt |  |  _ q | d k r d | k rt |  |  _ qq q Wd  S(   Nt   encodings   project-id-versiont    u    is   report-msgid-bugs-tos   last-translatort   languaget   -t   _s   language-teams   content-typeR{   s   plural-formss    ;t   npluralsi   t   plurals   (n != 1)s   pot-creation-dates   po-revision-dateR   (   R   t   lowerR{   t   splitt   joinRu   Rv   Rx   Ry   R#   R   Rz   R    R"   t   getR   R   R0   R}   R~   (   RA   Rj   Rl   R$   t   partst   mimetypet   paramsR   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _set_mime_headers  s:    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:

    >>> from babel.dates import UTC
    >>> 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: de_DE
    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(   s   The number of plurals used by the catalog or locale.

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

        :type: `int`i   i    N(   R   R!   Rr   R   (   RA   t   num(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   num_plurals  s    
	c         C   sG   |  j  d k r@ d } |  j r4 t |  j  d } n  | |  _  n  |  j  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 : n>=3 && n<=6 ? 2 : n>=7 && n<=10 ? 3 : 4)'
        >>> Catalog(locale='ding').plural_expr  # unknown locale
        '(n != 1)'

        :type: `string_types`s   (n != 1)i   N(   R   R!   Rr   R   (   RA   t   expr(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   plural_expr  s    	c         C   s   d |  j  |  j f 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`s   nplurals=%s; plural=%s(   R   R   (   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR     s    
c         C   s   |  j  |  |  j k S(   s?   Return whether the catalog has a message with the specified ID.(   t   _key_forRt   (   RA   R1   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __contains__"  s    c         C   s   t  |  j  S(   se   The number of messages in the catalog.

        This does not include the special ``msgid ""`` entry.(   t   lenRt   (   RA   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __len__&  s    c         c   s   g  } x. |  j  D]# \ } } | j d | | f  q Wt   } |  j rY | d h 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: %sR[   u    s   
R7   N(   t   mime_headersRU   R6   R[   R   R   Rt   (   RA   t   bufRl   R$   R7   t   key(    (    s5   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(   NRF   s    %ss	   <%s %r%s>(   Rr   RC   RD   Rq   (   RA   Rr   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyRE   ;  s    	c         C   s   |  j  |  d S(   s)   Delete the message with the specified ID.N(   t   delete(   RA   R1   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __delitem__A  s    c         C   s   |  j  |  S(   sU   Return the message with the specified ID.

        :param id: the message ID
        (   R   (   RA   R1   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __getitem__E  s    c         C   s  t  | t  s t d   |  j | | j  } |  j j |  } | r | j rv | j rv | j | _ | j	 | _	 n  t
 t | j | j   | _ t
 t | j | j   | _ t
 t | j | j   | _ | j | j O_ | } n | d k rSt | j	  j   |  _ d j g  | j D] } d | j   ^ 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 objectRF   s   
s   # %ss   Expected sequence but got %sN(   R=   R   t   AssertionErrorR   R@   Rt   R   R2   R1   R3   R4   R   R5   R;   R<   R7   Rm   Rg   R   R   t   rstripR   R[   R\   RC   (   RA   R1   t   messageR   t   currentt   c(    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   __setitem__L  s0    		)c
         C   s>   t  | | t |  | | | | d | d |	 }
 |
 |  | <|
 S(   st  Add or update the message with the specified ID.

        >>> catalog = Catalog()
        >>> catalog.add(u'foo')
        <Message ...>
        >>> 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 ``(filename, 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
        :param context: the message context
        R?   R@   (   R   R4   (   RA   R1   R3   R5   R7   R;   R<   R>   R?   R@   R   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR9   ~  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``
        RV   N(   Rt   t   valuesRZ   (   RA   R   RW   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyRZ     s    	c         C   s   |  j  j |  j | |   S(   s   Return the message with the specified ID and context.

        :param id: the message ID
        :param context: the message context, or ``None`` for no context
        (   Rt   R   R   (   RA   R1   R@   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR     s    c         C   s2   |  j  | |  } | |  j k r. |  j | =n  d S(   s   Delete the message with the specified ID and context.

        :param id: the message ID
        :param context: the message context, or ``None`` for no context
        N(   R   Rt   (   RA   R1   R@   R   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR     s    c            s   j    j    t    _  g  } | sx t g   D]5 } | r7  | j r7  j |   | j f ^ q7  } n  t           f d   } x | D] } | j r  j | j | j  }	 |	  k r | | |	 |	  q| t	 k rt
 |	 t  r|	 d }
 n |	 }
 t |
 j   j   | j   d  } | r| d } | | } | d k	 rp| | f } n  | | | |	  q qn  |  | j <q q Wx4  D], } | s|   k r |  j | <qqW| r| j  _ n  | 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)])
        <Message ...>
        >>> template.add('blue', locations=[('main.py', 100)])
        <Message ...>
        >>> template.add(('salad', 'salads'), locations=[('util.py', 42)])
        <Message ...>
        >>> catalog = Catalog(locale='de_DE')
        >>> catalog.add('blue', u'blau', locations=[('main.py', 98)])
        <Message ...>
        >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)])
        <Message ...>
        >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'),
        ...             locations=[('util.py', 38)])
        <Message ...>

        >>> 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
        >>> list(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 |  _  r t	 t | j   |  _ n  t |  j t	 t f  rat |  j t	 t f  st } t |  j g d g t |  j  d  |  _ qt |  j   j k rt } t |  j t | j    |  _ qn1 t |  j t	 t f  rt } |  j d |  _ n  |  j | j O_ | r|  j d h O_ n  |   |  j <d  S(   Nu    i   i    u   fuzzy(   RR   t   Falset   TrueR9   R   R=   R1   R   R>   R4   t   popR!   R3   R   R<   R\   R   R   R7   (   R   t   oldkeyt   newkeyR[   t   oldmsg(   t   fuzzy_matchest   keep_user_commentst   messagest	   remainingRA   (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   _merge  s8    -%i    i   N(   Rt   R   R   t   dictR3   R   R@   R6   R1   R   R=   R\   R   R   t   stript   keysR!   R   R   R}   (   RA   t   templatet   no_fuzzy_matchingt   update_header_commentR   t   fuzzy_candidatest   msgidR   R   R   t   matchkeyt   matchesR   t   newctxt(    (   R   R   R   R   RA   s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   update  sF    5	E	#	

	c         C   sG   | } t  | t t f  r( | d } n  | d k	 rC | | f } n  | S(   s   The key for a message is just the singular ID even for pluralizable
        messages, but is a ``(msgid, msgctxt)`` tuple for context-specific
        messages.
        i    N(   R=   R4   R\   R!   (   RA   R1   R@   R   (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR   I  s    N(    (    (    (    (    ($   RD   Rb   Rc   R!   t   DEFAULT_HEADERR   RB   R   R   R   Rd   Rr   R   R   R   R   R   R   R   R   R   R   R   R   R   RE   R   R   R   R9   RZ   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyR      sH   			6							 	 1								2 	
(/   Rc   R   R   t   cgiR    t   collectionsR   R   R   t   difflibR   t   emailR   R   t   babelR   Ro   t
   babel.coreR   R	   t   babel.datesR
   t   babel.messages.pluralsR   t
   babel.utilR   R   R   t   babel._compatR   R   R   R   R   R   t   __all__t   compilet   VERBOSER]   R0   t   objectR   t	   ExceptionR   R   Rm   R   (    (    (    s5   lib/python2.7/site-packages/babel/messages/catalog.pyt   <module>
   s2   .		 
