1
1
#! /usr/bin/env python3
2
- # -*- coding: iso-8859-1 -*-
3
- # Originally written by Barry Warsaw <[email protected] >
4
- #
5
- # Minimally patched to make it even more xgettext compatible
6
- # by Peter Funk <[email protected] >
7
- #
8
- # 2002-11-22 Jürgen Hermann <[email protected] >
9
- # Added checks that _() only contains string literals, and
10
- # command line args are resolved to module lists, i.e. you
11
- # can now pass a filename, a module or package name, or a
12
- # directory (including globbing chars, important for Win32).
13
- # Made docstring fit in 80 chars wide displays using pydoc.
14
- #
15
-
16
- # for selftesting
17
- try :
18
- import fintl
19
- _ = fintl .gettext
20
- except ImportError :
21
- _ = lambda s : s
22
2
23
- __doc__ = _ ( """pygettext -- Python equivalent of xgettext(1)
3
+ """pygettext -- Python equivalent of xgettext(1)
24
4
25
5
Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the
26
6
internationalization of C programs. Most of these tools are independent of
153
133
conjunction with the -D option above.
154
134
155
135
If `inputfile' is -, standard input is read.
156
- """ )
136
+ """
157
137
158
- import os
138
+ import ast
139
+ import getopt
140
+ import glob
159
141
import importlib .machinery
160
142
import importlib .util
143
+ import os
161
144
import sys
162
- import glob
163
145
import time
164
- import getopt
165
- import ast
166
146
import tokenize
167
147
from collections import defaultdict
168
148
from dataclasses import dataclass , field
173
153
174
154
# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
175
155
# there.
176
- pot_header = _ ( '''\
156
+ pot_header = '''\
177
157
# SOME DESCRIPTIVE TITLE.
178
158
# Copyright (C) YEAR ORGANIZATION
179
159
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
190
170
"Content-Transfer-Encoding: %(encoding)s\\ n"
191
171
"Generated-By: pygettext.py %(version)s\\ n"
192
172
193
- ''' )
173
+ '''
194
174
195
175
196
176
def usage (code , msg = '' ):
@@ -204,7 +184,7 @@ def make_escapes(pass_nonascii):
204
184
global escapes , escape
205
185
if pass_nonascii :
206
186
# Allow non-ascii characters to pass through so that e.g. 'msgid
207
- # "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we
187
+ # "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we
208
188
# escape any character outside the 32..126 range.
209
189
mod = 128
210
190
escape = escape_ascii
@@ -224,6 +204,7 @@ def make_escapes(pass_nonascii):
224
204
def escape_ascii (s , encoding ):
225
205
return '' .join (escapes [ord (c )] if ord (c ) < 128 else c for c in s )
226
206
207
+
227
208
def escape_nonascii (s , encoding ):
228
209
return '' .join (escapes [b ] for b in s .encode (encoding ))
229
210
@@ -416,7 +397,7 @@ def __waiting(self, ttype, tstring, lineno):
416
397
if func_name not in opts .keywords :
417
398
continue
418
399
if len (call .args ) != 1 :
419
- print (_ (
400
+ print ((
420
401
'*** %(file)s:%(lineno)s: Seen unexpected amount of'
421
402
' positional arguments in gettext call: %(source_segment)s'
422
403
) % {
@@ -426,7 +407,7 @@ def __waiting(self, ttype, tstring, lineno):
426
407
}, file = sys .stderr )
427
408
continue
428
409
if call .keywords :
429
- print (_ (
410
+ print ((
430
411
'*** %(file)s:%(lineno)s: Seen unexpected keyword arguments'
431
412
' in gettext call: %(source_segment)s'
432
413
) % {
@@ -437,7 +418,7 @@ def __waiting(self, ttype, tstring, lineno):
437
418
continue
438
419
arg = call .args [0 ]
439
420
if not isinstance (arg , ast .Constant ):
440
- print (_ (
421
+ print ((
441
422
'*** %(file)s:%(lineno)s: Seen unexpected argument type'
442
423
' in gettext call: %(source_segment)s'
443
424
) % {
@@ -550,7 +531,7 @@ def __addentry(self, msg, lineno=None, *, is_docstring=False):
550
531
)
551
532
552
533
def warn_unexpected_token (self , token ):
553
- print (_ (
534
+ print ((
554
535
'*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"'
555
536
) % {
556
537
'token' : token ,
@@ -677,21 +658,21 @@ class Options:
677
658
elif opt in ('-S' , '--style' ):
678
659
options .locationstyle = locations .get (arg .lower ())
679
660
if options .locationstyle is None :
680
- usage (1 , _ ( 'Invalid value for --style: %s' ) % arg )
661
+ usage (1 , f 'Invalid value for --style: { arg } ' )
681
662
elif opt in ('-o' , '--output' ):
682
663
options .outfile = arg
683
664
elif opt in ('-p' , '--output-dir' ):
684
665
options .outpath = arg
685
666
elif opt in ('-v' , '--verbose' ):
686
667
options .verbose = 1
687
668
elif opt in ('-V' , '--version' ):
688
- print (_ ( 'pygettext.py (xgettext for Python) %s' ) % __version__ )
669
+ print (f 'pygettext.py (xgettext for Python) { __version__ } ' )
689
670
sys .exit (0 )
690
671
elif opt in ('-w' , '--width' ):
691
672
try :
692
673
options .width = int (arg )
693
674
except ValueError :
694
- usage (1 , _ ( '--width argument must be an integer: %s' ) % arg )
675
+ usage (1 , f '--width argument must be an integer: { arg } ' )
695
676
elif opt in ('-x' , '--exclude-file' ):
696
677
options .excludefilename = arg
697
678
elif opt in ('-X' , '--no-docstrings' ):
@@ -719,8 +700,8 @@ class Options:
719
700
with open (options .excludefilename ) as fp :
720
701
options .toexclude = fp .readlines ()
721
702
except IOError :
722
- print (_ (
723
- "Can't read --exclude-file: %s" ) % options . excludefilename , file = sys .stderr )
703
+ print (f"Can't read --exclude-file: { options . excludefilename } " ,
704
+ file = sys .stderr )
724
705
sys .exit (1 )
725
706
else :
726
707
options .toexclude = []
@@ -739,12 +720,12 @@ class Options:
739
720
for filename in args :
740
721
if filename == '-' :
741
722
if options .verbose :
742
- print (_ ( 'Reading standard input' ) )
723
+ print ('Reading standard input' )
743
724
fp = sys .stdin .buffer
744
725
closep = 0
745
726
else :
746
727
if options .verbose :
747
- print (_ ( 'Working on %s' ) % filename )
728
+ print (f 'Working on { filename } ' )
748
729
fp = open (filename , 'rb' )
749
730
closep = 1
750
731
try :
@@ -779,7 +760,3 @@ class Options:
779
760
780
761
if __name__ == '__main__' :
781
762
main ()
782
- # some more test strings
783
- # this one creates a warning
784
- _ ('*** Seen unexpected token "%(token)s"' ) % {'token' : 'test' }
785
- _ ('more' 'than' 'one' 'string' )
0 commit comments