#119 pyxb.exceptions_.SchemaValidationError: QName AuthenticationRequest with absent default namespace cannot be resolved

PyXB 1.1.4
closed
None
fixed
Binding model
major
PyXB 1.1.3
defect
2012-02-08
2012-02-07
No

Unable to round trip a document generated with pyxb

ar = ocibase.BroadsoftDocument(protocol="OCI", sessionId='d3cafbad', command=[bwas.AuthenticationRequest(userId='someuserID'),])
ar.toxml()

u'<?xml version="1.0" ?><ns1:BroadsoftDocument protocol="OCI" xmlns:ns1="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId>d3cafbad</sessionId><command xsi:type="AuthenticationRequest"><userId>someuserID</userId></command></ns1:BroadsoftDocument>'

bd = ocibase.CreateFromDocument(ar.toxml())

Traceback (most recent call last):

File "<stdin>", line 1, in <module>
File "ocibase.py", line 32, in CreateFromDocument

saxer.parse(StringIO.StringIO(xml_text))

File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 107, in parse

xmlreader.IncrementalParser.parse(self, source)

File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/xmlreader.py", line 123, in parse

self.feed(buffer)

File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 207, in feed

self._parser.Parse(data, isFinal)

File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 338, in start_element_ns

AttributesNSImpl(newattrs, qnames))

File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/binding/saxer.py", line 329, in startElementNS

(did_replace, type_class) = XSI._InterpretTypeAttribute(attrs.getValue(self.XSITypeTuple), ns_ctx, None, type_class)

File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/namespace/builtin.py", line 103, in _InterpretTypeAttribute

type_en = ns_ctx.interpretQName(type_name, namespace=fallback_namespace)

File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/namespace/resolution.py", line 611, in interpretQName

raise pyxb.SchemaValidationError('QName %s with absent default namespace cannot be resolved' % (local_name,))

pyxb.exceptions_.SchemaValidationError: QName AuthenticationRequest with absent default namespace cannot be resolved

2 Attachments

Discussion

  • Karl Putland

    Karl Putland - 2012-02-07

    required schema and generated source

     
  • Peter A. Bigot

    Peter A. Bigot - 2012-02-07
    • status changed from new to closed
    • resolution set to invalid

    PyXB is correct here.

    AuthenticationRequest is defined in OCISchemaLogin.xsd, which has an absent namespace. It must be found within the context of bwas.Namespace.

    When you create the document using the ocibase module, which contains material in namespace "C", there is no way for PyXB to know how to resolve symbols that are in an absent namespace, as there is no way (in XML) to associate those symbols with a namespace.

    If, instead, you create the document with:

    bd = bwas.CreateFromDocument(xmls)
    

    so the fallback namespace to use when resolving symbols in an absent namespace is bwas.Namespace, things work as they should.

    (Arguably, the definition of CreateFromDocument at the top of each module is wrong, since it provides a keyword argument default_namespace which if it wasn't ignored might have allowed you to do:

    bd = ocibase.CreateFromDocument(xmls,default_namespace=bwas.Namespace)
    

    However, some thought and testing of existing practice must be directed to whether this is the intent of that keyword, or whether it should be renamed to fallback_namespace, which is the keyword normally used for that function.)

     
  • Karl Putland

    Karl Putland - 2012-02-08
    • status changed from closed to reopened
    • resolution invalid deleted

    So... the round trip works when using

    >>> bd = bwas.CreateFromDocument(ocibase.BroadsoftDocument(sessionId="d3cafbad", protocol="OCI", command=[bwas.AuthenticationRequest(userId='someuserID')]).toxml())
    >>> bd
    <ocibase.OCIMessage object at 0x10124d590>
    >>> bd.toxml()
    u'<?xml version="1.0" ?><ns1:BroadsoftDocument protocol="OCI" xmlns:ns1="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId>d3cafbad</sessionId><command xsi:type="AuthenticationRequest"><userId>someuserID</userId></command></ns1:BroadsoftDocument>'
    

    But when starting the conversation with Broadsoft it fails when using bwas.CreateFromDocument

    >>> ar = ocibase.BroadsoftDocument(sessionId="d3cafbad", protocol="OCI", command=[bwas.AuthenticationRequest(userId='ociuser')])
    >>> s.sendall(ar.toxml())
    >>> res = s.recv(4096)
    >>> res
    '<?xml version="1.0" encoding="UTF-8"?>\n<BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId xmlns="">d3cafbad</sessionId><command echo="" xsi:type="AuthenticationResponse" xmlns=""><userId>ociuser</userId><nonce>1328660896121</nonce><passwordAlgorithm>MD5</passwordAlgorithm></command></BroadsoftDocument>\n'
    
    >>> bd = bwas.CreateFromDocument(res)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "bwas.py", line 33, in CreateFromDocument
        saxer.parse(StringIO.StringIO(xml_text))
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 107, in parse
        xmlreader.IncrementalParser.parse(self, source)
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/xmlreader.py", line 123, in parse
        self.feed(buffer)
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 207, in feed
        self._parser.Parse(data, isFinal)
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 338, in start_element_ns
        AttributesNSImpl(newattrs, qnames))
      File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/binding/saxer.py", line 329, in startElementNS
        (did_replace, type_class) = XSI._InterpretTypeAttribute(attrs.getValue(self.__XSITypeTuple), ns_ctx, None, type_class)
      File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/namespace/builtin.py", line 103, in _InterpretTypeAttribute
        type_en = ns_ctx.interpretQName(type_name, namespace=fallback_namespace)
      File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/namespace/resolution.py", line 611, in interpretQName
        raise pyxb.SchemaValidationError('QName %s with absent default namespace cannot be resolved' % (local_name,))
    pyxb.exceptions_.SchemaValidationError: QName AuthenticationResponse with absent default namespace cannot be resolved
    
    >>> 'AuthenticationResponse' in dir(bwas) 
    True
    

    AuthenticationResponse returned from server

    '<?xml version="1.0" encoding="UTF-8"?>\n<BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId xmlns="">d3cafbad</sessionId><command echo="" xsi:type="AuthenticationResponse" xmlns=""><userId>ociuser</userId><nonce>1328660896121</nonce><passwordAlgorithm>MD5</passwordAlgorithm></command></BroadsoftDocument>\n'
    

    Where am I going wrong with this?

     
  • Peter A. Bigot

    Peter A. Bigot - 2012-02-08
    • status changed from reopened to accepted

    You're not going wrong. Here the issue is that the outermost element defines a default namespace "C", which discards the normal fallback. PyXB is not interpreting the internal set of an empty default namespace as being the fallback namespace; probably because that deep inside processing it doesn't know which absent namespace to select.

    I expect this will turn out to be a PyXB issue, but I'll have to dig into this tomorrow.

     
  • Peter A. Bigot

    Peter A. Bigot - 2012-02-08

    patch for trac #119

     
  • Peter A. Bigot

    Peter A. Bigot - 2012-02-08
    • status changed from accepted to closed
    • resolution set to fixed

    Fixed in the trac0119.patch attachment and pushed to the next branch for the next release. (You do still have to use the module corresponding to the absent namespace to do the parsing.)

     
  • Karl Putland

    Karl Putland - 2012-02-08

    Verified initial test succeeds!
    Thank you!

    >>> s = socket.socket()
    >>> s.connect((socket.gethostbyname('hostname'),2208))
    >>> import ocibase, bwas
    >>> ar = ocibase.BroadsoftDocument(sessionId="d3cafbad", protocol="OCI", command=[bwas.AuthenticationRequest(userId='ocitest!')])
    >>> s.sendall(ar.toxml())
    >>> res = s.recv(4096)
    >>> bd = bwas.CreateFromDocument(res)
    >>> bd
    <ocibase.OCIMessage object at 0x101d12c90>
    >>> bd.toxml()
    u'<?xml version="1.0" ?><ns1:BroadsoftDocument protocol="OCI" xmlns:ns1="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId>d3cafbad</sessionId><command echo="" xsi:type="AuthenticationResponse"><userId>ocitest!</userId><nonce>1328721149827</nonce><passwordAlgorithm>MD5</passwordAlgorithm></command></ns1:BroadsoftDocument>'
    >>> bd.command
    [<bwas.AuthenticationResponse object at 0x101d7c890>]
    >>>
    
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks