Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cloudant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from resource import Resource
from account import Account
from database import Database
from document import Document
from design import Design
from attachment import Attachment
from index import Index
from .resource import Resource
from .account import Account
from .database import Database
from .document import Document
from .design import Design
from .attachment import Attachment
from .index import Index
8 changes: 6 additions & 2 deletions cloudant/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from .resource import Resource
from .database import Database
import urlparse

try:
import urllib.parse as urlparse
except ImportError:
import urlparse


class Account(Resource):
Expand Down Expand Up @@ -37,7 +41,7 @@ def __init__(self, uri="http://localhost:5984", **kwargs):

def database(self, name, **kwargs):
"""Create a `Database` object prefixed with this account's URL."""
opts = dict(self.opts.items() + kwargs.items())
opts = dict(self.opts, **kwargs)
return Database(self._make_url(name), session=self._session, **opts)

def __getitem__(self, name):
Expand Down
4 changes: 2 additions & 2 deletions cloudant/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def document(self, name, **kwargs):
"""
Create a `Document` object from `name`.
"""
opts = dict(self.opts.items() + kwargs.items())
opts = dict(self.opts, **kwargs)
return Document(self._make_url(name), session=self._session, **opts)

def design(self, name, **kwargs):
Expand All @@ -26,7 +26,7 @@ def design(self, name, **kwargs):
db.design('test')
# refers to DB/_design/test
"""
opts = dict(self.opts.items() + kwargs.items())
opts = dict(self.opts, **kwargs)
return Design(self._make_url('/'.join(['_design', name])), session=self._session, **opts)

def __getitem__(self, name):
Expand Down
4 changes: 2 additions & 2 deletions cloudant/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index(self, path, **kwargs):
index = doc.index('_view/index-name')
# refers to /DB/_design/DOC/_view/index-name
"""
opts = dict(self.opts.items() + kwargs.items())
opts = dict(self.opts, **kwargs)
return Index(self._make_url(path), session=self._session, **opts)

def view(self, function, **kwargs):
Expand Down Expand Up @@ -65,4 +65,4 @@ def show(self, function, id, **kwargs):
For more details on show functions, see
[Querying Show Functions](http://docs.cloudant.com/api/design-documents-shows-lists.html#querying-show-functions).
"""
return self.get(self._make_url('/'.join(['_show', function, id])), **kwargs)
return self.get(self._make_url('/'.join(['_show', function, id])), **kwargs)
2 changes: 1 addition & 1 deletion cloudant/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def attachment(self, name, **kwargs):
Create an `Attachment` object from `name` and the settings
for the current database.
"""
opts = dict(self.opts.items() + kwargs.items())
opts = dict(self.opts, **kwargs)
return Attachment(self._make_url(name), session=self._session, **opts)

def merge(self, change, **kwargs):
Expand Down
5 changes: 3 additions & 2 deletions cloudant/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def __iter__(self, **kwargs):
if hasattr(response, 'result'):
response = response.result()
for line in response.iter_lines():
line = line.decode('utf-8')
if line:
if line[-1] == ',':
line = line[:-1]
try:
yield json.loads(line)
except ValueError:
except (TypeError, ValueError):
# if we can't decode a line, ignore it
pass

Expand All @@ -49,4 +50,4 @@ def iter(self, **kwargs):
# emits only rows with the key 'thegoodstuff'
# with each row's emitting document
"""
return self.__iter__(**kwargs)
return self.__iter__(**kwargs)
23 changes: 12 additions & 11 deletions cloudant/resource.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import json
import copy

import requests


try:
from requests_futures.sessions import FuturesSession
requests_futures_available = True
except ImportError:
requests_futures_available = False

import urlparse
import json
import copy

import requests
try:
import urllib.parse as urlparse
except ImportError:
import urlparse


class RequestsFutureNotAvailable(Exception):
Expand All @@ -34,7 +40,7 @@ def __init__(self, uri, **kwargs):
if kwargs.get('session'):
self._session = kwargs['session']
del kwargs['session']
elif kwargs.has_key('async'):
elif 'async' in kwargs:
if kwargs['async']:
if not requests_futures_available:
raise RequestsFutureNotAvailable()
Expand Down Expand Up @@ -96,12 +102,7 @@ def _make_request(self, method, path='', **kwargs):
opts['params'] = params

# make the request
future = getattr(
self._session,
method)(
self._make_url(
path),
**opts)
future = getattr(self._session, method)(self._make_url(path), **opts)
return future

def head(self, path='', **kwargs):
Expand Down
7 changes: 3 additions & 4 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cloudant
from collections import defaultdict
import unittest
import os


class ResourceTest(unittest.TestCase):
Expand All @@ -11,7 +10,7 @@ def setUp(self):

names = cloudant.Account(self.uri).uuids(4).json()['uuids']
# database names must start with a letter
names = map(lambda name: 'a' + name, names)
names = ['a' + name for name in names]
self.db_name = names[0]
self.otherdb_name = names[1]
self.doc_name = names[2]
Expand Down Expand Up @@ -137,10 +136,10 @@ class DatabaseTest(ResourceTest):

def setUp(self):
super(DatabaseTest, self).setUp()

db_name = '/'.join([self.uri, self.db_name])
self.db = cloudant.Database(db_name)

response = self.db.put()
response.raise_for_status()

Expand Down