Пример #1
0
    def get_cls_attrs(self, cls):
        attr = self._attrcache.get(cls, None)
        if attr is not None:
            return attr

        self._attrcache[cls] = attr = DefaultAttrDict([
                (k, getattr(cls.Attributes, k))
                        for k in dir(cls.Attributes) + META_ATTR
                                                     if not k.startswith('__')])

        if cls.Attributes.prot_attrs:
            cls_attrs = cls.Attributes.prot_attrs.get(self.__class__, {})
            # logger.debug("%r cls attr %r", cls, cls_attrs)
            attr.update(cls_attrs)

            inst_attrs = cls.Attributes.prot_attrs.get(self, {})
            # logger.debug("%r inst attr %r", cls, cls_attrs)
            attr.update(inst_attrs)

        return attr
Пример #2
0
    def __init__(self, function, in_message, out_message, doc, is_callback,
                 is_async, mtom, in_header, out_header, faults, parent_class,
                 port_type, no_ctx, udd, class_key, aux, patterns, body_style,
                 args, operation_name, no_self, translations, when,
                 static_when, service_class, href, internal_key_suffix,
                 default_on_null, event_managers, logged):

        self.__real_function = function
        """The original callable for the user code."""

        self.reset_function()

        self.operation_name = operation_name
        """The base name of an operation without the request suffix, as
        generated by the ``@srpc`` decorator."""

        self.internal_key_suffix = internal_key_suffix
        """A string that is appended to the internal key string. Helpful when
        generating services programmatically."""

        self.in_message = in_message
        """A :class:`spyne.model.complex.ComplexModel` subclass that defines the
        input signature of the user function and that was automatically
        generated by the ``@srpc`` decorator."""

        self.name = None
        """The public name of the function. Equals to the type_name of the
        in_message."""

        if body_style is BODY_STYLE_BARE:
            self.name = in_message.Attributes.sub_name

        if self.name is None:
            self.name = self.in_message.get_type_name()

        self.out_message = out_message
        """A :class:`spyne.model.complex.ComplexModel` subclass that defines the
        output signature of the user function and that was automatically
        generated by the ``@srpc`` decorator."""

        self.doc = doc
        """The function docstring."""

        # these are not working, so they are not documented.
        self.is_callback = is_callback
        self.is_async = is_async
        self.mtom = mtom
        #"""Flag to indicate whether to use MTOM transport with SOAP."""
        self.port_type = port_type
        #"""The portType this function belongs to."""

        self.in_header = in_header
        """An iterable of :class:`spyne.model.complex.ComplexModel`
        subclasses to denote the types of header objects that this method can
        accept."""

        self.out_header = out_header
        """An iterable of :class:`spyne.model.complex.ComplexModel`
        subclasses to denote the types of header objects that this method can
        emit along with its return value."""

        self.faults = faults
        """An iterable of :class:`spyne.model.fault.Fault` subclasses to denote
        the types of exceptions that this method can throw."""

        self.no_ctx = no_ctx
        """no_ctx: Boolean flag to denote whether the user code gets an
        implicit :class:`spyne.MethodContext` instance as first argument."""

        self.udd = DefaultAttrDict(**udd)
        """Short for "User Defined Data", this is an empty DefaultAttrDict that
        can be updated by the user to pass arbitrary metadata via the ``@rpc``
        decorator."""

        self.class_key = class_key
        """ The identifier of this method in its parent
        :class:`spyne.service.Service` subclass."""

        self.aux = aux
        """Value to indicate what kind of auxiliary method this is. (None means
        primary)

        Primary methods block the request as long as they're running. Their
        return values are returned to the client. Auxiliary ones execute
        asyncronously after the primary method returns, and their return values
        are ignored by the rpc layer.
        """

        self.patterns = patterns
        """This list stores patterns which will match this callable using
        various elements of the request protocol.

        Currently, the only object supported here is the
        :class:`spyne.protocol.http.HttpPattern` object.
        """

        self.body_style = body_style
        """One of (BODY_STYLE_EMPTY, BODY_STYLE_BARE, BODY_STYLE_WRAPPED)."""

        self.args = args
        """A sequence of the names of the exposed arguments, or None."""

        self.no_self = no_self
        """When False, this passes self as first argument (before ctx) to the
        decorated function. This is what separates ``@rpc`` and ``@mrpc``."""

        self.service_class = service_class
        """The Service subclass the method belongs to. If not None for
        ``@mrpc`` methods, a Service subclass for anything else."""

        self.parent_class = parent_class
        """The ComplexModel subclass the method belongs to. Only set for
        ``@mrpc`` methods."""

        self.default_on_null = default_on_null
        if parent_class is None and not (default_on_null is False):
            raise LogicError("default_on_null is only to be used inside @mrpc")

        # HATEOAS Stuff
        self.translations = translations
        """None or a dict of locale-translation pairs."""

        self.href = href
        """None or a dict of locale-translation pairs."""

        self.when = when
        """None or a callable that takes an object instance and a
        :class:`MethodContext` and returns a boolean value. If this callable
        returns ``True``, the object can process that action.
        """

        self.static_when = static_when
        """None or a callable that takes an :class:`Application` instance and
        returns a boolean value. If true, the object can have that action
        registered in the interface document.
        """

        self.event_managers = event_managers
        """Event managers registered with this method."""

        self.logged = logged
        """Denotes the logging style for this method."""

        if self.service_class is not None:
            self.event_managers.append(self.service_class.event_manager)