Skip to content

Commit 8129b70

Browse files
catleeballhouglum
authored andcommitted
Ensure unicode strings for Python 2 / 3 compat (#269)
Fixes some bugs we found when running gsutil prerelease tests.
1 parent a620b80 commit 8129b70

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

apitools/base/py/credentials_lib.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ def __init__(self, scopes=None, service_account_name='default', **kwds):
250250
# identified these scopes in the same execution. However, the
251251
# available scopes don't change once an instance is created,
252252
# so there is no reason to perform more than one query.
253-
self.__service_account_name = service_account_name
253+
self.__service_account_name = six.ensure_text(
254+
service_account_name,
255+
encoding='utf-8',)
254256
cached_scopes = None
255257
cache_filename = kwds.get('cache_filename')
256258
if cache_filename:
@@ -317,7 +319,8 @@ def _WriteCacheFile(self, cache_filename, scopes):
317319
scopes: Scopes for the desired credentials.
318320
"""
319321
# Credentials metadata dict.
320-
creds = {'scopes': sorted(list(scopes)),
322+
scopes = sorted([six.ensure_text(scope) for scope in scopes])
323+
creds = {'scopes': scopes,
321324
'svc_acct_name': self.__service_account_name}
322325
creds_str = json.dumps(creds)
323326
cache_file = _MultiProcessCacheFile(cache_filename)
@@ -352,7 +355,7 @@ def _ScopesFromMetadataServer(self, scopes):
352355
def GetServiceAccount(self, account):
353356
relative_url = 'instance/service-accounts'
354357
response = _GceMetadataRequest(relative_url)
355-
response_lines = [line.rstrip('/\n\r')
358+
response_lines = [six.ensure_text(line).rstrip(u'/\n\r')
356359
for line in response.readlines()]
357360
return account in response_lines
358361

0 commit comments

Comments
 (0)