Start removing dependence on gflags.
Reviewed in https://codereview.appspot.com/7628044/.
This only removes the dependency from the core library, a second CL will
update all the samples.
diff --git a/oauth2client/util.py b/oauth2client/util.py
index ee6a100..90dff15 100644
--- a/oauth2client/util.py
+++ b/oauth2client/util.py
@@ -22,9 +22,11 @@
]
__all__ = [
'positional',
+ 'POSITIONAL_WARNING',
+ 'POSITIONAL_EXCEPTION',
+ 'POSITIONAL_IGNORE',
]
-import gflags
import inspect
import logging
import types
@@ -38,12 +40,13 @@
logger = logging.getLogger(__name__)
-FLAGS = gflags.FLAGS
+POSITIONAL_WARNING = 'WARNING'
+POSITIONAL_EXCEPTION = 'EXCEPTION'
+POSITIONAL_IGNORE = 'IGNORE'
+POSITIONAL_SET = frozenset([POSITIONAL_WARNING, POSITIONAL_EXCEPTION,
+ POSITIONAL_IGNORE])
-gflags.DEFINE_enum('positional_parameters_enforcement', 'WARNING',
- ['EXCEPTION', 'WARNING', 'IGNORE'],
- 'The action when an oauth2client.util.positional declaration is violated.')
-
+positional_parameters_enforcement = POSITIONAL_WARNING
def positional(max_positional_args):
"""A decorator to declare that only the first N arguments my be positional.
@@ -93,10 +96,11 @@
def my_method(cls, pos1, kwonly1=None):
...
- The positional decorator behavior is controlled by the
- --positional_parameters_enforcement flag. The flag may be set to 'EXCEPTION',
- 'WARNING' or 'IGNORE' to raise an exception, log a warning, or do nothing,
- respectively, if a declaration is violated.
+ The positional decorator behavior is controlled by
+ util.positional_parameters_enforcement, which may be set to
+ POSITIONAL_EXCEPTION, POSITIONAL_WARNING or POSITIONAL_IGNORE to raise an
+ exception, log a warning, or do nothing, respectively, if a declaration is
+ violated.
Args:
max_positional_arguments: Maximum number of positional arguments. All
@@ -107,9 +111,9 @@
being used as positional parameters.
Raises:
- TypeError if a key-word only argument is provided as a positional parameter,
- but only if the --positional_parameters_enforcement flag is set to
- 'EXCEPTION'.
+ TypeError if a key-word only argument is provided as a positional
+ parameter, but only if util.positional_parameters_enforcement is set to
+ POSITIONAL_EXCEPTION.
"""
def positional_decorator(wrapped):
def positional_wrapper(*args, **kwargs):
@@ -119,9 +123,9 @@
plural_s = 's'
message = '%s() takes at most %d positional argument%s (%d given)' % (
wrapped.__name__, max_positional_args, plural_s, len(args))
- if FLAGS.positional_parameters_enforcement == 'EXCEPTION':
+ if positional_parameters_enforcement == POSITIONAL_EXCEPTION:
raise TypeError(message)
- elif FLAGS.positional_parameters_enforcement == 'WARNING':
+ elif positional_parameters_enforcement == POSITIONAL_WARNING:
logger.warning(message)
else: # IGNORE
pass