%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib/python2.7/site-packages/babel/messages/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyc

�
*��Qc@sRdZddlZddlZddlmZmZmZmZmZddl	m
Z
mZmZddl
mZmZddlmZdZi	dd6dd	6dd6dd
6d d6d!d6d"d6dd6d$d6Zd%gZdZd�Zdeded&ded�Zed'ded�Zed(ded�Zd�Zd�Zd�ZdS()sa
    babel.messages.extract
    ~~~~~~~~~~~~~~~~~~~~~~

    Basic infrastructure for extracting localizable messages from source files.

    This module defines an extensible system for collecting localizable message
    strings from a variety of sources. A native extractor for Python source
    files is builtin, extractors for other sources can be added using very
    simple plugins.

    The main entry points into the extraction functionality are the functions
    `extract_from_dir` and `extract_from_file`.

    :copyright: (c) 2013 by the Babel Team.
    :license: BSD, see LICENSE for more details.
i����N(tgenerate_tokenstCOMMENTtNAMEtOPtSTRING(tparse_encodingt	pathmatchtrelpath(tPY2t	text_type(tdedentsbabel.extractorst_tgettextiitngettexttugettextt	ungettexttdgettextit	dngettexttN_tctpgettexts**.pytpythons�%s: warning: Empty msgid.  It is reserved by GNU gettext: gettext("") returns the header entry with meta information, not the empty string.cs#�fd�}t||�|(dS(s�Helper function for `extract` that strips comment tags from strings
    in a list of comment lines.  This functions operates in-place.
    cs8x1�D])}|j|�r|t|�j�SqW|S(N(t
startswithtlentstrip(tlinettag(ttags(sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyt_strip6s
N(tmap(tcommentsRR((RsG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyt_strip_comment_tags2sccs�|dkrtj�}n|dkr0i}ntjj|�}x�tj|�D]�\}}	}
x<|	D]4}|jd�s�|jd�rh|	j|�qhqhW|	j�|
j�x |
D]}t	tjj
||�jtjd�|�}x�|D]�\}
}t
|
|�r�tjj
||�}i}x2|j�D]$\}}t
||�r8|}q8q8W|ry||||�nxOt||d|d|d|d|�D]&\}}}}|||||fVq�WPq�q�Wq�WqRWdS(	s8Extract messages from any source files found in the given directory.

    This function generates tuples of the form ``(filename, lineno, message,
    comments, context)``.

    Which extraction method is used per file is determined by the `method_map`
    parameter, which maps extended glob patterns to extraction method names.
    For example, the following is the default mapping:

    >>> method_map = [
    ...     ('**.py', 'python')
    ... ]

    This basically says that files with the filename extension ".py" at any
    level inside the directory should be processed by the "python" extraction
    method. Files that don't match any of the mapping patterns are ignored. See
    the documentation of the `pathmatch` function for details on the pattern
    syntax.

    The following extended mapping would also use the "genshi" extraction
    method on any file in "templates" subdirectory:

    >>> method_map = [
    ...     ('**/templates/**.*', 'genshi'),
    ...     ('**.py', 'python')
    ... ]

    The dictionary provided by the optional `options_map` parameter augments
    these mappings. It uses extended glob patterns as keys, and the values are
    dictionaries mapping options names to option values (both strings).

    The glob patterns of the `options_map` do not necessarily need to be the
    same as those used in the method mapping. For example, while all files in
    the ``templates`` folders in an application may be Genshi applications, the
    options for those files may differ based on extension:

    >>> options_map = {
    ...     '**/templates/**.txt': {
    ...         'template_class': 'genshi.template:TextTemplate',
    ...         'encoding': 'latin-1'
    ...     },
    ...     '**/templates/**.html': {
    ...         'include_attrs': ''
    ...     }
    ... }

    :param dirname: the path to the directory to extract messages from.  If
                    not given the current working directory is used.
    :param method_map: a list of ``(pattern, method)`` tuples that maps of
                       extraction method names to extended glob patterns
    :param options_map: a dictionary of additional options (optional)
    :param keywords: a dictionary mapping keywords (i.e. names of functions
                     that should be recognized as translation functions) to
                     tuples that specify which of their arguments contain
                     localizable strings
    :param comment_tags: a list of tags of translator comments to search for
                         and include in the results
    :param callback: a function that is called for every file that message are
                     extracted from, just before the extraction itself is
                     performed; the function is passed the filename, the name
                     of the extraction method and and the options dictionary as
                     positional arguments, in that order
    :param strip_comment_tags: a flag that if set to `True` causes all comment
                               tags to be removed from the collected comments.
    :see: `pathmatch`
    t.Rt/tkeywordstcomment_tagstoptionststrip_comment_tagsN(tNonetostgetcwdtpathtabspathtwalkRtremovetsortRtjointreplacetsepRtitemstextract_from_file(tdirnamet
method_maptoptions_mapR"R#tcallbackR%tabsnametroottdirnamest	filenamestsubdirtfilenametpatterntmethodtfilepathR$topatterntodicttlinenotmessageRtcontext((sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pytextract_from_dir>s@E	



!	
cCsDt|d�}z#tt||||||��SWd|j�XdS(szExtract messages from a specific file.

    This function returns a list of tuples of the form ``(lineno, funcname,
    message)``.

    :param filename: the path to the file to extract messages from
    :param method: a string specifying the extraction method (.e.g. "python")
    :param keywords: a dictionary mapping keywords (i.e. names of functions
                     that should be recognized as translation functions) to
                     tuples that specify which of their arguments contain
                     localizable strings
    :param comment_tags: a list of translator tags to search for and include
                         in the results
    :param strip_comment_tags: a flag that if set to `True` causes all comment
                               tags to be removed from the collected comments.
    :param options: a dictionary of additional options (optional)
    trbN(topentlisttextracttclose(R>R<R"R#R$R%tfileobj((sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyR2�s
c	csOd}d|ksd|kr�d|krU|jd�}|| ||d}}	n|jdd�\}}	tt|ii|	g�|	�}n�yddlm}
Wntk
r�n1Xx-|
jt	|�D]}|j
dt�}Pq�W|dkr"itd6t
d6td	6}|j|�}n|dkrAtd
|��n|||j�|d|p_i�}
x�|
D]�\}}}}|r�||p�d}nd}t|ttf�s�|g}n|s�qlnd}g}t}t|�}x||D]t}t|t�r||dd}q�n||kr2t}Pn||d}|dkrVt}Pn|j|�q�W|rsqlnt|dt�r�|dd}n|dd}||s�d
t|d�r�|jp�d|f}tjjt|d�qlnt|�}t|�dkr |d}n|r6t||�n||||fVqlWdS(s�Extract messages from the given file-like object using the specified
    extraction method.

    This function returns tuples of the form ``(lineno, message, comments)``.

    The implementation dispatches the actual extraction to plugins, based on the
    value of the ``method`` parameter.

    >>> source = '''# foo module
    ... def run(argv):
    ...    print _('Hello, world!')
    ... '''

    >>> from StringIO import StringIO
    >>> for message in extract('python', StringIO(source)):
    ...     print message
    (3, u'Hello, world!', [], None)

    :param method: a string specifying the extraction method (.e.g. "python");
                   if this is a simple name, the extraction function will be
                   looked up by entry point; if it is an explicit reference
                   to a function (of the form ``package.module:funcname`` or
                   ``package.module.funcname``), the corresponding function
                   will be imported and used
    :param fileobj: the file-like object the messages should be extracted from
    :param keywords: a dictionary mapping keywords (i.e. names of functions
                     that should be recognized as translation functions) to
                     tuples that specify which of their arguments contain
                     localizable strings
    :param comment_tags: a list of translator tags to search for and include
                         in the results
    :param options: a dictionary of additional options (optional)
    :param strip_comment_tags: a flag that if set to `True` causes all comment
                               tags to be removed from the collected comments.
    :raise ValueError: if the extraction method is not registered
    t:R ii����(tworking_settrequiretignoreRt
javascriptsUnknown extraction method %rR$is%s:%itnames	(unknown)s
N(i(i(R&trfindtsplittgetattrt
__import__t
pkg_resourcesRMtImportErrortiter_entry_pointst
GROUP_NAMEtloadtTruetextract_nothingtextract_pythontextract_javascripttgett
ValueErrortkeyst
isinstanceRHttupletFalseRtappendthasattrRQtsyststderrtwritetempty_msgid_warningR(R>RKR"R#R$R%tfunctlastdottmoduletattrnameRMtentry_pointtbuiltintresultsRBtfuncnametmessagesRtspecRDtmsgstinvalidt
last_indextindexRCtfirst_msg_indextwhere((sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyRI�s�&$





cCsgS(sdPseudo extractor that does not actually extract anything, but simply
    returns an empty list.
    ((RKR"R#R$((sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyR\Asc#sYd}}}d}g}g}	g}
t}}d}
t��pQ|jdd��trf�j}n��fd�}t|�}x�|D]�\}}\}}}}|dkr�|tkr�|dkr�t}q�|t	kr|dkr|r�t}q�n|rQ|}|d7}qQq�|rC|t	krC|d	krCt}q�q�|dkr�|t
kr�trs|j��}n|dj�}|r�|
dd
|dkr�|
j
||f�q�nx�|D]2}
|j|
�r�t}|
j
||f�Pq�q�Wq�|r�|d
kr�|t	kr�|dkr�|rG|	j
dj|��|2n
|	j
d�t|	�dkrut|	�}	n
|	d
}	|
r�|
dd
|dkr�g}
n|||	g|
D]}|d^q�fVd}}}d}g}	g}
t}qQ|tkrdtd
t��|fiid6i�}trTt|t�rT|j��}n|j
|�qQ|t	krQ|dkrQ|r�|	j
dj|��|2n
|	j
d�|
r�|
j�\}}|
j
|d|f�q�qQq�|d
kr|t	kr|dkr|d8}q�|r0|dkr0d}q�|tkr�||kr�|}q�q�WdS(scExtract messages from Python source code.

    It returns an iterator yielding tuples in the following form ``(lineno,
    funcname, message, comments)``.

    :param fileobj: the seekable, file-like object the messages should be
                    extracted from
    :param keywords: a list of keywords (i.e. function names) that should be
                     recognized as translation functions
    :param comment_tags: a list of translator tags to search for and include
                         in the results
    :param options: a dictionary of additional options (optional)
    :rtype: ``iterator``
    i����tencodings
iso-8859-1cs�j�j��S(N(treadlinetdecode((R{RK(sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyt<lambda>dstdeftclasst(iRLit)ts# coding=%s
%st__builtins__t,N(RR�(R&RdRR_RR|RRR[RRR}RReRR.RRcRtevaltstrRbR	tpop(RKR"R#R$RrRBtmessage_linenot
call_stacktbufRsttranslator_commentstin_deftin_translator_commentstcomment_tagt	next_linettokensttoktvalueRtcommentt
old_linenotold_comment((R{RKsG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyR]Hs�
"$	


			
 $
	ccs�ddlm}m}d}}g}d}	g}
t}|jdd�}d}
d}xb||j�j|��D]E}|jdkr�|j	dkr�|r�|j
}|d7}q�n�|dkrc|jdkrc|j	d	j�}|
r |
dd
|j
dkr |
j|j
|f�qrnx�|D]5}|j
|�r'|
j|j
|j�f�Pq'q'WnN|jdkr8g}
|j	d	d!j�}x |D]�}|j
|�r�|j�}|r-|d
j�|d
<td
j|d��j�|d)x7t|�D]&\}}|
j|j
||f�qWnPq�q�Wny|r�|d
kr�|jdkrE|j	dkrE|	dk	r�|j|	�nt|�dkr�t|�}n|r�|d
}nd}|
r�|
dd
|dkr�g}
n|dk	r|||g|
D]}|d^qfVnd}}}	t}g}
g}d}q�|jdkr�||j	�}|r�|	prd|}	t}q�|}	q�|jdkr�|j	dkr�|	dk	r�|j|	�d}	n
|jd�t}q�|j	dkr�t}q�q�n�|d
kr6|jdkr6|j	dkr6|d8}n{|rQ|dkrQd}n`|dkr�|jdkr�|j	|kr�|
dks�|
jdks�|
j	dkr�|j	}n|}
qrWdS(s�Extract messages from JavaScript source code.

    :param fileobj: the seekable, file-like object the messages should be
                    extracted from
    :param keywords: a list of keywords (i.e. function names) that should be
                     recognized as translation functions
    :param comment_tags: a list of translator tags to search for and include
                         in the results
    :param options: a dictionary of additional options (optional)
    i����(ttokenizetunquote_stringR{sutf-8toperatorR�itlinecommentiitmultilinecommenti����s
R�tstringR�R�t+RQtfunctionN(tbabel.messages.jslexerR�R�R&RdR_treadR}ttypeR�RBRReRt
splitlinesR
R.t	enumerateRRcR[(RKR"R#R$R�R�RrR�Rst
last_argumentR�tconcatenate_nextR{t
last_tokenR�ttokenR�R�tlinestoffsetRR�t	new_value((sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyR^�s�
"	

#
		"			
	
	
	(ii(ii(i(ii(iR((iRi(s**.pyspython((((t__doc__R'RgR�RRRRRt
babel.utilRRRt
babel._compatRR	ttextwrapR
RYR&tDEFAULT_KEYWORDStDEFAULT_MAPPINGRjRRdRER2RIR\R]R^(((sG/opt/alt/python27/lib/python2.7/site-packages/babel/messages/extract.pyt<module>s<(
		h}		y

Zerion Mini Shell 1.0