Merge pull request #7 from hartym/master

code quality
This commit is contained in:
Romain Dorgueil
2016-12-26 13:50:52 +01:00
committed by GitHub
3 changed files with 17 additions and 66 deletions

View File

@ -8,6 +8,7 @@ python-targets:
ignore-paths:
- docs
- examples
- tests
pep257:
disable:
- D205

View File

@ -1,60 +0,0 @@
from bonobo import inject
try:
import couchdb
except ImportError as e:
import logging
logging.exception('You must install couchdb to use the bonobo couchdb extension. Easiest way is to install the '
'optional "couchdb" dependencies with «pip install bonobo[couchdb]», but you can also install a '
'specific version by yourself.')
import datetime
from bonobo import service
@service
def client(username, password):
client = couchdb.Server()
client.resource.credentials = (
username,
password, )
return client
@service
@inject(client)
def database(client, name):
return client[name]
def json_datetime(dt=None):
dt = dt or datetime.datetime.now()
return dt.replace(microsecond=0).isoformat() + 'Z'
@inject(database)
def query(db, map, reduce, *args, **kwargs):
pass
cli1 = client.define('admin', 'admin')
cli2 = client.define('foo', 'bar')
@inject(client[cli1])
def print_db(db):
print(db)
@inject(client[cli2])
def print_db2(db):
print(db)
if __name__ == '__main__':
print_db()
print_db2()
print_db()
print_db2()

View File

@ -1,7 +1,17 @@
def force_iterator(x):
if isinstance(x, str):
return [x]
""" Iterator utilities. """
def force_iterator(mixed):
"""Sudo make me an iterator.
Deprecated?
:param mixed:
:return: Iterator, baby.
"""
if isinstance(mixed, str):
return [mixed]
try:
return iter(x)
except Exception as e:
return [x] if x else []
return iter(mixed)
except TypeError:
return [mixed] if mixed else []