Skip to content

Commit

Permalink
PYCBC-343: SubdocResult: Add missing import
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Mark Nunberg <[email protected]>
  • Loading branch information
mnunberg authored and Mark Nunberg committed May 2, 2016
1 parent 6864b93 commit 8a439aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions couchbase/_pyport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions couchbase/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from couchbase._libcouchbase import (
Result,
ValueResult,
Expand All @@ -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

Expand Down
16 changes: 16 additions & 0 deletions couchbase/tests/cases/subdoc_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8a439aa

Please sign in to comment.