
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
HXU                 @   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mZ ddl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%m&Z& ddl'm(Z) ddl*m+Z, ddl-m.Z.m/Z/ yddl0m1Z1 W n" e2k
rF   ddl3m1Z1 Y nX d*ddZ4G dd de,Z+G dd de+Z5G dd de+Z6dd Z7G dd de+Z8G dd  d e+Z9G d!d" d"e:Z;d#d$ Z<d+d%d&Z=g fd'd(Z>e?d)kre<  dS ),z
    babel.messages.frontend
    ~~~~~~~~~~~~~~~~~~~~~~~

    Frontends for the message extraction functionality.

    :copyright: (c) 2013 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    )print_functionN)datetime)getpreferredencoding)__version__)Locale
localedata)StringIOstring_types	text_type)UnknownLocaleError)Catalog)DEFAULT_KEYWORDSDEFAULT_MAPPINGcheck_and_call_extract_fileextract_from_dir)write_mo)read_powrite_po)LOCALTZodict)log)Command)DistutilsOptionErrorDistutilsSetupError)RawConfigParserc             C   s   g }t | ttfs| g} xV| D ]N}|dkr,qt |ttfrN|jt||d q|jdd t|j|D  qW tdd |D st|S )a  
    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:
    N)splitc             s   s   | ]}|j  V  qd S )N)strip).0s r   /usr/lib/python3.6/frontend.py	<genexpr>O   s    z listify_value.<locals>.<genexpr>c             s   s   | ]}t |tV  qd S )N)
isinstancer	   )r   valr   r   r    r!   P   s    )	r"   listtupleextendlistify_valuer
   r   allAssertionError)argr   outr#   r   r   r    r'   *   s    
"r'   c               @   s.   e Zd ZdZf Zf Zi Zi ZeZ	dddZ
dS )r   Nc             C   s0   || _ | j  d | _d| _d | _d| _d| _d S )NFr   )distributioninitialize_optionsZ_dry_runverboseforcehelpZ	finalized)selfdistr   r   r    __init__r   s    zCommand.__init__)N)__name__
__module____qualname__as_argsmultiple_value_optionsboolean_optionsoption_aliasesoption_choicesdistutils_logr   r3   r   r   r   r    r   T   s   r   c            	   @   sN   e Zd ZdZdZd d!d"d#d$d%d&gZddgZdd Zdd Zdd Z	dd Z
dS )'compile_cataloga  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
    z+compile message catalogs to binary MO filesdomain=D>domains of PO files (space separated list, default 'messages')
directory=d.path to base directory containing the catalogsinput-file=iname of the input fileoutput-file=oQname of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.mo')locale=l locale of the catalog to compile	use-fuzzyfalso include fuzzy translations
statisticsN#print statistics about translationsc             C   s.   d| _ d | _d | _d | _d | _d| _d| _d S )NmessagesF)domain	directory
input_fileoutput_filelocale	use_fuzzyrP   )r1   r   r   r    r-      s    z"compile_catalog.initialize_optionsc             C   s@   t | j| _| j r$| j r$td| j r<| j r<tdd S )Nz<you must specify either the input file or the base directoryz=you must specify either the output file or the base directory)r'   rS   rU   rT   r   rV   )r1   r   r   r    finalize_options   s
    z compile_catalog.finalize_optionsc             C   s   x| j D ]}| j| qW d S )N)rS   _run_domain)r1   rS   r   r   r    run   s    zcompile_catalog.runc             C   sh  g }g }| j s| jr\|j| jtjj| j| jd|d f |jtjj| j| jd|d  nfxtj| jD ]T}tjj| j|d|d }tjj|rj|j||f |jtjj| j|d|d  qjW nF|j| j| j f | j	r|j| j	 n |jtjj| j| jd|d  |st
dxHt|D ]:\}\}}|| }t|d}t||}	W d Q R X | jrd}
x*t|	dd  D ]}|jrx|
d7 }
qxW d}t|	r|
d t|	 }| jjd	|
t|	|| |	jr| j r| jjd
| q$x:|	j D ].\}}x"|D ]}| jjd||j| qW qW | jjd|| t|d}t||	| jd W d Q R X q$W d S )NLC_MESSAGESz.poz.mozno message catalogs foundrbr      d   z)%d of %d messages (%d%%) translated in %sz'catalog %s is marked as fuzzy, skippingzerror: %s:%d: %szcompiling catalog %s to %swb)rX   )rU   rW   appendospathjoinrT   listdirexistsrV   r   	enumerateopenr   rP   r$   stringlenr   infofuzzyrX   Zcheckerrorlinenor   )r1   rS   po_filesZmo_filesrW   po_fileidxZmo_fileinfilecatalogZ
translatedmessageZ
percentageerrorsrm   outfiler   r   r    rZ      sh    

zcompile_catalog._run_domain)r>   r?   r@   )rA   rB   rC   )rD   rE   rF   )rG   rH   rI   )rJ   rK   rL   )rM   rN   rO   )rP   NrQ   )r4   r5   r6   __doc__descriptionuser_optionsr9   r-   rY   r[   rZ   r   r   r   r    r=   }   s*          		r=   c               @   s   e Zd ZdZdZdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYgZd	dddddd+gZd2ZdZZd[d\d]d^d9Z	d:d_iZ
d>d? Zd@dA ZdBdC ZdDdE ZdS )`extract_messagesa  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}
        )
    z1extract localizable strings from the project codecharset=N3charset to use in the output file (default "utf-8")	keywords=kispace-separated list of keywords to look for in addition to the defaults (may be repeated multiple times)no-default-keywords#do not include the default keywordsmapping-file=F&path to the mapping configuration fileno-location>do not include location comments with filename and line numberadd-location=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).omit-header'do not include msgid "" entry in headeroutput-file=rH   name of the output filewidth=w"set output line width (default 76)no-wrapVdo not break long message lines, longer than the output line width, into several linessort-output&generate sorted output (default False)sort-by-file,sort output by file location (default False)msgid-bugs-address=set report address for msgidcopyright-holder=set copyright holder in outputproject=set project name in outputversion=set project version in outputadd-comments=cuplace comment block with TAG (or those preceding keyword lines) in output file. Separate multiple TAGs with commas(,)strip-commentsr   )strip the comment TAGs from the comments.input-paths=ofiles or directories that should be scanned for messages. Separate multiple files or directories with commas(,)input-dirs=@alias for input-paths (does allow files as well as directories).zinput-pathsadd-commentskeywords	--keyword	--mapping--output--strip-comment-tags)r   zmapping-filezoutput-filezstrip-commentszadd-locationfullfileneverc             C   s   d| _ d | _d| _d | _d| _d | _d| _d | _d | _d | _	d | _
d| _d| _d| _d | _d | _d | _d | _d | _d| _d| _d S )Nzutf-8FT)charsetr   no_default_keywordsmapping_fileno_locationadd_locationomit_headerrV   
input_dirsinput_pathswidthno_wrapsort_outputsort_by_filemsgid_bugs_addresscopyright_holderprojectversionadd_commentsstrip_commentsinclude_lineno)r1   r   r   r    r-   M  s*    z#extract_messages.initialize_optionsc             C   s  | j r| js| j | _ntd| jr*i }ntj }|jtt| j	 || _	| j	sZtd| j
shtd| jr|| jr|td| j r| j rd| _n| jd k	rt| j| _| jr| jrtd| jrt| jtrtjd| j| _n8| jd k	rtjdd	 | jjpf D j | _ng | _| js*td
x*| jD ] }tjj|s2td| q2W t| jpbf d| _| jr| js| jj | _| js| jj  | _| j!dkrd| _"n| j!dkrd| _#d S )Nz1input-dirs and input-paths are mutually exclusivez=you must specify new keywords if you disable the default oneszno output file specifiedz0'--no-wrap' and '--width' are mutually exclusiveL   z;'--sort-output' and '--sort-by-file' are mutually exclusivez,\s*c             S   s   g | ]}|j d dd qS ).r^   r   )r   )r   r~   r   r   r    
<listcomp>  s   z5extract_messages.finalize_options.<locals>.<listcomp>z'no input files or directories specifiedzInput path: %s does not exist,r   Tr   F)$r   r   r   r   r   copyupdateparse_keywordsr'   r   rV   r   r   intr   r   r"   r	   rer   r,   dictfromkeysZpackageskeysrb   rc   rf   r   r   Zget_namer   Zget_versionr   r   r   )r1   r   rc   r   r   r    rY   d  sZ    

z!extract_messages.finalize_optionsc                s@  j  }tjd }tjjjjjd}x|D ]\ }} fdd}t	j
j rt	j }t |||jjj|}nt ||jj|jd}xX|D ]P\}	}
}}}t	j
j r|	}nt	j
jt	j
j |	}|j|d ||
fg||d qW q:W jjdj t||jjjjjjd W d Q R X d S )	Nr`   )r   r   r   r   r   c                sl   |dkrd S t jj r }nt jjt jj | }d}|rXddjdd |j D  }jjd|| d S )Nignore z (%s)z, c             S   s   g | ]\}}d ||f qS )z%s="%s"r   )r   r~   vr   r   r    r     s   z:extract_messages.run.<locals>.callback.<locals>.<listcomp>zextracting messages from %s%s)rb   rc   isfilenormpathrd   itemsr   rk   )filenamemethodoptionsfilepathZoptstr)rc   r1   r   r    callback  s    z&extract_messages.run.<locals>.callback)r   Zcomment_tagsr   Zstrip_comment_tags)Zauto_commentscontextzwriting PO template file to %s)r   r   r   r   r   r   )_get_mappingsrh   rV   r   r   r   r   r   r   rb   rc   r   getcwdr   r   r   r   r   r   rd   addr   rk   r   r   r   r   r   r   r   )r1   mappingsrv   rs   
method_mapoptions_mapr   Zcurrent_dirZ	extractedr   rn   rt   Zcommentsr   r   r   )rc   r1   r    r[     sD    



zextract_messages.runc             C   s  g }| j rPt| j d}t|\}}W d Q R X x| jD ]}|j|||f q6W nt| jdd r| jj}x|j D ]l\}}t	|t
rtt|\}}n8g i  }}x,|D ]$\}}	}
|j||	f |
pi ||< qW |j|||f qpW n x| jD ]}|j|ti f qW |S )NUmessage_extractors)r   rh   parse_mappingr   ra   getattrr,   r   r   r"   r	   r   r   )r1   r   fileobjr   r   rc   r   mappingpatternr   r   r   r   r    r     s&    

zextract_messages._get_mappings)r{   Nr|   )r}   r~   r   )r   Nr   )r   r   r   )r   Nr   )r   Nr   )r   Nr   )r   rH   r   )r   r   r   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   r   r   )r   r   r   )r   Nr   )r   Nr   )r   r   )r   )r   )r   )r   )r   r   r   )r4   r5   r6   rw   rx   ry   r9   r7   r8   r:   r;   r-   rY   r[   r   r   r   r   r    rz      sn                       
C=rz   c             C   s"   |dkst t|tstddS )ag  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   zDthe value of the "message_extractors" parameter must be a dictionaryN)r)   r"   r   r   )r2   namevaluer   r   r    check_message_extractors   s    	
r   c            	   @   sD   e Zd ZdZdZddd d!d"d#d$gZdgZdd Zdd Zdd Z	dS )%init_cataloga  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}
        )
    z(create a new catalog based on a POT filedomain=r?   &domain of PO file (default 'messages')input-file=rE   name of the input fileoutput-dir=rB   path to output directoryoutput-file=rH   Qname of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')locale=rK   $locale for the new localized catalogwidth=r   "set output line width (default 76)no-wrapNVdo not break long message lines, longer than the output line width, into several linesc             C   s.   d | _ d | _d | _d | _d| _d| _d | _d S )NrR   F)
output_dirrV   rU   rW   rS   r   r   )r1   r   r   r    r-   3  s    zinit_catalog.initialize_optionsc             C   s  | j std| jstdytj| j| _W n* tk
rX } zt|W Y d d }~X nX | j rr| j rrtd| jst	j
j| j| jd| jd | _t	j
jt	j
j| jst	jt	j
j| j | jr| jrtd| j r| j rd| _n| jd k	rt| j| _d S )Nzyou must specify the input filez-you must provide a locale for the new catalogz%you must specify the output directoryr\   z.poz0'--no-wrap' and '--width' are mutually exclusiver   )rU   r   rW   r   parse_localer   rV   r   rb   rc   rd   rS   rf   dirnamemakedirsr   r   r   )r1   er   r   r    rY   <  s*    zinit_catalog.finalize_optionsc             C   s   | j jd| j| j t| jd}t|| jd}W d Q R X | j|_tj	t
|_d|_t| jd}t||| jd W d Q R X d S )Nzcreating catalog %s based on %sr]   )rW   Fr`   )r   )r   rk   rV   rU   rh   r   rW   r   r   Znowr   Zrevision_daterl   r   r   )r1   rr   rs   rv   r   r   r    r[   X  s    zinit_catalog.run)r   r?   r   )r   rE   r   )r   rB   r   )r   rH   r   )r   rK   r   )r   r   r   )r   Nr   )
r4   r5   r6   rw   rx   ry   r9   r-   rY   r[   r   r   r   r    r     s(          	r   c               @   sT   e Zd ZdZdZd(d)d*d+d,d-d.d/d0d1d2gZdd!dddgZd"d# Zd$d% Zd&d' Z	dS )3update_cataloga  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
    z'update message catalogs from a POT filedomain=r?   &domain of PO file (default 'messages')input-file=rE   name of the input fileoutput-dir=rB   .path to base directory containing the catalogsoutput-file=rH   Qname of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')locale=rK    locale of the catalog to compilewidth=r   "set output line width (default 76)no-wrapNVdo not break long message lines, longer than the output line width, into several linesignore-obsolete=1whether to omit obsolete messages from the outputno-fuzzy-matchingNdo not use fuzzy matchingupdate-header-commentupdate target header commentprevious+keep previous msgids of translated messageszignore-obsoletec             C   sF   d| _ d | _d | _d | _d | _d | _d| _d| _d| _d| _	d| _
d S )NrR   F)rS   rU   r   rV   rW   r   r   ignore_obsoleteno_fuzzy_matchingupdate_header_commentr  )r1   r   r   r    r-     s    z!update_catalog.initialize_optionsc             C   s   | j std| j r&| j r&td| jr<| j r<td| jrP| jrPtd| j rh| j rhd| _n| jd k	r~t| j| _| jr| j	rd| _	d S )Nzyou must specify the input filez-you must specify the output file or directoryzyou must specify the localez0'--no-wrap' and '--width' are mutually exclusiver   F)
rU   r   rV   r   rW   r   r   r   r  r  )r1   r   r   r    rY     s    
zupdate_catalog.finalize_optionsc          '   C   s  g }| j s| jr:|j| jtjj| j| jd| jd f qx\tj| jD ]8}tjj| j|d| jd }tjj	|rH|j||f qHW n|j| j| j f |st
d| j}|stjjtjj| jd }t| jd}t|}W d Q R X x|D ]\}}| jjd|| j t|d}t|||d}W d Q R X |j|| j| jd tjjtjj|tj tjj| }	y2t|	d	}
t|
|| j| j| jd
 W d Q R X W n   tj|	  Y nX ytj|	| W q tk
r   tj| tj |	| tj|	 Y qX qW d S )Nr\   z.pozno message catalogs foundr   r]   zupdating catalog %s based on %s)rW   rS   )r  r`   )r  Zinclude_previousr   )!rV   rW   ra   rb   rc   rd   r   rS   re   rf   r   splitextbasenamerU   rh   r   r   rk   r   r  r  r   tempfileZgettempprefixr   r  r  r   removerenameOSErrorshutilr   )r1   ro   rW   rp   rS   rr   templater   rs   ZtmpnameZtmpfiler   r   r    r[     sZ    


zupdate_catalog.run)r  r?   r  )r  rE   r  )r  rB   r  )r  rH   r  )r	  rK   r
  )r  r   r  )r  Nr  )r  Nr  )r  r  r  )r  Nr  )r  Nr  )
r4   r5   r6   rw   rx   ry   r9   r-   rY   r[   r   r   r   r    r   j  s8              r   c               @   s^   e Zd ZdZdZde ZdddddZee	e
edZd	Zdd
dZdd Zdd Zdd Zd	S )CommandLineInterfacezCommand-line interface.

    This class provides a simple command-line interface to the message
    extraction and PO file generation functionality.
    z%%prog %s [options] %sz	%%prog %sz$compile message catalogs to MO filesz:extract messages from source files and generate a POT filez+create new message catalogs from a POT filez0update existing message catalogs from a POT file)compileextractZinitr   Nc             C   s  |dkrt j}tj| jd | jd| _| jj  | j| j_	| jj
ddddd	 | jj
d
dddtjdd | jj
ddddtjdd | jjdtjd | jj|dd \}}| j|j |jr:tj }tdd |D }|j  d|d  }xF|D ]>}tj|}|||jf }	t|	jt jjp*t p*dd qW dS |sL| jj d |d }
|
| j!krp| jj d|
  | j"|
|dd }|j# S )z{Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        Ncommand[args])usager   z--list-localeslist_locales
store_truez print all known locales and exit)destactionr0   z-vz	--verbosestore_constloglevelzprint as much as possible)r,  r+  constr0   z-qz--quietzprint as little as possibleF)r)  r.  r^   c             S   s   g | ]}t |qS r   )rj   )r   
identifierr   r   r    r   ,  s    z,CommandLineInterface.run.<locals>.<listcomp>z
%%-%ds %%sasciireplacer   zQno valid command or option passed. Try the -h/--help option for more information.zunknown command "%s")r&  r'  )$sysargvoptparseOptionParserr(  r   parserZdisable_interspersed_args_helpZ
print_help
add_optionloggingDEBUGZERRORZset_defaultsINFO
parse_args_configure_loggingr.  r)  r   Zlocale_identifiersmaxsortr   r   Zenglish_nameprintencodestdoutencodingr   rm   commands_configure_commandr[   )r1   r4  r   argsZidentifierslongestformatr0  rW   outputcmdnamecmdinstr   r   r    r[     sJ    




zCommandLineInterface.runc             C   sd   t jd| _| jj| | jjr.| jjd }nt j }| jj| |j| t jd}|j| d S )Nbabelr   z%(message)s)	r:  Z	getLoggerr   ZsetLevelZhandlersZStreamHandlerZ
addHandlerZ	FormatterZsetFormatter)r1   r.  ZhandlerZ	formatterr   r   r    r>  B  s    

z'CommandLineInterface._configure_loggingc             C   sp   t | jj  t d tdd | jD }dtd|d  }t| jj }x |D ]\}}t |||f  qPW d S )Nz	commands:c             S   s   g | ]}t |qS r   )rj   )r   r&  r   r   r    r   T  s    z.CommandLineInterface._help.<locals>.<listcomp>z  %%-%ds %%s   r^   )rA  r7  Zformat_helpr?  rE  sortedr   )r1   rH  rI  rE  r   rx   r   r   r    r8  Q  s    zCommandLineInterface._helpc             C   s  | j | }| }| jr| j|_t|ts,t|j  tj| j|df | j	| d}t
|df }x|jD ]\}}}	|jd}
t
||
jdd}d|
 g}|r|jd|  |j|jj|
f  |jj|
d	}|
|kr| jd
|
 7  _qf|
|jkr|j|d|	d qf|
|jkr(|j|d|	|d qf|j||	||d qfW |j|\}}|rht||jdd| x&t|j D ]\}}t||| qvW y|j  W n2 tk
r } z|jt| W Y d	d	}~X nX |S )zB
        :type cmdname: str
        :type argv: list[str]
        r   )r(  rx   r7   =-_z--%sz-%sNz<%s>r*  )r,  r0   ra   )r,  r0   choices)r0   defaultrS  )command_classesr   r"   r   r)   r-   r5  r6  r(  rE  r   ry   r   r2  ra   r&   r:   getr;   r9   r9  r8   r=  setattrvarsr   Zensure_finalizedr   rm   str)r1   rK  r4  ZcmdclassrL  r7  r7   ZlongZshortr0   r   rT  ZstrsrS  r   rG  keyr   errr   r   r    rF  Z  sF    


 z'CommandLineInterface._configure_command)N)r4   r5   r6   rw   r(  VERSIONr   rE  r=   rz   r   r   rU  r   r[   r>  r8  rF  r   r   r   r    r#    s    
3	r#  c               C   s   t  jtjS )N)r#  r[   r3  r4  r   r   r   r    main  s    r]  c       
      C   s   i }g }i }t  }t|j|_|j| | xb|j D ]V}|dkrPt|j|}q4dd |jddD \}}|j||f t|j|||< q4W |rx4t	|D ](\}	\}}||kr|| }||f||	< qW ||fS )a  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`
    
extractorsc             S   s   g | ]}|j  qS r   )r   )r   partr   r   r    r     s    z!parse_mapping.<locals>.<listcomp>:r^   )
r   r   Z	_sectionsZreadfpZsectionsr   r   r   ra   rg   )
r   r   r^  r   r   r7  Zsectionr   r   rq   r   r   r    r     s$    1r   c             C   s   i }x| D ]}d|kr&|j d\}}n
|d }}||kr
|rg }xH|j dD ]:}|d dkrx|jt|dd df qL|jt| qLW t|}|||< q
W |S )aQ  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`  Nr   r^   r   ra  )r   ra   r   r%   )Zstringsr   ri   funcnameindicesZindsxr   r   r    r     s    

r   __main__)N)N)@rw   Z
__future__r   r:  r5  rb   r   r!  r3  r  r   rW   r   rM  r   r\  r   r   Zbabel._compatr   r	   r
   Z
babel.corer   Zbabel.messages.catalogr   Zbabel.messages.extractr   r   r   r   Zbabel.messages.mofiler   Zbabel.messages.pofiler   r   Z
babel.utilr   r   Z	distutilsr   r<   Zdistutils.cmdr   Z_CommandZdistutils.errorsr   r   ZConfigParserr   ImportErrorZconfigparserr'   r=   rz   r   r   r   objectr#  r]  r   r   r4   r   r   r   r    <module>
   sV   
*)  [  
I
