def __init__(self, app): self.app = app self.app.transport = self.transport # FIXME: this is weird self.appinit() self.event_manager = EventManager(self) self.doc = AllYourInterfaceDocuments(app.interface)
def __init__(self, cls_name, cls_bases, cls_dict): super(ServiceBaseMeta, self).__init__(cls_name, cls_bases, cls_dict) self.__has_aux_methods = self.__aux__ is not None self.public_methods = {} self.event_manager = EventManager( self, self.__get_base_event_handlers(cls_bases)) for k, v in cls_dict.items(): if hasattr(v, '_is_rpc'): descriptor = v(_default_function_name=k) # these two lines are needed for staticmethod wrapping to work setattr(self, k, staticmethod(descriptor.function)) descriptor.reset_function(getattr(self, k)) try: getattr(self, k).descriptor = descriptor except AttributeError as e: pass # FIXME: this fails with builtins. Temporary hack while we # investigate whether we really need this or not descriptor.service_class = self self.public_methods[k] = descriptor if descriptor.aux is None: if self.__has_aux_methods and self.__aux__ is None: raise Exception( "You can't mix primary and " "auxiliary methods in a single service definition." ) else: self.__has_aux_methods = True
def __init__(self, tpt, max_buffer_size=2 * 1024 * 1024): assert isinstance(tpt, ServerBase), \ "%r is not a ServerBase instance" % tpt self.tpt = tpt self.max_buffer_size = max_buffer_size self.event_manager = EventManager(self)
def __init__(self, cls_name, cls_bases, cls_dict): super(ServiceBaseMeta, self).__init__(cls_name, cls_bases, cls_dict) self.__has_aux_methods = self.__aux__ is not None self.public_methods = {} self.event_manager = EventManager( self, self.__get_base_event_handlers(cls_bases)) for k, v in cls_dict.items(): if hasattr(v, '_is_rpc'): descriptor = v(_default_function_name=k) # these two lines are needed for staticmethod wrapping to work setattr(self, k, staticmethod(descriptor.function)) descriptor.reset_function(getattr(self, k)) getattr(self, k).descriptor = descriptor descriptor.service_class = self self.public_methods[k] = descriptor if descriptor.aux is None: if self.__has_aux_methods and self.__aux__ is None: raise Exception( "You can't mix primary and " "auxiliary methods in a single service definition." ) else: self.__has_aux_methods = True
def __init__(self, services, tns, name=None, prefix_namespace=None, names_parts_in_messages=None, in_protocol=None, out_protocol=None, config=None, classes=()): self.services = tuple(services) self.tns = tns self.name = name self.config = config self.classes = classes self.names_parts_in_messages = names_parts_in_messages if prefix_namespace is None: self.prefix_namespace = DEFAULT_PREFIX_NAMESPACE else: self.prefix_namespace = prefix_namespace if self.name is None: self.name = self.__class__.__name__.split('.')[-1] logger.info("Initializing application {%s}%s...", self.tns, self.name) self.event_manager = EventManager(self) self.error_handler = None 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() if self.out_protocol is None: from spyne.protocol import ProtocolBase self.out_protocol = ProtocolBase() self.check_unique_method_keys() # is this really necessary nowadays? # this needs to be after protocol assignments to give _static_when # functions as much info as possible about the application self.interface = Interface(self) # set_app needs to be after interface init because the protocols use it. 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 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)
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.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) self.reinitialize()
def __init__(self, app=None, validator=None, mime_type=None, ignore_uncap=False): self.__app = None self.validator = None self.set_app(app) self.event_manager = EventManager(self) self.set_validator(validator) self.ignore_uncap = ignore_uncap if mime_type is not None: self.mime_type = mime_type self._to_string_handlers = cdict({ ModelBase: lambda cls, value: cls.to_string(value), Time: time_to_string, Uuid: uuid_to_string, Null: null_to_string, Double: double_to_string, AnyXml: any_xml_to_string, Unicode: unicode_to_string, Boolean: boolean_to_string, Decimal: decimal_to_string, Integer: integer_to_string, AnyHtml: any_html_to_string, DateTime: datetime_to_string, Duration: duration_to_string, ByteArray: byte_array_to_string, Attachment: attachment_to_string, ComplexModelBase: complex_model_base_to_string, }) self._to_string_iterable_handlers = cdict({ File: file_to_string_iterable, ByteArray: byte_array_to_string_iterable, ModelBase: lambda prot, cls, value: cls.to_string_iterable(value), SimpleModel: simple_model_to_string_iterable, }) self._from_string_handlers = cdict({ Null: null_from_string, Time: time_from_string, Date: date_from_string, Uuid: uuid_from_string, File: file_from_string, Double: double_from_string, String: string_from_string, AnyXml: any_xml_from_string, Boolean: boolean_from_string, Integer: integer_from_string, Unicode: unicode_from_string, Decimal: decimal_from_string, AnyHtml: any_html_from_string, DateTime: datetime_from_string, Duration: duration_from_string, ByteArray: byte_array_from_string, Attachment: attachment_from_string, ComplexModelBase: complex_model_base_from_string })
def __init__(self, app=None, validator=None, mime_type=None, skip_depth=0, ignore_uncap=False): self.__app = None self.validator = None self.set_app(app) self.event_manager = EventManager(self) self.set_validator(validator) self.skip_depth = skip_depth self.ignore_uncap=ignore_uncap if mime_type is not None: self.mime_type = mime_type
def api_handler(request, service): service_handler = Settings.get_service_handler(service) if service_handler: logger.debug("Hitting service %s." % service) log = LogEntry( url="%s %s" % (request.method, request.get_full_path()), application=service) request_body = request.META["wsgi.input"].read( request._stream.remaining) request.META["wsgi.input"] = StringIO(request_body) request._stream = LimitedStream( request.META["wsgi.input"], request._stream.remaining) service_handler.event_manager.add_listener( "wsgi_close", partial(handle_wsgi_close, log=log)) service_handler.app.event_manager.add_listener( "method_call_exception", partial(handle_exception, log=log)) try: response = csrf_exempt(service_handler)(request) except Exception: log.traceback = unicode(traceback.format_exc(), errors="ignore") raise else: if response.content: log.response = response.content finally: if request_body: log.request = request_body log.save() service_handler.event_manager = EventManager(service_handler) service_handler.app.event_manager = EventManager( service_handler.app) return response else: msg = "Service %s not found" % service logger.info(msg) raise Http404(msg)
def __init__(self, app=None, mime_type=None, ignore_wrappers=None, binary_encoding=None): self.__app = None self.set_app(app) self.ignore_wrappers = ignore_wrappers self.event_manager = EventManager(self) self.binary_encoding = binary_encoding if self.binary_encoding is None: self.binary_encoding = self.default_binary_encoding if mime_type is not None: self.mime_type = mime_type self._attrcache = WeakKeyDictionary()
def __init__(self, app=None, validator=None, mime_type=None, ignore_uncap=False, ignore_wrappers=False): self.__app = None self.set_app(app) self.validator = None self.set_validator(validator) self.event_manager = EventManager(self) self.ignore_uncap = ignore_uncap self.ignore_wrappers = ignore_wrappers self.message = None if mime_type is not None: self.mime_type = mime_type self._to_string_handlers = cdict({ ModelBase: self.model_base_to_string, Time: self.time_to_string, Uuid: self.uuid_to_string, Null: self.null_to_string, Double: self.double_to_string, AnyXml: self.any_xml_to_string, Unicode: self.unicode_to_string, Boolean: self.boolean_to_string, Decimal: self.decimal_to_string, Integer: self.integer_to_string, AnyHtml: self.any_html_to_string, DateTime: self.datetime_to_string, Duration: self.duration_to_string, ByteArray: self.byte_array_to_string, Attachment: self.attachment_to_string, XmlAttribute: self.xmlattribute_to_string, ComplexModelBase: self.complex_model_base_to_string, }) self._to_string_iterable_handlers = cdict({ File: self.file_to_string_iterable, ByteArray: self.byte_array_to_string_iterable, ModelBase: self.model_base_to_string_iterable, SimpleModel: self.simple_model_to_string_iterable, ComplexModelBase: self.complex_model_to_string_iterable, }) self._from_string_handlers = cdict({ Null: self.null_from_string, Time: self.time_from_string, Date: self.date_from_string, Uuid: self.uuid_from_string, File: self.file_from_string, Double: self.double_from_string, String: self.string_from_string, AnyXml: self.any_xml_from_string, Boolean: self.boolean_from_string, Integer: self.integer_from_string, Unicode: self.unicode_from_string, Decimal: self.decimal_from_string, AnyHtml: self.any_html_from_string, DateTime: self.datetime_from_string, Duration: self.duration_from_string, ByteArray: self.byte_array_from_string, ModelBase: self.model_base_from_string, Attachment: self.attachment_from_string, ComplexModelBase: self.complex_model_base_from_string }) self._datetime_dsmap = { None: self._datetime_from_string, 'sec': self._datetime_from_sec, 'sec_float': self._datetime_from_sec_float, 'msec': self._datetime_from_msec, 'msec_float': self._datetime_from_msec_float, 'usec': self._datetime_from_usec, }
def __init__(self, tpt): assert isinstance(tpt, ServerBase) self.tpt = tpt self.event_manager = EventManager(self)
def __init__(self, interface): self.interface = interface self.event_manager = EventManager(self)
def __init__(self, app, base=MessagePackServerBase): self.app = app self.base = base self.event_manager = EventManager(self)
def __init__(self, app=None, validator=None, mime_type=None, ignore_uncap=False, ignore_wrappers=False, binary_encoding=None): self.validator = None self.set_validator(validator) self.__app = None self.set_app(app) self._attrcache = WeakKeyDictionary() self.event_manager = EventManager(self) self.ignore_uncap = ignore_uncap self.ignore_wrappers = ignore_wrappers self.message = None self.binary_encoding = binary_encoding if self.binary_encoding is None: self.binary_encoding = self.default_binary_encoding if mime_type is not None: self.mime_type = mime_type self._to_string_handlers = cdict({ ModelBase: self.model_base_to_string, File: self.file_to_string, Time: self.time_to_string, Uuid: self.uuid_to_string, Null: self.null_to_string, Double: self.double_to_string, AnyXml: self.any_xml_to_string, Unicode: self.unicode_to_string, Boolean: self.boolean_to_string, Decimal: self.decimal_to_string, Integer: self.integer_to_string, AnyHtml: self.any_html_to_string, DateTime: self.datetime_to_string, Duration: self.duration_to_string, ByteArray: self.byte_array_to_string, Attachment: self.attachment_to_string, XmlAttribute: self.xmlattribute_to_string, ComplexModelBase: self.complex_model_base_to_string, }) self._to_unicode_handlers = cdict({ ModelBase: self.model_base_to_unicode, File: self.file_to_unicode, Time: self.time_to_string, Uuid: self.uuid_to_string, Null: self.null_to_string, Double: self.double_to_string, AnyXml: self.any_xml_to_unicode, Unicode: self.unicode_to_unicode, Boolean: self.boolean_to_string, Decimal: self.decimal_to_string, Integer: self.integer_to_string, AnyHtml: self.any_html_to_unicode, # FIXME: Would we need a to_unicode for localized dates? DateTime: self.datetime_to_string, Duration: self.duration_to_string, ByteArray: self.byte_array_to_unicode, XmlAttribute: self.xmlattribute_to_unicode, ComplexModelBase: self.complex_model_base_to_string, }) self._to_string_iterable_handlers = cdict({ File: self.file_to_string_iterable, ByteArray: self.byte_array_to_string_iterable, ModelBase: self.model_base_to_string_iterable, SimpleModel: self.simple_model_to_string_iterable, ComplexModelBase: self.complex_model_to_string_iterable, }) fsh = { Null: self.null_from_string, Time: self.time_from_string, Date: self.date_from_string, Uuid: self.uuid_from_string, File: self.file_from_string, Array: self.array_from_string, Double: self.double_from_string, String: self.string_from_string, AnyXml: self.any_xml_from_string, Boolean: self.boolean_from_string, Integer: self.integer_from_string, Unicode: self.unicode_from_string, Decimal: self.decimal_from_string, AnyHtml: self.any_html_from_string, DateTime: self.datetime_from_string, Duration: self.duration_from_string, ByteArray: self.byte_array_from_string, EnumBase: self.enum_base_from_string, ModelBase: self.model_base_from_string, Attachment: self.attachment_from_string, XmlAttribute: self.xmlattribute_from_string, ComplexModelBase: self.complex_model_base_from_string } self._from_string_handlers = cdict(fsh) self._from_unicode_handlers = cdict(fsh) self._datetime_dsmap = { None: self._datetime_from_string, 'sec': self._datetime_from_sec, 'sec_float': self._datetime_from_sec_float, 'msec': self._datetime_from_msec, 'msec_float': self._datetime_from_msec_float, 'usec': self._datetime_from_usec, }
def __init__(self, interface): self.import_base_namespaces=True self.interface = interface self.event_manager = EventManager(self)
def __init__(self, app): self.app = app self.app.transport = self.transport self.event_manager = EventManager(self) self.doc = AllYourInterfaceDocuments(app.interface)