当前位置: 首页>>代码示例>>Python>>正文


Python ndbm.open方法代码示例

本文整理汇总了Python中dbm.ndbm.open方法的典型用法代码示例。如果您正苦于以下问题:Python ndbm.open方法的具体用法?Python ndbm.open怎么用?Python ndbm.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dbm.ndbm的用法示例。


在下文中一共展示了ndbm.open方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_annotation

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def test_annotation(server, dbm_db, tracker_ctx):
    with client() as c:
        with SampleTracker.annotate(ann="value"):
            c.ping()

        with SampleTracker.annotate() as ann:
            ann.update({"sig": "c.hello()", "user_id": "125"})
            c.hello('you')

    time.sleep(0.2)

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())

    data = [pickle.loads(db[i]) for i in headers]
    data.sort(key=lambda x: x["seq"])

    assert data[0]["annotation"] == {"ann": "value"} and \
        data[1]["annotation"] == {"sig": "c.hello()", "user_id": "125"} 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:21,代码来源:test_tracking.py

示例2: test_counter

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def test_counter(server, dbm_db, tracker_ctx):
    with client() as c:
        c.get_phonenumbers("hello", 1)

        with SampleTracker.counter():
            c.ping()
            c.hello("counter")

        c.sleep(8)

    time.sleep(0.2)

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())

    data = [pickle.loads(db[i]) for i in headers]
    data.sort(key=lambda x: x["api"])
    get, hello, ping, sleep = data

    assert get["api"] == "get_phonenumbers" and get["seq"] == '1'
    assert ping["api"] == "ping" and ping["seq"] == '1'
    assert hello["api"] == "hello" and hello["seq"] == '2'
    assert sleep["api"] == "sleep" and sleep["seq"] == '2' 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:25,代码来源:test_tracking.py

示例3: record

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def record(self, header, exception):
        db = dbm.open(db_file, 'w')
        key = "%s:%s" % (header.request_id, header.seq)
        db[key.encode("ascii")] = pickle.dumps(header.__dict__)
        db.close() 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:7,代码来源:test_tracking.py

示例4: client

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def client(client_class=TTrackedClient, port=PORT):
    socket = TSocket("localhost", port)

    try:
        trans = TBufferedTransportFactory().get_transport(socket)
        proto = TBinaryProtocolFactory().get_protocol(trans)
        trans.open()
        args = [addressbook.AddressBookService, proto]
        if client_class.__name__ == TTrackedClient.__name__:
            args.insert(0, SampleTracker("test_client", "test_server"))
        yield client_class(*args)
    finally:
        trans.close() 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:15,代码来源:test_tracking.py

示例5: dbm_db

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def dbm_db(request):
    db = dbm.open(db_file, 'n')
    db.close()

    def fin():
        try:
            os.remove(db_file)
        except OSError:
            pass

    request.addfinalizer(fin) 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:13,代码来源:test_tracking.py

示例6: test_tracker

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def test_tracker(server, dbm_db, tracker_ctx):
    with client() as c:
        c.hello('you')
        assert c.tracker.response_header.meta == {'you': 'you'}

    time.sleep(0.2)

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())
    assert len(headers) == 1

    request_id = headers[0]
    data = pickle.loads(db[request_id])

    assert "start" in data and "end" in data
    data.pop("start")
    data.pop("end")
    assert data == {
        "request_id": request_id.decode("ascii").split(':')[0],
        "seq": '1',
        "client": "test_client",
        "server": "test_server",
        "api": "hello",
        "status": True,
        "annotation": {},
        "meta": {},
    } 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:29,代码来源:test_tracking.py

示例7: test_exception

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def test_exception(server, dbm_db, tracker_ctx):
    with pytest.raises(addressbook.PersonNotExistsError):
        with client() as c:
            c.get("jane")

    db = dbm.open(db_file, 'r')
    headers = list(db.keys())
    assert len(headers) == 1

    header = pickle.loads(db[headers[0]])
    assert header["status"] is False 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:13,代码来源:test_tracking.py

示例8: test_tracked_client_v2_tracked_server_v2

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def test_tracked_client_v2_tracked_server_v2(
        tracked_server_v2, dbm_db, tracker_ctx):
    with client(TTrackedClientV2, PORT + 4) as c:
        assert c._upgraded is True

        c.ping()
        time.sleep(0.2)

        db = dbm.open(db_file, 'r')
        headers = list(db.keys())
        assert len(headers) == 1

        request_id = headers[0]
        data = pickle.loads(db[request_id])

        assert "start" in data and "end" in data
        data.pop("start")
        data.pop("end")
        assert data == {
            "request_id": request_id.decode("ascii").split(':')[0],
            "seq": '1',
            "client": "test_client",
            "server": "test_server",
            "api": "ping",
            "status": True,
            "annotation": {},
            "meta": {},
        } 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:30,代码来源:test_tracking.py

示例9: test_tracked_client_v2_tracked_server_v3

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def test_tracked_client_v2_tracked_server_v3(server, dbm_db, tracker_ctx):
    with client(TTrackedClientV2) as c:
        assert c._upgraded is True

        c.ping()
        time.sleep(0.2)

        db = dbm.open(db_file, 'r')
        headers = list(db.keys())
        assert len(headers) == 1

        request_id = headers[0]
        data = pickle.loads(db[request_id])

        assert "start" in data and "end" in data
        data.pop("start")
        data.pop("end")
        assert data == {
            "request_id": request_id.decode("ascii").split(':')[0],
            "seq": '1',
            "client": "test_client",
            "server": "test_server",
            "api": "ping",
            "status": True,
            "annotation": {},
            "meta": {},
        }

        assert not hasattr(ctx, 'response_header') 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:31,代码来源:test_tracking.py

示例10: open

# 需要导入模块: from dbm import ndbm [as 别名]
# 或者: from dbm.ndbm import open [as 别名]
def open(file, flag='r', mode=0o666):
    """Open or create database at path given by *file*.

    Optional argument *flag* can be 'r' (default) for read-only access, 'w'
    for read-write access of an existing database, 'c' for read-write access
    to a new or existing database, and 'n' for read-write access to a new
    database.

    Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
    only if it doesn't exist; and 'n' always creates a new database.
    """
    global _defaultmod
    if _defaultmod is None:
        for name in _names:
            try:
                mod = __import__(name, fromlist=['open'])
            except ImportError:
                continue
            if not _defaultmod:
                _defaultmod = mod
            _modules[name] = mod
        if not _defaultmod:
            raise ImportError("no dbm clone found; tried %s" % _names)

    # guess the type of an existing database, if not creating a new one
    result = whichdb(file) if 'n' not in flag else None
    if result is None:
        # db doesn't exist or 'n' flag was specified to create a new db
        if 'c' in flag or 'n' in flag:
            # file doesn't exist and the new flag was used so use default type
            mod = _defaultmod
        else:
            raise error[0]("need 'c' or 'n' flag to open new db")
    elif result == "":
        # db type cannot be determined
        raise error[0]("db type could not be determined")
    elif result not in _modules:
        raise error[0]("db type is {0}, but the module is not "
                       "available".format(result))
    else:
        mod = _modules[result]
    return mod.open(file, flag, mode) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:44,代码来源:__init__.py


注:本文中的dbm.ndbm.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。