[Python-modules-commits] r19433 - in packages/python-riak/trunk/debian/patches (4 files)
soren-guest at users.alioth.debian.org
soren-guest at users.alioth.debian.org
Fri Nov 25 16:21:51 UTC 2011
Date: Friday, November 25, 2011 @ 16:21:49
Author: soren-guest
Revision: 19433
A couple of additional unicode fixes.
Added:
packages/python-riak/trunk/debian/patches/0039-Only-attempt-encoding-to-ascii-if-it-is-a-type-of-st.patch
packages/python-riak/trunk/debian/patches/0040-Only-catch-UnicodeEncodeError.patch
packages/python-riak/trunk/debian/patches/0041-Unit-tests.patch
Modified:
packages/python-riak/trunk/debian/patches/series
Added: packages/python-riak/trunk/debian/patches/0039-Only-attempt-encoding-to-ascii-if-it-is-a-type-of-st.patch
===================================================================
--- packages/python-riak/trunk/debian/patches/0039-Only-attempt-encoding-to-ascii-if-it-is-a-type-of-st.patch (rev 0)
+++ packages/python-riak/trunk/debian/patches/0039-Only-attempt-encoding-to-ascii-if-it-is-a-type-of-st.patch 2011-11-25 16:21:49 UTC (rev 19433)
@@ -0,0 +1,67 @@
+From a7ab12423a5671d338077bb8e72219beaea08829 Mon Sep 17 00:00:00 2001
+From: Soren Hansen <soren at linux2go.dk>
+Date: Thu, 20 Oct 2011 10:56:19 +0200
+Subject: [PATCH 2/4] Only attempt encoding to ascii if it is a type of
+ string.
+
+---
+ riak/bucket.py | 6 ++++--
+ riak/mapreduce.py | 3 ++-
+ riak/riak_object.py | 3 ++-
+ 3 files changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/riak/bucket.py b/riak/bucket.py
+index 69c044e..b1af10b 100644
+--- a/riak/bucket.py
++++ b/riak/bucket.py
+@@ -39,7 +39,8 @@ class RiakBucket(object):
+ :type name: string
+ """
+ try:
+- name.encode('ascii')
++ if isinstance(name, basestring):
++ name.encode('ascii')
+ except UnicodeEncodeError:
+ raise TypeError('Unicode bucket names are not supported.')
+
+@@ -213,7 +214,8 @@ class RiakBucket(object):
+ :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
+ """
+ try:
+- data.encode('ascii')
++ if isinstance(data, basestring):
++ data.encode('ascii')
+ except:
+ raise TypeError('Unicode data values are not supported.')
+
+diff --git a/riak/mapreduce.py b/riak/mapreduce.py
+index 0a3ddf3..3b7ce54 100644
+--- a/riak/mapreduce.py
++++ b/riak/mapreduce.py
+@@ -321,7 +321,8 @@ class RiakMapReducePhase(object):
+ reduce function.
+ """
+ try:
+- function.encode('ascii')
++ if isinstance(function, basestring):
++ function.encode('ascii')
+ except UnicodeEncodeError:
+ raise TypeError('Unicode encoded functions are not supported.')
+
+diff --git a/riak/riak_object.py b/riak/riak_object.py
+index 7e99174..6b03d21 100644
+--- a/riak/riak_object.py
++++ b/riak/riak_object.py
+@@ -40,7 +40,8 @@ class RiakObject(object):
+ :type key: string
+ """
+ try:
+- key.encode('ascii')
++ if isinstance(key, basestring):
++ key.encode('ascii')
+ except UnicodeEncodeError:
+ raise TypeError('Unicode keys are not supported.')
+
+--
+1.7.5.4
+
Added: packages/python-riak/trunk/debian/patches/0040-Only-catch-UnicodeEncodeError.patch
===================================================================
--- packages/python-riak/trunk/debian/patches/0040-Only-catch-UnicodeEncodeError.patch (rev 0)
+++ packages/python-riak/trunk/debian/patches/0040-Only-catch-UnicodeEncodeError.patch 2011-11-25 16:21:49 UTC (rev 19433)
@@ -0,0 +1,25 @@
+From c2252b2209c3bf4fbf7e2702ac082e916601d438 Mon Sep 17 00:00:00 2001
+From: Soren Hansen <soren at linux2go.dk>
+Date: Thu, 17 Nov 2011 16:10:50 +0100
+Subject: [PATCH 3/4] Only catch UnicodeEncodeError.
+
+---
+ riak/bucket.py | 2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/riak/bucket.py b/riak/bucket.py
+index b1af10b..b556c9d 100644
+--- a/riak/bucket.py
++++ b/riak/bucket.py
+@@ -216,7 +216,7 @@ class RiakBucket(object):
+ try:
+ if isinstance(data, basestring):
+ data.encode('ascii')
+- except:
++ except UnicodeEncodeError:
+ raise TypeError('Unicode data values are not supported.')
+
+ obj = RiakObject(self._client, self, key)
+--
+1.7.5.4
+
Added: packages/python-riak/trunk/debian/patches/0041-Unit-tests.patch
===================================================================
--- packages/python-riak/trunk/debian/patches/0041-Unit-tests.patch (rev 0)
+++ packages/python-riak/trunk/debian/patches/0041-Unit-tests.patch 2011-11-25 16:21:49 UTC (rev 19433)
@@ -0,0 +1,121 @@
+From 69c1cb0b5f40a31a6d2fc8b584c68a60578d5765 Mon Sep 17 00:00:00 2001
+From: Soren Hansen <soren at linux2go.dk>
+Date: Fri, 18 Nov 2011 16:38:24 +0100
+Subject: [PATCH 4/4] Unit tests
+
+Adjust unit tests so that they verify the patch,
+and then adjust the patch so that the unit tests pass :)
+---
+ riak/bucket.py | 8 ++++----
+ riak/mapreduce.py | 4 ++--
+ riak/riak_object.py | 4 ++--
+ riak/tests/test_all.py | 27 +++++++++++++++++++++------
+ 4 files changed, 29 insertions(+), 14 deletions(-)
+
+diff --git a/riak/bucket.py b/riak/bucket.py
+index b556c9d..83818fa 100644
+--- a/riak/bucket.py
++++ b/riak/bucket.py
+@@ -40,8 +40,8 @@ class RiakBucket(object):
+ """
+ try:
+ if isinstance(name, basestring):
+- name.encode('ascii')
+- except UnicodeEncodeError:
++ name = name.encode('ascii')
++ except UnicodeError:
+ raise TypeError('Unicode bucket names are not supported.')
+
+ self._client = client
+@@ -215,8 +215,8 @@ class RiakBucket(object):
+ """
+ try:
+ if isinstance(data, basestring):
+- data.encode('ascii')
+- except UnicodeEncodeError:
++ data = data.encode('ascii')
++ except UnicodeError:
+ raise TypeError('Unicode data values are not supported.')
+
+ obj = RiakObject(self._client, self, key)
+diff --git a/riak/mapreduce.py b/riak/mapreduce.py
+index 3b7ce54..fa7d4f2 100644
+--- a/riak/mapreduce.py
++++ b/riak/mapreduce.py
+@@ -322,8 +322,8 @@ class RiakMapReducePhase(object):
+ """
+ try:
+ if isinstance(function, basestring):
+- function.encode('ascii')
+- except UnicodeEncodeError:
++ function = function.encode('ascii')
++ except UnicodeError:
+ raise TypeError('Unicode encoded functions are not supported.')
+
+ self._type = type
+diff --git a/riak/riak_object.py b/riak/riak_object.py
+index 6b03d21..f91fb31 100644
+--- a/riak/riak_object.py
++++ b/riak/riak_object.py
+@@ -41,8 +41,8 @@ class RiakObject(object):
+ """
+ try:
+ if isinstance(key, basestring):
+- key.encode('ascii')
+- except UnicodeEncodeError:
++ key = key.encode('ascii')
++ except UnicodeError:
+ raise TypeError('Unicode keys are not supported.')
+
+ self._client = client
+diff --git a/riak/tests/test_all.py b/riak/tests/test_all.py
+index 6377b68..1e3e786 100644
+--- a/riak/tests/test_all.py
++++ b/riak/tests/test_all.py
+@@ -115,12 +115,20 @@ class BaseTestCase(object):
+ self.assertEqual(obj.get_key(), 'foo')
+ self.assertEqual(obj.get_data(), rand)
+
+- #unicode input should raise a TypeError,
+- #to avoid issues further down the line
+- self.assertRaises(TypeError, self.client.bucket, u'bucket')
++ # unicode objects are fine, as long as they don't
++ # contain any non-ASCII chars
++ self.client.bucket(u'bucket')
++ self.assertRaises(TypeError, self.client.bucket, u'búcket')
++ self.assertRaises(TypeError, self.client.bucket, 'búcket')
++
++ bucket.get(u'foo')
++ self.assertRaises(TypeError, bucket.get, u'føø')
++ self.assertRaises(TypeError, bucket.get, 'føø')
++
+ self.assertRaises(TypeError, bucket.new, u'foo', 'éå')
++ self.assertRaises(TypeError, bucket.new, u'foo', 'éå')
++ self.assertRaises(TypeError, bucket.new, 'foo', u'éå')
+ self.assertRaises(TypeError, bucket.new, 'foo', u'éå')
+- self.assertRaises(TypeError, bucket.get, u'foo')
+
+ def test_binary_store_and_get(self):
+ bucket = self.client.bucket('bucket')
+@@ -275,9 +283,16 @@ class BaseTestCase(object):
+ "function (v) { return [JSON.parse(v.values[0].data)]; }").run()
+ self.assertEqual(result, [2])
+
+- #test unicode function
++ # test ASCII-encodable unicode is accepted
++ mr.map(u"function (v) { return [JSON.parse(v.values[0].data)]; }")
++
++ # test non-ASCII-encodable unicode is rejected
++ self.assertRaises(TypeError, mr.map,
++ u"function (v) { /* æ */ return [JSON.parse(v.values[0].data)]; }")
++
++ # test non-ASCII-encodable string is rejected
+ self.assertRaises(TypeError, mr.map,
+- u"function (v) { return [JSON.parse(v.values[0].data)]; }")
++ "function (v) { /* æ */ return [JSON.parse(v.values[0].data)]; }")
+
+ def test_javascript_named_map(self):
+ # Create the object...
+--
+1.7.5.4
+
Modified: packages/python-riak/trunk/debian/patches/series
===================================================================
--- packages/python-riak/trunk/debian/patches/series 2011-11-25 03:38:11 UTC (rev 19432)
+++ packages/python-riak/trunk/debian/patches/series 2011-11-25 16:21:49 UTC (rev 19433)
@@ -36,3 +36,6 @@
0036-Test-the-retrieval-of-a-new-object-s-key-and-its-for.patch
0037-Fix-extraction-of-the-key-from-the-Location-header.patch
0038-Temporary-simple-fix-for-issue-32.patch
+0039-Only-attempt-encoding-to-ascii-if-it-is-a-type-of-st.patch
+0040-Only-catch-UnicodeEncodeError.patch
+0041-Unit-tests.patch
More information about the Python-modules-commits
mailing list