You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/11/04 21:14:20 UTC
[1/2] git commit: [LIBCLOUD-429] Fix libcloud.utils.py3.urlquote so
it works with unicode strings under Python 2.
Updated Branches:
refs/heads/trunk 69c5429c1 -> 93fde1568
[LIBCLOUD-429] Fix libcloud.utils.py3.urlquote so it works with unicode
strings under Python 2.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/3e012e37
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/3e012e37
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/3e012e37
Branch: refs/heads/trunk
Commit: 3e012e37565c8b8a0d62fc8265d82b2c3b4e9744
Parents: 69c5429
Author: Michael Farrell <mi...@gmail.com>
Authored: Wed Oct 30 13:00:44 2013 +1030
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Nov 4 20:11:08 2013 +0000
----------------------------------------------------------------------
libcloud/test/test_utils.py | 21 +++++++++++++++++++++
libcloud/utils/py3.py | 11 ++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/3e012e37/libcloud/test/test_utils.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_utils.py b/libcloud/test/test_utils.py
index 0265dfb..d5a373b 100644
--- a/libcloud/test/test_utils.py
+++ b/libcloud/test/test_utils.py
@@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# Allows unicode literals ('' == unicode) on Python 2, for compatibility with
+# Python 3
+from __future__ import unicode_literals
+
import sys
import unittest
import warnings
@@ -29,9 +33,11 @@ from libcloud.utils.misc import get_driver, set_driver
from libcloud.utils.py3 import PY3
from libcloud.utils.py3 import StringIO
from libcloud.utils.py3 import b
+from libcloud.utils.py3 import urlquote
from libcloud.compute.types import Provider
from libcloud.compute.providers import DRIVERS
+
WARNINGS_BUFFER = []
if PY3:
@@ -204,6 +210,21 @@ class TestUtils(unittest.TestCase):
result = libcloud.utils.files.exhaust_iterator(iterator=iterator)
self.assertEqual(result, b(data))
+ def test_unicode_urlquote(self):
+ # Regression tests for LIBCLOUD-429
+
+ # Note: this is a unicode literal
+ uri = libcloud.utils.py3.urlquote('\xe9')
+ self.assertEqual(b(uri), b('%C3%A9'))
+
+ # Unicode without unicode characters
+ uri = libcloud.utils.py3.urlquote('~abc')
+ self.assertEqual(b(uri), b('%7Eabc'))
+
+ # Already-encoded bytestring without unicode characters
+ uri = libcloud.utils.py3.urlquote(b('~abc'))
+ self.assertEqual(b(uri), b('%7Eabc'))
+
if __name__ == '__main__':
sys.exit(unittest.main())
http://git-wip-us.apache.org/repos/asf/libcloud/blob/3e012e37/libcloud/utils/py3.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/py3.py b/libcloud/utils/py3.py
index 5453bfb..6625c86 100644
--- a/libcloud/utils/py3.py
+++ b/libcloud/utils/py3.py
@@ -96,7 +96,7 @@ else:
import urllib2 # NOQA
import urlparse # NOQA
import xmlrpclib # NOQA
- from urllib import quote as urlquote # NOQA
+ from urllib import quote as _urlquote # NOQA
from urllib import unquote as urlunquote # NOQA
from urllib import urlencode as urlencode # NOQA
@@ -114,6 +114,9 @@ else:
if not PY25:
from os.path import relpath # NOQA
+ # Save the real value of unicode because urlquote needs it to tell the
+ # difference between a unicode string and a byte string.
+ _real_unicode = unicode
basestring = unicode = str
method_type = types.MethodType
@@ -133,6 +136,12 @@ else:
tostring = ET.tostring
+ def urlquote(s, safe='/'):
+ if isinstance(s, _real_unicode):
+ # Pretend to be py3 by encoding the URI automatically.
+ s = s.encode('utf8')
+ return _urlquote(s, safe)
+
if PY25:
import posixpath
[2/2] git commit: Update CHANGES.
Posted by to...@apache.org.
Update CHANGES.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/93fde156
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/93fde156
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/93fde156
Branch: refs/heads/trunk
Commit: 93fde1568d820ea84409ff9e1b6e3128098dd717
Parents: 3e012e3
Author: Tomaz Muraus <to...@apache.org>
Authored: Mon Nov 4 20:12:02 2013 +0000
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Nov 4 20:12:02 2013 +0000
----------------------------------------------------------------------
CHANGES | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/93fde156/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 158b070..a6f820c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,12 @@
Changes with Apache Libcloud in development
+ *) General
+
+ - Fix libcloud.utils.py3.urlquote so it works with unicode strings under
+ Python 2. (LIBCLOUD-429)
+ [Michael Farrell]
+
*) Compute
- Fix ex_delete_keypair method in the EC2 driver. (LIBCLOUD-415)