Repository: libcloud
Updated Branches:
  refs/heads/trunk c873a0d34 -> 94ab917f1


[GCS] Fixed some google_storage.py URL cleaning.

Closes #901

Signed-off-by: Eric Johnson <erjoh...@google.com>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/3214ce0a
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/3214ce0a
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/3214ce0a

Branch: refs/heads/trunk
Commit: 3214ce0a72e56da0c868c0b36a799ba15e6f899e
Parents: c873a0d
Author: Scott Crunkleton <crunkle...@google.com>
Authored: Tue Oct 11 15:41:13 2016 -0700
Committer: Eric Johnson <erjoh...@google.com>
Committed: Thu Oct 13 15:37:40 2016 +0000

----------------------------------------------------------------------
 libcloud/storage/drivers/google_storage.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/3214ce0a/libcloud/storage/drivers/google_storage.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/google_storage.py 
b/libcloud/storage/drivers/google_storage.py
index 91e117e..d4367f2 100644
--- a/libcloud/storage/drivers/google_storage.py
+++ b/libcloud/storage/drivers/google_storage.py
@@ -28,6 +28,7 @@ from libcloud.storage.drivers.s3 import BaseS3StorageDriver
 from libcloud.storage.drivers.s3 import S3RawResponse
 from libcloud.storage.drivers.s3 import S3Response
 from libcloud.utils.py3 import httplib
+from libcloud.utils.py3 import urlquote
 
 # Docs are a lie. Actual namespace returned is different that the one listed
 # in the docs.
@@ -36,6 +37,20 @@ API_VERSION = '2006-03-01'
 NAMESPACE = 'http://doc.s3.amazonaws.com/%s' % (API_VERSION)
 
 
+def _clean_object_name(name):
+    """
+    Return the URL encoded name. name=None returns None. Useful for input
+    checking without having to check for None first.
+
+    :param name: The object name
+    :type name: ``str`` or ``None``
+
+    :return: The url-encoded object name or None if name=None.
+    :rtype ``str`` or ``None``
+    """
+    return urlquote(name, safe='') if name else None
+
+
 class ContainerPermissions(object):
     values = ['NONE', 'READER', 'WRITER', 'OWNER']
     NONE = 0
@@ -298,6 +313,7 @@ class GoogleStorageDriver(BaseS3StorageDriver):
             authenticated user, if using an OAuth2 authentication scheme.
         :type entity: ``str`` or ``None``
         """
+        object_name = _clean_object_name(object_name)
         if not entity:
             user_id = self._get_user()
             if not user_id:
@@ -330,6 +346,7 @@ class GoogleStorageDriver(BaseS3StorageDriver):
         :rtype: ``tuple`` of (``int``, ``int`` or ``None``) from
             ContainerPermissions and ObjectPermissions, respectively.
         """
+        object_name = _clean_object_name(object_name)
         obj_perms = self._get_object_permissions(
             container_name, object_name) if object_name else None
         return self._get_container_permissions(container_name), obj_perms
@@ -358,6 +375,7 @@ class GoogleStorageDriver(BaseS3StorageDriver):
         :raises ValueError: If no entity was given, but was required. Or if
             the role isn't valid for the bucket or object.
         """
+        object_name = _clean_object_name(object_name)
         if isinstance(role, int):
             perms = ObjectPermissions if object_name else ContainerPermissions
             try:

Reply via email to