Example #1
0
    def check_any_nill(self):
        result = ['23', {'a' : None, 'b': 5}]
        soap = str(SoapWriter().serialize(result, TC.Any(pname="NilRequest", nillable=True, aslist=True)))

        ps = ParsedSoap(soap)
        tc = TC.Any(nillable=True)
        pyobj = ps.Parse(tc)
Example #2
0
    def __call__(self, **params):
        # Pull out arguments that Send() uses
        kw = {}
        for key in ['auth_header', 'nsdict', 'requesttypecode', 'soapaction']:
            if params.has_key(key):
                kw[key] = params[key]
                del params[key]

        nsuri = self.namespace
        if nsuri is None:
            return self.binding.RPC(
                None,
                self.name,
                None,
                encodingStyle="http://schemas.xmlsoap.org/soap/encoding/",
                _args=params,
                replytype=TC.Any(self.name + "Response", aslist=False),
                **kw)

        return self.binding.RPC(
            None, (nsuri, self.name),
            None,
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/",
            _args=params,
            replytype=TC.Any((nsuri, self.name + "Response"), aslist=False),
            **kw)
Example #3
0
 def check_empty_array(self):
     """Empty Array returned as list()
     """
     data = []
     s = str(SoapWriter().serialize(data, TC.Any(aslist=True)))
     p = ParsedSoap(s).Parse(TC.Any())
     self.assertTrue(data == p, 'expecting "%s", got "%s"' % (data, p))
Example #4
0
 def check_empty_struct(self):
     """Empty Struct is None, maybe dict() makes more sense, but this
     is fairly hard to determine if not typed (which is the norm).
     """
     data = {}
     s = str(SoapWriter().serialize(data, TC.Any()))
     p = ParsedSoap(s).Parse(TC.Any())
     self.assertTrue(p == None, 'expecting "%s", got "%s"' % (None, p))
Example #5
0
    def check_valid_cast(self):
        text = "2002-10-10T17:00:00Z"
        tc = TC.gDateTime()
        data = tc.text_to_data(text, None, None)

        tct = TC.gTime()
        tcd = TC.gDate()
        self.assertEquals("2002-10-10", tcd.get_formatted_content(data), "Invalid cast from gDateTime to gDate")
        self.assertEquals("17:00:00Z", tct.get_formatted_content(data), "Invalid cast from gDateTime to gTime")
Example #6
0
 def check_any_dict_list_rpcenc(self):
     sw = SoapWriter()
     testObj = [{"a":1,"b":2}, {"d":4,"e":5}, {"f":{"x":9}, "g":[6,7.0]}]
     typecode = TC.Any(aslist=True)
     sw.serialize(testObj, typecode=typecode)
     xml = str(sw)
     ps = ParsedSoap(xml)
     result = TC.Any().parse(ps.body_root, ps)
     self.assertTrue(result == testObj)
Example #7
0
    def check_any_compound(self):
        # from zsi developer's guide
        xml = """
<tns:foo %(tns)s %(xsi)s %(soap)s>
    <tns:i xsi:type="SOAP-ENC:integer">12</tns:i>
    <tns:name xsi:type="SOAP-ENC:string">Hello world</tns:name>
</tns:foo>""" % NSDICT

        ps = ParsedSoap(xml, envelope=False)
        self.assertTrue(ps.Parse(TC.Any()) == {'i': 12, 'name': 'Hello world'})
        self.assertTrue(ps.Parse(TC.Any(aslist=True)) == [12, 'Hello world'])
Example #8
0
    def check_valid_cast(self):
        text = "2002-10-10T17:00:00Z"
        tc = TC.gDateTime()
        data = tc.text_to_data(text, None, None)

        tct = TC.gTime()
        tcd = TC.gDate()
        self.assertEquals("2002-10-10", tcd.get_formatted_content(data),
                          "Invalid cast from gDateTime to gDate")
        self.assertEquals("17:00:00Z", tct.get_formatted_content(data),
                          "Invalid cast from gDateTime to gTime")
Example #9
0
    def __call__(self, *args):
        nsuri = self.namespace
        if nsuri is None:
            return self.binding.RPC(
                None,
                self.name,
                args,
                encodingStyle="http://schemas.xmlsoap.org/soap/encoding/",
                replytype=TC.Any(self.name + "Response"))

        return self.binding.RPC(
            None, (nsuri, self.name),
            args,
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/",
            replytype=TC.Any((nsuri, self.name + "Response")))
Example #10
0
 def check_any_untyped_int(self):
     # from zsi developer's guide
     d = dict(value=12)
     d.update(NSDICT)
     xml = """<tns:i %(tns)s>12</tns:i>""" %NSDICT
     ps = ParsedSoap(xml, envelope=False)
     self.assertTrue(int(ps.Parse(TC.Any())) == 12)
Example #11
0
 def __call__(self, *args):
     return self.binding.RPC(
         None,
         self.name,
         args,
         encodingStyle="http://schemas.xmlsoap.org/soap/encoding/",
         replytype=TC.Any(self.name + "Response"))
Example #12
0
 def check_parse_microseconds(self):
     good = (1968, 4, 2, 13, 20, 15, 511, 0, 0)
     typecode = TC.gDateTime()
     data = typecode.text_to_data('1968-04-02T13:20:15.511', None, None)
     self.failUnless(
         data == good,
         'did not parse something %s, not equal %s' % (data, good))
Example #13
0
 def _check_date_timezone(self):
     correct = "2002-10-10"
     for t in [
             '2002-10-10-05:00', '2002-10-10+02:00', '2002-10-10+00:00',
             '2002-10-10Z'
     ]:
         self._check_data2data(TC.gDate(), t, correct, 'date')
Example #14
0
 def check_serialize_microseconds_lessZero(self):
     '''ignore negative microseconds
     '''
     bad = (1968, 4, 2, 13, 20, 15, -1, 0)
     typecode = TC.gDateTime()
     text = typecode.get_formatted_content(bad)
     typecode.get_formatted_content(bad)
Example #15
0
 def check_parse_microseconds2(self):
     good = (1968, 4, 2, 13 - time.timezone / 3600, 20, 15, 500, 0, 0)
     typecode = TC.gDateTime()
     data = typecode.text_to_data('1968-04-02T13:20:15.5Z', None, None)
     self.failUnless(
         data == good,
         'did not serialze correctly %s, not equal %s' % (data, good))
Example #16
0
    def _check_datetime_timezone(self):
        # UTC with local timezone offset
        # Base example from http://www.w3.org/TR/xmlschema11-2/#dateTime-lexical-mapping

        correct = "2002-10-10T17:00:00Z"
        for t in ['2002-10-10T12:00:00-05:00', '2002-10-10T19:00:00+02:00', '2002-10-10T17:00:00+00:00', '2002-10-10T17:00:00Z']:
            self._check_data2data(TC.gDateTime(), t, correct, 'dateTime')
Example #17
0
 def check_any_untyped_int(self):
     # from zsi developer's guide
     d = dict(value=12)
     d.update(NSDICT)
     xml = """<tns:i %(tns)s>12</tns:i>""" % NSDICT
     ps = ParsedSoap(xml, envelope=False)
     self.assertRaises(EvaluateException, ps.Parse, TC.Any())
Example #18
0
 def check_serialize_microseconds_lessZero(self):
     '''ignore negative microseconds
     '''
     bad = (1968, 4, 2, 13, 20, 15, -1, 0)
     typecode = TC.gDateTime()
     text = typecode.get_formatted_content(bad)
     typecode.get_formatted_content(bad)
def deserialize(objectToDeserialize):
    sw = SoapWriter(nsdict={}, header=True, outputclass=None,
                    encodingStyle=None)
    tc = TC.Any(pname=None, aslist=False)
    deserializedObject = sw.serialize(objectToDeserialize, tc).body
    root = etree.XML(str(deserializedObject))
    body = root[0]
    return etree.tostring(body, encoding='utf-8', pretty_print=True)
Example #20
0
 def check_any_typed_xsd_int(self):
     # from zsi developer's guide
     value = 12
     d = dict(value=value)
     d.update(NSDICT)
     xml = """<tns:i xsi:type="xsd:int" %(xsi)s %(soap)s %(tns)s %(xsd)s>%(value)d</tns:i>""" % d
     ps = ParsedSoap(xml, envelope=False)
     self.failUnless(ps.Parse(TC.Any()) == value)
Example #21
0
 def check_invalid_time(self):
     typecode = TC.gTime()
     for i in (
             '5:20:00',
             '13:20.5:00',
     ):
         self.failUnlessRaises(Exception, typecode.text_to_data, i, None,
                               None),
Example #22
0
 def check_any_typed_nonNegativeInteger(self):
     # from zsi developer's guide
     value = 12
     d = dict(value=value)
     d.update(NSDICT)
     xml = """<tns:i xsi:type="xsd:nonNegativeInteger" %(xsi)s %(soap)s %(tns)s %(xsd)s>%(value)d</tns:i>""" % d
     ps = ParsedSoap(xml, envelope=False)
     self.assertTrue(ps.Parse(TC.Any()) == value)
Example #23
0
 def check_serialize_microseconds(self):
     dateTime = '1968-04-02T13:20:15.511Z'
     typecode = TC.gDateTime()
     text = typecode.get_formatted_content(
         (1968, 4, 2, 13 - time.timezone / 3600, 20, 15, 511, 0, 0))
     self.failUnless(
         text == dateTime,
         'did not serialze correctly %s, not equal %s' % (text, dateTime))
Example #24
0
    def check_type_attribute_qname_in_default_ns(self):
        msg = """
<ns1:test xsi:type="int" xmlns:ns1="urn:vim25" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://www.w3.org/2001/XMLSchema">
100
</ns1:test>"""
        ps = ParsedSoap(msg, envelope=False)
        pyobj = ps.Parse(TC.Integer(pname=("urn:vim25", "test")))
Example #25
0
    def check_type_attribute_qname_in_default_ns(self):
        msg = """
<ns1:test xsi:type="ns1:myInt" xmlns:ns1="urn:vim25" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://www.w3.org/2001/XMLSchema">
100
</ns1:test>"""
        ps = ParsedSoap(msg, envelope=False)
        pyobj = ps.Parse(TC.AnyType(pname=("urn:vim25","test")))
        self.failUnless(pyobj == 100, 'failed to parse type in default ns')
Example #26
0
    def check_element_in_default_ns(self):
        msg = """
<test xsi:type="myInt" xmlns="urn:vim25" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
100
</test>"""
        ps = ParsedSoap(msg, envelope=False)
        pyobj = ps.Parse(TC.AnyType(pname=("urn:vim25","test")))
        self.failUnless(pyobj == 100, 'failed to parse element in default ns')
def listMembers(url):
    Binding.defaultHttpsTransport = HTTPSConnection2
    fp = open('soap_trace', 'w')
    b = Binding(url=url, tracefile=fp)
    reply = b.RPC(None,
                  'listMembers', [],
                  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/",
                  replytype=TC.Any("listMembersResponse", nillable=True))
    return reply['listMembersReturn']
Example #28
0
 def check_invalid_date(self):
     typecode = TC.gDate()
     for i in (
             '68-04-02',
             '1968-4-2',
             '1968/04/02',
             '04-02-1968',
     ):
         self.failUnlessRaises(Exception, typecode.text_to_data, i, None,
                               None),
Example #29
0
    def _check_datetime_timezone(self):
        # UTC with local timezone offset
        # Base example from http://www.w3.org/TR/xmlschema11-2/#dateTime-lexical-mapping

        correct = "2002-10-10T17:00:00Z"
        for t in [
                '2002-10-10T12:00:00-05:00', '2002-10-10T19:00:00+02:00',
                '2002-10-10T17:00:00+00:00', '2002-10-10T17:00:00Z'
        ]:
            self._check_data2data(TC.gDateTime(), t, correct, 'dateTime')
Example #30
0
 def check_parse_empty_string(self):
     # Empty String
     typecodes = list(TC.Any.parsemap.values())
     for tc in [c for c in list(TC.Any.parsemap.values()) if isinstance(c, TC.String)]:
         sw = SoapWriter()
         sw.serialize("", typecode=tc, typed=True)
         soap = str(sw)
         ps = ParsedSoap(soap)
         parsed = ps.Parse(TC.Any())
         self.assertEqual("", parsed)
Example #31
0
    def __parse_child(self, node):
        '''for rpc-style map each message part to a class in typesmodule
        '''
        try:
            tc = self.gettypecode(self.typesmodule, node)
        except:
            self.logger.debug('didnt find typecode for "%s" in typesmodule: %s', 
                node.localName, self.typesmodule)
            tc = TC.Any(aslist=1)
            return tc.parse(node, self.ps)

        self.logger.debug('parse child with typecode : %s', tc)
        try:
            return tc.parse(node, self.ps)
        except Exception:
            self.logger.debug('parse failed try Any : %s', tc)

        tc = TC.Any(aslist=1)
        return tc.parse(node, self.ps)
Example #32
0
 def check_parse_empty_all(self):
     # None
     skip = [TC.FPEnumeration, TC.Enumeration, TC.IEnumeration, TC.List, TC.Integer]
     for typeclass in [c for c in list(TC.__dict__.values()) if type(c) in [type,type] and not issubclass(c, TC.String) and issubclass(c, TC.SimpleType)]:
         if typeclass in skip: continue
         tc = typeclass()
         sw = SoapWriter()
         sw.serialize(None, typecode=tc, typed=True)
         soap = str(sw)
         ps = ParsedSoap(soap)
         parsed = ps.Parse(TC.Any())
         self.assertEqual(None, parsed)
Example #33
0
def soap_parse_ZSI(xml):
    ''' This function receives an XML SOAP and returns a dictionary. It is
    intended to be used inside a Node, this is why it raises a NodeParserError
    '''

    parsed_obj = None
    parsed_dict = dict()

    try:
        parsed_obj = ParsedSoap(xml)
        parsed_dict = parsed_obj.Parse(TC.Any())

    except Exception, e:
        print e
Example #34
0
    def check_gdates(self):
        def _assert_tc(tc, val, msg):
            self.assertEquals(val, tc.get_formatted_content(tc.text_to_data(val, None, None)), "%s: %s" % (msg, val))

        _assert_tc(TC.gYear(), '1984', "Invalid gYear")
        _assert_tc(TC.gYearMonth(), '1984-10', "Invalid gYearMonth")
        _assert_tc(TC.gMonth(), '--10', "Invalid gMonth")
        _assert_tc(TC.gMonthDay(), '--10-30', "Invalid gMonthDay")
        _assert_tc(TC.gDay(), '---30', "Invalid gDay")
        _assert_tc(TC.gDate(), '1984-10-30', "Invalid gDate")
Example #35
0
 def check_valid_dateTime(self):
     typecode = TC.gDateTime()
     for i in ('1968-04-02T13:20:00', '1968-04-02T13:20:15.5', 
         '1968-04-02T13:20:00-05:00', '1968-04-02T13:20:00Z'):
         data = typecode.text_to_data(i, None, None)
         text = typecode.get_formatted_content(data)
Example #36
0
 def _check_date_timezone(self):
     correct = "2002-10-10"
     for t in ['2002-10-10-05:00', '2002-10-10+02:00', '2002-10-10+00:00', '2002-10-10Z']:
         self._check_data2data(TC.gDate(), t, correct, 'date')
Example #37
0
 def _check_time_timezone(self):
     correct = "17:30:00Z"
     for t in ['12:30:00-05:00', '19:30:00+02:00', '17:30:00+00:00']:
         self._check_data2data(TC.gTime(), t, correct, 'time')
Example #38
0
 def _check_minimum(self):
     data = "0001-01-01T00:00:00.0000000-07:00"
     tc = TC.gDateTime()
     tc.text_to_data(data, None, None)
Example #39
0
 def broke_valid_time(self):
     typecode = TC.gTime()
     data = typecode.text_to_data('13:20:00-05:00', None, None)
Example #40
0
 def check_serialize_microseconds_1000(self):
     bad = (1968, 4, 2, 13, 20, 15, 1000, 0)
     typecode = TC.gDateTime()
     self.failUnlessRaises(ValueError, typecode.get_formatted_content, bad)
Example #41
0
 def check_parse_microseconds2(self):
     good = (1968, 4, 2, 13 - time.timezone / 3600, 20, 15, 500, 0, 0)
     typecode = TC.gDateTime()
     data = typecode.text_to_data('1968-04-02T13:20:15.5Z', None,None)
     self.failUnless(data == good,
         'did not serialze correctly %s, not equal %s' %(data, good))
Example #42
0
 def check_invalid_date(self):
     typecode = TC.gDate()
     for i in ('68-04-02', '1968-4-2', '1968/04/02', '04-02-1968',):
         self.failUnlessRaises(Exception, typecode.text_to_data, i, None, None),
Example #43
0
 def check_valid_date(self):
     typecode = TC.gDate()
     for i in ('1968-04-02', '-0045-01-01', '11968-04-02', '1968-04-02+05:00', '1968-04-02Z'):
         data = typecode.text_to_data(i, None, None)
         text = typecode.get_formatted_content(data)
Example #44
0
 def broke_invalid_time_bad_timeofday(self):
     typecode = TC.gTime()
     i = '13:65:00'
     self.failUnlessRaises(Exception, typecode.text_to_data, i, None, None)
Example #45
0
 def broke_invalid_time_no_seconds(self):
     typecode = TC.gTime()
     i = '13:20:'
     self.failUnlessRaises(Exception, typecode.text_to_data, i, None, None)
Example #46
0
 def check_invalid_time(self):
     typecode = TC.gTime()
     for i in ('5:20:00', '13:20.5:00',):
         self.failUnlessRaises(Exception, typecode.text_to_data, i, None, None),
Example #47
0
 def check_parse_microseconds(self):
     good = (1968, 4, 2, 13, 20, 15, 511, 0, 0)
     typecode = TC.gDateTime()
     data = typecode.text_to_data('1968-04-02T13:20:15.511', None, None)
     self.failUnless(data == good,
         'did not parse something %s, not equal %s' %(data,good))
Example #48
0
 def check_serialize_microseconds(self):
     dateTime = '1968-04-02T13:20:15.511Z'
     typecode = TC.gDateTime()
     text = typecode.get_formatted_content((1968, 4, 2, 13 - time.timezone / 3600, 20, 15, 511, 0, 0))
     self.failUnless(text == dateTime,
         'did not serialze correctly %s, not equal %s' %(text, dateTime))
Example #49
0
 def broke_invalid_date_april31(self):
     # No checks for valid date April 30 days
     typecode = TC.gDate()
     self.failUnlessRaises(Exception, typecode.text_to_data, '1968-04-31', None, None),
Example #50
0
 def check_valid_time(self):
     typecode = TC.gTime()
     for i in ('13:20:00', '13:20:30.5555', '13:20:00Z'):
         data = typecode.text_to_data(i, None, None)
         text = typecode.get_formatted_content(data)
Example #51
0
 def check_invalid_dateTime(self):
     typecode = TC.gDateTime()