From: jhermann Date: Thu, 22 Nov 2001 01:15:26 +0000 (+0000) Subject: Added warning for non-string _() markup (which is also ignored) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6f3b02dcb38947084cab35262d565bceb23613d9;p=roundup.git Added warning for non-string _() markup (which is also ignored) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@416 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/tools/pygettext.py b/tools/pygettext.py index 82d1fef..c7c9830 100644 --- a/tools/pygettext.py +++ b/tools/pygettext.py @@ -9,7 +9,7 @@ try: import fintl _ = fintl.gettext except ImportError: - def _(s): return s + _ = lambda s: s __doc__ = _("""pygettext -- Python equivalent of xgettext(1) @@ -138,6 +138,7 @@ import os import sys import time import getopt +import token import tokenize __version__ = '1.1' @@ -274,7 +275,12 @@ class TokenEater: self.__state = self.__waiting elif ttype == tokenize.STRING: self.__data.append(safe_eval(tstring)) - # TBD: should we warn if we seen anything else? + elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT, + token.NEWLINE, tokenize.NL]: + # warn if we seen anything else than STRING or whitespace + print >>sys.stderr, _('*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"') % { + 'token': tstring, 'file': self.__curfile, 'lineno': self.__lineno} + self.__state = self.__waiting def set_filename(self, filename): self.__curfile = filename @@ -459,3 +465,6 @@ if __name__ == '__main__': main() # some more test strings _(u'a unicode string') + _('*** Seen unexpected token "%(token)s"' % {'token': 'test'}) + _('more' 'than' 'one' 'string') +