[Python-checkins] CVS: python/dist/src/Tools/i18n pygettext.py,1.20,1.21

Barry Warsaw bwarsaw@users.sourceforge.net
2001年7月27日 09:47:20 -0700


Update of /cvsroot/python/python/dist/src/Tools/i18n
In directory usw-pr-cvs1:/tmp/cvs-serv19245
Modified Files:
	pygettext.py 
Log Message:
Added the -X/--no-docstrings flag which takes a filename containing a
list of files to not extract docstrings from when the -D option is
given. This isn't optimal, but I didn't want to change the semantics
of -D, and it's bad form to allow optional switch arguments.
Bumping __version__ to 1.4.
TokenEater.__init__(): Initialize __curfile to None.
__waiting(): In order to extract docstrings from the module, both the
 -D flag should be set, and the __curfile should not be named in
 the -X filename (i.e. it isn't in opts.nodocstrings).
set_filename(): Fixed a bug where once the first module docstring is
 extracted, no subsequent module docstrings will be extracted. The
 bug was that the first extraction set __freshmodule to 0, but that
 flag was never reset back to 1. set_filename() is always called
 when the next file is being processed, so use it to reset the
 __freshmodule flag.
main(): Add support for -X/--no-docstring.
Index: pygettext.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/i18n/pygettext.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** pygettext.py	2001年06月20日 19:41:40	1.20
--- pygettext.py	2001年07月27日 16:47:18	1.21
***************
*** 1,4 ****
 #! /usr/bin/env python
! # Originally written by Barry Warsaw <barry@digicool.com>
 #
 # Minimally patched to make it even more xgettext compatible 
--- 1,4 ----
 #! /usr/bin/env python
! # Originally written by Barry Warsaw <barry@zope.com>
 #
 # Minimally patched to make it even more xgettext compatible 
***************
*** 50,58 ****
 -a
 --extract-all
! Extract all strings
 
 -d name
 --default-domain=name
! Rename the default output file from messages.pot to name.pot 
 
 -E
--- 50,58 ----
 -a
 --extract-all
! Extract all strings.
 
 -d name
 --default-domain=name
! Rename the default output file from messages.pot to name.pot.
 
 -E
***************
*** 64,72 ****
 Extract module, class, method, and function docstrings. These do not
 need to be wrapped in _() markers, and in fact cannot be for Python to
! consider them docstrings.
 
 -h
 --help
! print this help message and exit
 
 -k word
--- 64,72 ----
 Extract module, class, method, and function docstrings. These do not
 need to be wrapped in _() markers, and in fact cannot be for Python to
! consider them docstrings. (See also the -X option).
 
 -h
 --help
! Print this help message and exit.
 
 -k word
***************
*** 129,134 ****
 appear on a line by itself in the file.
 
! If `inputfile' is -, standard input is read.
 
 """
 
--- 129,139 ----
 appear on a line by itself in the file.
 
! -X filename
! --no-docstrings=filename
! Specify a file that contains a list of files (one per line) that
! should not have their docstrings extracted. This is only useful in
! conjunction with the -D option above.
 
+ If `inputfile' is -, standard input is read.
 """
 
***************
*** 147,151 ****
 def _(s): return s
 
! __version__ = '1.3'
 
 default_keywords = ['_']
--- 152,156 ----
 def _(s): return s
 
! __version__ = '1.4'
 
 default_keywords = ['_']
***************
*** 156,161 ****
 
 
! # The normal pot-file header. msgmerge and EMACS' po-mode work better if
! # it's there.
 pot_header = _('''\
 # SOME DESCRIPTIVE TITLE.
--- 161,166 ----
 
 
! # The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
! # there.
 pot_header = _('''\
 # SOME DESCRIPTIVE TITLE.
***************
*** 248,251 ****
--- 253,257 ----
 self.__lineno = -1
 self.__freshmodule = 1
+ self.__curfile = None
 
 def __call__(self, ttype, tstring, stup, etup, line):
***************
*** 257,262 ****
 
 def __waiting(self, ttype, tstring, lineno):
 # Do docstring extractions, if enabled
! if self.__options.docstrings:
 # module docstring?
 if self.__freshmodule:
--- 263,269 ----
 
 def __waiting(self, ttype, tstring, lineno):
+ opts = self.__options
 # Do docstring extractions, if enabled
! if opts.docstrings and not opts.nodocstrings.get(self.__curfile):
 # module docstring?
 if self.__freshmodule:
***************
*** 271,275 ****
 self.__state = self.__suiteseen
 return
! if ttype == tokenize.NAME and tstring in self.__options.keywords:
 self.__state = self.__keywordseen
 
--- 278,282 ----
 self.__state = self.__suiteseen
 return
! if ttype == tokenize.NAME and tstring in opts.keywords:
 self.__state = self.__keywordseen
 
***************
*** 319,322 ****
--- 326,330 ----
 def set_filename(self, filename):
 self.__curfile = filename
+ self.__freshmodule = 1
 
 def write(self, fp):
***************
*** 384,393 ****
 opts, args = getopt.getopt(
 sys.argv[1:],
! 'ad:DEhk:Kno:p:S:Vvw:x:',
 ['extract-all', 'default-domain=', 'escape', 'help',
 'keyword=', 'no-default-keywords',
 'add-location', 'no-location', 'output=', 'output-dir=',
 'style=', 'verbose', 'version', 'width=', 'exclude-file=',
! 'docstrings',
 ])
 except getopt.error, msg:
--- 392,401 ----
 opts, args = getopt.getopt(
 sys.argv[1:],
! 'ad:DEhk:Kno:p:S:Vvw:x:X:',
 ['extract-all', 'default-domain=', 'escape', 'help',
 'keyword=', 'no-default-keywords',
 'add-location', 'no-location', 'output=', 'output-dir=',
 'style=', 'verbose', 'version', 'width=', 'exclude-file=',
! 'docstrings', 'no-docstrings',
 ])
 except getopt.error, msg:
***************
*** 411,414 ****
--- 419,423 ----
 excludefilename = ''
 docstrings = 0
+ nodocstrings = {}
 
 options = Options()
***************
*** 457,460 ****
--- 466,479 ----
 elif opt in ('-x', '--exclude-file'):
 options.excludefilename = arg
+ elif opt in ('-X', '--no-docstrings'):
+ fp = open(arg)
+ try:
+ while 1:
+ line = fp.readline()
+ if not line:
+ break
+ options.nodocstrings[line[:-1]] = 1
+ finally:
+ fp.close()
 
 # calculate escapes

AltStyle によって変換されたページ (->オリジナル) /