Example #1
0
    def __init__(self, impl_or_constructor, get_context=None):
        init = False
        if callable(impl_or_constructor):
            # we are constructing a new object
            impl = impl_or_constructor()
            if impl is None:
                self.__dict__["_impl"] = impl
                self.__dict__["_attrs"] = EMPTY_ATTRS
                self.__dict__["_record"] = None
                from proton import ProtonException
                raise ProtonException(
                    "Wrapper failed to create wrapped object. Check for file descriptor or memory exhaustion."
                )
            init = True
        else:
            # we are wrapping an existing object
            impl = impl_or_constructor
            pn_incref(impl)

        if get_context:
            record = get_context(impl)
            attrs = pn_void2py(pn_record_get(record, PYCTX))
            if attrs is None:
                attrs = {}
                pn_record_def(record, PYCTX, PN_PYREF)
                pn_record_set(record, PYCTX, pn_py2void(attrs))
                init = True
        else:
            attrs = EMPTY_ATTRS
            init = False
            record = None
        self.__dict__["_impl"] = impl
        self.__dict__["_attrs"] = attrs
        self.__dict__["_record"] = record
        if init: self._init()
Example #2
0
    def __init__(self, impl_or_constructor, get_context=None):
        init = False
        if callable(impl_or_constructor):
            # we are constructing a new object
            impl = impl_or_constructor()
            if impl is None:
                self.__dict__["_impl"] = impl
                self.__dict__["_attrs"] = EMPTY_ATTRS
                self.__dict__["_record"] = None
                raise ProtonException(
                    "Wrapper failed to create wrapped object. Check for file descriptor or memory exhaustion.")
            init = True
        else:
            # we are wrapping an existing object
            impl = impl_or_constructor
            pn_incref(impl)

        if get_context:
            record = get_context(impl)
            attrs = pn_void2py(pn_record_get(record, PYCTX))
            if attrs is None:
                attrs = {}
                pn_record_def(record, PYCTX, PN_PYREF)
                pn_record_set(record, PYCTX, pn_py2void(attrs))
                init = True
        else:
            attrs = EMPTY_ATTRS
            init = False
            record = None
        self.__dict__["_impl"] = impl
        self.__dict__["_attrs"] = attrs
        self.__dict__["_record"] = record
        if init: self._init()
Example #3
0
 def wrap(impl):
     if impl is None:
         return None
     else:
         record = pn_reactor_attachments(impl)
         attrs = pn_void2py(pn_record_get(record, PYCTX))
         if attrs and 'subclass' in attrs:
             return attrs['subclass'](impl=impl)
         else:
             return Reactor(impl=impl)
Example #4
0
 def wrap(impl):
     if impl is None:
         return None
     else:
         record = pn_reactor_attachments(impl)
         attrs = pn_void2py(pn_record_get(record, PYCTX))
         if attrs and 'subclass' in attrs:
             return attrs['subclass'](impl=impl)
         else:
             return Reactor(impl=impl)
Example #5
0
        return dispatch(handler, self.type.method, self)


def _none(x):
    return None


DELEGATED = Constant("DELEGATED")


def _core(number, method):
    return EventType(number=number, method=method)


wrappers = {
    "pn_void": lambda x: pn_void2py(x),
    "pn_pyref": lambda x: pn_void2py(x),
    "pn_connection": lambda x: Connection.wrap(pn_cast_pn_connection(x)),
    "pn_session": lambda x: Session.wrap(pn_cast_pn_session(x)),
    "pn_link": lambda x: Link.wrap(pn_cast_pn_link(x)),
    "pn_delivery": lambda x: Delivery.wrap(pn_cast_pn_delivery(x)),
    "pn_transport": lambda x: Transport.wrap(pn_cast_pn_transport(x)),
    "pn_selectable": lambda x: Selectable.wrap(pn_cast_pn_selectable(x))
}


class Event(Wrapper, EventBase):
    REACTOR_INIT = _core(PN_REACTOR_INIT, "on_reactor_init")
    REACTOR_QUIESCED = _core(PN_REACTOR_QUIESCED, "on_reactor_quiesced")
    REACTOR_FINAL = _core(PN_REACTOR_FINAL, "on_reactor_final")
Example #6
0
                self.dispatch(h, type)

    def __repr__(self):
        return "%s(%r)" % (self._type, self.context)


def _core(number, method):
    return EventType(number=number, method=method)


def _internal(name):
    return EventType(name=name)


wrappers = {
    "pn_void": lambda x: pn_void2py(x),
    "pn_pyref": lambda x: pn_void2py(x),
    "pn_connection": lambda x: Connection.wrap(pn_cast_pn_connection(x)),
    "pn_session": lambda x: Session.wrap(pn_cast_pn_session(x)),
    "pn_link": lambda x: Link.wrap(pn_cast_pn_link(x)),
    "pn_delivery": lambda x: Delivery.wrap(pn_cast_pn_delivery(x)),
    "pn_transport": lambda x: Transport.wrap(pn_cast_pn_transport(x))
}


class Event(EventBase):
    TIMER_TASK = _core(PN_TIMER_TASK, "on_timer_task")

    CONNECTION_INIT = _core(PN_CONNECTION_INIT, "on_connection_init")
    CONNECTION_BOUND = _core(PN_CONNECTION_BOUND, "on_connection_bound")
    CONNECTION_UNBOUND = _core(PN_CONNECTION_UNBOUND, "on_connection_unbound")