Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/python31.../bin
File: pygettext3.12.py
#! /opt/alt/python312/bin/python3.12
[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] https://www.python.org/workshops/1997-10/proceedings/loewis.html
[54] Fix | Delete
[2] https://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 importlib.machinery
[158] Fix | Delete
import importlib.util
[159] Fix | Delete
import sys
[160] Fix | Delete
import glob
[161] Fix | Delete
import time
[162] Fix | Delete
import getopt
[163] Fix | Delete
import ast
[164] Fix | Delete
import token
[165] Fix | Delete
import tokenize
[166] Fix | Delete
[167] Fix | Delete
__version__ = '1.5'
[168] Fix | Delete
[169] Fix | Delete
default_keywords = ['_']
[170] Fix | Delete
DEFAULTKEYWORDS = ', '.join(default_keywords)
[171] Fix | Delete
[172] Fix | Delete
EMPTYSTRING = ''
[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)s\\n"
[191] Fix | Delete
"Content-Transfer-Encoding: %(encoding)s\\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(__doc__ % globals(), file=sys.stderr)
[199] Fix | Delete
if msg:
[200] Fix | Delete
print(msg, file=sys.stderr)
[201] Fix | Delete
sys.exit(code)
[202] Fix | Delete
[203] Fix | Delete
[204] Fix | Delete
def make_escapes(pass_nonascii):
[205] Fix | Delete
global escapes, escape
[206] Fix | Delete
if pass_nonascii:
[207] Fix | Delete
# Allow non-ascii characters to pass through so that e.g. 'msgid
[208] Fix | Delete
[209] Fix | Delete
# escape any character outside the 32..126 range.
[210] Fix | Delete
mod = 128
[211] Fix | Delete
escape = escape_ascii
[212] Fix | Delete
else:
[213] Fix | Delete
mod = 256
[214] Fix | Delete
escape = escape_nonascii
[215] Fix | Delete
escapes = [r"\%03o" % i for i in range(mod)]
[216] Fix | Delete
for i in range(32, 127):
[217] Fix | Delete
escapes[i] = chr(i)
[218] Fix | Delete
escapes[ord('\\')] = r'\\'
[219] Fix | Delete
escapes[ord('\t')] = r'\t'
[220] Fix | Delete
escapes[ord('\r')] = r'\r'
[221] Fix | Delete
escapes[ord('\n')] = r'\n'
[222] Fix | Delete
escapes[ord('\"')] = r'\"'
[223] Fix | Delete
[224] Fix | Delete
[225] Fix | Delete
def escape_ascii(s, encoding):
[226] Fix | Delete
return ''.join(escapes[ord(c)] if ord(c) < 128 else c for c in s)
[227] Fix | Delete
[228] Fix | Delete
def escape_nonascii(s, encoding):
[229] Fix | Delete
return ''.join(escapes[b] for b in s.encode(encoding))
[230] Fix | Delete
[231] Fix | Delete
[232] Fix | Delete
def is_literal_string(s):
[233] Fix | Delete
return s[0] in '\'"' or (s[0] in 'rRuU' and s[1] in '\'"')
[234] Fix | Delete
[235] Fix | Delete
[236] Fix | Delete
def safe_eval(s):
[237] Fix | Delete
# unwrap quotes, safely
[238] Fix | Delete
return eval(s, {'__builtins__':{}}, {})
[239] Fix | Delete
[240] Fix | Delete
[241] Fix | Delete
def normalize(s, encoding):
[242] Fix | Delete
# This converts the various Python string types into a format that is
[243] Fix | Delete
# appropriate for .po files, namely much closer to C style.
[244] Fix | Delete
lines = s.split('\n')
[245] Fix | Delete
if len(lines) == 1:
[246] Fix | Delete
s = '"' + escape(s, encoding) + '"'
[247] Fix | Delete
else:
[248] Fix | Delete
if not lines[-1]:
[249] Fix | Delete
del lines[-1]
[250] Fix | Delete
lines[-1] = lines[-1] + '\n'
[251] Fix | Delete
for i in range(len(lines)):
[252] Fix | Delete
lines[i] = escape(lines[i], encoding)
[253] Fix | Delete
lineterm = '\\n"\n"'
[254] Fix | Delete
s = '""\n"' + lineterm.join(lines) + '"'
[255] Fix | Delete
return s
[256] Fix | Delete
[257] Fix | Delete
[258] Fix | Delete
def containsAny(str, set):
[259] Fix | Delete
"""Check whether 'str' contains ANY of the chars in 'set'"""
[260] Fix | Delete
return 1 in [c in str for c in set]
[261] Fix | Delete
[262] Fix | Delete
[263] Fix | Delete
def getFilesForName(name):
[264] Fix | Delete
"""Get a list of module files for a filename, a module or package name,
[265] Fix | Delete
or a directory.
[266] Fix | Delete
"""
[267] Fix | Delete
if not os.path.exists(name):
[268] Fix | Delete
# check for glob chars
[269] Fix | Delete
if containsAny(name, "*?[]"):
[270] Fix | Delete
files = glob.glob(name)
[271] Fix | Delete
list = []
[272] Fix | Delete
for file in files:
[273] Fix | Delete
list.extend(getFilesForName(file))
[274] Fix | Delete
return list
[275] Fix | Delete
[276] Fix | Delete
# try to find module or package
[277] Fix | Delete
try:
[278] Fix | Delete
spec = importlib.util.find_spec(name)
[279] Fix | Delete
name = spec.origin
[280] Fix | Delete
except ImportError:
[281] Fix | Delete
name = None
[282] Fix | Delete
if not name:
[283] Fix | Delete
return []
[284] Fix | Delete
[285] Fix | Delete
if os.path.isdir(name):
[286] Fix | Delete
# find all python files in directory
[287] Fix | Delete
list = []
[288] Fix | Delete
# get extension for python source files
[289] Fix | Delete
_py_ext = importlib.machinery.SOURCE_SUFFIXES[0]
[290] Fix | Delete
for root, dirs, files in os.walk(name):
[291] Fix | Delete
# don't recurse into CVS directories
[292] Fix | Delete
if 'CVS' in dirs:
[293] Fix | Delete
dirs.remove('CVS')
[294] Fix | Delete
# add all *.py files to list
[295] Fix | Delete
list.extend(
[296] Fix | Delete
[os.path.join(root, file) for file in files
[297] Fix | Delete
if os.path.splitext(file)[1] == _py_ext]
[298] Fix | Delete
)
[299] Fix | Delete
return list
[300] Fix | Delete
elif os.path.exists(name):
[301] Fix | Delete
# a single file
[302] Fix | Delete
return [name]
[303] Fix | Delete
[304] Fix | Delete
return []
[305] Fix | Delete
[306] Fix | Delete
[307] Fix | Delete
class TokenEater:
[308] Fix | Delete
def __init__(self, options):
[309] Fix | Delete
self.__options = options
[310] Fix | Delete
self.__messages = {}
[311] Fix | Delete
self.__state = self.__waiting
[312] Fix | Delete
self.__data = []
[313] Fix | Delete
self.__lineno = -1
[314] Fix | Delete
self.__freshmodule = 1
[315] Fix | Delete
self.__curfile = None
[316] Fix | Delete
self.__enclosurecount = 0
[317] Fix | Delete
[318] Fix | Delete
def __call__(self, ttype, tstring, stup, etup, line):
[319] Fix | Delete
# dispatch
[320] Fix | Delete
## import token
[321] Fix | Delete
## print('ttype:', token.tok_name[ttype], 'tstring:', tstring,
[322] Fix | Delete
## file=sys.stderr)
[323] Fix | Delete
self.__state(ttype, tstring, stup[0])
[324] Fix | Delete
[325] Fix | Delete
def __waiting(self, ttype, tstring, lineno):
[326] Fix | Delete
opts = self.__options
[327] Fix | Delete
# Do docstring extractions, if enabled
[328] Fix | Delete
if opts.docstrings and not opts.nodocstrings.get(self.__curfile):
[329] Fix | Delete
# module docstring?
[330] Fix | Delete
if self.__freshmodule:
[331] Fix | Delete
if ttype == tokenize.STRING and is_literal_string(tstring):
[332] Fix | Delete
self.__addentry(safe_eval(tstring), lineno, isdocstring=1)
[333] Fix | Delete
self.__freshmodule = 0
[334] Fix | Delete
return
[335] Fix | Delete
if ttype in (tokenize.COMMENT, tokenize.NL, tokenize.ENCODING):
[336] Fix | Delete
return
[337] Fix | Delete
self.__freshmodule = 0
[338] Fix | Delete
# class or func/method docstring?
[339] Fix | Delete
if ttype == tokenize.NAME and tstring in ('class', 'def'):
[340] Fix | Delete
self.__state = self.__suiteseen
[341] Fix | Delete
return
[342] Fix | Delete
if ttype == tokenize.NAME and tstring in opts.keywords:
[343] Fix | Delete
self.__state = self.__keywordseen
[344] Fix | Delete
return
[345] Fix | Delete
if ttype == tokenize.STRING:
[346] Fix | Delete
maybe_fstring = ast.parse(tstring, mode='eval').body
[347] Fix | Delete
if not isinstance(maybe_fstring, ast.JoinedStr):
[348] Fix | Delete
return
[349] Fix | Delete
for value in filter(lambda node: isinstance(node, ast.FormattedValue),
[350] Fix | Delete
maybe_fstring.values):
[351] Fix | Delete
for call in filter(lambda node: isinstance(node, ast.Call),
[352] Fix | Delete
ast.walk(value)):
[353] Fix | Delete
func = call.func
[354] Fix | Delete
if isinstance(func, ast.Name):
[355] Fix | Delete
func_name = func.id
[356] Fix | Delete
elif isinstance(func, ast.Attribute):
[357] Fix | Delete
func_name = func.attr
[358] Fix | Delete
else:
[359] Fix | Delete
continue
[360] Fix | Delete
[361] Fix | Delete
if func_name not in opts.keywords:
[362] Fix | Delete
continue
[363] Fix | Delete
if len(call.args) != 1:
[364] Fix | Delete
print(_(
[365] Fix | Delete
'*** %(file)s:%(lineno)s: Seen unexpected amount of'
[366] Fix | Delete
' positional arguments in gettext call: %(source_segment)s'
[367] Fix | Delete
) % {
[368] Fix | Delete
'source_segment': ast.get_source_segment(tstring, call) or tstring,
[369] Fix | Delete
'file': self.__curfile,
[370] Fix | Delete
'lineno': lineno
[371] Fix | Delete
}, file=sys.stderr)
[372] Fix | Delete
continue
[373] Fix | Delete
if call.keywords:
[374] Fix | Delete
print(_(
[375] Fix | Delete
'*** %(file)s:%(lineno)s: Seen unexpected keyword arguments'
[376] Fix | Delete
' in gettext call: %(source_segment)s'
[377] Fix | Delete
) % {
[378] Fix | Delete
'source_segment': ast.get_source_segment(tstring, call) or tstring,
[379] Fix | Delete
'file': self.__curfile,
[380] Fix | Delete
'lineno': lineno
[381] Fix | Delete
}, file=sys.stderr)
[382] Fix | Delete
continue
[383] Fix | Delete
arg = call.args[0]
[384] Fix | Delete
if not isinstance(arg, ast.Constant):
[385] Fix | Delete
print(_(
[386] Fix | Delete
'*** %(file)s:%(lineno)s: Seen unexpected argument type'
[387] Fix | Delete
' in gettext call: %(source_segment)s'
[388] Fix | Delete
) % {
[389] Fix | Delete
'source_segment': ast.get_source_segment(tstring, call) or tstring,
[390] Fix | Delete
'file': self.__curfile,
[391] Fix | Delete
'lineno': lineno
[392] Fix | Delete
}, file=sys.stderr)
[393] Fix | Delete
continue
[394] Fix | Delete
if isinstance(arg.value, str):
[395] Fix | Delete
self.__addentry(arg.value, lineno)
[396] Fix | Delete
[397] Fix | Delete
def __suiteseen(self, ttype, tstring, lineno):
[398] Fix | Delete
# skip over any enclosure pairs until we see the colon
[399] Fix | Delete
if ttype == tokenize.OP:
[400] Fix | Delete
if tstring == ':' and self.__enclosurecount == 0:
[401] Fix | Delete
# we see a colon and we're not in an enclosure: end of def
[402] Fix | Delete
self.__state = self.__suitedocstring
[403] Fix | Delete
elif tstring in '([{':
[404] Fix | Delete
self.__enclosurecount += 1
[405] Fix | Delete
elif tstring in ')]}':
[406] Fix | Delete
self.__enclosurecount -= 1
[407] Fix | Delete
[408] Fix | Delete
def __suitedocstring(self, ttype, tstring, lineno):
[409] Fix | Delete
# ignore any intervening noise
[410] Fix | Delete
if ttype == tokenize.STRING and is_literal_string(tstring):
[411] Fix | Delete
self.__addentry(safe_eval(tstring), lineno, isdocstring=1)
[412] Fix | Delete
self.__state = self.__waiting
[413] Fix | Delete
elif ttype not in (tokenize.NEWLINE, tokenize.INDENT,
[414] Fix | Delete
tokenize.COMMENT):
[415] Fix | Delete
# there was no class docstring
[416] Fix | Delete
self.__state = self.__waiting
[417] Fix | Delete
[418] Fix | Delete
def __keywordseen(self, ttype, tstring, lineno):
[419] Fix | Delete
if ttype == tokenize.OP and tstring == '(':
[420] Fix | Delete
self.__data = []
[421] Fix | Delete
self.__lineno = lineno
[422] Fix | Delete
self.__state = self.__openseen
[423] Fix | Delete
else:
[424] Fix | Delete
self.__state = self.__waiting
[425] Fix | Delete
[426] Fix | Delete
def __openseen(self, ttype, tstring, lineno):
[427] Fix | Delete
if ttype == tokenize.OP and tstring == ')':
[428] Fix | Delete
# We've seen the last of the translatable strings. Record the
[429] Fix | Delete
# line number of the first line of the strings and update the list
[430] Fix | Delete
# of messages seen. Reset state for the next batch. If there
[431] Fix | Delete
# were no strings inside _(), then just ignore this entry.
[432] Fix | Delete
if self.__data:
[433] Fix | Delete
self.__addentry(EMPTYSTRING.join(self.__data))
[434] Fix | Delete
self.__state = self.__waiting
[435] Fix | Delete
elif ttype == tokenize.STRING and is_literal_string(tstring):
[436] Fix | Delete
self.__data.append(safe_eval(tstring))
[437] Fix | Delete
elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT,
[438] Fix | Delete
token.NEWLINE, tokenize.NL]:
[439] Fix | Delete
# warn if we see anything else than STRING or whitespace
[440] Fix | Delete
print(_(
[441] Fix | Delete
'*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"'
[442] Fix | Delete
) % {
[443] Fix | Delete
'token': tstring,
[444] Fix | Delete
'file': self.__curfile,
[445] Fix | Delete
'lineno': self.__lineno
[446] Fix | Delete
}, file=sys.stderr)
[447] Fix | Delete
self.__state = self.__waiting
[448] Fix | Delete
[449] Fix | Delete
def __addentry(self, msg, lineno=None, isdocstring=0):
[450] Fix | Delete
if lineno is None:
[451] Fix | Delete
lineno = self.__lineno
[452] Fix | Delete
if not msg in self.__options.toexclude:
[453] Fix | Delete
entry = (self.__curfile, lineno)
[454] Fix | Delete
self.__messages.setdefault(msg, {})[entry] = isdocstring
[455] Fix | Delete
[456] Fix | Delete
def set_filename(self, filename):
[457] Fix | Delete
self.__curfile = filename
[458] Fix | Delete
self.__freshmodule = 1
[459] Fix | Delete
[460] Fix | Delete
def write(self, fp):
[461] Fix | Delete
options = self.__options
[462] Fix | Delete
timestamp = time.strftime('%Y-%m-%d %H:%M%z')
[463] Fix | Delete
encoding = fp.encoding if fp.encoding else 'UTF-8'
[464] Fix | Delete
print(pot_header % {'time': timestamp, 'version': __version__,
[465] Fix | Delete
'charset': encoding,
[466] Fix | Delete
'encoding': '8bit'}, file=fp)
[467] Fix | Delete
# Sort the entries. First sort each particular entry's keys, then
[468] Fix | Delete
# sort all the entries by their first item.
[469] Fix | Delete
reverse = {}
[470] Fix | Delete
for k, v in self.__messages.items():
[471] Fix | Delete
keys = sorted(v.keys())
[472] Fix | Delete
reverse.setdefault(tuple(keys), []).append((k, v))
[473] Fix | Delete
rkeys = sorted(reverse.keys())
[474] Fix | Delete
for rkey in rkeys:
[475] Fix | Delete
rentries = reverse[rkey]
[476] Fix | Delete
rentries.sort()
[477] Fix | Delete
for k, v in rentries:
[478] Fix | Delete
# If the entry was gleaned out of a docstring, then add a
[479] Fix | Delete
# comment stating so. This is to aid translators who may wish
[480] Fix | Delete
# to skip translating some unimportant docstrings.
[481] Fix | Delete
isdocstring = any(v.values())
[482] Fix | Delete
# k is the message string, v is a dictionary-set of (filename,
[483] Fix | Delete
# lineno) tuples. We want to sort the entries in v first by
[484] Fix | Delete
# file name and then by line number.
[485] Fix | Delete
v = sorted(v.keys())
[486] Fix | Delete
if not options.writelocations:
[487] Fix | Delete
pass
[488] Fix | Delete
# location comments are different b/w Solaris and GNU:
[489] Fix | Delete
elif options.locationstyle == options.SOLARIS:
[490] Fix | Delete
for filename, lineno in v:
[491] Fix | Delete
d = {'filename': filename, 'lineno': lineno}
[492] Fix | Delete
print(_(
[493] Fix | Delete
'# File: %(filename)s, line: %(lineno)d') % d, file=fp)
[494] Fix | Delete
elif options.locationstyle == options.GNU:
[495] Fix | Delete
# fit as many locations on one line, as long as the
[496] Fix | Delete
# resulting line length doesn't exceed 'options.width'
[497] Fix | Delete
locline = '#:'
[498] Fix | Delete
for filename, lineno in v:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function