Exemplo n.º 1
0
Arquivo: route.py Projeto: zxy-zxy/hug
    def __call__(self, method_or_class=None, **kwargs):
        if not method_or_class and kwargs:
            return self.where(**kwargs)

        if isinstance(method_or_class, (MethodType, FunctionType)):
            routes = getattr(method_or_class, '_hug_http_routes', [])
            routes.append(self.route)
            method_or_class._hug_http_routes = routes
            return method_or_class

        instance = method_or_class
        if isinstance(method_or_class, type):
            instance = method_or_class()

        for argument in dir(instance):
            argument = getattr(instance, argument, None)

            http_routes = getattr(argument, '_hug_http_routes', ())
            for route in http_routes:
                http(**self.where(**route).route)(argument)

            cli_routes = getattr(argument, '_hug_cli_routes', ())
            for route in cli_routes:
                cli(**self.where(**route).route)(argument)

        return method_or_class
Exemplo n.º 2
0
        def decorator(class_definition):
            instance = class_definition
            if isinstance(class_definition, type):
                instance = class_definition()

            router = self.urls(urls if urls else "/{0}".format(instance.__class__.__name__.lower()), **route_data)
            for method in HTTP_METHODS:
                handler = getattr(instance, method.lower(), None)
                if handler:
                    routes = getattr(handler, '_hug_routes', None)
                    if routes:
                        for route in routes:
                            http(**router.accept(method).where(**route).route)(handler)
                    else:
                        http(**router.accept(method).route)(handler)
            return class_definition
Exemplo n.º 3
0
    def __call__(self, method_or_class):
        if isinstance(method_or_class, (MethodType, FunctionType)):
            routes = getattr(method_or_class, '_hug_routes', [])
            routes.append(self.route)
            method_or_class._hug_routes = routes
            return method_or_class

        instance = method_or_class
        if isinstance(method_or_class, type):
            instance = method_or_class()

        for argument in dir(instance):
            argument = getattr(instance, argument, None)
            routes = getattr(argument, '_hug_routes', None)
            if routes:
                for route in routes:
                    http(**self.where(**route).route)(argument)

        return method_or_class
Exemplo n.º 4
0
 def http(self, *args, **kwargs):
     """Starts the process of building a new HTTP route linked to this API instance"""
     kwargs['api'] = self.api
     return http(*args, **kwargs)
Exemplo n.º 5
0
 def trace(self, *args, **kwargs):
     """Builds a new TRACE HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("TRACE", )
     return http(*args, **kwargs)
Exemplo n.º 6
0
 def put_post(self, *args, **kwargs):
     """Builds a new PUT or POST HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("PUT", "POST")
     return http(*args, **kwargs)
Exemplo n.º 7
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def get(self, *args, **kwargs):
     """Builds a new GET HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('GET', )
     return http(*args, **kwargs)
Exemplo n.º 8
0
 def patch(self, *args, **kwargs):
     """Builds a new PATCH HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("PATCH", )
     return http(*args, **kwargs)
Exemplo n.º 9
0
 def get_post(self, *args, **kwargs):
     """Builds a new GET or POST HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('GET', 'POST')
     return http(*args, **kwargs)
Exemplo n.º 10
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def delete(self, *args, **kwargs):
     """Builds a new DELETE HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('DELETE', )
     return http(*args, **kwargs)
Exemplo n.º 11
0
 def head(self, *args, **kwargs):
     """Builds a new HEAD HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('HEAD', )
     return http(*args, **kwargs)
Exemplo n.º 12
0
 def patch(self, *args, **kwargs):
     """Builds a new PATCH HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('PATCH', )
     return http(*args, **kwargs)
Exemplo n.º 13
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def put_post(self, *args, **kwargs):
     """Builds a new PUT or POST HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('PUT', 'POST')
     return http(*args, **kwargs)
Exemplo n.º 14
0
 def delete(self, *args, **kwargs):
     """Builds a new DELETE HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('DELETE', )
     return http(*args, **kwargs)
Exemplo n.º 15
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def trace(self, *args, **kwargs):
     """Builds a new TRACE HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('TRACE', )
     return http(*args, **kwargs)
Exemplo n.º 16
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def patch(self, *args, **kwargs):
     """Builds a new PATCH HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('PATCH', )
     return http(*args, **kwargs)
Exemplo n.º 17
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def options(self, *args, **kwargs):
     """Builds a new OPTIONS HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('OPTIONS', )
     return http(*args, **kwargs)
Exemplo n.º 18
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def head(self, *args, **kwargs):
     """Builds a new HEAD HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('HEAD', )
     return http(*args, **kwargs)
Exemplo n.º 19
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def connect(self, *args, **kwargs):
     """Builds a new CONNECT HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('CONNECT', )
     return http(*args, **kwargs)
Exemplo n.º 20
0
 def connect(self, *args, **kwargs):
     """Builds a new CONNECT HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('CONNECT', )
     return http(*args, **kwargs)
Exemplo n.º 21
0
 def get(self, *args, **kwargs):
     """Builds a new GET HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("GET", )
     return http(*args, **kwargs)
Exemplo n.º 22
0
 def options(self, *args, **kwargs):
     """Builds a new OPTIONS HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('OPTIONS', )
     return http(*args, **kwargs)
Exemplo n.º 23
0
 def delete(self, *args, **kwargs):
     """Builds a new DELETE HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("DELETE", )
     return http(*args, **kwargs)
Exemplo n.º 24
0
 def trace(self, *args, **kwargs):
     """Builds a new TRACE HTTP route that is registered to this API"""
     kwargs['api'] = self.api
     kwargs['accept'] = ('TRACE', )
     return http(*args, **kwargs)
Exemplo n.º 25
0
 def connect(self, *args, **kwargs):
     """Builds a new CONNECT HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("CONNECT", )
     return http(*args, **kwargs)
Exemplo n.º 26
0
 def head(self, *args, **kwargs):
     """Builds a new HEAD HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("HEAD", )
     return http(*args, **kwargs)
Exemplo n.º 27
0
 def options(self, *args, **kwargs):
     """Builds a new OPTIONS HTTP route that is registered to this API"""
     kwargs["api"] = self.api
     kwargs["accept"] = ("OPTIONS", )
     return http(*args, **kwargs)
Exemplo n.º 28
0
 def urls(self, *kargs, **kwargs):
     """Starts the process of building a new URL route linked to this API instance"""
     kwargs['api'] = self.api
     return http(*kargs, **kwargs)
Exemplo n.º 29
0
Arquivo: route.py Projeto: zxy-zxy/hug
 def http(self, *args, **kwargs):
     """Starts the process of building a new HTTP route linked to this API instance"""
     kwargs['api'] = self.api
     return http(*args, **kwargs)