예제 #1
0
    def test_local_serialize_schema(self):
        from ZSI import SoapWriter
        from ZSI import _child_elements
        from xml.dom.ext.reader import PyExpat
        msg = self.client_module.DSQueryRegistrySoapOut()
        msg.DSQueryRegistryResult = msg.new_DSQueryRegistryResult()
        msg.DSQueryRegistryResult.Any = 'hi'

        input = open('wsdl/nvo-admin.wsdl').read()
        reader = PyExpat.Reader()
        dom = reader.fromString(input)

        dnode =  _child_elements(dom)[0]
        tnode =  _child_elements(dnode)[0]
        snode =  _child_elements(tnode)[0]

        msg.DSQueryRegistryResult.Schema = snode

        sw = SoapWriter()
        sw.serialize(msg)
        soap = str(sw)
        print soap

        ps = ParsedSoap(soap)
        pyobj = ps.Parse(msg.typecode)
        self.failUnlessEqual(pyobj.DSQueryRegistryResult.Any, msg.DSQueryRegistryResult.Any)
        self.failUnless(_is_element(pyobj.DSQueryRegistryResult.Schema))
        print _get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema)
        self.failUnlessEqual(_get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema), (u'http://www.w3.org/2001/XMLSchema', u'schema'))
예제 #2
0
    def test_local_serialize_schema(self):
        from ZSI import SoapWriter
        from ZSI import _child_elements
        from xml.dom.ext.reader import PyExpat
        msg = self.client_module.DSQueryRegistrySoapOut()
        msg.DSQueryRegistryResult = msg.new_DSQueryRegistryResult()
        msg.DSQueryRegistryResult.Any = 'hi'

        input = open('wsdl/nvo-admin.wsdl').read()
        reader = PyExpat.Reader()
        dom = reader.fromString(input)

        dnode = _child_elements(dom)[0]
        tnode = _child_elements(dnode)[0]
        snode = _child_elements(tnode)[0]

        msg.DSQueryRegistryResult.Schema = snode

        sw = SoapWriter()
        sw.serialize(msg)
        soap = str(sw)
        print(soap)

        ps = ParsedSoap(soap)
        pyobj = ps.Parse(msg.typecode)
        self.assertEqual(pyobj.DSQueryRegistryResult.Any,
                         msg.DSQueryRegistryResult.Any)
        self.assertTrue(_is_element(pyobj.DSQueryRegistryResult.Schema))
        print(_get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema))
        self.assertEqual(
            _get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema),
            ('http://www.w3.org/2001/XMLSchema', 'schema'))
예제 #3
0
 def getOperationName(self, ps, action):
     '''Returns operation name.
        action -- soapAction value
     '''
     method = self.root.get(_get_element_nsuri_name(ps.body_root)) or \
         self.soapAction.get(action)
     if method is None:
         raise UnknownRequestException, \
             'failed to map request to a method: action(%s), root%s' %(action,_get_element_nsuri_name(ps.body_root))
     return method
예제 #4
0
 def getOperationName(self, ps, action):
     '''Returns operation name.
        action -- soapAction value
     '''
     method = self.soapAction.get(action) or \
         self.root.get(_get_element_nsuri_name(ps.body_root))
     if method is None:
         raise UnknownRequestException, \
             'failed to map request to a method: action(%s), root%s' %(action,_get_element_nsuri_name(ps.body_root))
     return method
예제 #5
0
 def processRequest(cls, ps, **kw):
     """invokes callback that should return a (request,response) tuple.
     representing the SOAP request and response respectively.
     ps -- ParsedSoap instance representing HTTP Body.
     request -- twisted.web.server.Request
     """
     resource = kw['resource']
     request = kw['request']
     method =  getattr(resource, 'wsa_%s' %
                        _get_element_nsuri_name(ps.body_root)[-1])
                                           
     # TODO: grab ps.address, clean this up.
     try:
         req_pyobj,rsp_pyobj = method(ps, ps.address, request=request)
     except TypeError as ex:
         log.err(
             'ERROR: service %s is broken, method MUST return request, response'\
                 %self.__class__.__name__
         )
         raise
     except Exception as ex:
         log.err('failure when calling bound method')
         raise
     
     return rsp_pyobj
예제 #6
0
    def processRequest(self, ps, **kw):
        # TODO: Clean this up
        resource = kw['resource']

        d = getattr(resource, 'root', None)
        key = _get_element_nsuri_name(ps.body_root)
        if d is None or d.has_key(key) is False:
            raise RuntimeError,\
                'Error looking for key(%s) in root dictionary(%s)' %(key, str(d))

        self.op_name = d[key]
        self.address = address = Address()
        address.parse(ps)
        action = address.getAction()
        if not action:
            raise WSActionException('No WS-Action specified in Request')

        request = kw['request']
        http_headers = request.getAllHeaders()
        soap_action = http_headers.get('soapaction')
        if soap_action and soap_action.strip('\'"') != action:
            raise WSActionException(\
                'SOAP Action("%s") must match WS-Action("%s") if specified.'\
                %(soap_action,action)
            )
            
        # Save WS-Address in ParsedSoap instance.
        ps.address = address
        return ps
예제 #7
0
    def processRequest(cls, ps, **kw):
        """invokes callback that should return a (request,response) tuple.
        representing the SOAP request and response respectively.
        ps -- ParsedSoap instance representing HTTP Body.
        request -- twisted.web.server.Request
        """
        resource = kw['resource']
        request = kw['request']
        method = getattr(resource,
                         'wsa_%s' % _get_element_nsuri_name(ps.body_root)[-1])

        # TODO: grab ps.address, clean this up.
        try:
            req_pyobj, rsp_pyobj = method(ps, ps.address, request=request)
        except TypeError as ex:
            log.err(
                'ERROR: service %s is broken, method MUST return request, response'\
                    %self.__class__.__name__
            )
            raise
        except Exception as ex:
            log.err('failure when calling bound method')
            raise

        return rsp_pyobj
예제 #8
0
파일: wsgi.py 프로젝트: 0z-cloud/ZSI-Py3
    def processRequest(cls, ps, **kw):
        """invokes callback that should return a (request,response) tuple.
        representing the SOAP request and response respectively.
        ps -- ParsedSoap instance representing HTTP Body.
        request -- twisted.web.server.Request
        """
        resource = kw['resource']
        request = kw['request']

        root = _get_element_nsuri_name(ps.body_root)
        for key, method in inspect.getmembers(resource, inspect.ismethod):
            if (getattr(method, 'soapmethod', False) and method.root == root):
                break
        else:
            raise RuntimeError('Missing soap callback method for root "%s"' %
                               root)

        try:
            req = ps.Parse(method.requesttypecode)
        except Exception as ex:
            raise
        try:
            rsp = method.responsetypecode.pyclass()
        except Exception as ex:
            raise

        try:
            req, rsp = method(req, rsp)
        except Exception as ex:
            raise

        return rsp
예제 #9
0
 def processRequest(cls, ps, **kw):
     """invokes callback that should return a (request,response) tuple.
     representing the SOAP request and response respectively.
     ps -- ParsedSoap instance representing HTTP Body.
     request -- twisted.web.server.Request
     """
     resource = kw['resource']
     request = kw['request']
     method =  getattr(resource, 'soap_%s' %
                        _get_element_nsuri_name(ps.body_root)[-1])
                                           
     try:
         req,rsp = method(ps, request=request)
     except Exception, ex:
         raise
예제 #10
0
    def processRequest(cls, ps, **kw):
        """invokes callback that should return a (request,response) tuple.
        representing the SOAP request and response respectively.
        ps -- ParsedSoap instance representing HTTP Body.
        request -- twisted.web.server.Request
        """
        resource = kw["resource"]
        request = kw["request"]
        method = getattr(resource, "soap_%s" % _get_element_nsuri_name(ps.body_root)[-1])

        try:
            req_pyobj, rsp_pyobj = method(ps, request=request)
        except TypeError, ex:
            log.err("ERROR: service %s is broken, method MUST return request, response" % cls.__name__)
            raise
예제 #11
0
    def processRequest(cls, ps, **kw):
        """invokes callback that should return a (request,response) tuple.
        representing the SOAP request and response respectively.
        ps -- ParsedSoap instance representing HTTP Body.
        request -- twisted.web.server.Request
        """
        resource = kw['resource']
        request = kw['request']
        method = getattr(resource,
                         'soap_%s' % _get_element_nsuri_name(ps.body_root)[-1])

        try:
            req, rsp = method(ps, request=request)
        except Exception, ex:
            raise
예제 #12
0
 def processRequest(cls, ps, **kw):
     """invokes callback that should return a (request,response) tuple.
     representing the SOAP request and response respectively.
     ps -- ParsedSoap instance representing HTTP Body.
     request -- twisted.web.server.Request
     """
     resource = kw['resource']
     request = kw['request']
     method =  getattr(resource, 'soap_%s' %
                        _get_element_nsuri_name(ps.body_root)[-1])
                                           
     try:
         req_pyobj,rsp_pyobj = method(ps, request=request)
     except TypeError, ex:
         log.err(
             'ERROR: service %s is broken, method MUST return request, response'\
                 % cls.__name__
         )
         raise
예제 #13
0
    def processRequest(cls, ps, **kw):
        """invokes callback that should return a (request,response) tuple.
        representing the SOAP request and response respectively.
        ps -- ParsedSoap instance representing HTTP Body.
        request -- twisted.web.server.Request
        """
        resource = kw['resource']
        request = kw['request']

        root = _get_element_nsuri_name(ps.body_root)
        for key,method in inspect.getmembers(resource, inspect.ismethod):
            if (getattr(method, 'soapmethod', False) and method.root == root):
                break
        else:
            raise RuntimeError, 'Missing soap callback method for root "%s"' %root

        try:
            req = ps.Parse(method.requesttypecode)
        except Exception, ex:
            raise
예제 #14
0
파일: test_t9.py 프로젝트: pombredanne/ZSI
    def xcheck_c14n_exc4(self):
        RCVDIGEST = "jhTbi7gWlY9oLqsRr+EZ0bokRFA="
        CALDIGEST = "IkMyI4zCDlK41qE7sZxvkFHJioU="

        d1 = base64.encodestring(local_sha(WRONG).digest()).strip()
        d2 = base64.encodestring(local_sha(CORRECT).digest()).strip()

        ps = ParsedSoap(XML_INST4)
        el = filter(lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "MessageID"), ps.header_elements)[0]

        s = StringIO()
        Canonicalize(el, s, unsuppressedPrefixes=[])
        cxml = s.getvalue()
        #        print "-- "*20
        #        print cxml
        #        print "-- "*20
        d3 = base64.encodestring(local_sha(cxml).digest()).strip()

        self.assertEqual(d1, RCVDIGEST)
        self.assertEqual(d2, CALDIGEST)
        self.assertEqual(d3, CALDIGEST)
예제 #15
0
    def xcheck_c14n_exc4(self):
        RCVDIGEST = "jhTbi7gWlY9oLqsRr+EZ0bokRFA="
        CALDIGEST = "IkMyI4zCDlK41qE7sZxvkFHJioU="

        d1 = base64.encodestring(sha.sha(WRONG).digest()).strip()
        d2 = base64.encodestring(sha.sha(CORRECT).digest()).strip()

        ps = ParsedSoap(XML_INST4)
        el = filter(lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "MessageID"), 
                      ps.header_elements)[0]

        s = StringIO()
        Canonicalize(el, s, unsuppressedPrefixes=[])
        cxml = s.getvalue()
        print "-- "*20
        print cxml
        print "-- "*20
        d3 = base64.encodestring(sha.sha(cxml).digest()).strip()

        self.assertEqual(d1, RCVDIGEST)
        self.assertEqual(d2, CALDIGEST)
        self.assertEqual(d3, CALDIGEST)
예제 #16
0
파일: schema.py 프로젝트: pombredanne/ZSI
    def getSubstitutionElement(self, elt, ps):
        """if elt matches a member of the head substitutionGroup, return
        the GED typecode representation of the member.

        head -- ElementDeclaration typecode,
        elt -- the DOM element being parsed
        ps -- ParsedSoap instance
        """
        nsuri, ncname = _get_element_nsuri_name(elt)
        typecode = GED(nsuri, ncname)
        if typecode is None:
            return

        try:
            nsuri, ncname = typecode.substitutionGroup
        except (AttributeError, TypeError):
            return

        if (ncname == self.pname) and (nsuri == self.nspname or (not nsuri and not self.nspname)):
            return typecode

        return
예제 #17
0
파일: schema.py 프로젝트: hoprocker/mylons
    def getSubstitutionElement(self, elt, ps):
        '''if elt matches a member of the head substitutionGroup, return 
        the GED typecode representation of the member.

        head -- ElementDeclaration typecode, 
        elt -- the DOM element being parsed
        ps -- ParsedSoap instance
        '''
        nsuri,ncname = _get_element_nsuri_name(elt)
        typecode = GED(nsuri,ncname)
        if typecode is None:
            return

        try:
            nsuri,ncname = typecode.substitutionGroup
        except (AttributeError, TypeError):
            return

        if (ncname == self.pname) and (nsuri == self.nspname or 
           (not nsuri and not self.nspname)):
             return typecode
       
        return 
예제 #18
0
파일: test_t9.py 프로젝트: acigna/pywez
 def setUp(self):
     self.ps = ParsedSoap(XML_INST1)
     self.el = filter(
         lambda el: _get_element_nsuri_name(el) ==
         (WSA200403.ADDRESS, "From"), self.ps.header_elements)[0]
예제 #19
0
파일: test_t9.py 프로젝트: acigna/pywez
 def setUp(self):
     self.ps = ParsedSoap(XML_INST1)
     self.el = filter(lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "From"), 
                   self.ps.header_elements)[0]
예제 #20
0
파일: test_t9.py 프로젝트: 0z-cloud/ZSI-Py3
 def setUp(self):
     self.ps = ParsedSoap(XML_INST1)
     self.el = [
         el for el in self.ps.header_elements
         if _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "From")
     ][0]