Example #1
0
 def __dump(self, value, write):
     try:
         f = self.dispatch[type(ensure_new_type(value))]
     except KeyError:
         # check if this object can be marshalled as a structure
         if not hasattr(value, '__dict__'):
             raise TypeError("cannot marshal %s objects" % type(value))
         # check if this class is a sub-class of a basic type,
         # because we don't know how to marshal these types
         # (e.g. a string sub-class)
         for type_ in type(value).__mro__:
             if type_ in self.dispatch.keys():
                 raise TypeError("cannot marshal %s objects" % type(value))
         # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
         # for the p3yk merge, this should probably be fixed more neatly.
         f = self.dispatch["_arbitrary_instance"]
     f(self, value, write)
Example #2
0
 def __dump(self, value, write):
     try:
         f = self.dispatch[type(ensure_new_type(value))]
     except KeyError:
         # check if this object can be marshalled as a structure
         if not hasattr(value, '__dict__'):
             raise TypeError("cannot marshal %s objects" % type(value))
         # check if this class is a sub-class of a basic type,
         # because we don't know how to marshal these types
         # (e.g. a string sub-class)
         for type_ in type(value).__mro__:
             if type_ in self.dispatch.keys():
                 raise TypeError("cannot marshal %s objects" % type(value))
         # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
         # for the p3yk merge, this should probably be fixed more neatly.
         f = self.dispatch["_arbitrary_instance"]
     f(self, value, write)
Example #3
0
    def test_ensure_new_type(self):
        s = u'abcd'
        s2 = str(s)
        self.assertEqual(ensure_new_type(s), s2)
        self.assertEqual(type(ensure_new_type(s)), str)

        b = b'xyz'
        b2 = bytes(b)
        self.assertEqual(ensure_new_type(b), b2)
        self.assertEqual(type(ensure_new_type(b)), bytes)

        i = 10000000000000
        i2 = int(i)
        self.assertEqual(ensure_new_type(i), i2)
        self.assertEqual(type(ensure_new_type(i)), int)

        l = []
        self.assertIs(ensure_new_type(l), l)
Example #4
0
    def test_ensure_new_type(self):
        s = u'abcd'
        s2 = str(s)
        self.assertEqual(ensure_new_type(s), s2)
        self.assertEqual(type(ensure_new_type(s)), str)

        b = b'xyz'
        b2 = bytes(b)
        self.assertEqual(ensure_new_type(b), b2)
        self.assertEqual(type(ensure_new_type(b)), bytes)

        i = 10000000000000
        i2 = int(i)
        self.assertEqual(ensure_new_type(i), i2)
        self.assertEqual(type(ensure_new_type(i)), int)

        l = []
        self.assertIs(ensure_new_type(l), l)
Example #5
0
 def dump_double(self, value, write):
     write("<value><double>")
     write(repr(ensure_new_type(value)))
     write("</double></value>\n")
Example #6
0
 def __repr__(self):
     return "<DateTime %r at %x>" % (ensure_new_type(self.value), id(self))
Example #7
0
 def __repr__(self):
     return "<Fault %s: %r>" % (ensure_new_type(
         self.faultCode), ensure_new_type(self.faultString))
Example #8
0
 def dump_double(self, value, write):
     write("<value><double>")
     write(repr(ensure_new_type(value)))
     write("</double></value>\n")
Example #9
0
 def __repr__(self):
     return "<DateTime %r at %x>" % (ensure_new_type(self.value), id(self))
Example #10
0
 def __repr__(self):
     return "<Fault %s: %r>" % (ensure_new_type(self.faultCode),
                                ensure_new_type(self.faultString))