Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../bin
File: pygettext2.py
#! /usr/bin/python2.7
[0] Fix | Delete
# -*- coding: iso-8859-1 -*-
[1] Fix | Delete
# Originally written by Barry Warsaw <barry@python.org>
[2] Fix | Delete
#
[3] Fix | Delete
# Minimally patched to make it even more xgettext compatible
[4] Fix | Delete
# by Peter Funk <pf@artcom-gmbh.de>
[5] Fix | Delete
#
[6] Fix | Delete
[7] Fix | Delete
# Added checks that _() only contains string literals, and
[8] Fix | Delete
# command line args are resolved to module lists, i.e. you
[9] Fix | Delete
# can now pass a filename, a module or package name, or a
[10] Fix | Delete
# directory (including globbing chars, important for Win32).
[11] Fix | Delete
# Made docstring fit in 80 chars wide displays using pydoc.
[12] Fix | Delete
#
[13] Fix | Delete
[14] Fix | Delete
# for selftesting
[15] Fix | Delete
try:
[16] Fix | Delete
import fintl
[17] Fix | Delete
_ = fintl.gettext
[18] Fix | Delete
except ImportError:
[19] Fix | Delete
_ = lambda s: s
[20] Fix | Delete
[21] Fix | Delete
__doc__ = _("""pygettext -- Python equivalent of xgettext(1)
[22] Fix | Delete
[23] Fix | Delete
Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the
[24] Fix | Delete
internationalization of C programs. Most of these tools are independent of
[25] Fix | Delete
the programming language and can be used from within Python programs.
[26] Fix | Delete
Martin von Loewis' work[1] helps considerably in this regard.
[27] Fix | Delete
[28] Fix | Delete
There's one problem though; xgettext is the program that scans source code
[29] Fix | Delete
looking for message strings, but it groks only C (or C++). Python
[30] Fix | Delete
introduces a few wrinkles, such as dual quoting characters, triple quoted
[31] Fix | Delete
strings, and raw strings. xgettext understands none of this.
[32] Fix | Delete
[33] Fix | Delete
Enter pygettext, which uses Python's standard tokenize module to scan
[34] Fix | Delete
Python source code, generating .pot files identical to what GNU xgettext[2]
[35] Fix | Delete
generates for C and C++ code. From there, the standard GNU tools can be
[36] Fix | Delete
used.
[37] Fix | Delete
[38] Fix | Delete
A word about marking Python strings as candidates for translation. GNU
[39] Fix | Delete
xgettext recognizes the following keywords: gettext, dgettext, dcgettext,
[40] Fix | Delete
and gettext_noop. But those can be a lot of text to include all over your
[41] Fix | Delete
code. C and C++ have a trick: they use the C preprocessor. Most
[42] Fix | Delete
internationalized C source includes a #define for gettext() to _() so that
[43] Fix | Delete
what has to be written in the source is much less. Thus these are both
[44] Fix | Delete
translatable strings:
[45] Fix | Delete
[46] Fix | Delete
gettext("Translatable String")
[47] Fix | Delete
_("Translatable String")
[48] Fix | Delete
[49] Fix | Delete
Python of course has no preprocessor so this doesn't work so well. Thus,
[50] Fix | Delete
pygettext searches only for _() by default, but see the -k/--keyword flag
[51] Fix | Delete
below for how to augment this.
[52] Fix | Delete
[53] Fix | Delete
[1] http://www.python.org/workshops/1997-10/proceedings/loewis.html
[54] Fix | Delete
[2] http://www.gnu.org/software/gettext/gettext.html
[55] Fix | Delete
[56] Fix | Delete
NOTE: pygettext attempts to be option and feature compatible with GNU
[57] Fix | Delete
xgettext where ever possible. However some options are still missing or are
[58] Fix | Delete
not fully implemented. Also, xgettext's use of command line switches with
[59] Fix | Delete
option arguments is broken, and in these cases, pygettext just defines
[60] Fix | Delete
additional switches.
[61] Fix | Delete
[62] Fix | Delete
Usage: pygettext [options] inputfile ...
[63] Fix | Delete
[64] Fix | Delete
Options:
[65] Fix | Delete
[66] Fix | Delete
-a
[67] Fix | Delete
--extract-all
[68] Fix | Delete
Extract all strings.
[69] Fix | Delete
[70] Fix | Delete
-d name
[71] Fix | Delete
--default-domain=name
[72] Fix | Delete
Rename the default output file from messages.pot to name.pot.
[73] Fix | Delete
[74] Fix | Delete
-E
[75] Fix | Delete
--escape
[76] Fix | Delete
Replace non-ASCII characters with octal escape sequences.
[77] Fix | Delete
[78] Fix | Delete
-D
[79] Fix | Delete
--docstrings
[80] Fix | Delete
Extract module, class, method, and function docstrings. These do
[81] Fix | Delete
not need to be wrapped in _() markers, and in fact cannot be for
[82] Fix | Delete
Python to consider them docstrings. (See also the -X option).
[83] Fix | Delete
[84] Fix | Delete
-h
[85] Fix | Delete
--help
[86] Fix | Delete
Print this help message and exit.
[87] Fix | Delete
[88] Fix | Delete
-k word
[89] Fix | Delete
--keyword=word
[90] Fix | Delete
Keywords to look for in addition to the default set, which are:
[91] Fix | Delete
%(DEFAULTKEYWORDS)s
[92] Fix | Delete
[93] Fix | Delete
You can have multiple -k flags on the command line.
[94] Fix | Delete
[95] Fix | Delete
-K
[96] Fix | Delete
--no-default-keywords
[97] Fix | Delete
Disable the default set of keywords (see above). Any keywords
[98] Fix | Delete
explicitly added with the -k/--keyword option are still recognized.
[99] Fix | Delete
[100] Fix | Delete
--no-location
[101] Fix | Delete
Do not write filename/lineno location comments.
[102] Fix | Delete
[103] Fix | Delete
-n
[104] Fix | Delete
--add-location
[105] Fix | Delete
Write filename/lineno location comments indicating where each
[106] Fix | Delete
extracted string is found in the source. These lines appear before
[107] Fix | Delete
each msgid. The style of comments is controlled by the -S/--style
[108] Fix | Delete
option. This is the default.
[109] Fix | Delete
[110] Fix | Delete
-o filename
[111] Fix | Delete
--output=filename
[112] Fix | Delete
Rename the default output file from messages.pot to filename. If
[113] Fix | Delete
filename is `-' then the output is sent to standard out.
[114] Fix | Delete
[115] Fix | Delete
-p dir
[116] Fix | Delete
--output-dir=dir
[117] Fix | Delete
Output files will be placed in directory dir.
[118] Fix | Delete
[119] Fix | Delete
-S stylename
[120] Fix | Delete
--style stylename
[121] Fix | Delete
Specify which style to use for location comments. Two styles are
[122] Fix | Delete
supported:
[123] Fix | Delete
[124] Fix | Delete
Solaris # File: filename, line: line-number
[125] Fix | Delete
GNU #: filename:line
[126] Fix | Delete
[127] Fix | Delete
The style name is case insensitive. GNU style is the default.
[128] Fix | Delete
[129] Fix | Delete
-v
[130] Fix | Delete
--verbose
[131] Fix | Delete
Print the names of the files being processed.
[132] Fix | Delete
[133] Fix | Delete
-V
[134] Fix | Delete
--version
[135] Fix | Delete
Print the version of pygettext and exit.
[136] Fix | Delete
[137] Fix | Delete
-w columns
[138] Fix | Delete
--width=columns
[139] Fix | Delete
Set width of output to columns.
[140] Fix | Delete
[141] Fix | Delete
-x filename
[142] Fix | Delete
--exclude-file=filename
[143] Fix | Delete
Specify a file that contains a list of strings that are not be
[144] Fix | Delete
extracted from the input files. Each string to be excluded must
[145] Fix | Delete
appear on a line by itself in the file.
[146] Fix | Delete
[147] Fix | Delete
-X filename
[148] Fix | Delete
--no-docstrings=filename
[149] Fix | Delete
Specify a file that contains a list of files (one per line) that
[150] Fix | Delete
should not have their docstrings extracted. This is only useful in
[151] Fix | Delete
conjunction with the -D option above.
[152] Fix | Delete
[153] Fix | Delete
If `inputfile' is -, standard input is read.
[154] Fix | Delete
""")
[155] Fix | Delete
[156] Fix | Delete
import os
[157] Fix | Delete
import imp
[158] Fix | Delete
import sys
[159] Fix | Delete
import glob
[160] Fix | Delete
import time
[161] Fix | Delete
import getopt
[162] Fix | Delete
import token
[163] Fix | Delete
import tokenize
[164] Fix | Delete
import operator
[165] Fix | Delete
[166] Fix | Delete
__version__ = '1.5'
[167] Fix | Delete
[168] Fix | Delete
default_keywords = ['_']
[169] Fix | Delete
DEFAULTKEYWORDS = ', '.join(default_keywords)
[170] Fix | Delete
[171] Fix | Delete
EMPTYSTRING = ''
[172] Fix | Delete
[173] Fix | Delete
[174] Fix | Delete
[175] Fix | Delete
# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
[176] Fix | Delete
# there.
[177] Fix | Delete
pot_header = _('''\
[178] Fix | Delete
# SOME DESCRIPTIVE TITLE.
[179] Fix | Delete
# Copyright (C) YEAR ORGANIZATION
[180] Fix | Delete
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
[181] Fix | Delete
#
[182] Fix | Delete
msgid ""
[183] Fix | Delete
msgstr ""
[184] Fix | Delete
"Project-Id-Version: PACKAGE VERSION\\n"
[185] Fix | Delete
"POT-Creation-Date: %(time)s\\n"
[186] Fix | Delete
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
[187] Fix | Delete
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
[188] Fix | Delete
"Language-Team: LANGUAGE <LL@li.org>\\n"
[189] Fix | Delete
"MIME-Version: 1.0\\n"
[190] Fix | Delete
"Content-Type: text/plain; charset=CHARSET\\n"
[191] Fix | Delete
"Content-Transfer-Encoding: ENCODING\\n"
[192] Fix | Delete
"Generated-By: pygettext.py %(version)s\\n"
[193] Fix | Delete
[194] Fix | Delete
''')
[195] Fix | Delete
[196] Fix | Delete
[197] Fix | Delete
def usage(code, msg=''):
[198] Fix | Delete
print >> sys.stderr, __doc__ % globals()
[199] Fix | Delete
if msg:
[200] Fix | Delete
print >> sys.stderr, msg
[201] Fix | Delete
sys.exit(code)
[202] Fix | Delete
[203] Fix | Delete
[204] Fix | Delete
[205] Fix | Delete
escapes = []
[206] Fix | Delete
[207] Fix | Delete
def make_escapes(pass_iso8859):
[208] Fix | Delete
global escapes
[209] Fix | Delete
escapes = [chr(i) for i in range(256)]
[210] Fix | Delete
if pass_iso8859:
[211] Fix | Delete
# Allow iso-8859 characters to pass through so that e.g. 'msgid
[212] Fix | Delete
[213] Fix | Delete
# escape any character outside the 32..126 range.
[214] Fix | Delete
mod = 128
[215] Fix | Delete
else:
[216] Fix | Delete
mod = 256
[217] Fix | Delete
for i in range(mod):
[218] Fix | Delete
if not(32 <= i <= 126):
[219] Fix | Delete
escapes[i] = "\\%03o" % i
[220] Fix | Delete
escapes[ord('\\')] = '\\\\'
[221] Fix | Delete
escapes[ord('\t')] = '\\t'
[222] Fix | Delete
escapes[ord('\r')] = '\\r'
[223] Fix | Delete
escapes[ord('\n')] = '\\n'
[224] Fix | Delete
escapes[ord('\"')] = '\\"'
[225] Fix | Delete
[226] Fix | Delete
[227] Fix | Delete
def escape(s):
[228] Fix | Delete
global escapes
[229] Fix | Delete
s = list(s)
[230] Fix | Delete
for i in range(len(s)):
[231] Fix | Delete
s[i] = escapes[ord(s[i])]
[232] Fix | Delete
return EMPTYSTRING.join(s)
[233] Fix | Delete
[234] Fix | Delete
[235] Fix | Delete
def safe_eval(s):
[236] Fix | Delete
# unwrap quotes, safely
[237] Fix | Delete
return eval(s, {'__builtins__':{}}, {})
[238] Fix | Delete
[239] Fix | Delete
[240] Fix | Delete
def normalize(s):
[241] Fix | Delete
# This converts the various Python string types into a format that is
[242] Fix | Delete
# appropriate for .po files, namely much closer to C style.
[243] Fix | Delete
lines = s.split('\n')
[244] Fix | Delete
if len(lines) == 1:
[245] Fix | Delete
s = '"' + escape(s) + '"'
[246] Fix | Delete
else:
[247] Fix | Delete
if not lines[-1]:
[248] Fix | Delete
del lines[-1]
[249] Fix | Delete
lines[-1] = lines[-1] + '\n'
[250] Fix | Delete
for i in range(len(lines)):
[251] Fix | Delete
lines[i] = escape(lines[i])
[252] Fix | Delete
lineterm = '\\n"\n"'
[253] Fix | Delete
s = '""\n"' + lineterm.join(lines) + '"'
[254] Fix | Delete
return s
[255] Fix | Delete
[256] Fix | Delete
[257] Fix | Delete
def containsAny(str, set):
[258] Fix | Delete
"""Check whether 'str' contains ANY of the chars in 'set'"""
[259] Fix | Delete
return 1 in [c in str for c in set]
[260] Fix | Delete
[261] Fix | Delete
[262] Fix | Delete
def _get_modpkg_path(dotted_name, pathlist=None):
[263] Fix | Delete
"""Get the filesystem path for a module or a package.
[264] Fix | Delete
[265] Fix | Delete
Return the file system path to a file for a module, and to a directory for
[266] Fix | Delete
a package. Return None if the name is not found, or is a builtin or
[267] Fix | Delete
extension module.
[268] Fix | Delete
"""
[269] Fix | Delete
# split off top-most name
[270] Fix | Delete
parts = dotted_name.split('.', 1)
[271] Fix | Delete
[272] Fix | Delete
if len(parts) > 1:
[273] Fix | Delete
# we have a dotted path, import top-level package
[274] Fix | Delete
try:
[275] Fix | Delete
file, pathname, description = imp.find_module(parts[0], pathlist)
[276] Fix | Delete
if file: file.close()
[277] Fix | Delete
except ImportError:
[278] Fix | Delete
return None
[279] Fix | Delete
[280] Fix | Delete
# check if it's indeed a package
[281] Fix | Delete
if description[2] == imp.PKG_DIRECTORY:
[282] Fix | Delete
# recursively handle the remaining name parts
[283] Fix | Delete
pathname = _get_modpkg_path(parts[1], [pathname])
[284] Fix | Delete
else:
[285] Fix | Delete
pathname = None
[286] Fix | Delete
else:
[287] Fix | Delete
# plain name
[288] Fix | Delete
try:
[289] Fix | Delete
file, pathname, description = imp.find_module(
[290] Fix | Delete
dotted_name, pathlist)
[291] Fix | Delete
if file:
[292] Fix | Delete
file.close()
[293] Fix | Delete
if description[2] not in [imp.PY_SOURCE, imp.PKG_DIRECTORY]:
[294] Fix | Delete
pathname = None
[295] Fix | Delete
except ImportError:
[296] Fix | Delete
pathname = None
[297] Fix | Delete
[298] Fix | Delete
return pathname
[299] Fix | Delete
[300] Fix | Delete
[301] Fix | Delete
def getFilesForName(name):
[302] Fix | Delete
"""Get a list of module files for a filename, a module or package name,
[303] Fix | Delete
or a directory.
[304] Fix | Delete
"""
[305] Fix | Delete
if not os.path.exists(name):
[306] Fix | Delete
# check for glob chars
[307] Fix | Delete
if containsAny(name, "*?[]"):
[308] Fix | Delete
files = glob.glob(name)
[309] Fix | Delete
list = []
[310] Fix | Delete
for file in files:
[311] Fix | Delete
list.extend(getFilesForName(file))
[312] Fix | Delete
return list
[313] Fix | Delete
[314] Fix | Delete
# try to find module or package
[315] Fix | Delete
name = _get_modpkg_path(name)
[316] Fix | Delete
if not name:
[317] Fix | Delete
return []
[318] Fix | Delete
[319] Fix | Delete
if os.path.isdir(name):
[320] Fix | Delete
# find all python files in directory
[321] Fix | Delete
list = []
[322] Fix | Delete
# get extension for python source files
[323] Fix | Delete
if '_py_ext' not in globals():
[324] Fix | Delete
global _py_ext
[325] Fix | Delete
_py_ext = [triple[0] for triple in imp.get_suffixes()
[326] Fix | Delete
if triple[2] == imp.PY_SOURCE][0]
[327] Fix | Delete
for root, dirs, files in os.walk(name):
[328] Fix | Delete
# don't recurse into CVS directories
[329] Fix | Delete
if 'CVS' in dirs:
[330] Fix | Delete
dirs.remove('CVS')
[331] Fix | Delete
# add all *.py files to list
[332] Fix | Delete
list.extend(
[333] Fix | Delete
[os.path.join(root, file) for file in files
[334] Fix | Delete
if os.path.splitext(file)[1] == _py_ext]
[335] Fix | Delete
)
[336] Fix | Delete
return list
[337] Fix | Delete
elif os.path.exists(name):
[338] Fix | Delete
# a single file
[339] Fix | Delete
return [name]
[340] Fix | Delete
[341] Fix | Delete
return []
[342] Fix | Delete
[343] Fix | Delete
[344] Fix | Delete
class TokenEater:
[345] Fix | Delete
def __init__(self, options):
[346] Fix | Delete
self.__options = options
[347] Fix | Delete
self.__messages = {}
[348] Fix | Delete
self.__state = self.__waiting
[349] Fix | Delete
self.__data = []
[350] Fix | Delete
self.__lineno = -1
[351] Fix | Delete
self.__freshmodule = 1
[352] Fix | Delete
self.__curfile = None
[353] Fix | Delete
[354] Fix | Delete
def __call__(self, ttype, tstring, stup, etup, line):
[355] Fix | Delete
# dispatch
[356] Fix | Delete
## import token
[357] Fix | Delete
## print >> sys.stderr, 'ttype:', token.tok_name[ttype], \
[358] Fix | Delete
## 'tstring:', tstring
[359] Fix | Delete
self.__state(ttype, tstring, stup[0])
[360] Fix | Delete
[361] Fix | Delete
def __waiting(self, ttype, tstring, lineno):
[362] Fix | Delete
opts = self.__options
[363] Fix | Delete
# Do docstring extractions, if enabled
[364] Fix | Delete
if opts.docstrings and not opts.nodocstrings.get(self.__curfile):
[365] Fix | Delete
# module docstring?
[366] Fix | Delete
if self.__freshmodule:
[367] Fix | Delete
if ttype == tokenize.STRING:
[368] Fix | Delete
self.__addentry(safe_eval(tstring), lineno, isdocstring=1)
[369] Fix | Delete
self.__freshmodule = 0
[370] Fix | Delete
elif ttype not in (tokenize.COMMENT, tokenize.NL):
[371] Fix | Delete
self.__freshmodule = 0
[372] Fix | Delete
return
[373] Fix | Delete
# class docstring?
[374] Fix | Delete
if ttype == tokenize.NAME and tstring in ('class', 'def'):
[375] Fix | Delete
self.__state = self.__suiteseen
[376] Fix | Delete
return
[377] Fix | Delete
if ttype == tokenize.NAME and tstring in opts.keywords:
[378] Fix | Delete
self.__state = self.__keywordseen
[379] Fix | Delete
[380] Fix | Delete
def __suiteseen(self, ttype, tstring, lineno):
[381] Fix | Delete
# ignore anything until we see the colon
[382] Fix | Delete
if ttype == tokenize.OP and tstring == ':':
[383] Fix | Delete
self.__state = self.__suitedocstring
[384] Fix | Delete
[385] Fix | Delete
def __suitedocstring(self, ttype, tstring, lineno):
[386] Fix | Delete
# ignore any intervening noise
[387] Fix | Delete
if ttype == tokenize.STRING:
[388] Fix | Delete
self.__addentry(safe_eval(tstring), lineno, isdocstring=1)
[389] Fix | Delete
self.__state = self.__waiting
[390] Fix | Delete
elif ttype not in (tokenize.NEWLINE, tokenize.INDENT,
[391] Fix | Delete
tokenize.COMMENT):
[392] Fix | Delete
# there was no class docstring
[393] Fix | Delete
self.__state = self.__waiting
[394] Fix | Delete
[395] Fix | Delete
def __keywordseen(self, ttype, tstring, lineno):
[396] Fix | Delete
if ttype == tokenize.OP and tstring == '(':
[397] Fix | Delete
self.__data = []
[398] Fix | Delete
self.__lineno = lineno
[399] Fix | Delete
self.__state = self.__openseen
[400] Fix | Delete
else:
[401] Fix | Delete
self.__state = self.__waiting
[402] Fix | Delete
[403] Fix | Delete
def __openseen(self, ttype, tstring, lineno):
[404] Fix | Delete
if ttype == tokenize.OP and tstring == ')':
[405] Fix | Delete
# We've seen the last of the translatable strings. Record the
[406] Fix | Delete
# line number of the first line of the strings and update the list
[407] Fix | Delete
# of messages seen. Reset state for the next batch. If there
[408] Fix | Delete
# were no strings inside _(), then just ignore this entry.
[409] Fix | Delete
if self.__data:
[410] Fix | Delete
self.__addentry(EMPTYSTRING.join(self.__data))
[411] Fix | Delete
self.__state = self.__waiting
[412] Fix | Delete
elif ttype == tokenize.STRING:
[413] Fix | Delete
self.__data.append(safe_eval(tstring))
[414] Fix | Delete
elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT,
[415] Fix | Delete
token.NEWLINE, tokenize.NL]:
[416] Fix | Delete
# warn if we see anything else than STRING or whitespace
[417] Fix | Delete
print >> sys.stderr, _(
[418] Fix | Delete
'*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"'
[419] Fix | Delete
) % {
[420] Fix | Delete
'token': tstring,
[421] Fix | Delete
'file': self.__curfile,
[422] Fix | Delete
'lineno': self.__lineno
[423] Fix | Delete
}
[424] Fix | Delete
self.__state = self.__waiting
[425] Fix | Delete
[426] Fix | Delete
def __addentry(self, msg, lineno=None, isdocstring=0):
[427] Fix | Delete
if lineno is None:
[428] Fix | Delete
lineno = self.__lineno
[429] Fix | Delete
if not msg in self.__options.toexclude:
[430] Fix | Delete
entry = (self.__curfile, lineno)
[431] Fix | Delete
self.__messages.setdefault(msg, {})[entry] = isdocstring
[432] Fix | Delete
[433] Fix | Delete
def set_filename(self, filename):
[434] Fix | Delete
self.__curfile = filename
[435] Fix | Delete
self.__freshmodule = 1
[436] Fix | Delete
[437] Fix | Delete
def write(self, fp):
[438] Fix | Delete
options = self.__options
[439] Fix | Delete
timestamp = time.strftime('%Y-%m-%d %H:%M+%Z')
[440] Fix | Delete
# The time stamp in the header doesn't have the same format as that
[441] Fix | Delete
# generated by xgettext...
[442] Fix | Delete
print >> fp, pot_header % {'time': timestamp, 'version': __version__}
[443] Fix | Delete
# Sort the entries. First sort each particular entry's keys, then
[444] Fix | Delete
# sort all the entries by their first item.
[445] Fix | Delete
reverse = {}
[446] Fix | Delete
for k, v in self.__messages.items():
[447] Fix | Delete
keys = v.keys()
[448] Fix | Delete
keys.sort()
[449] Fix | Delete
reverse.setdefault(tuple(keys), []).append((k, v))
[450] Fix | Delete
rkeys = reverse.keys()
[451] Fix | Delete
rkeys.sort()
[452] Fix | Delete
for rkey in rkeys:
[453] Fix | Delete
rentries = reverse[rkey]
[454] Fix | Delete
rentries.sort()
[455] Fix | Delete
for k, v in rentries:
[456] Fix | Delete
isdocstring = 0
[457] Fix | Delete
# If the entry was gleaned out of a docstring, then add a
[458] Fix | Delete
# comment stating so. This is to aid translators who may wish
[459] Fix | Delete
# to skip translating some unimportant docstrings.
[460] Fix | Delete
if reduce(operator.__add__, v.values()):
[461] Fix | Delete
isdocstring = 1
[462] Fix | Delete
# k is the message string, v is a dictionary-set of (filename,
[463] Fix | Delete
# lineno) tuples. We want to sort the entries in v first by
[464] Fix | Delete
# file name and then by line number.
[465] Fix | Delete
v = v.keys()
[466] Fix | Delete
v.sort()
[467] Fix | Delete
if not options.writelocations:
[468] Fix | Delete
pass
[469] Fix | Delete
# location comments are different b/w Solaris and GNU:
[470] Fix | Delete
elif options.locationstyle == options.SOLARIS:
[471] Fix | Delete
for filename, lineno in v:
[472] Fix | Delete
d = {'filename': filename, 'lineno': lineno}
[473] Fix | Delete
print >>fp, _(
[474] Fix | Delete
'# File: %(filename)s, line: %(lineno)d') % d
[475] Fix | Delete
elif options.locationstyle == options.GNU:
[476] Fix | Delete
# fit as many locations on one line, as long as the
[477] Fix | Delete
# resulting line length doesn't exceed 'options.width'
[478] Fix | Delete
locline = '#:'
[479] Fix | Delete
for filename, lineno in v:
[480] Fix | Delete
d = {'filename': filename, 'lineno': lineno}
[481] Fix | Delete
s = _(' %(filename)s:%(lineno)d') % d
[482] Fix | Delete
if len(locline) + len(s) <= options.width:
[483] Fix | Delete
locline = locline + s
[484] Fix | Delete
else:
[485] Fix | Delete
print >> fp, locline
[486] Fix | Delete
locline = "#:" + s
[487] Fix | Delete
if len(locline) > 2:
[488] Fix | Delete
print >> fp, locline
[489] Fix | Delete
if isdocstring:
[490] Fix | Delete
print >> fp, '#, docstring'
[491] Fix | Delete
print >> fp, 'msgid', normalize(k)
[492] Fix | Delete
print >> fp, 'msgstr ""\n'
[493] Fix | Delete
[494] Fix | Delete
[495] Fix | Delete
[496] Fix | Delete
def main():
[497] Fix | Delete
global default_keywords
[498] Fix | Delete
try:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function