def __init__(self, app=None, validator=None, xml_declaration=True): ProtocolBase.__init__(self, app, validator) self.xml_declaration = xml_declaration self.serialization_handlers = cdict({ ModelBase: base_to_parent_element, ByteArray: binary_to_parent_element, Attachment: binary_to_parent_element, ComplexModelBase: complex_to_parent_element, Fault: fault_to_parent_element, AnyXml: xml_to_parent_element, AnyDict: dict_to_parent_element, EnumBase: enum_to_parent_element, }) self.deserialization_handlers = cdict({ ModelBase: base_from_element, ByteArray: binary_from_element, Attachment: binary_from_element, ComplexModelBase: complex_from_element, Fault: fault_from_element, AnyXml: xml_from_element, AnyDict: dict_from_element, EnumBase: enum_from_element, Array: array_from_element, Iterable: iterable_from_element, }) self.log_messages = (logger.level == logging.DEBUG)
def __init__(self, app=None, validator=None, xml_declaration=True): ProtocolBase.__init__(self, app, validator) self.xml_declaration = xml_declaration self.serialization_handlers = cdict( { ModelBase: base_to_parent_element, ByteArray: binary_to_parent_element, Attachment: binary_to_parent_element, ComplexModelBase: complex_to_parent_element, Fault: fault_to_parent_element, AnyXml: xml_to_parent_element, AnyDict: dict_to_parent_element, EnumBase: enum_to_parent_element, } ) self.deserialization_handlers = cdict( { ModelBase: base_from_element, ByteArray: binary_from_element, Attachment: binary_from_element, ComplexModelBase: complex_from_element, Fault: fault_from_element, AnyXml: xml_from_element, AnyDict: dict_from_element, EnumBase: enum_from_element, Array: array_from_element, Iterable: iterable_from_element, } ) self.log_messages = logger.level == logging.DEBUG
def test_cdict(self): d = cdict() class A(object): pass class B(A): pass class C(A): pass class D(object): pass d[A] = 1 d[C] = 2 self.assertEquals(d[A], 1) self.assertEquals(d[B], 1) self.assertEquals(d[C], 2) try: d[D] raise Exception("Must fail") except KeyError: pass try: d[object] raise Exception("Must fail") except KeyError: pass
def test_cdict(self): d = cdict({A: "fun", object: "base"}) assert d[A] == "fun" assert d[B] == "fun" assert d[C] == "base" try: d[D] except KeyError: pass else: raise Exception("Must fail.")
def __init__(self, app=None, validator=None, root_tag='div', child_tag='div', field_name_attr='class', skip_depth=0): """Protocol that returns the response object as a html microformat. See https://en.wikipedia.org/wiki/Microformats for more info. The simple flavour is like the XmlObject protocol, but returns data in <div> or <span> tags. :param app: A rpclib.application.Application instance. :param validator: The validator to use. Ignored. :param root_tag: The type of the root tag that encapsulates the return data. :param child_tag: The type of the tag that encapsulates the fields of the returned object. :param field_name_attr: The name of the attribute that will contain the field names of the complex object children. :param field_type_attr: The name of the attribute that will contain the type names of the complex object children. """ HtmlBase.__init__(self, app, validator, skip_depth) assert root_tag in ('div','span') assert child_tag in ('div','span') assert field_name_attr in ('class','id') self.__root_tag = root_tag self.__child_tag = child_tag self.__field_name_attr = field_name_attr self.serialization_handlers = cdict({ ModelBase: self.serialize_model_base, ByteArray: not_supported, Attachment: not_supported, ComplexModelBase: self.serialize_complex_model, })
from rpclib.model.enum import EnumBase from rpclib.model.fault import Fault from rpclib.interface.xml_schema.model import simple_add from rpclib.interface.xml_schema.model.complex import complex_add from rpclib.interface.xml_schema.model.fault import fault_add from rpclib.interface.xml_schema.model.enum import enum_add from rpclib.interface.xml_schema.model import simple_get_restriction_tag from rpclib.interface.xml_schema.model.primitive import string_get_restriction_tag from rpclib.interface.xml_schema.model.primitive import decimal_get_restriction_tag _add_handlers = cdict({ object: lambda interface, cls: None, SimpleModel: simple_add, ComplexModelBase: complex_add, Fault: fault_add, EnumBase: enum_add, }) _get_restriction_tag_handlers = cdict({ object: lambda self, cls: None, SimpleModel: simple_get_restriction_tag, String: string_get_restriction_tag, Decimal: decimal_get_restriction_tag, }) _ns_xsd = rpclib.const.xml_ns.xsd _ns_wsa = rpclib.const.xml_ns.wsa _ns_wsdl = rpclib.const.xml_ns.wsdl _ns_soap = rpclib.const.xml_ns.soap