本文整理汇总了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)
示例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
示例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()
示例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)
示例5: test_thrift
# 需要导入模块: import thriftpy [as 别名]
# 或者: from thriftpy import load [as 别名]
def test_thrift():
return thriftpy.load('tests/test.thrift', module_name='test_thrift')
示例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")
示例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")
示例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
示例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)
示例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"))
示例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
示例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) != ''
示例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)}
示例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
示例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))