23
23
except ImportError :
24
24
_ = lambda s : s
25
25
26
+ import getopt
27
+ import glob
28
+ import importlib
29
+ import operator
30
+ import os
31
+ import sys
32
+ import time
33
+ import token
34
+ import tokenize
35
+ from functools import reduce
36
+
37
+ __version__ = '1.5'
38
+
26
39
__doc__ = _ ("""pygettext -- Python equivalent of xgettext(1)
27
40
28
41
Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the
158
171
If `inputfile' is -, standard input is read.
159
172
""" )
160
173
161
- import os
162
- import importlib
163
- import sys
164
- import glob
165
- import time
166
- import getopt
167
- import token
168
- import tokenize
169
- import operator
170
-
171
- from functools import reduce
172
-
173
- __version__ = '1.5'
174
-
175
174
default_keywords = ['_' ]
176
175
DEFAULTKEYWORDS = ', ' .join (default_keywords )
177
176
199
198
200
199
''' )
201
200
201
+
202
202
def usage (code , msg = '' ):
203
203
print (__doc__ % globals (), file = sys .stderr )
204
204
if msg :
@@ -208,6 +208,7 @@ def usage(code, msg=''):
208
208
209
209
escapes = []
210
210
211
+
211
212
def make_escapes (pass_iso8859 ):
212
213
global escapes
213
214
escapes = [chr (i ) for i in range (256 )]
@@ -219,7 +220,7 @@ def make_escapes(pass_iso8859):
219
220
else :
220
221
mod = 256
221
222
for i in range (mod ):
222
- if not (32 <= i <= 126 ):
223
+ if not (32 <= i <= 126 ):
223
224
escapes [i ] = "\\ %03o" % i
224
225
escapes [ord ('\\ ' )] = '\\ \\ '
225
226
escapes [ord ('\t ' )] = '\\ t'
@@ -238,7 +239,7 @@ def escape(s):
238
239
239
240
def safe_eval (s ):
240
241
# unwrap quotes, safely
241
- return eval (s , {'__builtins__' :{}}, {})
242
+ return eval (s , {'__builtins__' : {}}, {})
242
243
243
244
244
245
def normalize (s ):
@@ -257,9 +258,10 @@ def normalize(s):
257
258
s = '""\n "' + lineterm .join (lines ) + '"'
258
259
return s
259
260
260
- def containsAny (str , set ):
261
+
262
+ def containsAny (string , inset ):
261
263
"""Check whether 'str' contains ANY of the chars in 'set'"""
262
- return 1 in [c in str for c in set ]
264
+ return 1 in [c in string for c in inset ]
263
265
264
266
265
267
def _get_modpkg_path (dotted_name , pathlist = None ):
@@ -270,11 +272,11 @@ def _get_modpkg_path(dotted_name, pathlist=None):
270
272
extension module.
271
273
"""
272
274
pathname = None
273
- r = importlib .util .find_spec (dotted_name , pathlist )
275
+ r = importlib .util .find_spec (dotted_name , pathlist )
274
276
275
277
if r .loader .is_package (dotted_name ):
276
278
pathname = r .submodule_search_locations [0 ]
277
- elif issubclass (r .loader .__class__ ,(importlib .abc .SourceLoader )):
279
+ elif issubclass (r .loader .__class__ , (importlib .abc .SourceLoader )):
278
280
pathname = r .origin
279
281
return pathname
280
282
@@ -287,10 +289,10 @@ def getFilesForName(name):
287
289
# check for glob chars
288
290
if containsAny (name , "*?[]" ):
289
291
files = glob .glob (name )
290
- list = []
292
+ lst = []
291
293
for file in files :
292
- list .extend (getFilesForName (file ))
293
- return list
294
+ lst .extend (getFilesForName (file ))
295
+ return lst
294
296
295
297
# try to find module or package
296
298
name = _get_modpkg_path (name )
@@ -299,7 +301,7 @@ def getFilesForName(name):
299
301
300
302
if os .path .isdir (name ):
301
303
# find all python files in directory
302
- list = []
304
+ lst = []
303
305
# get extension for python source files
304
306
if '_py_ext' not in globals ():
305
307
global _py_ext
@@ -309,17 +311,18 @@ def getFilesForName(name):
309
311
if 'CVS' in dirs :
310
312
dirs .remove ('CVS' )
311
313
# add all *.py files to list
312
- list .extend (
314
+ lst .extend (
313
315
[os .path .join (root , file ) for file in files
314
316
if os .path .splitext (file )[1 ] == _py_ext ]
315
317
)
316
- return list
318
+ return lst
317
319
elif os .path .exists (name ):
318
320
# a single file
319
321
return [name ]
320
322
321
323
return []
322
324
325
+
323
326
class TokenEater :
324
327
def __init__ (self , options ):
325
328
self .__options = options
@@ -398,14 +401,14 @@ def __openseen(self, ttype, tstring, lineno):
398
401
) % {
399
402
'token' : tstring ,
400
403
'file' : self .__curfile ,
401
- 'lineno' : self .__lineno
404
+ 'lineno' : self .__lineno ,
402
405
}, file = sys .stderr )
403
406
self .__state = self .__waiting
404
407
405
408
def __addentry (self , msg , lineno = None , isdocstring = 0 ):
406
409
if lineno is None :
407
410
lineno = self .__lineno
408
- if not msg in self .__options .toexclude :
411
+ if msg not in self .__options .toexclude :
409
412
entry = (self .__curfile , lineno )
410
413
self .__messages .setdefault (msg , {})[entry ] = isdocstring
411
414
@@ -506,8 +509,8 @@ class Options:
506
509
nodocstrings = {}
507
510
508
511
options = Options ()
509
- locations = {'gnu' : options .GNU ,
510
- 'solaris' : options .SOLARIS ,
512
+ locations = {'gnu' : options .GNU ,
513
+ 'solaris' : options .SOLARIS ,
511
514
}
512
515
513
516
# parse options
@@ -629,6 +632,7 @@ class Options:
629
632
if closep :
630
633
fp .close ()
631
634
635
+
632
636
if __name__ == '__main__' :
633
637
main ()
634
638
# some more test strings
0 commit comments