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

Unified Diff: third_party/oauth2client/util.py

Issue 1085893002: Upgrade 3rd packages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rebase Created 5 years, 8 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: third_party/oauth2client/util.py
diff --git a/third_party/oauth2client/util.py b/third_party/oauth2client/util.py
index 90dff155bcfb90d3125c167b11c5773a3b876a54..b0963ef520d836a03fb8340613afe5f015925f66 100644
--- a/third_party/oauth2client/util.py
+++ b/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,26 +17,27 @@
"""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_WARNING',
- 'POSITIONAL_EXCEPTION',
- 'POSITIONAL_IGNORE',
+ 'positional',
+ 'POSITIONAL_WARNING',
+ 'POSITIONAL_EXCEPTION',
+ 'POSITIONAL_IGNORE',
]
+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
+from third_party import six
+from third_party.six.moves import urllib
+
logger = logging.getLogger(__name__)
@@ -51,56 +52,58 @@ 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):
+ ...
+
+ @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.
+ ``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
@@ -114,8 +117,10 @@ def positional(max_positional_args):
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 = ''
@@ -132,7 +137,7 @@ def positional(max_positional_args):
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)
@@ -152,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)
@@ -189,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