本文整理汇总了Python中spyne.util.xml.get_schema_documents函数的典型用法代码示例。如果您正苦于以下问题:Python get_schema_documents函数的具体用法?Python get_schema_documents怎么用?Python get_schema_documents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_schema_documents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_subs
def test_subs(self):
from lxml import etree
from spyne.util.xml import get_schema_documents
xpath = lambda o, x: o.xpath(x, namespaces={"xs": NS_XSD})
m = {
"s0": "aa",
"s2": "cc",
"s3": "dd",
}
class C(ComplexModel):
__namespace__ = "aa"
a = Integer
b = Integer(sub_name="bb")
c = Integer(sub_ns="cc")
d = Integer(sub_ns="dd", sub_name="dd")
elt = get_schema_documents([C], "aa")['tns']
print(etree.tostring(elt, pretty_print=True))
seq, = xpath(elt, "xs:complexType/xs:sequence")
assert len(seq) == 4
assert len(xpath(seq, 'xs:element[@name="a"]')) == 1
assert len(xpath(seq, 'xs:element[@name="bb"]')) == 1
示例2: test_choice_tag
def test_choice_tag(self):
class SomeObject(ComplexModel):
__namespace__ = "badass_ns"
one = Integer(xml_choice_group="numbers")
two = Integer(xml_choice_group="numbers")
punk = Unicode
class KickassService(ServiceBase):
@rpc(_returns=SomeObject)
def wooo(ctx):
return SomeObject()
Application([KickassService],
tns='kickass.ns',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11()
)
docs = get_schema_documents([SomeObject])
doc = docs['tns']
print(etree.tostring(doc, pretty_print=True))
assert len(doc.xpath('/xs:schema/xs:complexType[@name="SomeObject"]'
'/xs:sequence/xs:element[@name="punk"]',
namespaces={'xs': NS_XSD})) > 0
assert len(doc.xpath('/xs:schema/xs:complexType[@name="SomeObject"]'
'/xs:sequence/xs:choice/xs:element[@name="one"]',
namespaces={'xs': NS_XSD})) > 0
示例3: test_subs
def test_subs(self):
from lxml import etree
from spyne.util.xml import get_schema_documents
xpath = lambda o, x: o.xpath(x, namespaces={"xs": ns.xsd})
m = {
"s0": "aa",
"s2": "cc",
"s3": "dd",
}
class C(ComplexModel):
__namespace__ = "aa"
a = Integer
b = Integer(sub_name="bb")
c = Integer(sub_ns="cc")
d = Integer(sub_ns="dd", sub_name="dd")
elt = get_schema_documents([C], "aa")['tns']
print etree.tostring(elt, pretty_print=True)
seq, = xpath(elt, "xs:complexType/xs:sequence")
assert len(seq) == 4
assert len(xpath(seq, 'xs:element[@name="a"]')) == 1
assert len(xpath(seq, 'xs:element[@name="bb"]')) == 1
# TODO: this doesn't feel right.
# check the spec to see whether it should it be prefixed.
assert len(xpath(seq, 'xs:element[@name="{cc}c"]')) == 1
assert len(xpath(seq, 'xs:element[@name="{dd}dd"]')) == 1
示例4: test_deserialize
def test_deserialize(self):
class Punk(ComplexModel):
__namespace__ = 'some_namespace'
a = Unicode
b = Integer
c = Decimal
d = DateTime
class Foo(ComplexModel):
__namespace__ = 'some_other_namespace'
a = Unicode
b = Integer
c = Decimal
d = DateTime
e = XmlAttribute(Integer)
def __eq__(self, other):
# remember that this is a test object
assert (
self.a == other.a and
self.b == other.b and
self.c == other.c and
self.d == other.d and
self.e == other.e
)
return True
docs = get_schema_documents([Punk, Foo])
pprint(docs)
assert docs['s0'].tag == '{http://www.w3.org/2001/XMLSchema}schema'
assert docs['tns'].tag == '{http://www.w3.org/2001/XMLSchema}schema'
print()
print("the other namespace %r:" % docs['tns'].attrib['targetNamespace'])
assert docs['tns'].attrib['targetNamespace'] == 'some_namespace'
print(etree.tostring(docs['tns'], pretty_print=True))
print()
print("the other namespace %r:" % docs['s0'].attrib['targetNamespace'])
assert docs['s0'].attrib['targetNamespace'] == 'some_other_namespace'
print(etree.tostring(docs['s0'], pretty_print=True))
print()
foo = Foo(a=u'a', b=1, c=decimal.Decimal('3.4'),
d=datetime(2011,02,20,tzinfo=pytz.utc), e=5)
doc = get_object_as_xml(foo, Foo)
print(etree.tostring(doc, pretty_print=True))
foo_back = get_xml_as_object(doc, Foo)
assert foo_back == foo
# as long as it doesn't fail, it's ok.
get_validation_schema([Punk, Foo])
示例5: test_annotation
def test_annotation(self):
tns = 'some_ns'
doc = "Some Doc"
class SomeClass(ComplexModel):
__namespace__ = tns
some_attr = Unicode(doc=doc)
schema = get_schema_documents([SomeClass], tns)['tns']
print(etree.tostring(schema, pretty_print=True))
assert schema.xpath("//xs:documentation/text()",
namespaces={'xs': NS_XSD}) == [doc]
示例6: test_mandatory
def test_mandatory(self):
xpath = lambda o, x: o.xpath(x, namespaces={"xs": NS_XSD})
class C(ComplexModel):
__namespace__ = "aa"
foo = XmlAttribute(M(Unicode))
elt = get_schema_documents([C])['tns']
print(etree.tostring(elt, pretty_print=True))
foo, = xpath(elt, 'xs:complexType/xs:attribute[@name="foo"]')
attrs = foo.attrib
assert 'use' in attrs and attrs['use'] == 'required'
示例7: test_boolean_default
def test_boolean_default(self):
tns = 'some_ns'
class SomeGuy(ComplexModel):
__namespace__ = tns
bald = Boolean(default=True)
schema = get_schema_documents([SomeGuy], tns)['tns']
print(etree.tostring(schema, pretty_print=True))
objects = parse_schema_element(schema)
pprint(objects[tns].types)
NewGuy = objects['some_ns'].types["SomeGuy"]
assert NewGuy._type_info['bald'].Attributes.default == True
示例8: test_attribute
def test_attribute(self):
tns = 'some_ns'
class SomeGuy(ComplexModel):
__namespace__ = tns
name = XmlAttribute(Unicode)
schema = get_schema_documents([SomeGuy], tns)['tns']
print etree.tostring(schema, pretty_print=True)
objects = parse_schema_element(schema)
pprint(objects[tns].types)
NewGuy = objects['some_ns'].types["SomeGuy"]
assert NewGuy._type_info['name'].type is Unicode
示例9: test_attribute_with_customized_type
def test_attribute_with_customized_type(self):
tns = 'some_ns'
class SomeGuy(ComplexModel):
__namespace__ = tns
name = XmlAttribute(Unicode(default="aa"))
schema = get_schema_documents([SomeGuy], tns)['tns']
print(etree.tostring(schema, pretty_print=True))
objects = parse_schema_element(schema)
pprint(objects[tns].types)
NewGuy = objects['some_ns'].types["SomeGuy"]
assert NewGuy._type_info['name'].type.__orig__ is Unicode
assert NewGuy._type_info['name'].type.Attributes.default == "aa"
示例10: test_any_tag
def test_any_tag(self):
logging.basicConfig(level=logging.DEBUG)
class SomeType(ComplexModel):
__namespace__ = "zo"
anything = AnyXml(schema_tag='{%s}any' % NS_XSD, namespace='##other',
process_contents='lax')
docs = get_schema_documents([SomeType])
print(etree.tostring(docs['tns'], pretty_print=True))
_any = docs['tns'].xpath('//xsd:any', namespaces={'xsd': NS_XSD})
assert len(_any) == 1
assert _any[0].attrib['namespace'] == '##other'
assert _any[0].attrib['processContents'] == 'lax'
示例11: test_customized_unicode
def test_customized_unicode(self):
tns = 'some_ns'
class SomeGuy(ComplexModel):
__namespace__ = tns
name = Unicode(max_len=10, pattern="a", min_len=5, default="aa")
schema = get_schema_documents([SomeGuy], tns)['tns']
print(etree.tostring(schema, pretty_print=True))
objects = parse_schema_element(schema)
pprint(objects[tns].types)
NewGuy = objects['some_ns'].types["SomeGuy"]
assert NewGuy._type_info['name'].Attributes.max_len == 10
assert NewGuy._type_info['name'].Attributes.min_len == 5
assert NewGuy._type_info['name'].Attributes.pattern == "a"
assert NewGuy._type_info['name'].Attributes.default == "aa"
示例12: test_simple
def test_simple(self):
tns = 'some_ns'
class SomeGuy(ComplexModel):
__namespace__ = 'some_ns'
id = Integer
schema = get_schema_documents([SomeGuy], tns)['tns']
print(etree.tostring(schema, pretty_print=True))
objects = parse_schema_element(schema)
pprint(objects[tns].types)
NewGuy = objects[tns].types["SomeGuy"]
assert NewGuy.get_type_name() == SomeGuy.get_type_name()
assert NewGuy.get_namespace() == SomeGuy.get_namespace()
assert dict(NewGuy._type_info) == dict(SomeGuy._type_info)
示例13: SomeObject
from spyne.util.xml import get_xml_as_object
from spyne.util.xml import parse_schema_string
# Define the object
class SomeObject(ComplexModel):
i = Integer
s = Unicode
d = DateTime
__repr__ = hier_repr
# Instantiate the object
instance = SomeObject(i=5, s="str", d=datetime.now())
# Generate schema documents
schema_elts = get_schema_documents([SomeObject], 'some_ns')
# Serialize the xml schema document for object
schema = etree.tostring(schema_elts['tns'], pretty_print=True)
# Serialize the object to XML
instance_elt = get_object_as_xml(instance, SomeObject)
# Serialize the element tree to string
data = etree.tostring(instance_elt, pretty_print=True)
print(instance)
print()
print(schema)
print(data)
示例14: _get_schema
def _get_schema(self, *args):
schema_doc = get_schema_documents(args)['tns']
return parse_schema_element(schema_doc)
示例15: ProductEdition
class ProductEdition(ComplexModel):
__namespace__ = 'kickass_namespace'
id = XmlAttribute(Uuid)
name = XmlData(Unicode)
class Product(ComplexModel):
__namespace__ = 'kickass_namespace'
id = XmlAttribute(Uuid)
edition = ProductEdition
docs = get_schema_documents([Punk, Foo, Product])
pprint(docs)
print()
pprint({k: v.attrib['targetNamespace'] for k,v in docs.items()})
# the default ns prefix is always tns
print("the default namespace %r:" % docs['tns'].attrib['targetNamespace'])
print(etree.tostring(docs['tns'], pretty_print=True))
print()
# Namespace prefixes are assigned like s0, s1, s2, etc...
print("the other namespace %r:" % docs['s0'].attrib['targetNamespace'])
print(etree.tostring(docs['s0'], pretty_print=True))
print()