def test_local_attribute1(self):
        """
        """
        self.types_module

        xml = """<?xml version="1.0" encoding="UTF-8"?>
        <holder xmlns='urn:subGroup:types'>
        <baseElt><base>from base</base></baseElt>
        <childElt><base>from base</base><child>from child</child></childElt></holder>"""

        ps = ParsedSoap(xml, envelope=False)
        p1 = ps.Parse(GED("urn:subGroup:types", "holder"))

        b1 = p1.BaseElt[0]
        c1 = p1.BaseElt[1]

        sw = SoapWriter(envelope=False)
        sw.serialize(p1)

        ps = ParsedSoap(str(sw), envelope=False)
        p2 = ps.Parse(GED("urn:subGroup:types", "holder"))
        b2 = p2.BaseElt[0]
        c2 = p2.BaseElt[1]

        self.failUnlessEqual(b1.Base, b2.Base)
        self.failUnlessEqual(c1.Base, c2.Base)
        self.failUnlessEqual(c1.Child, c2.Child)
Example #2
0
    def test_local_attribute1(self):
        """
        """
        self.types_module

        xml = """<?xml version="1.0" encoding="UTF-8"?>
        <holder xmlns='urn:subGroup:types'>
        <baseElt><base>from base</base></baseElt>
        <childElt><base>from base</base><child>from child</child></childElt></holder>"""

        ps = ParsedSoap(xml, envelope=False)
        p1 = ps.Parse(GED("urn:subGroup:types", "holder"))

        b1 = p1.BaseElt[0]
        c1 = p1.BaseElt[1]

        sw = SoapWriter(envelope=False)
        sw.serialize(p1)

        ps = ParsedSoap(str(sw), envelope=False)
        p2 = ps.Parse(GED("urn:subGroup:types", "holder"))
        b2 = p2.BaseElt[0]
        c2 = p2.BaseElt[1]

        self.assertEqual(b1.Base, b2.Base)
        self.assertEqual(c1.Base, c2.Base)
        self.assertEqual(c1.Child, c2.Child)
Example #3
0
    def check_list_defs(self):
        gl = globals()
        for klass in map(
                lambda h: gl[h],
                filter(
                    lambda g: (g.startswith('TestList') and issubclass(
                        gl[g], ZSI.TC.List)), gl)):

            typecode = klass('whatever', nillable=True)
            data = None
            for i in range(10):
                sw = SoapWriter()
                sw.serialize(data, typecode)
                s = str(sw)
                print s
                ps = ParsedSoap(s)
                pyobj = ps.Parse(typecode)
                assert pyobj == data, 'Data corruption expected "%s", got "%s"' % (
                    str(data), str(pyobj))
                if data is None:
                    data = []
                    continue

                #
                # cut last 3 fields off: weekday (0-6, Monday is 0), Julian day (day in the year, 1-366),
                # DST (Daylight Savings Time) flag (-1, 0 or 1)
                #
                utc = list(time.gmtime(i)[:-3]) + [999, 0, 0]
                data.append(tuple(utc))
Example #4
0
 def test_local_choice_default_facets_legal1(self):
     """<choice minOccurs=1 maxOccurs=1>
     """
     pyobj = GED("urn:example", "Easy").pyclass()
     pyobj.Rank = 1
     sw = SoapWriter()
     sw.serialize(pyobj)
     print str(sw)
Example #5
0
 def test_local_choice_default_facets_legal1(self):
     """<choice minOccurs=1 maxOccurs=1>
     """
     pyobj = GED("urn:example", "Easy").pyclass()
     pyobj.Rank = 1
     sw = SoapWriter()
     sw.serialize(pyobj)
     print(str(sw))
Example #6
0
    def test_local_type_substitution2(self):
        """test extension of extension"""

        attr1 = 'aone'
        attr2 = 'atwo'
        attr3 = 'athree'
        self.types_module
        pyobj = GED('urn:test', 'test').pyclass()

        # [ 1489129 ] Unexpected subsitution error message
        #  try to parse before type ever initialized
        """
        ps = ParsedSoap(MSG1)
        pyobj0 = ps.Parse(pyobj.typecode)
        sub0 = pyobj0.Actor
        self.failUnless(sub0.get_attribute_attr1() == attr1, 'bad attribute1')
        self.failUnless(sub0.get_attribute_attr2() == attr2, 'bad attribute2')
        """

        # [ 1489090 ] Derived type attributes don't populate the attr dictionary
        # [ 1489677 ] Derivation from derived type missing derived element
        #
        pyobj.Actor = sub1 = GTD('urn:test', 'TopActor')(None).pyclass()
        sub1.Element1 = 'one'
        sub1.Element2 = 'two'
        sub1.Element3 = 'three'
        sub1.set_attribute_attr1(attr1)
        sub1.set_attribute_attr2(attr2)
        sub1.set_attribute_attr3(attr3)

        sw = SoapWriter()
        sw.serialize(pyobj)
        xml = str(sw)
        ps = ParsedSoap(xml)
        pyobj2 = ps.Parse(pyobj.typecode)
        sub2 = pyobj2.Actor

        self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute 1')
        self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute 2')
        self.failUnless(sub2.get_attribute_attr3() == attr3, 'bad attribute 3')

        self.failUnless(sub2.Element1 == sub1.Element1, 'bad element 1')
        self.failUnless(sub2.Element2 == sub1.Element2, 'bad element 2')
        self.failUnless(sub2.Element3 == sub1.Element3, 'bad element 3')

        # check parsed out correct type
        self.failUnless(
            isinstance(sub2.typecode, sub1.typecode.__class__),
            'local element actor "%s" must be an instance of "%s"' %
            (sub2.typecode, sub1.typecode.__class__))

        # check local element is derived from base
        base = GTD('urn:test', 'BaseActor')
        self.failUnless(
            isinstance(sub2.typecode, base),
            'local element actor must be a derived type of "%s"' % base)
Example #7
0
 def test_local_choice_maxOccurs_unbounded(self):
     """<choice minOccurs=1 maxOccurs=unbounded>
     """
     pyobj = GED("urn:example", "Hard").pyclass()
     pyobj.Name = ["steve", "mark"]
     pyobj.Any = ["whatever"]
     pyobj.Rank = [2,3,4]
     sw = SoapWriter()
     sw.serialize(pyobj)
     print str(sw)
Example #8
0
 def test_local_choice_maxOccurs_unbounded(self):
     """<choice minOccurs=1 maxOccurs=unbounded>
     """
     pyobj = GED("urn:example", "Hard").pyclass()
     pyobj.Name = ["steve", "mark"]
     pyobj.Any = ["whatever"]
     pyobj.Rank = [2, 3, 4]
     sw = SoapWriter()
     sw.serialize(pyobj)
     print(str(sw))
Example #9
0
    def test_local_type_substitution2(self):
        """test extension of extension"""

        attr1 = 'aone'
        attr2 = 'atwo'
        attr3 = 'athree'
        self.types_module
        pyobj = GED('urn:test', 'test').pyclass()

        # [ 1489129 ] Unexpected subsitution error message
        #  try to parse before type ever initialized
        """
        ps = ParsedSoap(MSG1)
        pyobj0 = ps.Parse(pyobj.typecode)
        sub0 = pyobj0.Actor
        self.failUnless(sub0.get_attribute_attr1() == attr1, 'bad attribute1')
        self.failUnless(sub0.get_attribute_attr2() == attr2, 'bad attribute2')
        """

        # [ 1489090 ] Derived type attributes don't populate the attr dictionary
        # [ 1489677 ] Derivation from derived type missing derived element
        # 
        pyobj.Actor = sub1 = GTD('urn:test', 'TopActor')(None).pyclass()
        sub1.Element1 = 'one'
        sub1.Element2 = 'two'
        sub1.Element3 = 'three'
        sub1.set_attribute_attr1(attr1)
        sub1.set_attribute_attr2(attr2)
        sub1.set_attribute_attr3(attr3)
        
        sw = SoapWriter()
        sw.serialize(pyobj)
        xml = str(sw)
        ps = ParsedSoap(xml)
        pyobj2 = ps.Parse(pyobj.typecode)
        sub2 = pyobj2.Actor

        self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute 1')
        self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute 2')
        self.failUnless(sub2.get_attribute_attr3() == attr3, 'bad attribute 3')

        self.failUnless(sub2.Element1 == sub1.Element1, 'bad element 1')
        self.failUnless(sub2.Element2 == sub1.Element2, 'bad element 2')
        self.failUnless(sub2.Element3 == sub1.Element3, 'bad element 3')
                
        # check parsed out correct type
        self.failUnless(isinstance(sub2.typecode, sub1.typecode.__class__), 
            'local element actor "%s" must be an instance of "%s"'%
                (sub2.typecode, sub1.typecode.__class__))
        
        # check local element is derived from base
        base = GTD('urn:test', 'BaseActor')
        self.failUnless(isinstance(sub2.typecode, base), 
            'local element actor must be a derived type of "%s"'%
                base)
Example #10
0
 def test_local_choice_maxOccurs_unbounded(self):
     """<choice minOccurs=1 maxOccurs=unbounded>
     """
     pyobj = GED("urn:example", "Hard").pyclass()
     pyobj.Name = "steve"
     pyobj.Name.append("mark")
     pyobj.Any = "whatever"
     pyobj.Rank = 2
     pyobj.Rank.append(3)
     pyobj.Rank.append(4)
     sw = SoapWriter()
     sw.serialize(pyobj)
     print(str(sw))
Example #11
0
 def test_local_choice_maxOccurs_unbounded(self):
     """<choice minOccurs=1 maxOccurs=unbounded>
     """
     pyobj = GED("urn:example", "Hard").pyclass()
     pyobj.Name = "steve"
     pyobj.Name.append("mark")
     pyobj.Any = "whatever"
     pyobj.Rank = 2
     pyobj.Rank.append(3)
     pyobj.Rank.append(4)
     sw = SoapWriter()
     sw.serialize(pyobj)
     print(str(sw))
Example #12
0
    def processRequest(cls, obj, nsdict={}, header=True,
                       **kw):
        tc = None
        if kw.has_key('requesttypecode'):
            tc = kw['requesttypecode']
        elif kw.has_key('requestclass'):
            tc = kw['requestclass'].typecode
        else:
            tc = getattr(obj.__class__, 'typecode', None)

        sw = SoapWriter(nsdict=nsdict, header=header,
                        outputclass=cls.writerClass)
        sw.serialize(obj, tc)
        return sw
Example #13
0
    def processRequest(cls, obj, nsdict={}, header=True, **kw):
        tc = None
        if 'requesttypecode' in kw:
            tc = kw['requesttypecode']
        elif 'requestclass' in kw:
            tc = kw['requestclass'].typecode
        else:
            tc = getattr(obj.__class__, 'typecode', None)

        sw = SoapWriter(nsdict=nsdict,
                        header=header,
                        outputclass=cls.writerClass)
        sw.serialize(obj, tc)
        return sw
Example #14
0
    def test_local_empty_attribute(self):
        # [ 1452752 ] attribute with empty value doesn't appear in parsed object
        myString = ""
        pyobj = GED("urn:example", "Test1").pyclass()
        pyobj.set_attribute_myString(myString)

        sw = SoapWriter()
        sw.serialize(pyobj)
        soap = str(sw)

        print soap
        ps = ParsedSoap(soap)
        pyobj2 = ps.Parse(pyobj.typecode)

        test = pyobj2.get_attribute_myString()
        self.failUnlessEqual(myString, str(test))
Example #15
0
    def test_local_empty_attribute(self):
        # [ 1452752 ] attribute with empty value doesn't appear in parsed object
        myString = ""
        pyobj = GED("urn:example", "Test1").pyclass()
        pyobj.set_attribute_myString(myString)

        sw = SoapWriter()
        sw.serialize(pyobj)
        soap = str(sw)

        print soap
        ps = ParsedSoap(soap)
        pyobj2 = ps.Parse(pyobj.typecode)

        test = pyobj2.get_attribute_myString()
        self.failUnlessEqual(myString, str(test))
Example #16
0
def _test_local_serialize1():
    """
      <element name="GlobalElementLocalType">
          <complexType>
            <sequence>
              <element name="Unqualified1">
                  <complexType/>
              </element>
              <element name="Unqualified2" type="xsd:int"/>
              <element name="Unqualified3" type="tns:GlobalType"/>

              <element name="Unqualified4">
                  <simpleType>
                       <restriction base="xsd:string"/>
                  </simpleType>
              </element>

            </sequence>
          </complexType>
      </element>
        """
    tns = "urn:test"
    pyobj = GED(tns, "GlobalElementLocalType").pyclass()
    pyobj.Unqualified1 = pyobj.new_Unqualified1()
    pyobj.Unqualified2 = 2

    pyobj.Unqualified3 = pyobj.new_Unqualified3()
    pyobj.Unqualified3.Unqualified1 = pyobj.Unqualified3.new_Unqualified1()
    pyobj.Unqualified3.Unqualified2 = 32

    pyobj.Unqualified4 = "whatever"

    sw = SoapWriter(envelope=False)
    sw.serialize(pyobj)
    xml = str(sw)
    print xml

    et = ElementTree.fromstring(xml)

    # GlobalElementLocalType
    assert (et.tag == '{urn:test}GlobalElementLocalType'), "root GED"

    for i, j in zip(
        ['Unqualified1', 'Unqualified2', 'Unqualified3', 'Unqualified4'],
            map(lambda c: c.tag, et.getchildren())):

        assert (i == j), 'Match Failed: expected "%s" not "%s"' % (i, j)
Example #17
0
    def test_local_type_substitution_test2(self):
        """test extension of extension"""

        attr1 = 'aone'
        attr2 = 'atwo'
        attr3 = 'athree'
        self.types_module
        pyobj = GED('urn:test', 'test2').pyclass()

        # Test maxOccurs>1 for substitution
        #
        pyobj.Actor = [GTD('urn:test', 'TopActor')(None).pyclass()]
        sub1 = pyobj.Actor[0]
        sub1.Element1 = 'one'
        sub1.Element2 = 'two'
        sub1.Element3 = 'three'
        sub1.set_attribute_attr1(attr1)
        sub1.set_attribute_attr2(attr2)
        sub1.set_attribute_attr3(attr3)

        sw = SoapWriter()
        sw.serialize(pyobj)
        xml = str(sw)
        ps = ParsedSoap(xml)
        pyobj2 = ps.Parse(pyobj.typecode)
        sub2 = pyobj2.Actor[0]

        self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute 1')
        self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute 2')
        self.failUnless(sub2.get_attribute_attr3() == attr3, 'bad attribute 3')

        self.failUnless(sub2.Element1 == sub1.Element1, 'bad element 1')
        self.failUnless(sub2.Element2 == sub1.Element2, 'bad element 2')
        self.failUnless(sub2.Element3 == sub1.Element3, 'bad element 3')

        # check parsed out correct type
        self.failUnless(
            isinstance(sub2.typecode, sub1.typecode.__class__),
            'local element actor "%s" must be an instance of "%s"' %
            (sub2.typecode, sub1.typecode.__class__))

        # check local element is derived from base
        base = GTD('urn:test', 'BaseActor')
        self.failUnless(
            isinstance(sub2.typecode, base),
            'local element actor must be a derived type of "%s"' % base)
Example #18
0
def _test_local_serialize1():
        """
      <element name="GlobalElementLocalType">
          <complexType>
            <sequence>
              <element name="Unqualified1">
                  <complexType/>
              </element>
              <element name="Unqualified2" type="xsd:int"/>
              <element name="Unqualified3" type="tns:GlobalType"/>

              <element name="Unqualified4">
                  <simpleType>
                       <restriction base="xsd:string"/>
                  </simpleType>
              </element>

            </sequence>
          </complexType>
      </element>
        """
        tns = "urn:test"
        pyobj = GED(tns, "GlobalElementLocalType").pyclass()
        pyobj.Unqualified1 = pyobj.new_Unqualified1()
        pyobj.Unqualified2 = 2

        pyobj.Unqualified3 = pyobj.new_Unqualified3()
        pyobj.Unqualified3.Unqualified1 = pyobj.Unqualified3.new_Unqualified1()
        pyobj.Unqualified3.Unqualified2 = 32

        pyobj.Unqualified4 = "whatever"

        sw = SoapWriter(envelope=False)
        sw.serialize(pyobj)
        xml = str(sw)
        print xml

        et = ElementTree.fromstring(xml)

        # GlobalElementLocalType
        assert(et.tag == '{urn:test}GlobalElementLocalType'), "root GED"

        for i,j in zip([ 'Unqualified1', 'Unqualified2', 'Unqualified3', 'Unqualified4'],
            map(lambda c: c.tag, et.getchildren())):

            assert(i == j), 'Match Failed: expected "%s" not "%s"' %(i,j)
Example #19
0
    def test_local_type_substitution1(self):
        """test extension.   Parse known instance, serialize an equivalent, Parse it back. """
        attr1 = 'myclass'
        attr2 = 'whatever'
        self.types_module
        pyobj = GED('urn:test', 'test').pyclass()

        # [ 1489129 ] Unexpected subsitution error message
        #  try to parse before type ever initialized
        ps = ParsedSoap(MSG1)
        pyobj0 = ps.Parse(pyobj.typecode)
        sub0 = pyobj0.Actor
        self.failUnless(sub0.get_attribute_attr1() == attr1, 'bad attribute1')
        self.failUnless(sub0.get_attribute_attr2() == attr2, 'bad attribute2')

        # [ 1489090 ] Derived type attributes don't populate the attr dictionary
        #
        pyobj.Actor = sub1 = GTD('urn:test', 'MiddleActor')(None).pyclass()
        sub1.Element1 = 'foo'
        sub1.Element2 = 'bar'
        sub1.set_attribute_attr1(attr1)
        sub1.set_attribute_attr2(attr2)

        sw = SoapWriter()
        sw.serialize(pyobj)
        xml = str(sw)
        ps = ParsedSoap(xml)
        pyobj2 = ps.Parse(pyobj.typecode)
        sub2 = pyobj2.Actor

        self.failUnless(sub2.get_attribute_attr1() == attr1,
                        'bad attribute class')
        self.failUnless(sub2.get_attribute_attr2() == attr2,
                        'bad attribute name')

        # check parsed out correct type
        self.failUnless(
            isinstance(sub2.typecode, sub1.typecode.__class__),
            'local element actor "%s" must be an instance of "%s"' %
            (sub2.typecode, sub1.typecode.__class__))

        # check local element is derived from base
        base = GTD('urn:test', 'BaseActor')
        self.failUnless(
            isinstance(sub2.typecode, base),
            'local element actor must be a derived type of "%s"' % base)
Example #20
0
    def test_local_type_substitution_test2(self):
        """test extension of extension"""

        attr1 = 'aone'
        attr2 = 'atwo'
        attr3 = 'athree'
        self.types_module
        pyobj = GED('urn:test', 'test2').pyclass()

        # Test maxOccurs>1 for substitution 
        # 
        pyobj.Actor = [GTD('urn:test', 'TopActor')(None).pyclass()]
        sub1 = pyobj.Actor[0]
        sub1.Element1 = 'one'
        sub1.Element2 = 'two'
        sub1.Element3 = 'three'
        sub1.set_attribute_attr1(attr1)
        sub1.set_attribute_attr2(attr2)
        sub1.set_attribute_attr3(attr3)
        
        sw = SoapWriter()
        sw.serialize(pyobj)
        xml = str(sw)
        ps = ParsedSoap(xml)
        pyobj2 = ps.Parse(pyobj.typecode)
        sub2 = pyobj2.Actor[0]

        self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute 1')
        self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute 2')
        self.failUnless(sub2.get_attribute_attr3() == attr3, 'bad attribute 3')

        self.failUnless(sub2.Element1 == sub1.Element1, 'bad element 1')
        self.failUnless(sub2.Element2 == sub1.Element2, 'bad element 2')
        self.failUnless(sub2.Element3 == sub1.Element3, 'bad element 3')
                
        # check parsed out correct type
        self.failUnless(isinstance(sub2.typecode, sub1.typecode.__class__), 
            'local element actor "%s" must be an instance of "%s"'%
                (sub2.typecode, sub1.typecode.__class__))
        
        # check local element is derived from base
        base = GTD('urn:test', 'BaseActor')
        self.failUnless(isinstance(sub2.typecode, base), 
            'local element actor must be a derived type of "%s"'%
                base)
Example #21
0
    def test_local_type_substitution1(self):
        """test extension.   Parse known instance, serialize an equivalent, Parse it back. """
        attr1 = 'myclass'
        attr2 = 'whatever'
        self.types_module
        pyobj = GED('urn:test', 'test').pyclass()

        # [ 1489129 ] Unexpected subsitution error message
        #  try to parse before type ever initialized
        ps = ParsedSoap(MSG1)
        pyobj0 = ps.Parse(pyobj.typecode)
        sub0 = pyobj0.Actor
        self.failUnless(sub0.get_attribute_attr1() == attr1, 'bad attribute1')
        self.failUnless(sub0.get_attribute_attr2() == attr2, 'bad attribute2')

        # [ 1489090 ] Derived type attributes don't populate the attr dictionary
        # 
        pyobj.Actor = sub1 = GTD('urn:test', 'MiddleActor')(None).pyclass()
        sub1.Element1 = 'foo'
        sub1.Element2 = 'bar'
        sub1.set_attribute_attr1(attr1)
        sub1.set_attribute_attr2(attr2)
        
        sw = SoapWriter()
        sw.serialize(pyobj)
        xml = str(sw)
        ps = ParsedSoap(xml)
        pyobj2 = ps.Parse(pyobj.typecode)
        sub2 = pyobj2.Actor

        self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute class')
        self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute name')
                
        # check parsed out correct type
        self.failUnless(isinstance(sub2.typecode, sub1.typecode.__class__), 
            'local element actor "%s" must be an instance of "%s"'%
                (sub2.typecode, sub1.typecode.__class__))
        
        # check local element is derived from base
        base = GTD('urn:test', 'BaseActor')
        self.failUnless(isinstance(sub2.typecode, base), 
            'local element actor must be a derived type of "%s"'%
                base)
Example #22
0
    def test_local_ged_substitution(self):
        """This test is designed to fail, trying to dump
        a GED in via type substitution.
        """
        self.types_module
        pyobj = GED('urn:test', 'test').pyclass()

        # use GED of a derived type
        pyobj.Actor = sub = GED('urn:test', 'MiddleActor').pyclass()
        sub.Element1 = 'foo'
        sub.Element2 = 'bar'

        sw = SoapWriter()
        self.failUnlessRaises(TypeError, sw.serialize, pyobj)
Example #23
0
    def check_list_defs(self):
        gl = globals()
        for klass in map(lambda h: gl[h], filter(lambda g: (g.startswith('TestList') and 
            issubclass(gl[g],ZSI.TC.List)), gl)):

            typecode = klass('whatever', nillable=True)
            data = None
            for i in range(10):
                sw = SoapWriter()
                sw.serialize(data, typecode)
                s = str(sw)
                #print s
                ps = ParsedSoap(s); pyobj = ps.Parse(typecode)
                assert pyobj == data, 'Data corruption expected "%s", got "%s"' %(str(data),str(pyobj))
                if data is None: 
                    data = []; continue;

                # 
                # cut last 3 fields off: weekday (0-6, Monday is 0), Julian day (day in the year, 1-366),
                # DST (Daylight Savings Time) flag (-1, 0 or 1)
                # 
                utc = list(time.gmtime(i)[:-3]) + [999,0,0] 
                data.append(tuple(utc))
Example #24
0
def _Dispatch(ps,
              server,
              SendResponse,
              SendFault,
              post,
              action,
              nsdict={},
              **kw):
    '''Send ParsedSoap instance to ServiceContainer, which dispatches to
    appropriate service via post, and method via action.  Response is a
    self-describing pyobj, which is passed to a SoapWriter.

    Call SendResponse or SendFault to send the reply back, appropriately.
        server -- ServiceContainer instance

    '''
    localURL = 'http://%s:%d%s' % (server.server_name, server.server_port,
                                   post)
    address = action
    service = server.getNode(post)
    isWSResource = False
    if isinstance(service, WSAResource):
        isWSResource = True
        service.setServiceURL(localURL)
        address = Address()
        try:
            address.parse(ps)
        except Exception as e:
            return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
        if action and action != address.getAction():
            e = WSActionException('SOAP Action("%s") must match WS-Action("%s") if specified.' \
                %(action,address.getAction()))
            return SendFault(FaultFromException(e, 0, None), **kw)
        action = address.getAction()

    if isinstance(service, ServiceInterface) is False:
        e = NoSuchService('no service at POST(%s) in container: %s' %
                          (post, server))
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    if not service.authorize(None, post, action):
        return SendFault(Fault(Fault.Server, "Not authorized"), code=401)
        #try:
        #    raise NotAuthorized()
        #except Exception, e:
        #return SendFault(FaultFromException(e, 0, None), code=401, **kw)
        ##return SendFault(FaultFromException(NotAuthorized(), 0, None), code=401, **kw)

    try:
        method = service.getOperation(ps, address)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    try:
        if isWSResource is True:
            _, result = method(ps, address)
        else:
            _, result = method(ps)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Verify if Signed
    service.verify(ps)

    # If No response just return.
    if result is None:
        return SendResponse('', **kw)

    sw = SoapWriter(nsdict=nsdict)
    try:
        sw.serialize(result)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    if isWSResource is True:
        action = service.getResponseAction(ps, action)
        addressRsp = Address(action=action)
        try:
            addressRsp.setResponseFromWSAddress(address, localURL)
            addressRsp.serialize(sw)
        except Exception as e:
            return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Create Signatures
    service.sign(sw)

    try:
        soapdata = str(sw)
        return SendResponse(soapdata, **kw)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
Example #25
0
 def processResponse(cls, output, **kw):
     sw = SoapWriter(outputclass=cls.writerClass)
     sw.serialize(output)
     return sw
Example #26
0
    def test_local_attribute1(self):
        """
        """
        myDouble = 4.5
        myInt = 9
        myFloat = 3.0001
        myDecimal = 8.999
        myGDateTime = time.gmtime()
        myAnyURI = "urn:whatever"
        myQName = ("urn:test", "qbert")
        myString = "whatever"
        myHexBinary = hex(888)

        pyobj = GED("urn:example", "Test1").pyclass()
        # Test serialize/parse
        pyobj.set_attribute_myDecimal(myDecimal)
        pyobj.set_attribute_myDouble(myDouble)
        pyobj.set_attribute_myFloat(myFloat)
        pyobj.set_attribute_myInt(myInt)
        pyobj.set_attribute_myDateTime(myGDateTime)

        pyobj.set_attribute_myGDay(myGDateTime)
        pyobj.set_attribute_myGMonth(myGDateTime)
        pyobj.set_attribute_myGYear(myGDateTime)
        pyobj.set_attribute_myGYearMonth(myGDateTime)
        pyobj.set_attribute_myDate(myGDateTime)
        pyobj.set_attribute_myTime(myGDateTime)

        pyobj.set_attribute_myAnyURI(myAnyURI)
        pyobj.set_attribute_myString(myString)
        pyobj.set_attribute_myHexBinary(myHexBinary)
        pyobj.set_attribute_myDuration(myGDateTime)

        # Problems parsings
        pyobj.set_attribute_myQName(myQName)
        pyobj.set_attribute_myGMonthDay(myGDateTime)


        #TODO:
        #pyobj.set_attribute_myBase64Binary("")
        #pyobj.set_attribute_myNOTATION("NOT")

        sw = SoapWriter()
        sw.serialize(pyobj)
        soap = str(sw)

        ps = ParsedSoap(soap)
        pyobj2 = ps.Parse(pyobj.typecode)

        test = pyobj2.get_attribute_myInt()
        self.failUnlessEqual(myInt, test)

        test = pyobj2.get_attribute_myDouble()
        self.failUnlessEqual(myDouble, test)

        test = pyobj2.get_attribute_myFloat()
        self.failUnlessEqual(myFloat, test)

        test = pyobj2.get_attribute_myDecimal()
        self.failUnlessEqual(myDecimal, test)

        test = pyobj2.get_attribute_myAnyURI()
        self.failUnlessEqual(myAnyURI, test)

        test = pyobj2.get_attribute_myQName()
        self.failUnlessEqual(myQName, test)

        test = pyobj2.get_attribute_myString()
        self.failUnlessEqual(myString, test)

        test = pyobj2.get_attribute_myHexBinary()
        self.failUnlessEqual(myHexBinary, test)

        # DateTime stuff
        test = pyobj2.get_attribute_myDateTime()
        self.failUnlessEqual(myGDateTime[:-3], test[:-3])

        test = pyobj2.get_attribute_myDate()
        self.failUnlessEqual(myGDateTime[:3], test[:3])

        test = pyobj2.get_attribute_myTime()
        self.failUnlessEqual(myGDateTime[4:5], test[4:5])

        test = pyobj.get_attribute_myDuration()
        self.failUnlessEqual(myGDateTime, test)

        # Bug [ 1453421 ] Incorrect format for type gDay
        test = pyobj2.get_attribute_myGDay()
        self.failUnlessEqual(myGDateTime[2], test[2])

        test = pyobj2.get_attribute_myGMonth()
        self.failUnlessEqual(myGDateTime[1], test[1])

        test = pyobj2.get_attribute_myGYear()
        self.failUnlessEqual(myGDateTime[0], test[0])

        test = pyobj2.get_attribute_myGYearMonth()
        self.failUnlessEqual(myGDateTime[:2], test[:2])
Example #27
0
        else:
            request, result = method(ps)
    except FaultException, e:
        return SendFault(FaultFromFaultException(e))
    except Exception, e:
        logger.exception("Caught an exception")
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Verify if Signed
    service.verify(ps)

    # If No response just return.
    if result is None:
        return SendResponse('', **kw)

    sw = SoapWriter(nsdict=nsdict)
    try:
        sw.serialize(result)
    except Exception, e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    if isWSResource is True:
        action = service.getResponseAction(ps, action)
        addressRsp = Address(action=action)
        try:
            addressRsp.setResponseFromWSAddress(address, localURL)
            addressRsp.serialize(sw)
        except Exception, e:
            return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Create Signatures
def _Dispatch(ps, server, SendResponse, SendFault, post, action, nsdict={}, **kw):
    '''Send ParsedSoap instance to ServiceContainer, which dispatches to
    appropriate service via post, and method via action.  Response is a
    self-describing pyobj, which is passed to a SoapWriter.

    Call SendResponse or SendFault to send the reply back, appropriately.
        server -- ServiceContainer instance

    '''
    localURL = 'http://%s:%d%s' %(server.server_name,server.server_port,post)
    address = action
    service = server.getNode(post)
    isWSResource = False
    if isinstance(service, SimpleWSResource):
        isWSResource = True
        service.setServiceURL(localURL)
        address = Address()
        try:
            address.parse(ps)
        except Exception as e:
            return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
        if action and action != address.getAction():
            e = WSActionException('SOAP Action("%s") must match WS-Action("%s") if specified.' \
                %(action,address.getAction()))
            return SendFault(FaultFromException(e, 0, None), **kw)
        action = address.getAction()

    if isinstance(service, ServiceInterface) is False:
        e = NoSuchService('no service at POST(%s) in container: %s' %(post,server))
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    if not service.authorize(None, post, action):
        return SendFault(Fault(Fault.Server, "Not authorized"), code=401)
        #try:
        #    raise NotAuthorized()
        #except Exception, e:
            #return SendFault(FaultFromException(e, 0, None), code=401, **kw)
            ##return SendFault(FaultFromException(NotAuthorized(), 0, None), code=401, **kw)

    try:
        method = service.getOperation(ps, address)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    try:
        if isWSResource is True: 
            result = method(ps, address)
        else: 
            result = method(ps)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Verify if Signed
    service.verify(ps)

    # If No response just return.
    if result is None:
        return

    sw = SoapWriter(nsdict=nsdict)
    try:
        sw.serialize(result)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    if isWSResource is True:
        action = service.getResponseAction(action)
        addressRsp = Address(action=action)
        try:
            addressRsp.setResponseFromWSAddress(address, localURL)
            addressRsp.serialize(sw)
        except Exception as e:
            return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Create Signatures
    service.sign(sw)

    try:
        soapdata = str(sw)
        return SendResponse(soapdata, **kw)
    except Exception as e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
Example #29
0
    try:
        if isWSResource is True: 
            request,result = method(ps, address)
        else: 
            request,result = method(ps)
    except Exception, e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Verify if Signed
    service.verify(ps)

    # If No response just return.
    if result is None:
        return SendResponse('', **kw)

    sw = SoapWriter(nsdict=nsdict)
    try:
        sw.serialize(result)
    except Exception, e:
        return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    if isWSResource is True:
        action = service.getResponseAction(ps, action)
        addressRsp = Address(action=action)
        try:
            addressRsp.setResponseFromWSAddress(address, localURL)
            addressRsp.serialize(sw)
        except Exception, e:
            return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)

    # Create Signatures
Example #30
0
 def test_local_EchoBoolean(self):
     from ZSI.writer import SoapWriter
     msg = self.client_module.echoBooleanRequest()
     msg._inputBoolean = True
     sw = SoapWriter()
     sw.serialize(msg)
Example #31
0
                    serviceSOAPBinding.referencedWSGIFilters = \
                                    dict([(i, environ[i]) 
                                          for i in self.referencedFilterKeys])
                except KeyError:
                    raise ZSIMiddlewareConfigError('No filter ID "%s" found '
                                                   'in environ' % i)    
            ps = self.parseRequest(environ)
               
            # Map SOAP Action to method in binding class
            soapActionName = environ[
                            SOAPBindingMiddleware.SOAP_ACTION_ENVIRON_KEYNAME
                            ].strip('"')
            soapMethodName = SOAPBindingMiddleware.SOAP_METHOD_STRING % \
                            soapActionName
                    
            
            method = getattr(serviceSOAPBinding, soapMethodName)            
            resp = method(ps)
        except Exception, e:
            sw = self.exception2SOAPFault(environ, e)
        else: 
            # Serialize output using SOAP writer class
            sw = SoapWriter(outputclass=self.writerClass)
            sw.serialize(resp)
        
        # Make SoapWriter object available to any SOAP filters that follow
        self.setSOAPWriter(environ, sw)
        soapOut = str(sw)

        return self.writeResponse(environ, start_response)
Example #32
0
 def test_local_EchoBoolean(self):
     from ZSI.writer import SoapWriter
     msg = self.client_module.echoBooleanRequest()
     msg._inputBoolean = True
     sw = SoapWriter()
     sw.serialize(msg)
Example #33
0
    def test_local_attribute1(self):
        """
        """
        myDouble = 4.5
        myInt = 9
        myFloat = 3.0001
        myDecimal = 8.999
        myGDateTime = time.gmtime()
        myAnyURI = "urn:whatever"
        myQName = ("urn:test", "qbert")
        myString = "whatever"
        myHexBinary = hex(888)

        pyobj = GED("urn:example", "Test1").pyclass()
        # Test serialize/parse
        pyobj.set_attribute_myDecimal(myDecimal)
        pyobj.set_attribute_myDouble(myDouble)
        pyobj.set_attribute_myFloat(myFloat)
        pyobj.set_attribute_myInt(myInt)
        pyobj.set_attribute_myDateTime(myGDateTime)

        pyobj.set_attribute_myGDay(myGDateTime)
        pyobj.set_attribute_myGMonth(myGDateTime)
        pyobj.set_attribute_myGYear(myGDateTime)
        pyobj.set_attribute_myGYearMonth(myGDateTime)
        pyobj.set_attribute_myDate(myGDateTime)
        pyobj.set_attribute_myTime(myGDateTime)

        pyobj.set_attribute_myAnyURI(myAnyURI)
        pyobj.set_attribute_myString(myString)
        pyobj.set_attribute_myHexBinary(myHexBinary)
        pyobj.set_attribute_myDuration(myGDateTime)

        # Problems parsings
        pyobj.set_attribute_myQName(myQName)
        pyobj.set_attribute_myGMonthDay(myGDateTime)

        #TODO:
        #pyobj.set_attribute_myBase64Binary("")
        #pyobj.set_attribute_myNOTATION("NOT")

        sw = SoapWriter()
        sw.serialize(pyobj)
        soap = str(sw)

        ps = ParsedSoap(soap)
        pyobj2 = ps.Parse(pyobj.typecode)

        test = pyobj2.get_attribute_myInt()
        self.failUnlessEqual(myInt, test)

        test = pyobj2.get_attribute_myDouble()
        self.failUnlessEqual(myDouble, test)

        test = pyobj2.get_attribute_myFloat()
        self.failUnlessEqual(myFloat, test)

        test = pyobj2.get_attribute_myDecimal()
        self.failUnlessEqual(myDecimal, test)

        test = pyobj2.get_attribute_myAnyURI()
        self.failUnlessEqual(myAnyURI, test)

        test = pyobj2.get_attribute_myQName()
        self.failUnlessEqual(myQName, test)

        test = pyobj2.get_attribute_myString()
        self.failUnlessEqual(myString, test)

        test = pyobj2.get_attribute_myHexBinary()
        self.failUnlessEqual(myHexBinary, test)

        # DateTime stuff
        test = pyobj2.get_attribute_myDateTime()
        self.failUnlessEqual(myGDateTime[:-3], test[:-3])

        test = pyobj2.get_attribute_myDate()
        self.failUnlessEqual(myGDateTime[:3], test[:3])

        test = pyobj2.get_attribute_myTime()
        self.failUnlessEqual(myGDateTime[4:5], test[4:5])

        test = pyobj.get_attribute_myDuration()
        self.failUnlessEqual(myGDateTime, test)

        # Bug [ 1453421 ] Incorrect format for type gDay
        test = pyobj2.get_attribute_myGDay()
        self.failUnlessEqual(myGDateTime[2], test[2])

        test = pyobj2.get_attribute_myGMonth()
        self.failUnlessEqual(myGDateTime[1], test[1])

        test = pyobj2.get_attribute_myGYear()
        self.failUnlessEqual(myGDateTime[0], test[0])

        test = pyobj2.get_attribute_myGYearMonth()
        self.failUnlessEqual(myGDateTime[:2], test[:2])