Esempio n. 1
0
 def __init__(self, host, port, db, queue_col, page_col, jobid):
     store = MongoConnection(host, port)[db]
     self.jobid = jobid
     self.pageStore = store[page_col]
     self.queueStore = store[queue_col]
     self.queueStore.ensure_index(mongosort(ASCENDING('_job')),
                                  background=True)
Esempio n. 2
0
def SingleMongo(coll, method, *args, **kwargs):
    conn = MongoConnection(MONGODB['HOST'], MONGODB['PORT'])
    db = conn[MONGODB['DATABASE']]
    yield db.authenticate(MONGODB['USER'], MONGODB['PSWD'])
    res = yield getattr(db[coll], method)(*args, **kwargs)
    conn.disconnect()
    returnD(res)
Esempio n. 3
0
 def __init__(self, conf, pool=25):
     self.host = environ.get(
         'HYPHE_MONGODB_HOST',
         conf.get("host", conf.get("mongo_host", "localhost")))
     self.port = int(
         environ.get('HYPHE_MONGODB_PORT',
                     conf.get("port", conf.get("mongo_port", 27017))))
     self.dbname = conf.get("db_name", conf.get("project", "hyphe"))
     self.conn = MongoConnection(self.host, self.port, pool_size=pool)
Esempio n. 4
0
def db():
    return MongoConnection()[TEST_DB]
Esempio n. 5
0
import json
import datetime
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from klein import Klein
from bson import ObjectId
from txmongo import MongoConnection
from klein_babel import gettext, locale_from_request

from umongo import Instance, Document, fields, ValidationError, set_gettext
from umongo.marshmallow_bonus import SchemaFromUmongo

app = Klein()
db = MongoConnection().demo_umongo
instance = Instance(db)
set_gettext(gettext)


class MongoJsonEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, (datetime.datetime, datetime.date)):
            return obj.isoformat()
        elif isinstance(obj, ObjectId):
            return str(obj)
        return json.JSONEncoder.default(self, obj)


def jsonify(request, *args, **kwargs):
    """
    jsonify with support for MongoDB ObjectId
    """
Esempio n. 6
0
 def __init__(self, conf, pool=10):
     self.host = conf.get("host", conf.get("mongo_host", "localhost"))
     self.port = conf.get("port", conf.get("mongo_port", 27017))
     self.dbname = conf.get("db_name", conf.get("project", "hyphe"))
     self.conn = MongoConnection(self.host, self.port, pool_size=pool)
     self.db = self.conn[self.dbname]