Hello community,
here is the log from the commit of package python-python-gflags for
openSUSE:Factory checked in at 2013-08-14 23:03:09
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-python-gflags (Old)
and /work/SRC/openSUSE:Factory/.python-python-gflags.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-python-gflags"
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-python-gflags/python-python-gflags.changes
2011-12-20 14:31:31.000000000 +0100
+++
/work/SRC/openSUSE:Factory/.python-python-gflags.new/python-python-gflags.changes
2013-08-14 23:03:11.000000000 +0200
@@ -1,0 +2,13 @@
+Fri Aug 9 15:35:26 UTC 2013 - [email protected]
+
+- update to version 2.0
+ * Don't raise DuplicateFlag when re-importing a module (mmcdonald)
+ * Changed the 'official' python-gflags email in setup.py/etc
+ * Changed copyright text to reflect Google's relinquished ownership
+ * Prepare gflags for python 3.x, keeping 2.4 compatibility (twouters)
+ * If output is a tty, use terminal's width to wrap help-text (wiesmann)
+ * PORTING: Fix ImportError for non-Unix platforms (kdeus)
+ * PORTING: Run correctly when termios isn't available (shines)
+ * Add unicode support to flags (csilvers)
+
+-------------------------------------------------------------------
Old:
----
python-gflags-1.6.tar.gz
New:
----
python-gflags-2.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-python-gflags.spec ++++++
--- /var/tmp/diff_new_pack.bgeJ4m/_old 2013-08-14 23:03:12.000000000 +0200
+++ /var/tmp/diff_new_pack.bgeJ4m/_new 2013-08-14 23:03:12.000000000 +0200
@@ -1,7 +1,7 @@
#
# spec file for package python-python-gflags
#
-# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -11,12 +11,13 @@
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
-#
+
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
+
Name: python-python-gflags
-Version: 1.6
+Version: 2.0
Release: 0
Url: http://code.google.com/p/python-gflags
Summary: Google Commandline Flags Module
++++++ python-gflags-1.6.tar.gz -> python-gflags-2.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/AUTHORS
new/python-gflags-2.0/AUTHORS
--- old/python-gflags-1.6/AUTHORS 2011-07-29 21:36:21.000000000 +0200
+++ new/python-gflags-2.0/AUTHORS 2012-01-18 23:00:49.000000000 +0100
@@ -1,2 +1,2 @@
[email protected]
[email protected]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/ChangeLog
new/python-gflags-2.0/ChangeLog
--- old/python-gflags-1.6/ChangeLog 2011-07-29 21:36:21.000000000 +0200
+++ new/python-gflags-2.0/ChangeLog 2012-01-18 23:00:50.000000000 +0100
@@ -1,3 +1,24 @@
+Wed Jan 18 13:57:39 2012 Google Inc. <[email protected]>
+
+ * python-gflags: version 2.0
+ * No changes from version 1.8.
+
+Wed Jan 18 11:54:03 2012 Google Inc. <[email protected]>
+
+ * python-gflags: version 1.8
+ * Don't raise DuplicateFlag when re-importing a module (mmcdonald)
+ * Changed the 'official' python-gflags email in setup.py/etc
+ * Changed copyright text to reflect Google's relinquished ownership
+
+Tue Dec 20 17:10:41 2011 Google Inc. <[email protected]>
+
+ * python-gflags: version 1.7
+ * Prepare gflags for python 3.x, keeping 2.4 compatibility (twouters)
+ * If output is a tty, use terminal's width to wrap help-text (wiesmann)
+ * PORTING: Fix ImportError for non-Unix platforms (kdeus)
+ * PORTING: Run correctly when termios isn't available (shines)
+ * Add unicode support to flags (csilvers)
+
Fri Jul 29 12:24:08 2011 Google Inc. <[email protected]>
* python-gflags: version 1.6
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/NEWS new/python-gflags-2.0/NEWS
--- old/python-gflags-1.6/NEWS 2011-07-29 21:36:21.000000000 +0200
+++ new/python-gflags-2.0/NEWS 2012-01-18 23:00:50.000000000 +0100
@@ -1,4 +1,34 @@
-== 29 July 2011 ==
+== 18 January 2012 ==
+
+[Prependum:] I just realized I should have named the new version 2.0,
+to reflect the new ownership and status as a community run project.
+Not too late, I guess. I've just released python-gflags 2.0, which is
+identical to python-gflags 1.8 except for the version number.
+
+I've just released python-gflags 1.8. This fixes a bug, allowing
+modules defining flags to be re-imported without raising duplicate
+flag errors.
+
+Administrative note: In the coming weeks, I'll be stepping down as
+maintainer for the python-gflags project, and as part of that Google
+is relinquishing ownership of the project; it will now be entirely
+community run. The remaining
+[http://python-gflags.googlecode.com/svn/tags/python-gflags-1.8/ChangeLog
changes]
+in this release reflect that shift.
+
+
+=== 20 December 2011 ===
+
+I've just released python-gflags 1.7. The major change here is
+improved unicode support, in both flag default values and
+help-strings. We've also made big steps toward making gflags work
+with python 3.x (while keeping 2.4 compatibility), and improving
+--help output in the common case where output is a tty.
+
+For a full list of changes since last release, see the
+[http://python-gflags.googlecode.com/svn/tags/python-gflags-1.7/ChangeLog
ChangeLog].
+
+=== 29 July 2011 ===
I've just released python-gflags 1.6. This release has only minor
changes, including support for multi_float flags. The full list of
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/PKG-INFO
new/python-gflags-2.0/PKG-INFO
--- old/python-gflags-1.6/PKG-INFO 2011-07-29 21:50:39.000000000 +0200
+++ new/python-gflags-2.0/PKG-INFO 2012-01-25 05:15:04.000000000 +0100
@@ -1,10 +1,10 @@
Metadata-Version: 1.0
Name: python-gflags
-Version: 1.6
+Version: 2.0
Summary: Google Commandline Flags Module
Home-page: http://code.google.com/p/python-gflags
-Author: Google Inc.
-Author-email: [email protected]
+Author: Google Inc. and others
+Author-email: [email protected]
License: BSD
Description: UNKNOWN
Platform: UNKNOWN
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/debian/changelog
new/python-gflags-2.0/debian/changelog
--- old/python-gflags-1.6/debian/changelog 2011-07-29 21:36:21.000000000
+0200
+++ new/python-gflags-2.0/debian/changelog 2012-01-18 23:00:50.000000000
+0100
@@ -1,3 +1,21 @@
+python-gflags (2.0-1) unstable; urgency=low
+
+ * New upstream release.
+
+ -- Google Inc. <[email protected]> Wed, 18 Jan 2012 13:57:39
-0800
+
+python-gflags (1.8-1) unstable; urgency=low
+
+ * New upstream release.
+
+ -- Google Inc. <[email protected]> Wed, 18 Jan 2012 11:54:03
-0800
+
+python-gflags (1.7-1) unstable; urgency=low
+
+ * New upstream release.
+
+ -- Google Inc. <[email protected]> Tue, 20 Dec 2011 17:10:41 -0800
+
python-gflags (1.6-1) unstable; urgency=low
* New upstream release.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/debian/control
new/python-gflags-2.0/debian/control
--- old/python-gflags-1.6/debian/control 2011-07-29 21:36:21.000000000
+0200
+++ new/python-gflags-2.0/debian/control 2012-01-18 23:00:49.000000000
+0100
@@ -2,7 +2,7 @@
Section: python
XS-Python-Version: all
Priority: optional
-Maintainer: Tim 'mithro' Ansell <[email protected]>
+Maintainer: Craig Silverstein <[email protected]>
Build-Depends-Indep: python-central (>= 0.5.6), python-setuptools (>=
0.6b3-1), python-all
Build-Depends: debhelper (>= 5.0.38)
Standards-Version: 3.7.2
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/debian/copyright
new/python-gflags-2.0/debian/copyright
--- old/python-gflags-1.6/debian/copyright 2011-07-29 21:36:21.000000000
+0200
+++ new/python-gflags-2.0/debian/copyright 2012-01-18 23:00:49.000000000
+0100
@@ -1,10 +1,10 @@
-This package was debianized by Tim 'mithro' Ansell <[email protected]> on
-Thu, 12 Nov 2009 11:25:53 +1100.
+This package was debianized by Craig Silverstein
<[email protected]> on
+Wed, 18 Jan 2012 13:57:39 -0800.
-It was downloaded from http://code.google.com/p/google-gflags/downloads/list
+It was downloaded from http://code.google.com/p/python-gflags/downloads/list
-Upstream Author: Google Inc. <[email protected]>
-Copyright: Google Inc. <[email protected]>
+Upstream Author: Google Inc. and others <[email protected]>
+Copyright: Google Inc. and others <[email protected]>
License:
@@ -37,5 +37,5 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-The Debian packaging is (C) 2009, Tim 'mithro' Ansell <[email protected]> and
+The Debian packaging is (C) 2011, Tim 'mithro' Ansell <[email protected]> and
is licensed under the above.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/gflags.py
new/python-gflags-2.0/gflags.py
--- old/python-gflags-1.6/gflags.py 2011-07-29 21:36:22.000000000 +0200
+++ new/python-gflags-2.0/gflags.py 2012-01-18 23:00:51.000000000 +0100
@@ -392,17 +392,29 @@
import os
import re
import string
+import struct
import sys
+# pylint: disable-msg=C6204
+try:
+ import fcntl
+except ImportError:
+ fcntl = None
+try:
+ # Importing termios will fail on non-unix platforms.
+ import termios
+except ImportError:
+ termios = None
import gflags_validators
+# pylint: enable-msg=C6204
# Are we running under pychecker?
_RUNNING_PYCHECKER = 'pychecker.python' in sys.modules
-def _GetCallingModule():
- """Returns the name of the module that's calling into this module.
+def _GetCallingModuleObjectAndName():
+ """Returns the module that's calling into this module.
We generally use this function to get the name of the module calling a
DEFINE_foo... function.
@@ -411,12 +423,17 @@
for depth in range(1, sys.getrecursionlimit()):
if not sys._getframe(depth).f_globals is globals():
globals_for_frame = sys._getframe(depth).f_globals
- module_name = _GetModuleObjectAndName(globals_for_frame)[1]
+ module, module_name = _GetModuleObjectAndName(globals_for_frame)
if module_name is not None:
- return module_name
+ return module, module_name
raise AssertionError("No module was found")
+def _GetCallingModule():
+ """Returns the name of the module that's calling into this module."""
+ return _GetCallingModuleObjectAndName()[1]
+
+
def _GetThisModuleObjectAndName():
"""Returns: (module object, module name) for this module."""
return _GetModuleObjectAndName(globals())
@@ -496,7 +513,7 @@
# An UnrecognizedFlagError conveys more information than an UnrecognizedFlag.
# Since there are external modules that create DuplicateFlags, the interface to
# DuplicateFlag shouldn't change. The flagvalue will be assigned the full
value
-# of the flag and its argument, if any, allowing handling of unrecognzed flags
+# of the flag and its argument, if any, allowing handling of unrecognized flags
# in an exception handler.
# If flagvalue is the empty string, then this exception is an due to a
# reference to a flag that was not already defined.
@@ -514,7 +531,20 @@
def GetHelpWidth():
"""Returns: an integer, the width of help lines that is used in TextWrap."""
- return _help_width
+ if (not sys.stdout.isatty()) or (termios is None) or (fcntl is None):
+ return _help_width
+ try:
+ data = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, '1234')
+ columns = struct.unpack('hh', data)[1]
+ # Emacs mode returns 0.
+ # Here we assume that any value below 40 is unreasonable
+ if columns >= 40:
+ return columns
+ # Returning an int as default is fine, int(int) just return the int.
+ return int(os.getenv('COLUMNS', _help_width))
+
+ except (TypeError, IOError, struct.error):
+ return _help_width
def CutCommonSpacePrefix(text):
@@ -525,8 +555,8 @@
for. That means the first line will stay untouched. This is especially
useful to turn doc strings into help texts. This is because some
people prefer to have the doc comment start already after the
- apostrophy and then align the following lines while others have the
- apostrophies on a seperately line.
+ apostrophe and then align the following lines while others have the
+ apostrophes on a separate line.
The function also drops trailing empty lines and ignores empty lines
following the initial content line while calculating the initial
@@ -548,7 +578,7 @@
text_first_line = []
else:
text_first_line = [text_lines.pop(0)]
- # Calculate length of common leading whitesppace (only over content lines)
+ # Calculate length of common leading whitespace (only over content lines)
common_prefix = os.path.commonprefix([line for line in text_lines if line])
space_prefix_len = len(common_prefix) - len(common_prefix.lstrip())
# If we have a common space prefix, drop it from all lines
@@ -563,7 +593,7 @@
def TextWrap(text, length=None, indent='', firstline_indent=None, tabs=' '):
"""Wraps a given text to a maximum line length and returns it.
- We turn lines that only contain whitespaces into empty lines. We keep
+ We turn lines that only contain whitespace into empty lines. We keep
new lines and tabs (e.g., we do not treat tabs as spaces).
Args:
@@ -597,7 +627,7 @@
else:
line = firstline_indent
if len(firstline_indent) >= length:
- raise FlagsError('First iline indent must be shorter than length')
+ raise FlagsError('First line indent must be shorter than length')
# If the callee does not care about tabs we simply convert them to
# spaces If callee wanted tabs to be single space then we do that
@@ -651,7 +681,7 @@
line += ' '
# Add word and shorten it up to allowed line length. Restart next
# line with indent and repeat, or add a space if we're done (word
- # finished) This deals with words that caanot fit on one line
+ # finished) This deals with words that cannot fit on one line
# (e.g. indent + word longer than allowed line length).
while len(line) + len(word) >= length:
line += word
@@ -663,7 +693,7 @@
line += word + ' '
# End of input line. If we have content we finish the line. If the
# current line is just the indent but we had content in during this
- # original line then we need to add an emoty line.
+ # original line then we need to add an empty line.
if (result and line != indent) or (not result and line !=
firstline_indent):
result.append(line.rstrip())
elif len(result) == old_result_len:
@@ -726,7 +756,7 @@
def _GetMainModule():
"""Returns: string, name of the module from which execution started."""
- # First, try to use the same logic used by _GetCallingModule(),
+ # First, try to use the same logic used by _GetCallingModuleObjectAndName(),
# i.e., call _GetModuleObjectAndName(). For that we first need to
# find the dictionary that the main module uses to store the
# globals.
@@ -741,7 +771,7 @@
# The above strategy fails in some cases (e.g., tools that compute
# code coverage by redefining, among other things, the main module).
# If so, just use sys.argv[0]. We can probably always do this, but
- # it's safest to try to use the same logic as _GetCallingModule().
+ # it's safest to try to use the same logic as
_GetCallingModuleObjectAndName()
if main_module_name is None:
main_module_name = sys.argv[0]
return main_module_name
@@ -789,6 +819,9 @@
# Dictionary: module name (string) -> list of Flag objects that are defined
# by that module.
self.__dict__['__flags_by_module'] = {}
+ # Dictionary: module id (int) -> list of Flag objects that are defined by
+ # that module.
+ self.__dict__['__flags_by_module_id'] = {}
# Dictionary: module name (string) -> list of Flag objects that are
# key for that module.
self.__dict__['__key_flags_by_module'] = {}
@@ -822,6 +855,15 @@
"""
return self.__dict__['__flags_by_module']
+ def FlagsByModuleIdDict(self):
+ """Returns the dictionary of module_id -> list of defined flags.
+
+ Returns:
+ A dictionary. Its keys are module IDs (ints). Its values
+ are lists of Flag objects.
+ """
+ return self.__dict__['__flags_by_module_id']
+
def KeyFlagsByModuleDict(self):
"""Returns the dictionary of module_name -> list of key flags.
@@ -844,6 +886,16 @@
flags_by_module = self.FlagsByModuleDict()
flags_by_module.setdefault(module_name, []).append(flag)
+ def _RegisterFlagByModuleId(self, module_id, flag):
+ """Records the module that defines a specific flag.
+
+ Args:
+ module_id: An int, the ID of the Python module.
+ flag: A Flag object, a flag that is key to the module.
+ """
+ flags_by_module_id = self.FlagsByModuleIdDict()
+ flags_by_module_id.setdefault(module_id, []).append(flag)
+
def _RegisterKeyFlagForModule(self, module_name, flag):
"""Specifies that a flag is a key flag for a module.
@@ -918,6 +970,25 @@
return module
return default
+ def FindModuleIdDefiningFlag(self, flagname, default=None):
+ """Return the ID of the module defining this flag, or default.
+
+ Args:
+ flagname: Name of the flag to lookup.
+ default: Value to return if flagname is not defined. Defaults
+ to None.
+
+ Returns:
+ The ID of the module which registered the flag with this name.
+ If no such module exists (i.e. no flag with this name exists),
+ we return default.
+ """
+ for module_id, flags in self.FlagsByModuleIdDict().iteritems():
+ for flag in flags:
+ if flag.name == flagname or flag.short_name == flagname:
+ return module_id
+ return default
+
def AppendFlagValues(self, flag_values):
"""Appends flags registered in another FlagValues instance.
@@ -957,12 +1028,19 @@
raise FlagsError("Flag name cannot be empty")
# If running under pychecker, duplicate keys are likely to be
# defined. Disable check for duplicate keys when pycheck'ing.
- if (fl.has_key(name) and not flag.allow_override and
+ if (name in fl and not flag.allow_override and
not fl[name].allow_override and not _RUNNING_PYCHECKER):
+ module, module_name = _GetCallingModuleObjectAndName()
+ if (self.FindModuleDefiningFlag(name) == module_name and
+ id(module) != self.FindModuleIdDefiningFlag(name)):
+ # If the flag has already been defined by a module with the same name,
+ # but a different ID, we can stop here because it indicates that the
+ # module is simply being imported a subsequent time.
+ return
raise DuplicateFlagError(name, self)
short_name = flag.short_name
if short_name is not None:
- if (fl.has_key(short_name) and not flag.allow_override and
+ if (short_name in fl and not flag.allow_override and
not fl[short_name].allow_override and not _RUNNING_PYCHECKER):
raise DuplicateFlagError(short_name, self)
fl[short_name] = flag
@@ -977,7 +1055,7 @@
def __getattr__(self, name):
"""Retrieves the 'value' attribute of the flag --name."""
fl = self.FlagDict()
- if not fl.has_key(name):
+ if name not in fl:
raise AttributeError(name)
return fl[name].value
@@ -1071,9 +1149,10 @@
if not self._FlagIsRegistered(flag_obj):
# If the Flag object indicated by flag_name is no longer
# registered (please see the docstring of _FlagIsRegistered), then
- # we delete the occurences of the flag object in all our internal
+ # we delete the occurrences of the flag object in all our internal
# dictionaries.
self.__RemoveFlagFromDictByModule(self.FlagsByModuleDict(), flag_obj)
+ self.__RemoveFlagFromDictByModule(self.FlagsByModuleIdDict(), flag_obj)
self.__RemoveFlagFromDictByModule(self.KeyFlagsByModuleDict(), flag_obj)
def __RemoveFlagFromDictByModule(self, flags_by_module_dict, flag_obj):
@@ -1085,7 +1164,7 @@
flag_obj: A flag object.
"""
for unused_module, flags_in_module in flags_by_module_dict.iteritems():
- # while (as opposed to if) takes care of multiple occurences of a
+ # while (as opposed to if) takes care of multiple occurrences of a
# flag in the list for the same module.
while flag_obj in flags_in_module:
flags_in_module.remove(flag_obj)
@@ -1093,7 +1172,7 @@
def SetDefault(self, name, value):
"""Changes the default value of the named flag object."""
fl = self.FlagDict()
- if not fl.has_key(name):
+ if name not in fl:
raise AttributeError(name)
fl[name].SetDefault(value)
self._AssertValidators(fl[name].validators)
@@ -1105,7 +1184,7 @@
has_key = __contains__ # a synonym for __contains__()
def __iter__(self):
- return self.FlagDict().iterkeys()
+ return iter(self.FlagDict())
def __call__(self, argv):
"""Parses flags from argv; stores parsed flags into this FlagValues object.
@@ -1153,7 +1232,7 @@
prefix = shortest_matches[name]
no_prefix = shortest_matches[no_name]
- # Replace all occurences of this boolean with extended forms
+ # Replace all occurrences of this boolean with extended forms
for arg_idx in range(1, len(argv)):
arg = argv[arg_idx]
if arg.find('=') >= 0: continue
@@ -1190,7 +1269,7 @@
break
except getopt.GetoptError, e:
if not e.opt or e.opt in fl:
- # Not an unrecognized option, reraise the exception as a FlagsError
+ # Not an unrecognized option, re-raise the exception as a FlagsError
raise FlagsError(e)
# Remove offender from args and try again
for arg_index in range(len(args)):
@@ -1228,7 +1307,7 @@
# short option
name = name[1:]
short_option = 1
- if fl.has_key(name):
+ if name in fl:
flag = fl[name]
if flag.boolean and short_option: arg = 1
flag.Parse(arg)
@@ -1261,7 +1340,7 @@
def RegisteredFlags(self):
"""Returns: a list of the names and short names of all registered flags."""
- return self.FlagDict().keys()
+ return list(self.FlagDict())
def FlagValuesDict(self):
"""Returns: a dictionary that maps flag names to flag values."""
@@ -1284,8 +1363,7 @@
flags_by_module = self.FlagsByModuleDict()
if flags_by_module:
- modules = flags_by_module.keys()
- modules.sort()
+ modules = sorted(flags_by_module)
# Print the help for the main module first, if possible.
main_module = _GetMainModule()
@@ -1369,7 +1447,7 @@
# a different flag is using this name now
continue
# only print help once
- if flagset.has_key(flag): continue
+ if flag in flagset: continue
flagset[flag] = 1
flaghelp = ""
if flag.short_name: flaghelp += "-%s," % flag.short_name
@@ -1516,11 +1594,11 @@
parsed_file_list)
flag_line_list.extend(included_flags)
else: # Case of hitting a circularly included file.
- print >>sys.stderr, ('Warning: Hit circular flagfile dependency: %s'
- % sub_filename)
+ sys.stderr.write('Warning: Hit circular flagfile dependency: %s\n' %
+ (sub_filename,))
else:
# Any line that's not a comment or a nested flagfile should get
- # copied into 2nd position. This leaves earlier arguements
+ # copied into 2nd position. This leaves earlier arguments
# further back in the list, thus giving them higher priority.
flag_line_list.append(line.strip())
return flag_line_list
@@ -1686,6 +1764,14 @@
FLAGS = FlagValues()
+def _StrOrUnicode(value):
+ """Converts value to a python string or, if necessary, unicode-string."""
+ try:
+ return str(value)
+ except UnicodeEncodeError:
+ return unicode(value)
+
+
def _MakeXMLSafe(s):
"""Escapes <, >, and & from s, and removes XML 1.0-illegal chars."""
s = cgi.escape(s) # Escape <, >, and &
@@ -1695,6 +1781,8 @@
# NOTE: if there are problems with current solution, one may move to
# XML 1.1, which allows such chars, if they're entity-escaped (&#xHH;).
s = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f]', '', s)
+ # Convert non-ascii characters to entities. Note: requires python >=2.3
+ s = s.encode('ascii', 'xmlcharrefreplace') # u'\xce\x88' -> 'uΈ'
return s
@@ -1708,12 +1796,12 @@
as the value of the XML element.
indent: A string, prepended to each line of generated output.
"""
- value_str = str(value)
+ value_str = _StrOrUnicode(value)
if isinstance(value, bool):
# Display boolean values as the C++ flag library does: no caps.
value_str = value_str.lower()
- outfile.write('%s<%s>%s</%s>\n' %
- (indent, name, _MakeXMLSafe(value_str), name))
+ safe_value_str = _MakeXMLSafe(value_str)
+ outfile.write('%s<%s>%s</%s>\n' % (indent, name, safe_value_str, name))
class Flag:
@@ -1769,6 +1857,17 @@
self.SetDefault(default)
+ def __hash__(self):
+ return hash(id(self))
+
+ def __eq__(self, other):
+ return self is other
+
+ def __lt__(self, other):
+ if isinstance(other, Flag):
+ return id(self) < id(other)
+ return NotImplemented
+
def __GetParsedValueAsString(self, value):
if value is None:
return None
@@ -1779,7 +1878,7 @@
return repr('true')
else:
return repr('false')
- return repr(str(value))
+ return repr(_StrOrUnicode(value))
def Parse(self, argument):
try:
@@ -1965,7 +2064,7 @@
"""Base class for generating string representations of a flag value."""
def Serialize(self, value):
- return str(value)
+ return _StrOrUnicode(value)
class ListSerializer(ArgumentSerializer):
@@ -1974,7 +2073,7 @@
self.list_sep = list_sep
def Serialize(self, value):
- return self.list_sep.join([str(x) for x in value])
+ return self.list_sep.join([_StrOrUnicode(x) for x in value])
# Flags validators
@@ -2097,7 +2196,9 @@
# FLAGS test here) and redefine flags with the same name (e.g.,
# debug). To avoid breaking their code, we perform the
# registration only if flag_values is a real FlagValues object.
- flag_values._RegisterFlagByModule(_GetCallingModule(), flag)
+ module, module_name = _GetCallingModuleObjectAndName()
+ flag_values._RegisterFlagByModule(module_name, flag)
+ flag_values._RegisterFlagByModuleId(id(module), flag)
def _InternalDeclareKeyFlags(flag_names,
@@ -2190,8 +2291,8 @@
# If module is this flag module, take _SPECIAL_FLAGS into account.
if module == _GetThisModuleObjectAndName()[0]:
_InternalDeclareKeyFlags(
- # As we associate flags with _GetCallingModule(), the special
- # flags defined in this module are incorrectly registered with
+ # As we associate flags with _GetCallingModuleObjectAndName(), the
+ # special flags defined in this module are incorrectly registered with
# a different module. So, we can't use _GetKeyFlagsForModule.
# Instead, we take all flags from _SPECIAL_FLAGS (a private
# FlagValues, where no other module should register flags).
@@ -2457,17 +2558,9 @@
base = 10
if len(argument) > 2 and argument[0] == "0" and argument[1] == "x":
base = 16
- try:
- return int(argument, base)
- # ValueError is thrown when argument is a string, and overflows an int.
- except ValueError:
- return long(argument, base)
+ return int(argument, base)
else:
- try:
- return int(argument)
- # OverflowError is thrown when argument is numeric, and overflows an int.
- except OverflowError:
- return long(argument)
+ return int(argument)
def Type(self):
return 'int'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/python_gflags.egg-info/PKG-INFO
new/python-gflags-2.0/python_gflags.egg-info/PKG-INFO
--- old/python-gflags-1.6/python_gflags.egg-info/PKG-INFO 2011-07-29
21:50:39.000000000 +0200
+++ new/python-gflags-2.0/python_gflags.egg-info/PKG-INFO 2012-01-25
05:15:03.000000000 +0100
@@ -1,10 +1,10 @@
Metadata-Version: 1.0
Name: python-gflags
-Version: 1.6
+Version: 2.0
Summary: Google Commandline Flags Module
Home-page: http://code.google.com/p/python-gflags
-Author: Google Inc.
-Author-email: [email protected]
+Author: Google Inc. and others
+Author-email: [email protected]
License: BSD
Description: UNKNOWN
Platform: UNKNOWN
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/python_gflags.egg-info/SOURCES.txt
new/python-gflags-2.0/python_gflags.egg-info/SOURCES.txt
--- old/python-gflags-1.6/python_gflags.egg-info/SOURCES.txt 2011-07-29
21:50:39.000000000 +0200
+++ new/python-gflags-2.0/python_gflags.egg-info/SOURCES.txt 2012-01-25
05:15:04.000000000 +0100
@@ -8,6 +8,7 @@
gflags.py
gflags2man.py
gflags_validators.py
+setup.cfg
setup.py
debian/README
debian/changelog
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/setup.py
new/python-gflags-2.0/setup.py
--- old/python-gflags-1.6/setup.py 2011-07-29 21:36:21.000000000 +0200
+++ new/python-gflags-2.0/setup.py 2012-01-18 23:00:51.000000000 +0100
@@ -32,11 +32,11 @@
from setuptools import setup
setup(name='python-gflags',
- version='1.6',
+ version='2.0',
description='Google Commandline Flags Module',
license='BSD',
- author='Google Inc.',
- author_email='[email protected]',
+ author='Google Inc. and others',
+ author_email='[email protected]',
url='http://code.google.com/p/python-gflags',
py_modules=["gflags", "gflags_validators"],
data_files=[("bin", ["gflags2man.py"])],
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/tests/gflags_googletest.py
new/python-gflags-2.0/tests/gflags_googletest.py
--- old/python-gflags-1.6/tests/gflags_googletest.py 2011-07-29
21:36:21.000000000 +0200
+++ new/python-gflags-2.0/tests/gflags_googletest.py 2012-01-18
23:00:51.000000000 +0100
@@ -90,17 +90,27 @@
class TestCase(unittest.TestCase):
def assertListEqual(self, list1, list2):
"""Asserts that, when sorted, list1 and list2 are identical."""
- self.assertEqual(Sorted(list1), Sorted(list2))
+ # This exists in python 2.7, but not previous versions. Use the
+ # built-in version if possible.
+ if hasattr(unittest.TestCase, "assertListEqual"):
+ unittest.TestCase.assertListEqual(self, Sorted(list1), Sorted(list2))
+ else:
+ self.assertEqual(Sorted(list1), Sorted(list2))
def assertMultiLineEqual(self, expected, actual):
- self.assert_(MultiLineEqual(expected, actual))
+ # This exists in python 2.7, but not previous versions. Use the
+ # built-in version if possible.
+ if hasattr(unittest.TestCase, "assertMultiLineEqual"):
+ unittest.TestCase.assertMultiLineEqual(self, expected, actual)
+ else:
+ self.assertTrue(MultiLineEqual(expected, actual))
def assertRaisesWithRegexpMatch(self, exception, regexp, fn, *args,
**kwargs):
try:
fn(*args, **kwargs)
except exception, why:
- self.assert_(re.search(regexp, str(why)),
- "'%s' does not match '%s'" % (regexp, why))
+ self.assertTrue(re.search(regexp, str(why)),
+ "'%s' does not match '%s'" % (regexp, why))
return
self.fail(exception.__name__ + " not raised")
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-gflags-1.6/tests/gflags_unittest.py
new/python-gflags-2.0/tests/gflags_unittest.py
--- old/python-gflags-1.6/tests/gflags_unittest.py 2011-07-29
21:36:22.000000000 +0200
+++ new/python-gflags-2.0/tests/gflags_unittest.py 2012-01-18
23:00:52.000000000 +0100
@@ -34,6 +34,7 @@
__pychecker__ = "no-local" # for unittest
+import cStringIO
import sys
import os
import shutil
@@ -47,6 +48,10 @@
import gflags_googletest as googletest
+# TODO(csilvers): add a wrapper function around FLAGS(argv) that
+# verifies the input is a list or tuple. This avoids bugs where we
+# make argv a string instead of a list, by mistake.
+
class FlagsUnitTest(googletest.TestCase):
"Flags Unit Test"
@@ -70,7 +75,7 @@
gflags.DEFINE_boolean("quack", 0, "superstring of 'q'")
gflags.DEFINE_boolean("noexec", 1, "boolean flag with no as prefix")
gflags.DEFINE_integer("x", 3, "how eXtreme to be")
- gflags.DEFINE_integer("l", 0x7fffffff00000000L, "how long to be")
+ gflags.DEFINE_integer("l", 0x7fffffff00000000, "how long to be")
gflags.DEFINE_list('letters', 'a,b,c', "a list of letters")
gflags.DEFINE_list('numbers', [1, 2, 3], "a list of numbers")
gflags.DEFINE_enum("kwery", None, ['who', 'what', 'why', 'where', 'when'],
@@ -87,8 +92,8 @@
assert FLAGS.debug == 0, "boolean default values not set:" + FLAGS.debug
assert FLAGS.q == 1, "boolean default values not set:" + FLAGS.q
assert FLAGS.x == 3, "integer default values not set:" + FLAGS.x
- assert FLAGS.l == 0x7fffffff00000000L, ("integer default values not set:"
- + FLAGS.l)
+ assert FLAGS.l == 0x7fffffff00000000, ("integer default values not set:"
+ + FLAGS.l)
assert FLAGS.letters == ['a', 'b', 'c'], ("list default values not set:"
+ FLAGS.letters)
assert FLAGS.numbers == [1, 2, 3], ("list default values not set:"
@@ -104,7 +109,7 @@
assert flag_values['q'] == 1
assert flag_values['quack'] == 0
assert flag_values['x'] == 3
- assert flag_values['l'] == 0x7fffffff00000000L
+ assert flag_values['l'] == 0x7fffffff00000000
assert flag_values['letters'] == ['a', 'b', 'c']
assert flag_values['numbers'] == [1, 2, 3]
assert flag_values['kwery'] is None
@@ -484,7 +489,7 @@
try:
gflags.DEFINE_boolean("run", 0, "runhelp", short_name='q')
raise AssertionError("duplicate flag detection failed")
- except gflags.DuplicateFlag, e:
+ except gflags.DuplicateFlag:
pass
# Duplicate short flag detection
@@ -531,7 +536,7 @@
allow_override=1)
flag = FLAGS.FlagDict()['dup1']
self.assertEqual(flag.default, 1)
- except gflags.DuplicateFlag, e:
+ except gflags.DuplicateFlag:
raise AssertionError("allow_override did not permit a flag duplication")
# Make sure allow_override works
@@ -545,7 +550,7 @@
allow_override=0)
flag = FLAGS.FlagDict()['dup2']
self.assertEqual(flag.default, 1)
- except gflags.DuplicateFlag, e:
+ except gflags.DuplicateFlag:
raise AssertionError("allow_override did not permit a flag duplication")
# Make sure allow_override doesn't work with None default
@@ -558,9 +563,18 @@
gflags.DEFINE_boolean("dup3", None, "runhelp d32", short_name='u3',
allow_override=1)
raise AssertionError('Cannot override a flag with a default of None')
- except gflags.DuplicateFlagCannotPropagateNoneToSwig, e:
+ except gflags.DuplicateFlagCannotPropagateNoneToSwig:
pass
+ # Make sure that re-importing a module does not cause a DuplicateFlagError
+ # to be raised.
+ try:
+ sys.modules.pop(
+ "flags_modules_for_testing.module_baz")
+ import flags_modules_for_testing.module_baz
+ except gflags.DuplicateFlagError:
+ raise AssertionError("Module reimport caused flag duplication error")
+
# Make sure that when we override, the help string gets updated correctly
gflags.DEFINE_boolean("dup3", 0, "runhelp d31", short_name='u',
allow_override=1)
@@ -614,7 +628,7 @@
try:
FLAGS.AppendFlagValues(new_flags)
raise AssertionError("ignore_copy was not set but caused no exception")
- except gflags.DuplicateFlag, e:
+ except gflags.DuplicateFlag:
pass
# Integer out of bounds
@@ -795,7 +809,7 @@
# Test non-parseable defaults.
self.assertRaisesWithRegexpMatch(
gflags.IllegalFlagValue,
- 'flag --m_int2=abc: invalid literal for long\(\) with base 10:
\'abc\'',
+ 'flag --m_int2=abc: invalid literal for int\(\) with base 10: \'abc\'',
gflags.DEFINE_multi_int, 'm_int2', ['abc'], 'desc')
self.assertRaisesWithRegexpMatch(
@@ -809,7 +823,7 @@
argv = ('./program', '--m_int2=def')
self.assertRaisesWithRegexpMatch(
gflags.IllegalFlagValue,
- 'flag --m_int2=def: invalid literal for long\(\) with base 10:
\'def\'',
+ 'flag --m_int2=def: invalid literal for int\(\) with base 10: \'def\'',
FLAGS, argv)
gflags.DEFINE_multi_float('m_float2', 2.2,
@@ -821,6 +835,59 @@
FLAGS, argv)
+class UnicodeFlagsTest(googletest.TestCase):
+ """Testing proper unicode support for flags."""
+
+ def testUnicodeDefaultAndHelpstring(self):
+ gflags.DEFINE_string("unicode_str", "\xC3\x80\xC3\xBD".decode("utf-8"),
+ "help:\xC3\xAA".decode("utf-8"))
+ argv = ("./program",)
+ FLAGS(argv) # should not raise any exceptions
+
+ argv = ("./program", "--unicode_str=foo")
+ FLAGS(argv) # should not raise any exceptions
+
+ def testUnicodeInList(self):
+ gflags.DEFINE_list("unicode_list", ["abc", "\xC3\x80".decode("utf-8"),
+ "\xC3\xBD".decode("utf-8")],
+ "help:\xC3\xAB".decode("utf-8"))
+ argv = ("./program",)
+ FLAGS(argv) # should not raise any exceptions
+
+ argv = ("./program", "--unicode_list=hello,there")
+ FLAGS(argv) # should not raise any exceptions
+
+ def testXMLOutput(self):
+ gflags.DEFINE_string("unicode1", "\xC3\x80\xC3\xBD".decode("utf-8"),
+ "help:\xC3\xAC".decode("utf-8"))
+ gflags.DEFINE_list("unicode2", ["abc", "\xC3\x80".decode("utf-8"),
+ "\xC3\xBD".decode("utf-8")],
+ "help:\xC3\xAD".decode("utf-8"))
+ gflags.DEFINE_list("non_unicode", ["abc", "def", "ghi"],
+ "help:\xC3\xAD".decode("utf-8"))
+
+ outfile = cStringIO.StringIO()
+ FLAGS.WriteHelpInXMLFormat(outfile)
+ actual_output = outfile.getvalue()
+
+ # The xml output is large, so we just check parts of it.
+ self.assertTrue("<name>unicode1</name>\n"
+ " <meaning>help:ì</meaning>\n"
+ " <default>Àý</default>\n"
+ " <current>Àý</current>"
+ in actual_output)
+ self.assertTrue("<name>unicode2</name>\n"
+ " <meaning>help:í</meaning>\n"
+ " <default>abc,À,ý</default>\n"
+ " <current>[\'abc\', u\'\\xc0\', u\'\\xfd\']</current>"
+ in actual_output)
+ self.assertTrue("<name>non_unicode</name>\n"
+ " <meaning>help:í</meaning>\n"
+ " <default>abc,def,ghi</default>\n"
+ " <current>[\'abc\', \'def\', \'ghi\']</current>"
+ in actual_output)
+
+
class LoadFromFlagFileTest(googletest.TestCase):
"""Testing loading flags from a file and parsing them."""
@@ -1307,7 +1374,7 @@
'--undefok=nosuchflagg', 'extra')
self.flag_values(argv)
raise AssertionError("Unknown flag exception not raised")
- except gflags.UnrecognizedFlag:
+ except gflags.UnrecognizedFlag, e:
assert e.flagname == 'nosuchflag'
# Allow unknown short flag -w if specified with undefok
@@ -1725,18 +1792,18 @@
# code and execute it.
code = ("import gflags\n"
"module_name = gflags._GetCallingModule()")
- exec code
+ exec(code)
# Next two exec statements executes code with a global environment
# that is different from the global environment of any imported
# module.
- exec code in {}
+ exec(code, {})
# vars(self) returns a dictionary corresponding to the symbol
# table of the self object. dict(...) makes a distinct copy of
# this dictionary, such that any new symbol definition by the
# exec-ed code (e.g., import flags, module_name = ...) does not
# affect the symbol table of self.
- exec code in dict(vars(self))
+ exec(code, dict(vars(self)))
# Next test is actually more involved: it checks not only that
# _GetCallingModule does not crash inside exec code, it also checks
@@ -1745,7 +1812,7 @@
# check it twice: first time by executing exec from the main
# module, second time by executing it from module_bar.
global_dict = {}
- exec code in global_dict
+ exec(code, global_dict)
self.assertEqual(global_dict['module_name'],
sys.argv[0])
@@ -1781,6 +1848,22 @@
sys.modules = orig_sys_modules
+class FindModuleTest(googletest.TestCase):
+ """Testing methods that find a module that defines a given flag."""
+
+ def testFindModuleDefiningFlag(self):
+ self.assertEqual('default', FLAGS.FindModuleDefiningFlag(
+ '__NON_EXISTENT_FLAG__', 'default'))
+ self.assertEqual(
+ module_baz.__name__, FLAGS.FindModuleDefiningFlag('tmod_baz_x'))
+
+ def testFindModuleIdDefiningFlag(self):
+ self.assertEqual('default', FLAGS.FindModuleIdDefiningFlag(
+ '__NON_EXISTENT_FLAG__', 'default'))
+ self.assertEqual(
+ id(module_baz), FLAGS.FindModuleIdDefiningFlag('tmod_baz_x'))
+
+
class FlagsErrorMessagesTest(googletest.TestCase):
"""Testing special cases for integer and float flags error messages."""
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]