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


Python thriftpy.load方法代码示例

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


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

示例1: __init__

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def __init__(self, service_name, **kwargs):
        self.service_name = service_name
        super(ServiceHandler, self).__init__(**kwargs)

        self.system_exc_handler = self.default_exception_handler
        self.api_exc_handler = self.default_exception_handler
        self.thrift_exc_handler = lambda tp, v, tb: (tp, v, tb)

        # init hook registry
        self.hook_registry = HookRegistry()
        # register api hook
        self.hook_registry.register(api_called)
        # register log config hook
        self.hook_registry.register(config_log)

        module_name, _ = os.path.splitext(os.path.basename(config.thrift_file))
        # module name should ends with '_thrift'
        if not module_name.endswith('_thrift'):
            module_name = ''.join([module_name, '_thrift'])
        self.thrift_module = load(config.thrift_file, module_name=module_name) 
开发者ID:elemepi,项目名称:takumi,代码行数:22,代码来源:service.py

示例2: thrift_client

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def thrift_client(cls):
    def cls_wrapper(*args, **kwargs):
        def __getattribute__(self, item):
            thrift_module = object.__getattribute__(self, 'thrift_module')
            service_name = object.__getattribute__(self, '__class__').__name__
            thrift_services = getattr(thrift_module, service_name)
            thrift_services_list = thrift_services.thrift_services
            if item in thrift_services_list:
                return thrift_service_wrapper(object.__getattribute__(self, item))
            else:
                return object.__getattribute__(self, item)

        service_client_instance = cls(*args, **kwargs)
        thrift_file = service_client_instance.thrift_file
        thrift_module_name = os.path.splitext(os.path.basename(thrift_file))[0] + '_thrift'
        thrift_module = thriftpy.load(thrift_file, module_name=thrift_module_name)
        setattr(cls, 'thrift_module', thrift_module)
        setattr(cls, '__getattribute__', __getattribute__)
        return service_client_instance

    return cls_wrapper 
开发者ID:yuyu1987,项目名称:pithy-test,代码行数:23,代码来源:thrift_client.py

示例3: main

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def main():
    """
    @brief: Main
    """

    CLIENT_TIMEOUT = 50000

    spider = thriftpy.load(constant.THRIFT_FILE, module_name="spider_thrift")
    server = make_server(spider.SpiderService, DispatchSpider(), constant.RPC_HOST, 
                             constant.RPC_PORT, client_timeout=CLIENT_TIMEOUT)
    server.serve() 
开发者ID:linzhi,项目名称:minerva,代码行数:13,代码来源:master.py

示例4: __init__

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def __init__(self):
        spider = thriftpy.load(constant.THRIFT_FILE, module_name="spider_thrift")
        self.master_spider = make_client(spider.SpiderService, constant.RPC_HOST, 
                                         constant.RPC_PORT, timeout=self.TIMEOUT)
        
        self.mongo_db = utils.MongoDBHandler(hosts=constant.SPIDER_MONGO_ADDRESS,
                                             db=constant.SPIDER_MONGO_DATABASE) 
开发者ID:linzhi,项目名称:minerva,代码行数:9,代码来源:spider.py

示例5: test_thrift

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_thrift():
    return thriftpy.load('tests/test.thrift', module_name='test_thrift') 
开发者ID:ryanwang520,项目名称:aiothrift,代码行数:4,代码来源:conftest.py

示例6: test_obj_equalcheck

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_obj_equalcheck():
    ab = thriftpy.load("addressbook.thrift")
    ab2 = thriftpy.load("addressbook.thrift")

    assert ab.Person(name="hello") == ab2.Person(name="hello") 
开发者ID:adsharma,项目名称:flattools,代码行数:7,代码来源:test_base.py

示例7: test_exc_equalcheck

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_exc_equalcheck():
    ab = thriftpy.load("addressbook.thrift")

    assert ab.PersonNotExistsError("exc") != ab.PersonNotExistsError("exc") 
开发者ID:adsharma,项目名称:flattools,代码行数:6,代码来源:test_base.py

示例8: test_cls_equalcheck

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_cls_equalcheck():
    ab = thriftpy.load("addressbook.thrift")
    ab2 = thriftpy.load("addressbook.thrift")

    assert ab.Person == ab2.Person 
开发者ID:adsharma,项目名称:flattools,代码行数:7,代码来源:test_base.py

示例9: test_isinstancecheck

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_isinstancecheck():
    ab = thriftpy.load("addressbook.thrift")
    ab2 = thriftpy.load("addressbook.thrift")

    assert isinstance(ab.Person(), ab2.Person)
    assert isinstance(ab.Person(name="hello"), ab2.Person)

    assert isinstance(ab.PersonNotExistsError(), ab2.PersonNotExistsError) 
开发者ID:adsharma,项目名称:flattools,代码行数:10,代码来源:test_base.py

示例10: test_hashable

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_hashable():
    ab = thriftpy.load("addressbook.thrift")

    # exception is hashable
    hash(ab.PersonNotExistsError("test error"))

    # container struct is not hashable
    with pytest.raises(TypeError):
        hash(ab.Person(name="Tom")) 
开发者ID:adsharma,项目名称:flattools,代码行数:11,代码来源:test_base.py

示例11: test_parse_spec

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_parse_spec():
    ab = thriftpy.load("addressbook.thrift")

    cases = [
        ((TType.I32, None), "I32"),
        ((TType.STRUCT, ab.PhoneNumber), "PhoneNumber"),
        ((TType.LIST, TType.I32), "LIST<I32>"),
        ((TType.LIST, (TType.STRUCT, ab.PhoneNumber)), "LIST<PhoneNumber>"),
        ((TType.MAP, (TType.STRING, (
            TType.LIST, (TType.MAP, (TType.STRING, TType.STRING))))),
         "MAP<STRING, LIST<MAP<STRING, STRING>>>")
    ]

    for spec, res in cases:
        assert parse_spec(*spec) == res 
开发者ID:adsharma,项目名称:flattools,代码行数:17,代码来源:test_base.py

示例12: test_init_func

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_init_func():
    thriftpy.load("addressbook.thrift")
    assert linecache.getline('<generated PhoneNumber.__init__>', 1) != '' 
开发者ID:adsharma,项目名称:flattools,代码行数:5,代码来源:test_base.py

示例13: test_set

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_set():
    s = load("type.thrift")

    assert s.Set.thrift_spec == {1: (TType.SET, "a_set", TType.STRING, True)} 
开发者ID:adsharma,项目名称:flattools,代码行数:6,代码来源:test_type.py

示例14: test_import_hook

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_import_hook():
    ab_1 = thriftpy.load("addressbook.thrift")
    print("Load file succeed.")
    assert ab_1.DEFAULT_LIST_SIZE == 10

    try:
        import addressbook_thrift as ab  # noqa
    except ImportError:
        print("Import hook not installed.")

    thriftpy.install_import_hook()

    import addressbook_thrift as ab_2
    print("Magic import succeed.")
    assert ab_2.DEFAULT_LIST_SIZE == 10 
开发者ID:adsharma,项目名称:flattools,代码行数:17,代码来源:test_hook.py

示例15: test_load

# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_load():
    ab_1 = thriftpy.load("addressbook.thrift")
    ab_2 = thriftpy.load("addressbook.thrift",
                         module_name="addressbook_thrift")

    assert ab_1.__name__ == "addressbook"
    assert ab_2.__name__ == "addressbook_thrift"

    # load without module_name can't do pickle
    with pytest.raises(pickle.PicklingError):
        pickle.dumps(ab_1.Person(name='Bob'))

    # load with module_name set and it can be pickled
    person = ab_2.Person(name='Bob')
    assert person == pickle.loads(pickle.dumps(person)) 
开发者ID:adsharma,项目名称:flattools,代码行数:17,代码来源:test_hook.py


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