2323except ImportError :
2424 _ = lambda s : s
2525
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+
2639__doc__ = _ ("""pygettext -- Python equivalent of xgettext(1)
2740
2841Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the
158171If `inputfile' is -, standard input is read.
159172""" )
160173
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-
175174default_keywords = ['_' ]
176175DEFAULTKEYWORDS = ', ' .join (default_keywords )
177176
199198
200199''' )
201200
201+
202202def usage (code , msg = '' ):
203203 print (__doc__ % globals (), file = sys .stderr )
204204 if msg :
@@ -208,6 +208,7 @@ def usage(code, msg=''):
208208
209209escapes = []
210210
211+
211212def make_escapes (pass_iso8859 ):
212213 global escapes
213214 escapes = [chr (i ) for i in range (256 )]
@@ -219,7 +220,7 @@ def make_escapes(pass_iso8859):
219220 else :
220221 mod = 256
221222 for i in range (mod ):
222- if not (32 <= i <= 126 ):
223+ if not (32 <= i <= 126 ):
223224 escapes [i ] = "\\ %03o" % i
224225 escapes [ord ('\\ ' )] = '\\ \\ '
225226 escapes [ord ('\t ' )] = '\\ t'
@@ -238,7 +239,7 @@ def escape(s):
238239
239240def safe_eval (s ):
240241 # unwrap quotes, safely
241- return eval (s , {'__builtins__' :{}}, {})
242+ return eval (s , {'__builtins__' : {}}, {})
242243
243244
244245def normalize (s ):
@@ -257,9 +258,10 @@ def normalize(s):
257258 s = '""\n "' + lineterm .join (lines ) + '"'
258259 return s
259260
260- def containsAny (str , set ):
261+
262+ def containsAny (string , inset ):
261263 """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 ]
263265
264266
265267def _get_modpkg_path (dotted_name , pathlist = None ):
@@ -270,11 +272,11 @@ def _get_modpkg_path(dotted_name, pathlist=None):
270272 extension module.
271273 """
272274 pathname = None
273- r = importlib .util .find_spec (dotted_name , pathlist )
275+ r = importlib .util .find_spec (dotted_name , pathlist )
274276
275277 if r .loader .is_package (dotted_name ):
276278 pathname = r .submodule_search_locations [0 ]
277- elif issubclass (r .loader .__class__ ,(importlib .abc .SourceLoader )):
279+ elif issubclass (r .loader .__class__ , (importlib .abc .SourceLoader )):
278280 pathname = r .origin
279281 return pathname
280282
@@ -287,10 +289,10 @@ def getFilesForName(name):
287289 # check for glob chars
288290 if containsAny (name , "*?[]" ):
289291 files = glob .glob (name )
290- list = []
292+ lst = []
291293 for file in files :
292- list .extend (getFilesForName (file ))
293- return list
294+ lst .extend (getFilesForName (file ))
295+ return lst
294296
295297 # try to find module or package
296298 name = _get_modpkg_path (name )
@@ -299,7 +301,7 @@ def getFilesForName(name):
299301
300302 if os .path .isdir (name ):
301303 # find all python files in directory
302- list = []
304+ lst = []
303305 # get extension for python source files
304306 if '_py_ext' not in globals ():
305307 global _py_ext
@@ -309,17 +311,18 @@ def getFilesForName(name):
309311 if 'CVS' in dirs :
310312 dirs .remove ('CVS' )
311313 # add all *.py files to list
312- list .extend (
314+ lst .extend (
313315 [os .path .join (root , file ) for file in files
314316 if os .path .splitext (file )[1 ] == _py_ext ]
315317 )
316- return list
318+ return lst
317319 elif os .path .exists (name ):
318320 # a single file
319321 return [name ]
320322
321323 return []
322324
325+
323326class TokenEater :
324327 def __init__ (self , options ):
325328 self .__options = options
@@ -398,14 +401,14 @@ def __openseen(self, ttype, tstring, lineno):
398401 ) % {
399402 'token' : tstring ,
400403 'file' : self .__curfile ,
401- 'lineno' : self .__lineno
404+ 'lineno' : self .__lineno ,
402405 }, file = sys .stderr )
403406 self .__state = self .__waiting
404407
405408 def __addentry (self , msg , lineno = None , isdocstring = 0 ):
406409 if lineno is None :
407410 lineno = self .__lineno
408- if not msg in self .__options .toexclude :
411+ if msg not in self .__options .toexclude :
409412 entry = (self .__curfile , lineno )
410413 self .__messages .setdefault (msg , {})[entry ] = isdocstring
411414
@@ -506,8 +509,8 @@ class Options:
506509 nodocstrings = {}
507510
508511 options = Options ()
509- locations = {'gnu' : options .GNU ,
510- 'solaris' : options .SOLARIS ,
512+ locations = {'gnu' : options .GNU ,
513+ 'solaris' : options .SOLARIS ,
511514 }
512515
513516 # parse options
@@ -629,6 +632,7 @@ class Options:
629632 if closep :
630633 fp .close ()
631634
635+
632636if __name__ == '__main__' :
633637 main ()
634638 # some more test strings
0 commit comments