Upgrade python/apitools to v0.5.30 am: 61634a2073 am: 56796a005a
am: 14531d9975

Change-Id: I7ab6fbab32105c74864f7733562a19535849034d
diff --git a/METADATA b/METADATA
index feaa5b0..9c9b51c 100644
--- a/METADATA
+++ b/METADATA
@@ -9,10 +9,10 @@
     type: GIT
     value: "https://github.com/google/apitools"
   }
-  version: "v0.5.28"
+  version: "v0.5.30"
   last_upgrade_date {
     year: 2019
-    month: 5
-    day: 7
+    month: 6
+    day: 26
   }
 }
diff --git a/apitools/base/py/credentials_lib.py b/apitools/base/py/credentials_lib.py
index 7a08f0b..bf39285 100644
--- a/apitools/base/py/credentials_lib.py
+++ b/apitools/base/py/credentials_lib.py
@@ -250,7 +250,9 @@
         # identified these scopes in the same execution. However, the
         # available scopes don't change once an instance is created,
         # so there is no reason to perform more than one query.
-        self.__service_account_name = service_account_name
+        self.__service_account_name = six.ensure_text(
+            service_account_name,
+            encoding='utf-8',)
         cached_scopes = None
         cache_filename = kwds.get('cache_filename')
         if cache_filename:
@@ -317,7 +319,8 @@
           scopes: Scopes for the desired credentials.
         """
         # Credentials metadata dict.
-        creds = {'scopes': sorted(list(scopes)),
+        scopes = sorted([six.ensure_text(scope) for scope in scopes])
+        creds = {'scopes': scopes,
                  'svc_acct_name': self.__service_account_name}
         creds_str = json.dumps(creds)
         cache_file = _MultiProcessCacheFile(cache_filename)
@@ -352,7 +355,7 @@
     def GetServiceAccount(self, account):
         relative_url = 'instance/service-accounts'
         response = _GceMetadataRequest(relative_url)
-        response_lines = [line.rstrip('/\n\r')
+        response_lines = [six.ensure_str(line).rstrip(u'/\n\r')
                           for line in response.readlines()]
         return account in response_lines
 
@@ -360,7 +363,7 @@
         relative_url = 'instance/service-accounts/{0}/scopes'.format(
             self.__service_account_name)
         response = _GceMetadataRequest(relative_url)
-        return util.NormalizeScopes(scope.strip()
+        return util.NormalizeScopes(six.ensure_str(scope).strip()
                                     for scope in response.readlines())
 
     # pylint: disable=arguments-differ
@@ -393,7 +396,7 @@
             if self.store:
                 self.store.locked_put(self)
             raise
-        content = response.read()
+        content = six.ensure_str(response.read())
         try:
             credential_info = json.loads(content)
         except ValueError:
diff --git a/apitools/base/py/util.py b/apitools/base/py/util.py
index b131cdf..ac1a44c 100644
--- a/apitools/base/py/util.py
+++ b/apitools/base/py/util.py
@@ -76,8 +76,10 @@
 def NormalizeScopes(scope_spec):
     """Normalize scope_spec to a set of strings."""
     if isinstance(scope_spec, six.string_types):
+        scope_spec = six.ensure_str(scope_spec)
         return set(scope_spec.split(' '))
     elif isinstance(scope_spec, collections.Iterable):
+        scope_spec = [six.ensure_str(x) for x in scope_spec]
         return set(scope_spec)
     raise exceptions.TypecheckError(
         'NormalizeScopes expected string or iterable, found %s' % (
diff --git a/apitools/gen/util_test.py b/apitools/gen/util_test.py
index c94a0aa..7668b53 100644
--- a/apitools/gen/util_test.py
+++ b/apitools/gen/util_test.py
@@ -24,7 +24,7 @@
 import unittest2
 
 from apitools.gen import util
-from mock import MagicMock
+from mock import patch
 
 
 class NormalizeVersionTest(unittest2.TestCase):
@@ -85,16 +85,15 @@
 
     def testUnspecifiedContentEncoding(self):
         data = 'regular non-gzipped content'
-        urllib_request.urlopen = MagicMock(
-            return_value=MockRequestResponse(data, ''))
-
-        self.assertEqual(data, util._GetURLContent('unused_url_parameter'))
+        with patch.object(urllib_request, 'urlopen',
+                          return_value=MockRequestResponse(data, '')):
+            self.assertEqual(data, util._GetURLContent('unused_url_parameter'))
 
     def testGZippedContent(self):
         data = u'¿Hola qué tal?'
         compressed_data = _Gzip(data.encode('utf-8'))
-        urllib_request.urlopen = MagicMock(
-            return_value=MockRequestResponse(compressed_data, 'gzip'))
-
-        self.assertEqual(data, util._GetURLContent(
-            'unused_url_parameter').decode('utf-8'))
+        with patch.object(urllib_request, 'urlopen',
+                          return_value=MockRequestResponse(
+                              compressed_data, 'gzip')):
+            self.assertEqual(data, util._GetURLContent(
+                'unused_url_parameter').decode('utf-8'))
diff --git a/setup.py b/setup.py
index 9bb2ec7..fbf81b1 100644
--- a/setup.py
+++ b/setup.py
@@ -49,7 +49,7 @@
 
 py_version = platform.python_version()
 
-_APITOOLS_VERSION = '0.5.28'
+_APITOOLS_VERSION = '0.5.30'
 
 with open('README.rst') as fileobj:
     README = fileobj.read()