From 8a439aa96e227c86db87b54e15716778d9490357 Mon Sep 17 00:00:00 2001 From: Mark Nunberg Date: Mon, 2 May 2016 07:58:27 -0700 Subject: [PATCH] PYCBC-343: SubdocResult: Add missing import This allows iteration, whereas before it resulted in an exception due to a missing `izip` import. Code has been added to _pyport since the `izip` is a builtin (`zip`) in Py3 Change-Id: I1c3d74b2b4c0a6e2a60ca728c36c11717012c4b6 Reviewed-on: http://review.couchbase.org/63577 Reviewed-by: Will Gardner Tested-by: Mark Nunberg --- couchbase/_pyport.py | 2 ++ couchbase/result.py | 3 +-- couchbase/tests/cases/subdoc_t.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/couchbase/_pyport.py b/couchbase/_pyport.py index ac1621f17..966f3b40f 100644 --- a/couchbase/_pyport.py +++ b/couchbase/_pyport.py @@ -25,10 +25,12 @@ import urllib.parse as ulp from urllib.request import urlopen from urllib.parse import parse_qs + izip = zip else: import urllib as ulp from urllib2 import urlopen from urlparse import parse_qs + from itertools import izip long = long if V == 2 else int xrange = xrange if V == 2 else range diff --git a/couchbase/result.py b/couchbase/result.py index 616a89eca..dfa2b6ed5 100644 --- a/couchbase/result.py +++ b/couchbase/result.py @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from couchbase._libcouchbase import ( Result, ValueResult, @@ -23,7 +22,7 @@ MultiResult, ObserveInfo, AsyncResult) -from couchbase._pyport import long, xrange +from couchbase._pyport import long, xrange, izip import couchbase._libcouchbase as C import couchbase.exceptions as E diff --git a/couchbase/tests/cases/subdoc_t.py b/couchbase/tests/cases/subdoc_t.py index b1094d106..2bb79d670 100644 --- a/couchbase/tests/cases/subdoc_t.py +++ b/couchbase/tests/cases/subdoc_t.py @@ -232,3 +232,19 @@ def test_multi_value(self): cb.mutate_in(key, SD.array_prepend('array', [42])) self.assertEqual([[42], True, 1, 2, 3], cb.retrieve_in(key, 'array')[0]) + + def test_result_iter(self): + cb = self.cb + key = self.gen_key('sditer') + cb.upsert(key, [1, 2, 3]) + vals = cb.retrieve_in(key, '[0]', '[1]', '[2]') + v1, v2, v3 = vals + self.assertEqual(1, v1) + self.assertEqual(2, v2) + self.assertEqual(3, v3) + + vals = cb.retrieve_in(key, '[0]', '[34]', '[3]') + self.assertFalse(vals.success) + it = iter(vals) + self.assertEqual(1, next(it)) + self.assertRaises(E.SubdocPathNotFoundError, next, it) \ No newline at end of file