Exemplo n.º 1
0
def throws(exception_cls: Type[Exception],
           handler_cls: Optional[Type['ExceptionHandler']] = None):
    """Decorator to use on methods."""
    if handler_cls is not None:
        handler = handler_cls()
    else:
        handler = None

    return annotate(ExceptionAnnotation(exception_cls, handler), unique=True)
Exemplo n.º 2
0
def register_global_exception(
        exception_class: Type[Exception]) -> Type[Exception]:
    assert issubclass(
        exception_class, Exception
    ), f'Class "{exception_class}" must be a subclass of Exception'
    annotation = GlobalExceptionAnnotation(exception_cls=exception_class)
    annotation_decorator = annotate(annotation, unique=True)
    annotation_decorator(exception_class)
    return exception_class
Exemplo n.º 3
0
def route(
    url_path: str,
    http_method: Optional[str] = None,
    produces: Optional[Tuple[MediaType]] = None,
    consumes: Optional[Tuple[MediaType]] = None,
):
    route_annotation = RouteAnnotation(url_path, http_method, produces,
                                       consumes)
    return annotate(route_annotation, single=True)
Exemplo n.º 4
0
 def wrapper(exception_class):
     assert issubclass(
         exception_class, Exception
     ), f'Class "{exception_class}" must be a subclass of Exception'
     annotation = ProblemAnnotation(handling_info=ProblemHandlingInfo(
         status=int(status),
         type=type,
         title=title,
         detail=detail,
     ), )
     annotation_decorator = annotate(annotation, unique=True)
     class_ = annotation_decorator(exception_class)
     return class_
Exemplo n.º 5
0
def simple_annotation(string: str):
    return annotate(SimpleAnnotation(string))
Exemplo n.º 6
0
def limits(*, default: Optional[int], maximum: Optional[int], redirect_to_default: bool = False):
    limits_ = Limits(default=default, maximum=maximum, redirect_to_default=redirect_to_default)
    annotation = LimitsAnnotation(limits_)
    return annotate(annotation, single=True)
Exemplo n.º 7
0
def no_authentication(controller_class):
    return annotate(NotNeedAuthentication(), single=True)(controller_class)
Exemplo n.º 8
0
def input_serializer(serializer_class: Type[Serializer], argument_name: str,
                     **serializer_kwargs):
    input_serializer_ = InputSerializer(serializer_class, serializer_kwargs,
                                        argument_name)
    return annotate(input_serializer_, single=True)
Exemplo n.º 9
0
 def wrapper(method):
     method = annotate(annotation)(method)
     output_processor = DRFOutputProcessor(serializer_class, serializer_kwargs)
     method = register_output_processor(method, output_processor)
     return method