예제 #1
0
    def file_to_string_iterable(self, cls, value):
        if value.data is None:
            if value.handle is None:
                assert value.path is not None, "You need to write data to " \
                         "persistent storage first if you want to read it back."

                try:
                    path = value.path
                    if not isabs(value.path):
                        path = join(value.store, value.path)
                    f = open(path, 'rb')
                except IOError as e:
                    if e.errno == errno.ENOENT:
                        raise ResourceNotFoundError(value.path)
                    else:
                        raise InternalError("Error accessing requested file")

            else:
                f = value.handle
                f.seek(0)

            return _file_to_iter(f)

        else:
            if isinstance(value.data, (list,tuple)) and \
                                                isinstance(value.data[0], mmap):
                return _file_to_iter(value.data[0])
            else:
                return iter(value.data)
예제 #2
0
    def file_to_bytes_iterable(self, cls, value, **_):
        if value.data is not None:
            if isinstance(value.data, (list, tuple)) and \
                                                isinstance(value.data[0], mmap):
                return _file_to_iter(value.data[0])
            return iter(value.data)

        if value.handle is not None:
            f = value.handle
            f.seek(0)
            return _file_to_iter(f)

        assert value.path is not None, "You need to write data to " \
                 "persistent storage first if you want to read it back."

        try:
            path = value.path
            if not isabs(value.path):
                path = join(value.store, value.path)
                assert abspath(path).startswith(value.store), \
                                                 "No relative paths are allowed"
            return _file_to_iter(open(path, 'rb'))

        except IOError as e:
            if e.errno == errno.ENOENT:
                raise ResourceNotFoundError(value.path)
            else:
                raise InternalError("Error accessing requested file")
예제 #3
0
class Application(AppBase):
    def __init__(self,
                 services,
                 tns,
                 name=None,
                 in_protocol=None,
                 out_protocol=None,
                 db=None):
        AppBase.__init__(self, services, tns, name, in_protocol, out_protocol)

        self.event_manager.add_listener("method_call", _on_method_call)
        self.event_manager.add_listener("method_context_closed",
                                        _on_method_context_closed)

        self.db = db
        self.Session = sessionmaker(bind=db, expire_on_commit=False)

    def call_wrapper(self, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)

        except NoResultFound:
            raise ResourceNotFoundError(ctx.in_object)

        except Fault, e:
            log.err()
            raise

        except Exception, e:
            log.err()
            # This should not happen! Let the team know via email!
            if EXCEPTION_ADDRESS:
                email_exception(EXCEPTION_ADDRESS)
            raise InternalError(e)
예제 #4
0
class MyApplication(Application):
    def __init__(self, services, tns, name=None,
                                         in_protocol=None, out_protocol=None):
        Application.__init__(self, services, tns, name, in_protocol,
                                                                 out_protocol)

        self.event_manager.add_listener('method_call', _on_method_call)
        self.event_manager.add_listener("method_context_closed",
                                                    _on_method_context_closed)

    def call_wrapper(self, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)

        except NoResultFound:
            raise ResourceNotFoundError(ctx.in_object)

        except Fault, e:
            logger.error(e)
            raise

        except Exception, e:
            logger.exception(e)
            # This should not happen! Let the team know via email
            email_exception(EXCEPTION_ADDRESS)
            raise InternalError(e)
예제 #5
0
def _cb_deferred(ret, prot, p_ctx, others, nowrap=False):
    # if there is one return value or the output is bare (which means there
    # can't be anything other than 1 return value case) use the enclosing list.
    # otherwise, the return value is a tuple anyway, so leave it alone.
    if nowrap:
        p_ctx.out_object = ret

    else:
        if p_ctx.descriptor.is_out_bare():
            p_ctx.out_object = [ret]

        else:
            if len(p_ctx.descriptor.out_message._type_info) > 1:
                p_ctx.out_object = ret
            else:
                p_ctx.out_object = [ret]

    try:
        prot.spyne_tpt.get_out_string(p_ctx)
        prot.spyne_tpt.pack(p_ctx)

        out_string = b''.join(p_ctx.out_string)
        p_ctx.transport.resp_length = len(out_string)

        prot.enqueue_outresp_data(id(p_ctx), out_string)

    except Exception as e:
        logger.exception(e)
        logger.error("%r", p_ctx)
        prot.handle_error(p_ctx, others, InternalError(e))

    finally:
        p_ctx.close()

    process_contexts(prot.spyne_tpt, others, p_ctx)
예제 #6
0
class MyApplication(Application):
    def __init__(self,
                 services,
                 tns,
                 name=None,
                 in_protocol=None,
                 out_protocol=None):
        super(MyApplication, self).__init__(services, tns, name, in_protocol,
                                            out_protocol)

        self.event_manager.add_listener('method_call', _on_method_call)
        self.event_manager.add_listener("method_context_closed",
                                        _on_method_context_closed)

    def call_wrapper(self, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)

        except NoResultFound:
            raise ResourceNotFoundError(ctx.in_object)

        except Fault, e:
            logging.error(e)
            raise

        except Exception, e:
            logging.exception(e)
            raise InternalError(e)
예제 #7
0
def _eb_deferred(ret, request, p_ctx, others, resource):
    app = p_ctx.app

    # DRY this with what's in Application.process_request
    if issubclass(ret.type, Redirect):
        try:
            ret.value.do_redirect()

            # Now that the processing is switched to the outgoing message,
            # point ctx.protocol to ctx.out_protocol
            p_ctx.protocol = p_ctx.outprot_ctx

            _cb_deferred(None, request, p_ctx, others, resource, cb=False)

            # fire events
            app.event_manager.fire_event('method_redirect', p_ctx)
            if p_ctx.service_class is not None:
                p_ctx.service_class.event_manager.fire_event(
                    'method_redirect', p_ctx)

        except Exception as e:
            logger_server.exception(e)
            p_ctx.out_error = Fault('Server',
                                    get_fault_string_from_exception(e))

            # fire events
            app.event_manager.fire_event('method_redirect_exception', p_ctx)
            if p_ctx.service_class is not None:
                p_ctx.service_class.event_manager.fire_event(
                    'method_redirect_exception', p_ctx)

    elif issubclass(ret.type, Fault):
        p_ctx.out_error = ret.value

        ret = resource.handle_rpc_error(p_ctx, others, p_ctx.out_error,
                                        request)

        # fire events
        app.event_manager.fire_event('method_exception_object', p_ctx)
        if p_ctx.service_class is not None:
            p_ctx.service_class.event_manager.fire_event(
                'method_exception_object', p_ctx)

        request.write(ret)

    else:
        p_ctx.out_error = ret.value
        ret.printTraceback()
        p_ctx.out_error = InternalError(ret.value)

        # fire events
        app.event_manager.fire_event('method_exception_object', p_ctx)
        if p_ctx.service_class is not None:
            p_ctx.service_class.event_manager.fire_event(
                'method_exception_object', p_ctx)

    request.finish()
예제 #8
0
파일: http.py 프로젝트: tunks/spyne
def _eb_deferred(retval, request, p_ctx, others, resource):
    p_ctx.out_error = retval.value
    if not issubclass(retval.type, Fault):
        retval.printTraceback()
        p_ctx.out_error = InternalError(retval.value)

    ret = resource.handle_rpc_error(p_ctx, others, p_ctx.out_error, request)
    request.write(ret)
    request.finish()
예제 #9
0
파일: msgpack.py 프로젝트: jpunwin/spyne
def _eb_deferred(retval, prot, p_ctx, others):
    p_ctx.out_error = retval.value
    if not issubclass(retval.type, Fault):
        retval.printTraceback()
        p_ctx.out_error = InternalError(retval.value)

    ret = prot.handle_rpc_error(p_ctx, others, p_ctx.out_error)
    prot.transport.write(ret)
    prot.transport.loseConnection()
예제 #10
0
def _eb_deferred(fail, prot, p_ctx, others):
    assert isinstance(fail, Failure)

    if isinstance(fail.value, Fault):
        p_ctx.out_error = fail.value

    else:
        p_ctx.out_error = InternalError(fail.value)
        if not getattr(fail, 'logged', False):
            fail.printTraceback()

    prot.handle_error(p_ctx, others, p_ctx.out_error)
예제 #11
0
파일: msgpack.py 프로젝트: zhuhj89/spyne
def _eb_deferred(retval, prot, p_ctx, others):
    p_ctx.out_error = retval.value
    tb = None

    if isinstance(retval, Failure):
        tb = retval.getTracebackObject()
        retval.printTraceback()
        p_ctx.out_error = InternalError(retval.value)

    prot.handle_error(p_ctx, others, p_ctx.out_error)
    prot.transport.write(''.join(p_ctx.out_string))
    prot.transport.loseConnection()

    return Failure(p_ctx.out_error, p_ctx.out_error.__class__, tb)
예제 #12
0
    def call_wrapper(self, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)

        except NoResultFound:
            raise ResourceNotFoundError(ctx.in_object)

        except Fault as e:
            logging.error(e)
            raise

        except Exception as e:
            logging.exception(e)
            raise InternalError(e)
예제 #13
0
def _eb_deferred(fail, prot, p_ctx, others):
    assert isinstance(fail, Failure)

    if isinstance(fail.value, Fault):
        p_ctx.out_error = fail.value

    else:
        p_ctx.out_error = InternalError(fail.value)
        if not getattr(fail, 'logged', False):
            logger.error(fail.getTraceback())

    try:
        prot.handle_error(p_ctx, others, p_ctx.out_error)
    except Exception as e:
        logger.exception(e)
        raise
예제 #14
0
    def call_wrapper(self, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)

        except NoResultFound:
            raise ResourceNotFoundError(ctx.in_object)

        except Fault as e:
            log.err()
            raise

        except Exception as e:
            log.err()
            # This should not happen! Let the team know via email!
            if EXCEPTION_ADDRESS:
                email_exception(EXCEPTION_ADDRESS)
            raise InternalError(e)
 def CreateEvent(ctx, CreateEventInput: EventTicketRequest):
     create_event_url = ctx.udc.create_event_url
     # Get auth_key, event, list section, callback URL
     auth_key = ctx.udc.token
     event = CreateEventInput.event
     list_section = CreateEventInput.list_section
     callback_type = CreateEventInput.callback_type
     callback = CreateEventInput.callback
     # Create payload and request to create_event_url
     payload = create_request(event, list_section, callback, callback_type,
                              auth_key)
     camunda_resp = requests.post(create_event_url, json=payload)
     if camunda_resp.status_code == 404:
         raise ResourceNotFoundError(camunda_resp)
     elif not camunda_resp.ok:
         raise InternalError(Exception("Spyne Server Error"))
     return EventTicketResp(
         200,
         "Processing your input. Detail will be given to your callback URL")
예제 #16
0
def _eb_deferred(fail, prot, p_ctx, others):
    p_ctx.out_error = fail.value
    tb = None

    if isinstance(fail, Failure):
        tb = fail.getTracebackObject()
        fail.printTraceback()
        p_ctx.out_error = InternalError(fail.value)

    prot.handle_error(p_ctx, others, p_ctx.out_error)

    data_len = 0
    for data in p_ctx.out_string:
        prot.transport_write(data)
        data_len += len(data)

    p_ctx.transport.resp_length = data_len

    return Failure(p_ctx.out_error, p_ctx.out_error.__class__, tb)
예제 #17
0
def _eb_deferred(fail, prot, p_ctx, others):
    assert isinstance(fail, Failure)

    if isinstance(fail.value, Fault):
        p_ctx.out_error = fail.value

    else:
        p_ctx.out_error = InternalError(fail.value)
        if not getattr(fail, 'logged', False):
            fail.printTraceback()

    prot.handle_error(p_ctx, others, p_ctx.out_error)

    data_len = 0
    for data in p_ctx.out_string:
        prot.enqueue_outresp_data(id(p_ctx), data)
        data_len += len(data)

    p_ctx.transport.resp_length = data_len
예제 #18
0
class Application(SpyneApplication):
    """
    Замена Application из spyne. Позволяет дополнительно обрабатывать эксепшны

    файрит ивент, method_call_exception, но в аргументе передает не контекст,
    а форматированный текст exception
    """

    def call_wrapper(self, ctx):
        try:
            return super(Application, self).call_wrapper(ctx)
        except Fault, e:
            logger.exception(e)
            raise
        except Exception, e:
            e_text = unicode(format_exc(), errors="ignore")
            self.event_manager.fire_event("method_call_exception", e_text)
            logger.exception(e)
            raise InternalError(e)
예제 #19
0
파일: http.py 프로젝트: dsf459133415/spyne
def _eb_deferred(ret, request, p_ctx, others, resource):
    # DRY this with what's in Application.process_request
    if ret.check(Redirect):
        try:
            ret.value.do_redirect()

            # Now that the processing is switched to the outgoing message,
            # point ctx.protocol to ctx.out_protocol
            p_ctx.protocol = p_ctx.outprot_ctx

            _cb_deferred(None, request, p_ctx, others, resource, cb=False)

            p_ctx.fire_event('method_redirect')

        except Exception as e:
            logger_server.exception(e)
            p_ctx.out_error = Fault('Server',
                                    get_fault_string_from_exception(e))

            p_ctx.fire_event('method_redirect_exception')

    elif ret.check(Fault):
        p_ctx.out_error = ret.value

        ret = resource.handle_rpc_error(p_ctx, others, p_ctx.out_error,
                                        request)

        p_ctx.fire_event('method_exception_object')

        request.write(ret)

    else:
        p_ctx.out_error = InternalError(ret.value)
        logger.error(ret.getTraceback())

        ret = resource.handle_rpc_error(p_ctx, others, p_ctx.out_error,
                                        request)

        p_ctx.fire_event('method_exception_object')

        request.write(ret)

    request.finish()
예제 #20
0
    def _wrap(*args, **kwargs):
        self = args[0]

        try:
            retval = f(*args, **kwargs)
            self.session.expunge_all()
            return retval

        except NoResultFound:
            raise ResourceNotFoundError(self.ctx.in_object)

        except Fault as e:
            log.err()
            raise

        except Exception as e:
            log.err()
            # This should not happen! Let the team know via email!
            email_exception(EXCEPTION_ADDRESS)
            raise InternalError(e)
예제 #21
0
파일: msgpack.py 프로젝트: liaolifeng/spyne
    def _cb_deferred(self, ret, p_ctx, others, nowrap=False):
        # this means callback is not invoked directly instead of as part of a
        # deferred chain
        if not nowrap:
            # if there is one return value or the output is bare (which means
            # there can't be anything other than 1 return value case) use the
            # enclosing list. otherwise, the return value is a tuple anyway, so
            # leave it be.
            if p_ctx.descriptor.is_out_bare():
                p_ctx.out_object = [ret]

            else:
                if len(p_ctx.descriptor.out_message._type_info) > 1:
                    p_ctx.out_object = ret
                else:
                    p_ctx.out_object = [ret]

        if p_ctx.oob_ctx is not None:
            assert isinstance(p_ctx.oob_ctx.d, Deferred)

            p_ctx.oob_ctx.d.callback(p_ctx.out_object)
            return

        try:
            self.spyne_tpt.get_out_string(p_ctx)
            self.spyne_tpt.pack(p_ctx)

            out_string = b''.join(p_ctx.out_string)
            p_ctx.transport.resp_length = len(out_string)

            self.enqueue_outresp_data(id(p_ctx), out_string)

        except Exception as e:
            logger.exception(e)
            logger.error("%r", p_ctx)
            self.handle_error(p_ctx, others, InternalError(e))

        finally:
            p_ctx.close()

        process_contexts(self.spyne_tpt, others, p_ctx)
예제 #22
0
파일: msgpack.py 프로젝트: zhuhj89/spyne
def _cb_deferred(retval, prot, p_ctx, others, nowrap=False):
    if len(p_ctx.descriptor.out_message._type_info) > 1 or nowrap:
        p_ctx.out_object = retval
    else:
        p_ctx.out_object = [retval]

    try:
        prot._transport.get_out_string(p_ctx)
        prot._transport.pack(p_ctx)

        out_string = ''.join(p_ctx.out_string)
        prot.transport.write(out_string)

    except Exception as e:
        logger.exception(e)
        prot.handle_error(p_ctx, others, InternalError(e))

    finally:
        p_ctx.close()

    process_contexts(prot._transport, others, p_ctx)
예제 #23
0
    def process_contexts(self, contexts):
        p_ctx, others = contexts[0], contexts[1:]

        if p_ctx.in_error:
            return self.handle_error(p_ctx, others, p_ctx.in_error)

        self.get_in_object(p_ctx)
        if p_ctx.in_error:
            logger.error(p_ctx.in_error)
            return self.handle_error(p_ctx, others, p_ctx.in_error)

        self.get_out_object(p_ctx)
        if p_ctx.out_error:
            return self.handle_error(p_ctx, others, p_ctx.out_error)

        try:
            self.get_out_string(p_ctx)

        except Exception as e:
            logger.exception(e)
            contexts.out_error = InternalError("Serialization Error.")
            return self.handle_error(contexts, others, contexts.out_error)
예제 #24
0
def _cb_deferred(ret, prot, p_ctx, others, nowrap=False):
    if len(p_ctx.descriptor.out_message._type_info) > 1 or nowrap:
        p_ctx.out_object = ret
    else:
        p_ctx.out_object = [ret]

    try:
        prot.spyne_tpt.get_out_string(p_ctx)
        prot.spyne_tpt.pack(p_ctx)

        out_string = b''.join(p_ctx.out_string)
        p_ctx.transport.resp_length = len(out_string)

        prot.enqueue_outresp_data(id(p_ctx), out_string)

    except Exception as e:
        logger.exception(e)
        prot.handle_error(p_ctx, others, InternalError(e))

    finally:
        p_ctx.close()

    process_contexts(prot.spyne_tpt, others, p_ctx)