Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: appengine/chromium_build_logs/third_party/oauth2client/util.py

Issue 1260293009: make version of ts_mon compatible with appengine (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: clean up code Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/chromium_build_logs/third_party/oauth2client/util.py
diff --git a/appengine/chromium_rietveld/third_party/oauth2client/util.py b/appengine/chromium_build_logs/third_party/oauth2client/util.py
similarity index 59%
copy from appengine/chromium_rietveld/third_party/oauth2client/util.py
copy to appengine/chromium_build_logs/third_party/oauth2client/util.py
index ee6a1003877866503ff6fef9afd8ecfa4427bba7..a706f0261fbe6636666a392d01c9429fc7637b34 100644
--- a/appengine/chromium_rietveld/third_party/oauth2client/util.py
+++ b/appengine/chromium_build_logs/third_party/oauth2client/util.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2010 Google Inc.
+# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,86 +17,93 @@
"""Common utility library."""
-__author__ = ['rafek@google.com (Rafe Kaplan)',
- 'guido@google.com (Guido van Rossum)',
+__author__ = [
+ 'rafek@google.com (Rafe Kaplan)',
+ 'guido@google.com (Guido van Rossum)',
]
+
__all__ = [
- 'positional',
+ 'positional',
+ 'POSITIONAL_WARNING',
+ 'POSITIONAL_EXCEPTION',
+ 'POSITIONAL_IGNORE',
]
-import gflags
+import functools
import inspect
import logging
+import sys
import types
-import urllib
-import urlparse
-try:
- from urlparse import parse_qsl
-except ImportError:
- from cgi import parse_qsl
+import six
+from six.moves import urllib
-logger = logging.getLogger(__name__)
-FLAGS = gflags.FLAGS
+logger = logging.getLogger(__name__)
-gflags.DEFINE_enum('positional_parameters_enforcement', 'WARNING',
- ['EXCEPTION', 'WARNING', 'IGNORE'],
- 'The action when an oauth2client.util.positional declaration is violated.')
+POSITIONAL_WARNING = 'WARNING'
+POSITIONAL_EXCEPTION = 'EXCEPTION'
+POSITIONAL_IGNORE = 'IGNORE'
+POSITIONAL_SET = frozenset([POSITIONAL_WARNING, POSITIONAL_EXCEPTION,
+ POSITIONAL_IGNORE])
+positional_parameters_enforcement = POSITIONAL_WARNING
def positional(max_positional_args):
"""A decorator to declare that only the first N arguments my be positional.
- This decorator makes it easy to support Python 3 style key-word only
- parameters. For example, in Python 3 it is possible to write:
+ This decorator makes it easy to support Python 3 style keyword-only
+ parameters. For example, in Python 3 it is possible to write::
def fn(pos1, *, kwonly1=None, kwonly1=None):
...
- All named parameters after * must be a keyword:
+ All named parameters after ``*`` must be a keyword::
fn(10, 'kw1', 'kw2') # Raises exception.
fn(10, kwonly1='kw1') # Ok.
- Example:
- To define a function like above, do:
+ Example
+ ^^^^^^^
- @positional(1)
- def fn(pos1, kwonly1=None, kwonly2=None):
- ...
+ To define a function like above, do::
- If no default value is provided to a keyword argument, it becomes a required
- keyword argument:
+ @positional(1)
+ def fn(pos1, kwonly1=None, kwonly2=None):
+ ...
- @positional(0)
- def fn(required_kw):
- ...
+ If no default value is provided to a keyword argument, it becomes a required
+ keyword argument::
- This must be called with the keyword parameter:
+ @positional(0)
+ def fn(required_kw):
+ ...
- fn() # Raises exception.
- fn(10) # Raises exception.
- fn(required_kw=10) # Ok.
+ This must be called with the keyword parameter::
- When defining instance or class methods always remember to account for
- 'self' and 'cls':
+ fn() # Raises exception.
+ fn(10) # Raises exception.
+ fn(required_kw=10) # Ok.
- class MyClass(object):
+ When defining instance or class methods always remember to account for
+ ``self`` and ``cls``::
- @positional(2)
- def my_method(self, pos1, kwonly1=None):
- ...
+ class MyClass(object):
- @classmethod
- @positional(2)
- def my_method(cls, pos1, kwonly1=None):
- ...
+ @positional(2)
+ def my_method(self, 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.
+ @classmethod
+ @positional(2)
+ def my_method(cls, pos1, kwonly1=None):
+ ...
+
+ 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,11 +114,13 @@ def positional(max_positional_args):
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):
+ @functools.wraps(wrapped)
def positional_wrapper(*args, **kwargs):
if len(args) > max_positional_args:
plural_s = ''
@@ -119,16 +128,16 @@ def positional(max_positional_args):
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
return wrapped(*args, **kwargs)
return positional_wrapper
- if isinstance(max_positional_args, (int, long)):
+ if isinstance(max_positional_args, six.integer_types):
return positional_decorator
else:
args, _, _, defaults = inspect.getargspec(max_positional_args)
@@ -148,7 +157,7 @@ def scopes_to_string(scopes):
Returns:
The scopes formatted as a single string.
"""
- if isinstance(scopes, types.StringTypes):
+ if isinstance(scopes, six.string_types):
return scopes
else:
return ' '.join(scopes)
@@ -185,8 +194,8 @@ def _add_query_parameter(url, name, value):
if value is None:
return url
else:
- parsed = list(urlparse.urlparse(url))
- q = dict(parse_qsl(parsed[4]))
+ parsed = list(urllib.parse.urlparse(url))
+ q = dict(urllib.parse.parse_qsl(parsed[4]))
q[name] = value
- parsed[4] = urllib.urlencode(q)
- return urlparse.urlunparse(parsed)
+ parsed[4] = urllib.parse.urlencode(q)
+ return urllib.parse.urlunparse(parsed)

Powered by Google App Engine
This is Rietveld 408576698