本文整理汇总了Python中spyne.protocol.ProtocolBase类的典型用法代码示例。如果您正苦于以下问题:Python ProtocolBase类的具体用法?Python ProtocolBase怎么用?Python ProtocolBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProtocolBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, services, tns, name=None,
in_protocol=None, out_protocol=None, interface=None):
self.services = tuple(services)
self.tns = tns
self.name = name
if self.name is None:
self.name = self.__class__.__name__.split('.')[-1]
self.event_manager = EventManager(self)
self.error_handler = None
self.interface = Interface(self)
self.in_protocol = in_protocol
self.out_protocol = out_protocol
if self.in_protocol is None:
from spyne.protocol import ProtocolBase
self.in_protocol = ProtocolBase(self)
else:
self.in_protocol.set_app(self)
if self.out_protocol is None:
from spyne.protocol import ProtocolBase
self.out_protocol = ProtocolBase(self)
else:
self.out_protocol.set_app(self)
register_application(self)
self.reinitialize()
示例2: __init__
def __init__(self, app=None, validator=None, xml_declaration=True,
cleanup_namespaces=False):
ProtocolBase.__init__(self, app, validator)
self.xml_declaration = xml_declaration
self.cleanup_namespaces = cleanup_namespaces
self.serialization_handlers = cdict({
AnyXml: xml_to_parent_element,
Alias: alias_to_parent_element,
Fault: fault_to_parent_element,
AnyDict: dict_to_parent_element,
EnumBase: enum_to_parent_element,
ModelBase: base_to_parent_element,
ByteArray: binary_to_parent_element,
Attachment: binary_to_parent_element,
ComplexModelBase: complex_to_parent_element,
})
self.deserialization_handlers = cdict({
AnyXml: xml_from_element,
Fault: fault_from_element,
AnyDict: dict_from_element,
EnumBase: enum_from_element,
ModelBase: base_from_element,
Unicode: unicode_from_element,
ByteArray: binary_from_element,
Attachment: binary_from_element,
ComplexModelBase: complex_from_element,
Iterable: iterable_from_element,
Array: array_from_element,
})
self.log_messages = (logger.level == logging.DEBUG)
示例3: test_custom_strftime
def test_custom_strftime(self):
s = ProtocolBase.strftime(datetime.date(1800, 9, 23),
"%Y has the same days as 1980 and 2008")
if s != "1800 has the same days as 1980 and 2008":
raise AssertionError(s)
print("Testing all day names from 0001/01/01 until 2000/08/01")
# Get the weekdays. Can't hard code them; they could be
# localized.
days = []
for i in range(1, 10):
days.append(datetime.date(2000, 1, i).strftime("%A"))
nextday = {}
for i in range(8):
nextday[days[i]] = days[i + 1]
startdate = datetime.date(1, 1, 1)
enddate = datetime.date(2000, 8, 1)
prevday = ProtocolBase.strftime(startdate, "%A")
one_day = datetime.timedelta(1)
testdate = startdate + one_day
while testdate < enddate:
if (testdate.day == 1 and testdate.month == 1 and
(testdate.year % 100 == 0)):
print("Testing century", testdate.year)
day = ProtocolBase.strftime(testdate, "%A")
if nextday[prevday] != day:
raise AssertionError(str(testdate))
prevday = day
testdate = testdate + one_day
示例4: __init__
def __init__(self, services, tns, name=None,
in_protocol=None, out_protocol=None, config=None):
self.services = tuple(services)
self.tns = tns
self.name = name
self.config = config
if self.name is None:
self.name = self.__class__.__name__.split('.')[-1]
self.event_manager = EventManager(self)
self.error_handler = None
self.interface = Interface(self)
self.in_protocol = in_protocol
self.out_protocol = out_protocol
if self.in_protocol is None:
from spyne.protocol import ProtocolBase
self.in_protocol = ProtocolBase()
self.in_protocol.set_app(self)
# FIXME: this normally is another parameter to set_app but it's kept
# separate for backwards compatibility reasons.
self.in_protocol.message = self.in_protocol.REQUEST
if self.out_protocol is None:
from spyne.protocol import ProtocolBase
self.out_protocol = ProtocolBase()
self.out_protocol.set_app(self)
# FIXME: this normally is another parameter to set_app but it's kept
# separate for backwards compatibility reasons.
self.out_protocol.message = self.out_protocol.RESPONSE
register_application(self)
示例5: _from_dict_value
def _from_dict_value(cls, class_, value, validator):
# validate raw input
if validator is cls.SOFT_VALIDATION:
if issubclass(class_, Unicode) and not isinstance(value, basestring):
raise ValidationError(value)
if issubclass(class_, Unicode) and not isinstance(value, unicode):
# Note that String is a subclass of Unicode
if not (issubclass(class_, String) and isinstance(value, str)):
value = ProtocolBase.from_string(class_, value)
elif issubclass(class_, Decimal) and not isinstance(value,
(int, long, float)):
raise ValidationError(value)
elif issubclass(class_, DateTime) and not (
isinstance(value, unicode) and
class_.validate_string(class_, value)):
raise ValidationError(value)
# get native type
if issubclass(class_, ComplexModelBase):
retval = cls._doc_to_object(class_, value, validator)
elif issubclass(class_, DateTime):
retval = ProtocolBase.from_string(class_, value)
else:
retval = value
# validate native type
if validator is cls.SOFT_VALIDATION and \
not class_.validate_native(class_, retval):
raise ValidationError(retval)
return retval
示例6: test_time
def test_time(self):
n = datetime.time(1, 2, 3, 4)
ret = ProtocolBase.to_string(Time, n)
self.assertEquals(ret, n.isoformat())
dt = ProtocolBase.from_string(Time, ret)
self.assertEquals(n, dt)
示例7: test_date
def test_date(self):
n = datetime.date(2011,12,13)
ret = ProtocolBase.to_string(Date, n)
self.assertEquals(ret, n.isoformat())
dt = ProtocolBase.from_string(Date, ret)
self.assertEquals(n, dt)
示例8: test_duration_xml_duration
def test_duration_xml_duration(self):
dur = datetime.timedelta(days=5 + 30 + 365, hours=1, minutes=1,
seconds=12, microseconds=8e5)
str1 = 'P400DT3672.8S'
str2 = 'P1Y1M5DT1H1M12.8S'
self.assertEquals(dur, ProtocolBase.from_string(Duration, str1))
self.assertEquals(dur, ProtocolBase.from_string(Duration, str2))
self.assertEquals(dur, ProtocolBase.from_string(Duration, ProtocolBase.to_string(Duration, dur)))
示例9: set_app
def set_app(self, value):
ProtocolBase.set_app(self, value)
self.validation_schema = None
if value:
from spyne.interface.xml_schema import XmlSchema
xml_schema = XmlSchema(value.interface)
xml_schema.build_validation_schema()
self.validation_schema = xml_schema.validation_schema
示例10: __init__
def __init__(self, app=None, validator=None, mime_type=None,
ignore_uncap=False, ignore_wrappers=True, complex_as=dict,
ordered=False):
ProtocolBase.__init__(self, app, validator, mime_type, ignore_uncap)
self.ignore_wrappers = ignore_wrappers
self.complex_as = complex_as
self.ordered = ordered
if ordered:
raise NotImplementedError('ordered == False')
self.stringified_types = (DateTime, Date, Time, Uuid, Duration,
AnyXml, AnyHtml)
示例11: _to_value
def _to_value(cls, class_, value, k=None):
if issubclass(class_, ComplexModelBase):
return cls._to_dict(class_, value, k)
if issubclass(class_, DateTime):
return ProtocolBase.to_string(class_, value)
if issubclass(class_, Decimal):
if class_.Attributes.format is None:
return value
else:
return ProtocolBase.to_string(class_, value)
return value
示例12: __init__
def __init__(
self,
app=None,
validator=None,
xml_declaration=True,
cleanup_namespaces=True,
encoding="UTF-8",
pretty_print=False,
):
ProtocolBase.__init__(self, app, validator)
self.xml_declaration = xml_declaration
self.cleanup_namespaces = cleanup_namespaces
self.encoding = encoding
self.pretty_print = pretty_print
self.serialization_handlers = cdict(
{
AnyXml: xml_to_parent_element,
Alias: alias_to_parent_element,
Fault: fault_to_parent_element,
AnyDict: dict_to_parent_element,
AnyHtml: html_to_parent_element,
EnumBase: enum_to_parent_element,
ModelBase: base_to_parent_element,
ByteArray: byte_array_to_parent_element,
Attachment: attachment_to_parent_element,
ComplexModelBase: complex_to_parent_element,
}
)
self.deserialization_handlers = cdict(
{
AnyXml: xml_from_element,
Fault: fault_from_element,
AnyDict: dict_from_element,
EnumBase: enum_from_element,
ModelBase: base_from_element,
Unicode: unicode_from_element,
ByteArray: byte_array_from_element,
Attachment: attachment_from_element,
ComplexModelBase: complex_from_element,
Alias: alias_from_element,
Iterable: iterable_from_element,
Array: array_from_element,
}
)
self.log_messages = logger.level == logging.DEBUG
self.parser = etree.XMLParser(remove_comments=True)
示例13: serialize
def serialize(self, ctx, message):
assert message in (self.REQUEST, self.RESPONSE)
self.event_manager.fire_event('before_serialize', ctx)
if ctx.out_error is not None:
ctx.out_document = [ProtocolBase.to_dict(ctx.out_error.__class__, ctx.out_error)]
else:
# get the result message
if message is self.REQUEST:
out_type = ctx.descriptor.in_message
elif message is self.RESPONSE:
out_type = ctx.descriptor.out_message
if out_type is None:
return
out_type_info = out_type._type_info
# instantiate the result message
out_instance = out_type()
# assign raw result to its wrapper, result_message
for i in range(len(out_type_info)):
attr_name = out_type_info.keys()[i]
setattr(out_instance, attr_name, ctx.out_object[i])
ctx.out_document = self._object_to_doc(out_type, out_instance,
skip_depth=self.skip_depth)
self.event_manager.fire_event('after_serialize', ctx)
示例14: test_limits
def test_limits(self):
try:
ProtocolBase.from_string(Integer, "1" * (Integer.__max_str_len__ + 1))
except:
pass
else:
raise Exception("must fail.")
ProtocolBase.from_string(UnsignedInteger, "-1") # This is not supposed to fail.
try:
UnsignedInteger.validate_native(-1) # This is supposed to fail.
except:
pass
else:
raise Exception("must fail.")
示例15: __init__
def __init__(self, app=None, validator=None):
"""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 XmlDocument protocol, but returns data in
<div> or <span> tags.
:param app: A spyne.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.
"""
ProtocolBase.__init__(self, app, validator)