Esempio n. 1
0
    def __init__(self,
                 db,
                 collections,
                 username,
                 password,
                 host='localhost',
                 port=8091,
                 clear=False,
                 **entries):
        auth = restkit.BasicAuth(username, password)
        server = restkit.Resource('http://%s:%s' % (host, port),
                                  filters=[auth])

        def make_conn(bucket):
            self._ensure_bucket(server, bucket)
            return Couchbase.connect(bucket=bucket,
                                     host=host,
                                     port=port,
                                     timeout=5.0)

        if clear:
            all_buckets = self._all_buckets(server)
            for coll in collections:
                if coll in all_buckets:
                    self._flush_bucket(server, coll)
        update(self,
               server=server,
               connections=dict(('docs_%s' % coll, make_conn(coll))
                                for coll in collections))
Esempio n. 2
0
 def __init__(self, lang):
     lang = lang.upper()
     db = env('{REL}', lang=lang)
     update(self, conn=sqlite3.connect(db), lang=lang)
     with uopen(env('{SD}', lang=lang)) as domf:
         records = (l.strip().split() for l in domf)
         self.sources = noun2source(records)
Esempio n. 3
0
 def __init__(self,
              db,
              collections,
              host='localhost',
              port=27017,
              clear=False,
              **_):
     conn = MongoClient(host, port)
     update(self, db=conn[db])
     if clear:
         for coll in collections:
             self.db.drop_collection('docs_%s' % coll)
Esempio n. 4
0
    def __init__(self,
                 db,
                 collections,
                 host='localhost',
                 port=5984,
                 clear=False,
                 **_):
        def create_or_open_db(dbname):
            try:
                return server.create(dbname)
            except PreconditionFailed:
                return server[dbname]

        server = couchdb.Server('http://%s:%d' % (host, port))
        update(self,
               server=server,
               databases=dict(
                   ('docs_%s' % c, create_or_open_db('%s_docs_%s' % (db, c)))
                   for c in collections))
Esempio n. 5
0
 def __init__(self,
              db,
              collections,
              host='localhost',
              port=5984,
              clear=False,
              **_):
     server = couchdbkit.Server(uri='http://%s:%d' % (host, port),
                                uuid_batch_count=20000)
     # CouchDB has no collections, so we create one db for each language, instead of one collection.
     dbnames = [('docs_%s' % coll, '%s_docs_%s' % (db, coll))
                for coll in collections]
     if clear:
         all_dbs = server.all_dbs()
         for _, name in dbnames:
             if name in all_dbs:
                 server.delete_db(name)
     update(self,
            server=server,
            databases=dict((coll, server.get_or_create_db(name))
                           for coll, name in dbnames))
Esempio n. 6
0
def to_nodelist(block):
    def node(line=None):
        if line == None:
            return RootNode()
        else:
            fs = fields_re.match(line)
            d = depth_re.match(line)
        return FieldNode(fs) if fs else DepthNode(d) 

    nodes = map(node, block)
    fnodes = filter(lambda n: isinstance(n, FieldNode), nodes)
    snodes = sorted(fnodes, key=lambda n: int(n.beg))
    for n, node_ in enumerate(snodes, start=1):
        update(node_, n=n)
    
    def traverse(pairs, parent, children, d=0):
        if len(children) > 0:
            node, rest = children[0], children[1:]
#             print('d:', d, node, node.depth(), 'p:', parent, node.bracket)
            if node.bracket == '[':
                assert d == node.depth()
                node.parent = parent
                pairs.append((node, parent))
                traverse(pairs, node, rest, d + 1)
            elif node.bracket == ']':
                assert d - 1 == node.depth()
                p = parent.parent
                node.parent = p
                traverse(pairs, p, rest, d - 1)
            else:
                assert d == node.depth()
                pairs.append((node, parent))
                # node.bracket == ''
                node.parent = parent
                traverse(pairs, parent, rest, d)
  
    pairs = []
    traverse(pairs, node(), nodes)
    for d, h in pairs: assert d.parent == h
    return snodes
Esempio n. 7
0
 def __init__(self, **entries):
     update(self, entries, debug=False)
Esempio n. 8
0
 def __init__(self):
     update(self, n=0, beg=-1, indent='', bracket='[', word='<root>')
Esempio n. 9
0
 def __init__(self, match):
     update(self, match.groupdict())
Esempio n. 10
0
 def __init__(self, **entries):
     update(self, entries)