예제 #1
0
파일: request.py 프로젝트: aaronj1335/mesh
    def process(self, controller, request, response, mediators=None):
        message = 'processing request: %s' % request.description
        if self.verbose:
            message += '\n' + format_structure(request.data, abbreviate=True)
        log('info', message)

        if mediators:
            for mediator in mediators:
                try:
                    mediator.before_validation(self, request, response)
                    if response.status:
                        return response
                except StructuralError, exception:
                    error = exception.serialize()
                    log('info', 'request to %s failed during mediator', str(self))
                    return response(INVALID, error)
예제 #2
0
파일: request.py 프로젝트: siq-legacy/mesh
    def process(self, controller, request, response, mediators=None):
        if hasattr(request, 'headers') and request.headers.has_key('REMOTE_ADDR'):
            message = 'processing request: %s from %s' % (request.description, request.headers['REMOTE_ADDR'])
        else:
            message = 'processing request: %s' % (request.description)
        if self.verbose:
            message += '\n' + format_structure(request.data, abbreviate=True)
        log('info', message)

        if mediators:
            for mediator in mediators:
                try:
                    mediator.before_validation(self, request, response)
                    if response.status:
                        return response
                except StructuralError, exception:
                    error = exception.serialize()
                    log('info', 'request to %s failed during mediator', str(self))
                    return response(INVALID, error)
예제 #3
0
    def process(self, controller, request, response, mediators=None):
        if hasattr(request,
                   'headers') and request.headers.has_key('REMOTE_ADDR'):
            message = 'processing request: %s from %s' % (
                request.description, request.headers['REMOTE_ADDR'])
        else:
            message = 'processing request: %s' % (request.description)
        if self.verbose:
            message += '\n' + format_structure(request.data, abbreviate=True)
        log('info', message)

        if mediators:
            for mediator in mediators:
                try:
                    mediator.before_validation(self, request, response)
                    if response.status:
                        return response
                except StructuralError, exception:
                    error = exception.serialize()
                    log('info', 'request to %s failed during mediator',
                        str(self))
                    return response(INVALID, error)
예제 #4
0
파일: request.py 프로젝트: aaronj1335/mesh
        if not response.status:
            try:
                instance.dispatch(self, request, response, subject, data)
                if not response.status:
                    response.status = OK
            except StructuralError, exception:
                error = exception.serialize()
                log('exception', 'request to %s failed controller invocation', str(self))
                response(INVALID, error)
            except RequestError, exception:
                return response(exception.status, exception.content)

        if self.verbose and response.content:
            log('debug', 'response for request to %s:\n%s', request.description,
                format_structure(response.content, abbreviate=True))

        definition = self.responses.get(response.status)
        if not definition:
            if response.status in ERROR_STATUS_CODES and not response.content:
                return response
            else:
                log('error', 'response for %s has undeclared status code %s',
                    str(self), response.status)
                return response(SERVER_ERROR)

        if definition.schema:
            try:
                response.content = definition.schema.process(response.content, OUTGOING, request.serialized)
            except StructuralError, exception:
                log('error', 'response for %s failed schema validation\n%s\n%s',
예제 #5
0
파일: request.py 프로젝트: omersaeed/mesh
        definition = self.responses.get(response.status)
        if not definition:
            if response.status in ERROR_STATUS_CODES and not response.content:
                return response
            else:
                log('error', 'response for %s has undeclared status code %s',
                    str(self), response.status)
                return response(SERVER_ERROR)

        if definition.schema:
            try:
                response.content = definition.schema.process(response.content, OUTGOING, request.serialized)
            except StructuralError, exception:
                log('error', 'response for %s failed schema validation\n%s\n%s',
                    str(self), exception.format_errors(), format_structure(response.content))
                response.content = None
                return response(SERVER_ERROR)
        elif response.content:
            log('error', 'response for %s improperly specified content', str(self))
            return response(SERVER_ERROR)

    def validate(self, data):
        if self.batch:
            errors = []
            for item in data:
                try:
                    self._validate_data(item)
                except StructuralError, exception:
                    errors.append(exception)
                else:
예제 #6
0
파일: request.py 프로젝트: siq/mesh
                instance.dispatch(self, request, response, subject, data)
                if not response.status:
                    response.status = OK
            except StructuralError, exception:
                error = exception.serialize()
                log("exception", "request to %s failed controller invocation", str(self))
                response(INVALID, error)
            except RequestError, exception:
                return response(exception.status, exception.content)

        if self.verbose and response.content:
            log(
                "debug",
                "response for request to %s:\n%s",
                request.description,
                format_structure(response.content, abbreviate=True),
            )

        definition = self.responses.get(response.status)
        if not definition:
            if response.status in ERROR_STATUS_CODES and not response.content:
                return response
            else:
                log("error", "response for %s has undeclared status code %s", str(self), response.status)
                return response(SERVER_ERROR)

        if definition.schema:
            try:
                response.content = definition.schema.process(response.content, OUTGOING, request.serialized)
            except StructuralError, exception:
                log(
예제 #7
0
            try:
                instance.dispatch(self, request, response, subject, data)
                if not response.status:
                    response.status = OK
            except StructuralError, exception:
                error = exception.serialize()
                log('exception', 'request to %s failed controller invocation',
                    str(self))
                response(INVALID, error)
            except RequestError, exception:
                return response(exception.status, exception.content)

        if self.verbose and response.content:
            log('debug', 'response for request to %s:\n%s',
                request.description,
                format_structure(response.content, abbreviate=True))

        definition = self.responses.get(response.status)
        if not definition:
            if response.status in ERROR_STATUS_CODES and not response.content:
                return response
            else:
                log('error', 'response for %s has undeclared status code %s',
                    str(self), response.status)
                return response(SERVER_ERROR)

        if definition.schema:
            try:
                response.content = definition.schema.process(
                    response.content, OUTGOING, request.serialized)
            except StructuralError, exception: