
\c           @  s  d  Z  d d l m 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	 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 m Z m Z m Z d d
 l m Z d d l m Z d d l m Z m Z m  Z  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/ m0 Z0 m1 Z1 y d d l2 m3 Z3 Wn! e4 k
 rd d l5 m3 Z3 n Xe rd n d Z6 e7 d  Z8 d e. f d     YZ- d e- f d     YZ9 d e- f d     YZ: d   Z; d e- f d     YZ< d  e- f d!     YZ= d" e> f d#     YZ? d$   Z@ e7 d%  ZA g  d&  ZB eC d' k re@   n  d S((   s   
    babel.messages.frontend
    ~~~~~~~~~~~~~~~~~~~~~~~

    Frontends for the message extraction functionality.

    :copyright: (c) 2013-2019 by the Babel Team.
    :license: BSD, see LICENSE for more details.
i(   t   print_functionN(   t   OrderedDict(   t   datetime(   t   getpreferredencoding(   t   __version__(   t   Localet
   localedata(   t   StringIOt   string_typest	   text_typet   PY2(   t   UnknownLocaleError(   t   Catalog(   t   DEFAULT_KEYWORDSt   DEFAULT_MAPPINGt   check_and_call_extract_filet   extract_from_dir(   t   write_mo(   t   read_pot   write_po(   t   LOCALTZ(   t   log(   t   Command(   t   DistutilsOptionErrort   DistutilsSetupError(   t   RawConfigParsert   rUt   rc         C  s   g  } t  |  t t f  s' |  g }  n  xz |  D]r } | d k rF q. n  t  | t t f  rz | j t | d |  q. n  | j d   t |  j |  D  q. Wt d   | D  s t	  | S(   s  
    Make a list out of an argument.

    Values from `distutils` argument parsing are always single strings;
    values from `optparse` parsing may be lists of strings that may need
    to be further split.

    No matter the input, this function returns a flat list of whitespace-trimmed
    strings, with `None` values filtered out.

    >>> listify_value("foo bar")
    ['foo', 'bar']
    >>> listify_value(["foo bar"])
    ['foo', 'bar']
    >>> listify_value([["foo"], "bar"])
    ['foo', 'bar']
    >>> listify_value([["foo"], ["bar", None, "foo"]])
    ['foo', 'bar', 'foo']
    >>> listify_value("foo, bar, quux", ",")
    ['foo', 'bar', 'quux']

    :param arg: A string or a list of strings
    :param split: The argument to pass to `str.split()`.
    :return:
    t   splitc         s  s   |  ] } | j    Vq d  S(   N(   t   strip(   t   .0t   s(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pys	   <genexpr>S   s    c         s  s   |  ] } t  | t  Vq d  S(   N(   t
   isinstanceR   (   R   t   val(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pys	   <genexpr>T   s    N(
   R    t   listt   tuplet   Nonet   extendt   listify_valueR	   R   t   allt   AssertionError(   t   argR   t   outR!   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR&   .   s    *R   c           B  s8   e  Z d Z d Z d Z i  Z i  Z e Z	 d d   Z
 RS(   c         C  sD   | |  _  |  j   d  |  _ t |  _ d  |  _ d |  _ d |  _ d  S(   Ni    (	   t   distributiont   initialize_optionsR$   t   _dry_runt   Falset   verboset   forcet   helpt	   finalized(   t   selft   dist(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyt   __init__v   s    	
				N(    (    (   t   __name__t
   __module__R$   t   as_argst   multiple_value_optionst   boolean_optionst   option_aliasest   option_choicest   distutils_logR   R5   (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR   X   s   t   compile_catalogc        	   B  s_   e  Z d  Z d Z d d d d d d d! g Z d d g Z d   Z d   Z d   Z	 d   Z
 RS("   s  Catalog compilation command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import compile_catalog

        setup(
            ...
            cmdclass = {'compile_catalog': compile_catalog}
        )

    .. versionadded:: 0.9
    s+   compile message catalogs to binary MO filess   domain=t   Ds>   domains of PO files (space separated list, default 'messages')s
   directory=t   ds.   path to base directory containing the catalogss   input-file=t   is   name of the input files   output-file=t   osQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.mo')s   locale=t   ls    locale of the catalog to compiles	   use-fuzzyt   fs   also include fuzzy translationst
   statisticss#   print statistics about translationsc         C  sC   d |  _  d  |  _ d  |  _ d  |  _ d  |  _ t |  _ t |  _ d  S(   Nt   messages(	   t   domainR$   t	   directoryt
   input_filet   output_filet   localeR.   t	   use_fuzzyRE   (   R3   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR,      s    						c         C  s\   t  |  j  |  _ |  j r5 |  j r5 t d   n  |  j rX |  j rX t d   n  d  S(   Ns<   you must specify either the input file or the base directorys=   you must specify either the output file or the base directory(   R&   RG   RI   RH   R   RJ   (   R3   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyt   finalize_options   s
    c         C  s{   d } xG |  j  D]< } x3 |  j |  j   D] \ } } | t |  7} q, Wq W| rm |  j j d |  n  | rw d Sd S(   Ni    s   %d errors encountered.i   (   RG   t   _run_domaint   itemst   lenR   t   error(   R3   t   n_errorsRG   t   catalogt   errors(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyt   run   s    "c         C  sE  g  } g  } |  j  s|  j r | j |  j t j j |  j |  j d | d  f  | j t j j |  j |  j d | d   qvx t j |  j  D]y } t j j |  j | d | d  } t j j |  r | j | | f  | j t j j |  j | d | d   q q Wna | j |  j |  j  f  |  j	 rJ| j |  j	  n, | j t j j |  j |  j d | d   | st
 d   n  i  } xt |  D]\ } \ } } | | } t | d   }	 t |	 |  }
 Wd  QX|  j rod } x. t |
  d D] } | j r| d 7} qqWd } t |
  rJ| d t |
  } n  |  j j d	 | t |
  | |  n  |
 j r|  j r|  j j d
 |  qn  t |
 j    | |
 <} xA | D]9 \ } } x* | D]" } |  j j d | | j |  qWqW|  j j d | |  t | d   } t | |
 d |  j Wd  QXqW| S(   Nt   LC_MESSAGESs   .pos   .mos   no message catalogs foundt   rbi    i   id   s)   %d of %d messages (%d%%) translated in %ss'   catalog %s is marked as fuzzy, skippings   error: %s:%d: %ss   compiling catalog %s to %st   wbRL   (   RI   RK   t   appendt   ost   patht   joinRH   t   listdirt   existsRJ   R   t	   enumeratet   openR   RE   R"   t   stringRP   R   t   infot   fuzzyRL   t   checkRQ   t   linenoR   (   R3   RG   t   po_filest   mo_filesRK   t   po_filet   catalogs_and_errorst   idxt   mo_filet   infileRS   t
   translatedt   messaget
   percentaget   catalog_errorsRT   RQ   t   outfile(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRN      sn    			
				 (   s   domain=R?   s>   domains of PO files (space separated list, default 'messages')(   s
   directory=R@   s.   path to base directory containing the catalogs(   s   input-file=RA   s   name of the input file(   s   output-file=RB   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.mo')(   s   locale=RC   s    locale of the catalog to compile(   s	   use-fuzzyRD   s   also include fuzzy translationsN(   RE   Ns#   print statistics about translations(   R6   R7   t   __doc__t   descriptionR$   t   user_optionsR:   R,   RM   RU   RN   (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR>      s*          							t   extract_messagesc           B  s   e  Z d  Z d Z dB dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT dU g Z d d d d d d d) g Z d0 Z dV Z i dW d2 6dX d5 6dY d7 6dZ d) 6Z	 i d[ d< 6Z
 d=   Z d>   Z d?   Z d@   Z RS(\   s  Message extraction command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import extract_messages

        setup(
            ...
            cmdclass = {'extract_messages': extract_messages}
        )
    s1   extract localizable strings from the project codes   charset=s3   charset to use in the output file (default "utf-8")s	   keywords=t   ksi   space-separated list of keywords to look for in addition to the defaults (may be repeated multiple times)s   no-default-keywordss#   do not include the default keywordss   mapping-file=t   Fs&   path to the mapping configuration files   no-locations>   do not include location comments with filename and line numbers   add-location=s   location lines format. If it is not given or "full", it generates the lines with both file name and line number. If it is "file", the line number part is omitted. If it is "never", it completely suppresses the lines (same as --no-location).s   omit-headers'   do not include msgid "" entry in headers   output-file=RB   s   name of the output files   width=t   ws"   set output line width (default 76)s   no-wrapsV   do not break long message lines, longer than the output line width, into several liness   sort-outputs&   generate sorted output (default False)s   sort-by-files,   sort output by file location (default False)s   msgid-bugs-address=s   set report address for msgids   copyright-holder=s   set copyright holder in outputs   project=s   set project name in outputs   version=s   set project version in outputs   add-comments=t   csu   place comment block with TAG (or those preceding keyword lines) in output file. Separate multiple TAGs with commas(,)s   strip-commentsR   s)   strip the comment TAGs from the comments.s   input-paths=so   files or directories that should be scanned for messages. Separate multiple files or directories with commas(,)s   input-dirs=s@   alias for input-paths (does allow files as well as directories).s   input-pathss   add-commentst   keywordss	   --keywords	   --mappings   mapping-files   --outputs   output-files   --strip-comment-tagst   fullt   filet   nevers   add-locationc         C  s   d |  _  d  |  _ t |  _ d  |  _ t |  _ d  |  _ t |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ t |  _ t |  _ t |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ t |  _ t |  _ d  S(   Ns   utf-8(   t   charsetR$   Rz   R.   t   no_default_keywordst   mapping_filet   no_locationt   add_locationt   omit_headerRJ   t
   input_dirst   input_pathst   widtht   no_wrapt   sort_outputt   sort_by_filet   msgid_bugs_addresst   copyright_holdert   projectt   versiont   add_commentst   strip_commentst   Truet   include_lineno(   R3   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR,   [  s*    																				c         C  s  |  j  r0 |  j s! |  j  |  _ q0 t d   n  |  j rB i  } n t j   } | j t t |  j	    | |  _	 |  j	 s t d   n  |  j
 s t d   n  |  j r |  j r t d   n  |  j r |  j r d |  _ n$ |  j d  k	 rt |  j  |  _ n  |  j r)|  j r)t d   n  |  j rbt |  j t  rt j d |  j  |  _ qnb |  j d  k	 rt j g  |  j j pd D] } | j d d	  d
 ^ q j   |  _ n	 g  |  _ |  j st d   n  x6 |  j D]+ } t j j |  st d |   qqWt |  j p$d d  |  _ |  j rx|  j sW|  j j   |  _ n  |  j  sx|  j j!   |  _  qxn  |  j" d k rt# |  _$ n |  j" d k rt% |  _& n  d  S(   Ns1   input-dirs and input-paths are mutually exclusives=   you must specify new keywords if you disable the default oness   no output file specifieds0   '--no-wrap' and '--width' are mutually exclusiveiL   s;   '--sort-output' and '--sort-by-file' are mutually exclusives   ,\s*t   .i   i    s'   no input files or directories specifieds   Input path: %s does not existt   ,R}   R|   (    (    ('   R   R   R   R   R   t   copyt   updatet   parse_keywordsR&   Rz   RJ   R   R   R$   t   intR   R   R    R   t   reR   R+   t   dictt   fromkeyst   packagest   keysRZ   R[   R^   R   R   t   get_nameR   t   get_versionR   R   R   R.   R   (   R3   Rz   Rv   R[   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRM   r  sZ    								A					c           s   j    } t  j d  } t d  j d  j d  j d  j d  j  } x+| D]#\   } }    f d   } t	 j
 j    r t	 j   } t   | | |  j  j  j |  } n3 t   | | d  j d	  j d
 | d  j } x | D]y \ }	 }
 } } } t	 j
 j    r4|	 } n! t	 j
 j t	 j
 j   |	   } | j | d  | |
 f g d | d | qWq^ W j j d  j  t | | d  j d  j d  j d  j d  j d  j Wd  QXd  S(   NRX   R   R   R   R   R~   c           s   | d k r d  St  j j    r+   } n! t  j j t  j j   |    } d } | r d d j g  | j   D] \ } } d | | f ^ qn  } n   j j d | |  d  S(   Nt   ignoret    s    (%s)s   , s   %s="%s"s   extracting messages from %s%s(   RZ   R[   t   isfilet   normpathR\   RO   R   Rb   (   t   filenamet   methodt   optionst   filepatht   optstrRv   t   v(   R[   R3   (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyt   callback  s    	!3Rz   t   comment_tagsR   t   strip_comment_tagst   auto_commentst   contexts   writing PO template file to %sR   R   R   R   R   R   (   t   _get_mappingsR`   RJ   R   R   R   R   R   R~   RZ   R[   R   t   getcwdR   Rz   R   R   R   R   R\   t   addR$   R   Rb   R   R   R   R   R   R   R   (   R3   t   mappingsRq   RS   t
   method_mapt   options_mapR   t   current_dirt	   extractedR   Re   Rn   t   commentsR   R   (    (   R[   R3   s6   lib/python2.7/site-packages/babel/messages/frontend.pyRU     sD    							!				c         C  sb  g  } |  j  ri t |  j  t   } t |  \ } } Wd  QXx|  j D] } | j | | | f  qF Wn t |  j d d   r4|  j j	 } x | j
   D] \ } } t | t  r t t |   \ } } nJ g  i  } } x: | D]2 \ } }	 }
 | j | |	 f  |
 pi  | | <q W| j | | | f  q Wn* x' |  j D] } | j | t i  f  q>W| S(   Nt   message_extractors(   R   R`   t   po_file_read_modet   parse_mappingR   RY   t   getattrR+   R$   R   RO   R    R   R   R   (   R3   R   t   fileobjR   R   R[   R   t   mappingt   patternR   R   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR     s&    	N(   s   charset=Ns3   charset to use in the output file (default "utf-8")(   s	   keywords=Rv   si   space-separated list of keywords to look for in addition to the defaults (may be repeated multiple times)(   s   no-default-keywordsNs#   do not include the default keywords(   s   mapping-file=Rw   s&   path to the mapping configuration file(   s   no-locationNs>   do not include location comments with filename and line number(   s   add-location=Ns   location lines format. If it is not given or "full", it generates the lines with both file name and line number. If it is "file", the line number part is omitted. If it is "never", it completely suppresses the lines (same as --no-location).(   s   omit-headerNs'   do not include msgid "" entry in header(   s   output-file=RB   s   name of the output file(   s   width=Rx   s"   set output line width (default 76)(   s   no-wrapNsV   do not break long message lines, longer than the output line width, into several lines(   s   sort-outputNs&   generate sorted output (default False)(   s   sort-by-fileNs,   sort output by file location (default False)(   s   msgid-bugs-address=Ns   set report address for msgid(   s   copyright-holder=Ns   set copyright holder in output(   s   project=Ns   set project name in output(   s   version=Ns   set project version in output(   s   add-comments=Ry   su   place comment block with TAG (or those preceding keyword lines) in output file. Separate multiple TAGs with commas(,)(   s   strip-commentsR   s)   strip the comment TAGs from the comments.(   s   input-paths=Nso   files or directories that should be scanned for messages. Separate multiple files or directories with commas(,)(   s   input-dirs=Ns@   alias for input-paths (does allow files as well as directories).(   s   add-commentsRz   (   s	   --keyword(   s	   --mapping(   s   --output(   s   --strip-comment-tags(   R{   R|   R}   (   R6   R7   Rr   Rs   R$   Rt   R:   R8   R9   R;   R<   R,   RM   RU   R   (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRu   
  sr                       	

		C	=c         C  s4   | d k s t   t | t  s0 t d   n  d S(   sg  Validate the ``message_extractors`` keyword argument to ``setup()``.

    :param dist: the distutils/setuptools ``Distribution`` object
    :param name: the name of the keyword argument (should always be
                 "message_extractors")
    :param value: the value of the keyword argument
    :raise `DistutilsSetupError`: if the value is not valid
    R   sD   the value of the "message_extractors" parameter must be a dictionaryN(   R(   R    R   R   (   R4   t   namet   value(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyt   check_message_extractors  s    	t   init_catalogc        	   B  sS   e  Z d  Z d Z d d d d d d d  g Z d g Z d   Z d   Z d   Z	 RS(!   s  New catalog initialization command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import init_catalog

        setup(
            ...
            cmdclass = {'init_catalog': init_catalog}
        )
    s(   create a new catalog based on a POT files   domain=R?   s&   domain of PO file (default 'messages')s   input-file=RA   s   name of the input files   output-dir=R@   s   path to output directorys   output-file=RB   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')s   locale=RC   s$   locale for the new localized catalogs   width=Rx   s"   set output line width (default 76)s   no-wrapsV   do not break long message lines, longer than the output line width, into several linesc         C  sC   d  |  _ d  |  _ d  |  _ d  |  _ d |  _ t |  _ d  |  _ d  S(   NRF   (	   R$   t
   output_dirRJ   RI   RK   RG   R.   R   R   (   R3   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR,   A  s    						c         C  sn  |  j  s t d   n  |  j s0 t d   n  y t j |  j  |  _ Wn t k
 rj } t |   n X|  j r |  j r t d   n  |  j s t	 j
 j |  j |  j d |  j d  |  _ n  t	 j
 j t	 j
 j |  j   st	 j t	 j
 j |  j   n  |  j r&|  j r&t d   n  |  j rF|  j rFd |  _ n$ |  j d  k	 rjt |  j  |  _ n  d  S(   Ns   you must specify the input files-   you must provide a locale for the new catalogs%   you must specify the output directoryRV   s   .pos0   '--no-wrap' and '--width' are mutually exclusiveiL   (   RI   R   RK   R   t   parset   _localeR   RJ   R   RZ   R[   R\   RG   R^   t   dirnamet   makedirsR   R   R$   R   (   R3   t   e(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRM   J  s*    			!c      
   C  s   |  j  j d |  j |  j  t |  j d   } t | d |  j } Wd  QX|  j | _ t j	 t
  | _ t | _ t |  j d   } t | | d |  j Wd  QXd  S(   Ns   creating catalog %s based on %sRW   RK   RX   R   (   R   Rb   RJ   RI   R`   R   RK   R   R   t   nowR   t   revision_dateR.   Rc   R   R   (   R3   Rl   RS   Rq   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRU   f  s    		(   s   domain=R?   s&   domain of PO file (default 'messages')(   s   input-file=RA   s   name of the input file(   s   output-dir=R@   s   path to output directory(   s   output-file=RB   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')(   s   locale=RC   s$   locale for the new localized catalog(   s   width=Rx   s"   set output line width (default 76)N(   s   no-wrapNsV   do not break long message lines, longer than the output line width, into several lines(
   R6   R7   Rr   Rs   R$   Rt   R:   R,   RM   RU   (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR     s(          					t   update_catalogc           B  sq   e  Z d  Z d Z d% d& d' d( d* d+ d, d- d. d/ d0 d1 g Z d d d! d d d g Z d"   Z d#   Z d$   Z	 RS(2   s  Catalog merging command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import update_catalog

        setup(
            ...
            cmdclass = {'update_catalog': update_catalog}
        )

    .. versionadded:: 0.9
    s'   update message catalogs from a POT files   domain=R?   s&   domain of PO file (default 'messages')s   input-file=RA   s   name of the input files   output-dir=R@   s.   path to base directory containing the catalogss   output-file=RB   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')s   omit-headers%   do not include msgid  entry in headers   locale=RC   s    locale of the catalog to compiles   width=Rx   s"   set output line width (default 76)s   no-wrapsV   do not break long message lines, longer than the output line width, into several liness   ignore-obsolete=s1   whether to omit obsolete messages from the outputs   no-fuzzy-matchingt   Ns   do not use fuzzy matchings   update-header-comments   update target header commentt   previouss+   keep previous msgids of translated messagess   ignore-obsoletec         C  sp   d |  _  d  |  _ d  |  _ d  |  _ t |  _ d  |  _ d  |  _ t |  _	 t |  _
 t |  _ t |  _ t |  _ d  S(   NRF   (   RG   R$   RI   R   RJ   R.   R   RK   R   R   t   ignore_obsoletet   no_fuzzy_matchingt   update_header_commentR   (   R3   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR,     s    											c         C  s   |  j  s t d   n  |  j r; |  j r; t d   n  |  j r] |  j r] t d   n  |  j r~ |  j r~ t d   n  |  j r |  j r d |  _ n$ |  j d  k	 r t |  j  |  _ n  |  j	 r |  j
 r t |  _
 n  d  S(   Ns   you must specify the input files-   you must specify the output file or directorys   you must specify the locales0   '--no-wrap' and '--width' are mutually exclusiveiL   (   RI   R   RJ   R   RK   R   R   R$   R   R   R   R.   (   R3   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRM     s    	c         C  s  g  } |  j  s |  j rS | j |  j t j j |  j |  j d |  j d  f  q x t j |  j  D]S } t j j |  j | d |  j d  } t j j	 |  rf | j | | f  qf qf Wn | j |  j |  j  f  | s t
 d   n  |  j } | s%t j j t j j |  j   d } n  t |  j d   } t |  } Wd  QXxi| D]a\ } } |  j j d | |  j  t | d   } t | d | d | } Wd  QX| j | |  j d	 |  j t j j t j j |  t j   t j j |   }	 yM t |	 d
  8 }
 t |
 | d |  j d |  j d |  j d |  j Wd  QXWn t j |	    n Xy t j |	 |  WqSt k
 rt j |  t  j! |	 |  t j |	  qSXqSWd  S(   NRV   s   .pos   no message catalogs foundi    RW   s   updating catalog %s based on %sRK   RG   R   RX   R   R   t   include_previousR   ("   RJ   RK   RY   RZ   R[   R\   R   RG   R]   R^   R   t   splitextt   basenameRI   R`   R   R   Rb   R   R   R   R   t   tempfilet   gettempprefixR   R   R   R   R   t   removet   renamet   OSErrort   shutilR   (   R3   Rf   RK   Rh   RG   Rl   t   templateR   RS   t   tmpnamet   tmpfile(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRU     s\    			(
			(   s   domain=R?   s&   domain of PO file (default 'messages')(   s   input-file=RA   s   name of the input file(   s   output-dir=R@   s.   path to base directory containing the catalogs(   s   output-file=RB   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')N(   s   omit-headerNs%   do not include msgid  entry in header(   s   locale=RC   s    locale of the catalog to compile(   s   width=Rx   s"   set output line width (default 76)(   s   no-wrapNsV   do not break long message lines, longer than the output line width, into several lines(   s   ignore-obsolete=Ns1   whether to omit obsolete messages from the output(   s   no-fuzzy-matchingR   s   do not use fuzzy matching(   s   update-header-commentNs   update target header comment(   R   Ns+   keep previous msgids of translated messages(
   R6   R7   Rr   Rs   R$   Rt   R:   R,   RM   RU   (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR   x  s>               			t   CommandLineInterfacec           B  s   e  Z d  Z d Z d e Z i d d 6d d 6d d 6d	 d
 6Z i e d 6e d 6e	 d 6e
 d
 6Z d Z d d  Z d   Z d   Z d   Z RS(   s   Command-line interface.

    This class provides a simple command-line interface to the message
    extraction and PO file generation functionality.
    s   %%prog %s [options] %ss	   %%prog %ss$   compile message catalogs to MO filest   compiles:   extract messages from source files and generate a POT filet   extracts+   create new message catalogs from a POT filet   inits0   update existing message catalogs from a POT fileR   c         C  s<  | d k r t j } n  t j d |  j d d |  j  |  _ |  j j   |  j	 |  j _
 |  j j d d d d d	 d
 d |  j j d d d d d d d t j d
 d |  j j d d d d d d d t j d
 d |  j j d t d t j  |  j j | d  \ } } |  j | j  | j rt j   } t g  | D] } t |  ^ q> } | j   d | d } x[ | D]S } t j |  } | | | j f }	 t |	 j t j  j! pt"   pd d   qxWd S| s|  j j# d  n  | d }
 |
 |  j$ k r|  j j# d |
  n  |  j% |
 | d  } | j&   S(   s{   Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        t   usaget   commands   [args]R   s   --list-localest   destt   list_localest   actiont
   store_trueR1   s    print all known locales and exits   -vs	   --verboset   store_constt   loglevelt   consts   print as much as possibles   -qs   --quiets   print as little as possiblei   u
   %%-%ds %%st   asciit   replacei    sQ   no valid command or option passed. Try the -h/--help option for more information.s   unknown command "%s"N(   R   s   [args]('   R$   t   syst   argvt   optparset   OptionParserR   R   t   parsert   disable_interspersed_argst   _helpt
   print_helpt
   add_optiont   loggingt   DEBUGt   ERRORt   set_defaultsR.   t   INFOt
   parse_argst   _configure_loggingR   R   R   t   locale_identifierst   maxRP   t   sortR   R   t   english_namet   printt   encodet   stdoutt   encodingR   RQ   t   commandst   _configure_commandRU   (   R3   R   R   t   argst   identifierst
   identifiert   longestt   formatRK   t   outputt   cmdnamet   cmdinst(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyRU   $  sJ    	%
	
c         C  s   t  j d  |  _ |  j j |  |  j j rA |  j j d } n t  j   } |  j j |  | j |  t  j d  } | j |  d  S(   Nt   babeli    s   %(message)s(	   R   t	   getLoggerR   t   setLevelt   handlerst   StreamHandlert
   addHandlert	   Formattert   setFormatter(   R3   R   t   handlert	   formatter(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR   W  s    c         C  s   t  |  j j    t  d  t g  |  j D] } t |  ^ q*  } d t d | d  } t |  j j    } x( | D]  \ } } t  | | | f  qx Wd  S(   Ns	   commands:s     %%-%ds %%si   i   (   R   R   t   format_helpR   R  RP   t   sortedRO   (   R3   R   R  R	  R  R   Rs   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR   f  s    
(c      	   C  so  |  j  | } |   } |  j r. |  j | _ n  t | t  sC t  | j   t j d |  j | d f d |  j	 |  } t
 | d d  } x9| j D].\ } } }	 | j d  }
 t
 | |
 j d d   } d |
 g } | r | j d	 |  n  | j | j j |
 d   | j j |
 d  } |
 | k rH| j d
 |
 7_ q |
 | j k rs| j d d d |	 |  q |
 | j k r| j d d d |	 d | |  q | j d |	 d | d | |  q W| j |  \ } } | rt | | j d d  |  n  x0 t |  j   D] \ } } t | | |  qWy | j   Wn& t k
 rj} | j t |   n X| S(   sB   
        :type cmdname: str
        :type argv: list[str]
        R   R   Rs   R8   t   =t   -t   _s   --%ss   -%ss   <%s>R   R   R1   RY   t   choicest   default(    (    N(   t   command_classesR   R    R   R(   R,   R   R   R   R  R   Rt   R   R   RY   R%   R;   t   getR<   R$   R:   R   R9   R   t   setattrt   varsRO   t   ensure_finalizedR   RQ   t   str(   R3   R  R   t   cmdclassR  R   R8   t   longt   shortR1   R   R  t   strsR  R   R  t   keyR   t   err(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR  o  sF    		
	"#N(   R6   R7   Rr   R   t   VERSIONR   R  R>   Ru   R   R   R  R$   R   RU   R   R   R  (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR     s$   


3			c           C  s   t    j t j  S(   N(   R   RU   R   R   (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyt   main  s    c         C  sM  i  } g  } i  } t    } t | j  | _ t rF | j |  |  n | j |  |  x | j   D] } | d k r t | j |   } qc g  | j	 d d  D] } | j
   ^ q \ } }	 | j |	 | f  t | j |   | |	 <qc W| rCxL t |  D]; \ }
 \ }	 } | | k r,| | } n  |	 | f | |
 <qWn  | | f S(   s  Parse an extraction method mapping from a file-like object.

    >>> buf = StringIO('''
    ... [extractors]
    ... custom = mypackage.module:myfunc
    ...
    ... # Python source files
    ... [python: **.py]
    ...
    ... # Genshi templates
    ... [genshi: **/templates/**.html]
    ... include_attrs =
    ... [genshi: **/templates/**.txt]
    ... template_class = genshi.template:TextTemplate
    ... encoding = latin-1
    ...
    ... # Some custom extractor
    ... [custom: **/custom/*.*]
    ... ''')

    >>> method_map, options_map = parse_mapping(buf)
    >>> len(method_map)
    4

    >>> method_map[0]
    ('**.py', 'python')
    >>> options_map['**.py']
    {}
    >>> method_map[1]
    ('**/templates/**.html', 'genshi')
    >>> options_map['**/templates/**.html']['include_attrs']
    ''
    >>> method_map[2]
    ('**/templates/**.txt', 'genshi')
    >>> options_map['**/templates/**.txt']['template_class']
    'genshi.template:TextTemplate'
    >>> options_map['**/templates/**.txt']['encoding']
    'latin-1'

    >>> method_map[3]
    ('**/custom/*.*', 'mypackage.module:myfunc')
    >>> options_map['**/custom/*.*']
    {}

    :param fileobj: a readable file-like object containing the configuration
                    text to parse
    :see: `extract_from_directory`
    t
   extractorst   :i   (   R   R   t	   _sectionsR
   t   readfpt	   read_filet   sectionsR   RO   R   R   RY   R_   (   R   R   R,  R   R   R   t   sectiont   partR   R   Rj   (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR     s(    1	1c         C  s   i  } x |  D] } d | k r7 | j  d  \ } } n | d } } | | k r | r g  } xZ | j  d  D]I } | d d k r | j t | d   d f  ql | j t |   ql Wt |  } n  | | | <q q W| S(   sQ  Parse keywords specifications from the given list of strings.

    >>> kw = sorted(parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items())
    >>> for keyword, indices in kw:
    ...     print((keyword, indices))
    ('_', None)
    ('dgettext', (2,))
    ('dngettext', (2, 3))
    ('pgettext', ((1, 'c'), 2))
    R-  R   iRy   N(   R   R$   RY   R   R#   (   t   stringsRz   Ra   t   funcnamet   indicest   indst   x(    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyR     s     t   __main__(D   Rr   t
   __future__R    R   R   RZ   R   R   R   R   t   collectionsR   R   RK   R   R  R   R*  R   R   t   babel._compatR   R   R	   R
   t
   babel.coreR   t   babel.messages.catalogR   t   babel.messages.extractR   R   R   R   t   babel.messages.mofileR   t   babel.messages.pofileR   R   t
   babel.utilR   t	   distutilsR   R=   t   distutils.cmdR   t   _Commandt   distutils.errorsR   R   t   ConfigParserR   t   ImportErrort   configparserR   R$   R&   R>   Ru   R   R   R   t   objectR   R+  R   R   R6   (    (    (    s6   lib/python2.7/site-packages/babel/messages/frontend.pyt   <module>
   sT   ""*) 	[	N