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

Side by Side Diff: client/third_party/oauth2client/util.py

Issue 1768993002: Update oauth2client to v2.0.1 and googleapiclient to v1.5.0. Base URL: git@github.com:luci/luci-py.git@master
Patch Set: . Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python
2 #
3 # Copyright 2014 Google Inc. All rights reserved. 1 # Copyright 2014 Google Inc. All rights reserved.
4 # 2 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
8 # 6 #
9 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
10 # 8 #
11 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and 12 # See the License for the specific language governing permissions and
15 # limitations under the License. 13 # limitations under the License.
16 #
17 14
18 """Common utility library.""" 15 """Common utility library."""
19 16
20 import functools 17 import functools
21 import inspect 18 import inspect
22 import logging 19 import logging
23 20
24 import six 21 import six
25 from six.moves import urllib 22 from six.moves import urllib
26 23
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 The scopes in a list. 176 The scopes in a list.
180 """ 177 """
181 if not scopes: 178 if not scopes:
182 return [] 179 return []
183 if isinstance(scopes, six.string_types): 180 if isinstance(scopes, six.string_types):
184 return scopes.split(' ') 181 return scopes.split(' ')
185 else: 182 else:
186 return scopes 183 return scopes
187 184
188 185
189 def dict_to_tuple_key(dictionary):
190 """Converts a dictionary to a tuple that can be used as an immutable key.
191
192 The resulting key is always sorted so that logically equivalent
193 dictionaries always produce an identical tuple for a key.
194
195 Args:
196 dictionary: the dictionary to use as the key.
197
198 Returns:
199 A tuple representing the dictionary in it's naturally sorted ordering.
200 """
201 return tuple(sorted(dictionary.items()))
202
203
204 def _add_query_parameter(url, name, value): 186 def _add_query_parameter(url, name, value):
205 """Adds a query parameter to a url. 187 """Adds a query parameter to a url.
206 188
207 Replaces the current value if it already exists in the URL. 189 Replaces the current value if it already exists in the URL.
208 190
209 Args: 191 Args:
210 url: string, url to add the query parameter to. 192 url: string, url to add the query parameter to.
211 name: string, query parameter name. 193 name: string, query parameter name.
212 value: string, query parameter value. 194 value: string, query parameter value.
213 195
214 Returns: 196 Returns:
215 Updated query parameter. Does not update the url if value is None. 197 Updated query parameter. Does not update the url if value is None.
216 """ 198 """
217 if value is None: 199 if value is None:
218 return url 200 return url
219 else: 201 else:
220 parsed = list(urllib.parse.urlparse(url)) 202 parsed = list(urllib.parse.urlparse(url))
221 q = dict(urllib.parse.parse_qsl(parsed[4])) 203 q = dict(urllib.parse.parse_qsl(parsed[4]))
222 q[name] = value 204 q[name] = value
223 parsed[4] = urllib.parse.urlencode(q) 205 parsed[4] = urllib.parse.urlencode(q)
224 return urllib.parse.urlunparse(parsed) 206 return urllib.parse.urlunparse(parsed)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698