本文整理汇总了Python中spyne.interface.Interface.add_class方法的典型用法代码示例。如果您正苦于以下问题:Python Interface.add_class方法的具体用法?Python Interface.add_class怎么用?Python Interface.add_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyne.interface.Interface
的用法示例。
在下文中一共展示了Interface.add_class方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_to_schema_no_extends
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import add_class [as 别名]
def test_add_to_schema_no_extends(self):
import spyne.const.xml_ns
ns_xsd = spyne.const.xml_ns.xsd
class cls(Fault):
__namespace__='ns'
@classmethod
def get_type_name_ns(self, app):
return 'testing:My'
interface = Interface(FakeApp())
interface.add_class(cls)
pref = cls.get_namespace_prefix(interface)
wsdl = Wsdl11(interface)
wsdl.build_interface_document('prot://addr')
schema = wsdl.get_schema_info(pref)
self.assertEqual(len(schema.types), 1)
c_cls = interface.classes['{ns}cls']
c_elt = schema.types[0]
self.failUnless(c_cls is cls)
self.assertEqual(c_elt.tag, '{%s}complexType' % ns_xsd)
self.assertEqual(c_elt.get('name'), 'cls')
self.assertEqual(len(schema.elements), 1)
e_elt = schema.elements.values()[0]
self.assertEqual(e_elt.tag, '{%s}element' % ns_xsd)
self.assertEqual(e_elt.get('name'), 'cls')
self.assertEqual(e_elt.get('type'), 'testing:My')
self.assertEqual(len(e_elt), 0)
示例2: get_schema_documents
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import add_class [as 别名]
def get_schema_documents(models, default_namespace=None):
'''Returns the schema documents in a dict whose keys are namespace prefixes
and values are Element objects.
:param models: A list of spyne.model classes that will be represented in
the schema.
'''
if default_namespace is None:
default_namespace = models[0].get_namespace()
fake_app = FakeApplication()
fake_app.tns = default_namespace
fake_app.services = []
interface = Interface(fake_app)
for m in models:
interface.add_class(m)
interface.populate_interface(fake_app)
document = XmlSchema(interface)
document.build_interface_document()
return document.get_interface_document()
示例3: test_add_to_schema_w_extends
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import add_class [as 别名]
def test_add_to_schema_w_extends(self):
from spyne.const.xml import XSD
class base(Fault):
__namespace__ = 'ns'
@classmethod
def get_type_name_ns(self, app):
return 'testing:Base'
class cls(Fault):
__namespace__ = 'ns'
@classmethod
def get_type_name_ns(self, app):
return 'testing:My'
interface = Interface(FakeApp())
interface.add_class(cls)
pref = cls.get_namespace_prefix(interface)
wsdl = Wsdl11(interface)
wsdl.build_interface_document('prot://addr')
schema = wsdl.get_schema_info(pref)
self.assertEqual(len(schema.types), 1)
self.assertEqual(len(interface.classes), 1)
c_cls = next(iter(interface.classes.values()))
c_elt = next(iter(schema.types.values()))
self.failUnless(c_cls is cls)
self.assertEqual(c_elt.tag, XSD('complexType'))
self.assertEqual(c_elt.get('name'), 'cls')
from lxml import etree
print(etree.tostring(c_elt, pretty_print=True))
self.assertEqual(len(c_elt), 0)
示例4: get_validation_schema
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import add_class [as 别名]
def get_validation_schema(models, default_namespace=None):
"""Returns the validation schema object for the given models.
:param models: A list of spyne.model classes that will be represented in
the schema.
"""
if default_namespace is None:
default_namespace = models[0].get_namespace()
fake_app = FakeApplication(default_namespace)
interface = Interface(fake_app)
for m in models:
m.resolve_namespace(m, default_namespace)
interface.add_class(m)
schema = XmlSchema(interface)
schema.build_validation_schema()
return schema.validation_schema
示例5: test_add_to_schema
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import add_class [as 别名]
def test_add_to_schema(self):
class CM(ComplexModel):
i = Integer
s = String
a = XmlAttribute(String)
app = FakeApp()
app.tns = 'tns'
CM.resolve_namespace(CM, app.tns)
interface = Interface(app)
interface.add_class(CM)
wsdl = Wsdl11(interface)
wsdl.build_interface_document('http://a-aaaa.com')
pref = CM.get_namespace_prefix(interface)
type_def = wsdl.get_schema_info(pref).types[CM.get_type_name()]
attribute_def = type_def.find('{%s}attribute' % xml_ns.xsd)
print(etree.tostring(type_def, pretty_print=True))
self.assertIsNotNone(attribute_def)
self.assertEqual(attribute_def.get('name'), 'a')
self.assertEqual(attribute_def.get('type'), CM.a.type.get_type_name_ns(interface))
示例6: get_validation_schema
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import add_class [as 别名]
def get_validation_schema(models, default_namespace=None):
'''Returns the validation schema object for the given models.
:param models: A list of spyne.model classes that will be represented in
the schema.
'''
if default_namespace is None:
default_namespace = models[0].get_namespace()
fake_app = FakeApplication()
fake_app.tns = default_namespace
fake_app.services = []
interface = Interface(fake_app)
for m in models:
interface.add_class(m)
schema = XmlSchema(interface)
schema.build_validation_schema()
return schema.validation_schema