本文整理汇总了Python中pyxb.utils.six.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了u函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testAddAttributes
def testAddAttributes (self):
x = wildcard()
self.assertEqual(six.u('<wildcard/>'), x.toxml('utf-8', root_only=True).decode('utf-8'))
x.attr = False
self.assertEqual(six.u('<wildcard attr="false"/>').encode('utf-8'), x.toxml('utf-8', root_only=True))
x._setAttribute(ns1.createExpandedName('w1'), 'val')
self.assertEqual(six.u('<wildcard attr="false" n1:w1="val" xmlns:n1="urn:issue14.1"/>').encode('utf-8'), x.toxml('utf-8', root_only=True))
示例2: testMultichoice
def testMultichoice (self):
xmlt = six.u('<ns1:multiplechoice xmlns:ns1="URN:test-mg-choice"/>')
xmld = xmlt.encode('utf-8')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
instance = multiplechoice.createFromDOM(dom.documentElement)
self.assertEqual(0, len(instance.first))
self.assertEqual(0, len(instance.second))
self.assertEqual(0, len(instance.third))
self.assertEqual(ToDOM(instance).toxml("utf-8"), xmld)
xmlt = six.u('<ns1:multiplechoice xmlns:ns1="URN:test-mg-choice"><first/></ns1:multiplechoice>')
xmld = xmlt.encode('utf-8')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
instance = multiplechoice.createFromDOM(dom.documentElement)
self.assertEqual(1, len(instance.first))
self.assertEqual(0, len(instance.second))
self.assertEqual(0, len(instance.third))
self.assertEqual(ToDOM(instance).toxml("utf-8"), xmld)
xmlt = six.u('<ns1:multiplechoice xmlns:ns1="URN:test-mg-choice"><first/><first/><first/><third/></ns1:multiplechoice>')
xmld = xmlt.encode('utf-8')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
instance = multiplechoice.createFromDOM(dom.documentElement)
self.assertEqual(3, len(instance.first))
self.assertEqual(0, len(instance.second))
self.assertEqual(1, len(instance.third))
self.assertEqual(ToDOM(instance).toxml("utf-8"), xmld)
示例3: testGenerationValidation
def testGenerationValidation (self):
ship_to = USAddress('Robert Smith', 'General Delivery')
po = purchaseOrder(ship_to)
self.assertEqual('General Delivery', po.shipTo.street)
self.assertTrue(po.billTo is None)
self.assertTrue(pyxb.RequireValidWhenGenerating())
self.assertRaises(pyxb.IncompleteElementContentError, po.toxml)
try:
pyxb.RequireValidWhenGenerating(False)
self.assertFalse(pyxb.RequireValidWhenGenerating())
xmlt = six.u('<ns1:purchaseOrder xmlns:ns1="http://www.example.com/PO1"><shipTo><street>General Delivery</street><name>Robert Smith</name></shipTo></ns1:purchaseOrder>')
xmlta = six.u('<ns1:purchaseOrder xmlns:ns1="http://www.example.com/PO1"><shipTo><name>Robert Smith</name><street>General Delivery</street></shipTo></ns1:purchaseOrder>')
xmlds = [ _xmlt.encode('utf-8') for _xmlt in (xmlt, xmlta) ]
self.assertTrue(po.toxml("utf-8", root_only=True) in xmlds)
finally:
pyxb.RequireValidWhenGenerating(True)
self.assertRaises(pyxb.UnrecognizedContentError, CreateFromDocument, xmlt)
self.assertTrue(pyxb.RequireValidWhenParsing())
try:
pyxb.RequireValidWhenParsing(False)
self.assertFalse(pyxb.RequireValidWhenParsing())
po2 = CreateFromDocument(xmlt)
finally:
pyxb.RequireValidWhenParsing(True)
self.assertEqual('General Delivery', po2.shipTo.street)
self.assertTrue(po2.billTo is None)
示例4: XMLToPython
def XMLToPython (pattern):
"""Convert the given pattern to the format required for Python
regular expressions.
@param pattern: A Unicode string defining a pattern consistent
with U{XML regular
expressions<http://www.w3.org/TR/xmlschema-2/index.html#regexs>}.
@return: A Unicode string specifying a Python regular expression
that matches the same language as C{pattern}."""
assert isinstance(pattern, six.text_type)
new_pattern_elts = []
new_pattern_elts.append('^(')
position = 0
while position < len(pattern):
cg = MaybeMatchCharacterClass(pattern, position)
if cg is None:
ch = pattern[position]
if ch == six.u('^') or ch == six.u('$'):
# These characters have no special meaning in XSD. But they
# match start and end of string in Python, so they have to
# be escaped.
new_pattern_elts.append(six.unichr(0x5c) + ch)
else:
new_pattern_elts.append(ch)
position += 1
else:
(cps, position) = cg
new_pattern_elts.append(cps.asPattern())
new_pattern_elts.append(')$')
return ''.join(new_pattern_elts)
示例5: testContainerAssignment
def testContainerAssignment (self):
i = xs.string(self.body, _element=anything)
instance = container()
instance.anything = i
explicit_xml = instance.toxml("utf-8")
instance.anything = xs.string(self.body)
implicit_xml = instance.toxml("utf-8")
self.assertEqual(explicit_xml, implicit_xml)
instance.anything = xs.int(43)
self.assertTrue(isinstance(instance.anything, xs.int))
int_xml = instance.toxml("utf-8")
instance.anything = self.body
self.assertTrue(isinstance(instance.anything, xs.anyType))
oc = instance.anything.orderedContent()
self.assertEqual(1, len(oc))
self.assertTrue(isinstance(oc[0], pyxb.binding.basis.NonElementContent))
xmlt = six.u('<container><anything>something</anything></container>')
xmld = xmlt.encode('utf-8')
self.assertEqual(xmld, instance.toxml('utf-8', root_only=True))
instance.anything = 43
self.assertTrue(isinstance(instance.anything, xs.anyType))
oc = instance.anything.orderedContent()
self.assertEqual(1, len(oc))
self.assertTrue(isinstance(oc[0], pyxb.binding.basis.NonElementContent))
xmlt = six.u('<container><anything>43</anything></container>')
xmld = xmlt.encode('utf-8')
self.assertEqual(xmld, instance.toxml('utf-8', root_only=True))
示例6: testOrphan
def testOrphan (self):
i = self.makeText()
# Drop the second bold
dropped = i.bold.pop()
self.assertEqual(vc.orphanElementInContent, vc.IGNORE_ONCE)
xmlt = six.u('<text>Intro with <bold>bold text</bold> and <ital>italicized text with <bold>bold</bold> inside</ital> ending with a little text.</text>')
xmld = xmlt.encode('utf-8')
self.assertEqual(i.toxml('utf-8', root_only=True), xmld)
vc._setOrphanElementInContent(vc.GIVE_UP)
self.assertEqual(vc.orphanElementInContent, vc.GIVE_UP)
self.assertEqual(gvc.orphanElementInContent, gvc.IGNORE_ONCE)
xmlt = six.u('<text>Intro with <bold>bold text</bold> and <ital>italicized text with <bold>bold</bold> inside</ital> ending with a little text.</text>')
xmld = xmlt.encode('utf-8')
self.assertEqual(i.toxml('utf-8', root_only=True), xmld)
vc._setOrphanElementInContent(vc.RAISE_EXCEPTION)
self.assertEqual(vc.orphanElementInContent, vc.RAISE_EXCEPTION)
self.assertEqual(gvc.orphanElementInContent, gvc.IGNORE_ONCE)
if sys.version_info[:2] < (2, 7):
self.assertRaises(pyxb.OrphanElementContentError, i.toxml, 'utf-8', root_only=True)
return
with self.assertRaises(pyxb.OrphanElementContentError) as cm:
xmld = i.toxml('utf-8', root_only=True)
e = cm.exception
self.assertEqual(e.instance, i)
self.assertEqual(e.preferred.value, dropped)
示例7: testAddElements
def testAddElements (self):
bds = pyxb.utils.domutils.BindingDOMSupport()
elt = bds.createChildElement(ns2.createExpandedName('e2'))
bds.appendTextChild('content', elt)
x = wildcard()
self.assertEqual(six.u('<wildcard/>').encode('utf-8'), x.toxml('utf-8', root_only=True))
x._appendWildcardElement(elt)
self.assertEqual(six.u('<wildcard xmlns:n2="urn:issue14.2"><n2:e2>content</n2:e2></wildcard>').encode('utf-8'), x.toxml('utf-8', root_only=True))
示例8: testTooManySingle
def testTooManySingle (self):
xmlt = six.u('<ns1:choice xmlns:ns1="URN:test-mg-choice"><first/><second/></ns1:choice>')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
self.assertRaises(UnrecognizedContentError, choice.createFromDOM, dom.documentElement)
xmlt = six.u('<ns1:choice xmlns:ns1="URN:test-mg-choice"><second/><third/></ns1:choice>')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
self.assertRaises(UnrecognizedContentError, choice.createFromDOM, dom.documentElement)
示例9: testDeep
def testDeep (self):
w = wrapper(BIND(BIND(4, deep=4), BIND('hi')))
xmlt = six.u('<wrapper><holding><optional deep="4">4</optional><required>hi</required></holding></wrapper>')
xmld = xmlt.encode('utf-8')
self.assertEqual(w.toxml("utf-8", root_only=True), xmld)
w = wrapper(BIND(BIND('hi', deep=2)))
xmlt = six.u('<wrapper><holding><required deep="2">hi</required></holding></wrapper>')
xmld = xmlt.encode('utf-8')
self.assertEqual(w.toxml("utf-8", root_only=True), xmld)
示例10: testStrings
def testStrings (self):
encoded_values = [ six.u('01'), six.u('00'), six.u('ab'), six.u('Ab'), six.u('AB12') ]
for et in encoded_values:
ed = et.encode('utf-8')
v = xsd.hexBinary.Factory(ed)
self.assertEqual(v, ed)
v = xsd.hexBinary.Factory(et, _from_xml=True)
self.assertEqual(len(et)//2, len(v))
self.assertEqual(et.upper(), v.xsdLiteral())
示例11: testEnumerations
def testEnumerations (self):
instance = CreateFromDocument(six.u('<qne xmlns:ns1="urn:issue13.1">ns1:one</qne>'))
self.assertEqual(instance.value(), ns1.createExpandedName('one'))
with self.assertRaises(pyxb.SimpleFacetValueError) as cm:
instance = CreateFromDocument(six.u('<qne xmlns:ns1="urn:issue13.1">ns1:un</qne>'))
self.assertEqual('Type tQNE enumeration constraint violated by value {urn:issue13.1}un', str(cm.exception))
with self.assertRaises(pyxb.SimpleFacetValueError) as cm:
instance = CreateFromDocument(six.u('<qne xmlns:ns1="urn:issue13.2">ns1:one</qne>'))
self.assertEqual('Type tQNE enumeration constraint violated by value {urn:issue13.2}one', str(cm.exception))
示例12: testFixedMultichoice
def testFixedMultichoice (self):
xmlt = six.u('<fixedMultichoice xmlns="URN:test-mg-choice"></fixedMultichoice>')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
instance = fixedMultichoice.createFromDOM(dom.documentElement)
xmlt = six.u('<ns1:fixedMultichoice xmlns:ns1="URN:test-mg-choice"><A/><A/></ns1:fixedMultichoice>')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
instance = fixedMultichoice.createFromDOM(dom.documentElement)
xmlt = six.u('<ns1:fixedMultichoice xmlns:ns1="URN:test-mg-choice"><A/><B/></ns1:fixedMultichoice>')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
self.assertRaises(UnrecognizedContentError, fixedMultichoice.createFromDOM, dom.documentElement)
示例13: testBasic
def testBasic (self):
xmlt = six.u('<elt>30313233</elt>')
xmld = xmlt.encode('utf-8')
instance = CreateFromDocument(xmlt)
self.assertEqual(b'0123', instance.value())
xmlt = six.u('<elt Color="33323130">30313233</elt>')
xmld = xmlt.encode('utf-8')
instance = CreateFromDocument(xmlt)
self.assertEqual(b'0123', instance.value())
self.assertEqual(b'3210', instance.Color)
示例14: testComplex
def testComplex (self):
canonicalt = six.u('<complex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>')
canonicald = canonicalt.encode('utf-8')
for xmlt in ( canonicalt,
six.u('<complex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"></complex>'),
six.u('<complex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"><!-- comment --></complex>')) :
doc = pyxb.utils.domutils.StringToDOM(xmlt)
instance = CreateFromDOM(doc.documentElement)
self.assertTrue(instance._isNil())
self.assertEqual(instance.toDOM().documentElement.toxml("utf-8"), canonicald)
instance.validateBinding()
示例15: testSubstitutions
def testSubstitutions (self):
xmlt = six.u('<elt attrOne="low" xsi:type="alt1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><first>content</first></elt>')
doc = pyxb.utils.domutils.StringToDOM(xmlt)
instance = CreateFromDOM(doc.documentElement)
self.assertEqual('content', instance.first)
self.assertEqual('low', instance.attrOne)
xmlt = six.u('<elt attrTwo="hi" xsi:type="alt2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><second/></elt>')
doc = pyxb.utils.domutils.StringToDOM(xmlt)
instance = CreateFromDOM(doc.documentElement)
self.assertTrue(instance.second is not None)
self.assertEqual('hi', instance.attrTwo)