@@ -0,0 +1,3196 @@
+import inspect%0A%0Afrom domainics.domobj.pagination import DPage%0Afrom domainics.domobj.pagination import parse_query_range, parse_header_range%0Afrom domainics.domobj import dset, dobject, DObject, DSet%0A%0A%0Afrom domainics.pillar import _pillar_history, pillar_class%0A%0Afrom redbean.handler_argument import register_argument_getter, read_json%0Afrom redbean.handler_response import register_response_writer%0A%0Afrom aiohttp.web import json_response%0Afrom redbean.json import json_dumps%0A%0A%0Adef setup(app):%0A    register_argument_getter(_dobject_value_getter)%0A    register_argument_getter(_dpage_value_getter)%0A    register_response_writer(_rest_dobject_response_factory)%0A%0A#----------------------------------------------------------------------------%0A%0Adef _dobject_value_getter(proto, method, handler, path_params, arg_name):%0A    arg_spec = inspect.signature(handler).parameters%5Barg_name%5D%0A    ann_type = arg_spec.annotation%0A%0A%0A    if issubclass(ann_type, DSet%5BDObject%5D):%0A        item_type = ann_type.__parameters__%5B0%5D%0A%0A        async def _getter(request):%0A            json_obj = await read_json(request)%0A            return dset(item_type)(json_obj)%0A%0A        return _getter%0A%0A    if issubclass(ann_type, DObject):%0A        async def _getter(request):%0A            json_obj = await read_json(request)%0A            return ann_type(json_obj)%0A%0A        return _getter%0A%0A%0Adef _dpage_value_getter(proto, method, handler, path_params, arg_name):%0A    arg_spec = inspect.signature(handler).parameters%5Barg_name%5D%0A    ann_type = arg_spec.annotation%0A%0A    if not issubclass(ann_type, DPage):%0A        return%0A%0A    async def getter(request, arg_val):%0A        pass%0A        # arg_val = make_pagination(handler)%0A        # # arg_val = ann_type(arg_val)%0A        # return arg_val%0A%0A    return getter%0A%0A%0A%0A%0A# ----------------------------------------------------------------------------%0Adef _rest_dobject_response_factory(proto, method, handler):%0A    if proto != 'REST':%0A        return%0A%0A    ret_type = inspect.signature(handler).return_annotation%0A    if not (issubclass(ret_type, DSet%5BDObject%5D)%0A            or issubclass(ret_type, DObject)%0A            or issubclass(ret_type, Mapping)%0A            or issubclass(ret_type, Sequence)):%0A        return%0A%0A    def _response(request, return_value):%0A        return json_response(return_value, dumps=json_dumps)%0A%0A    return _response%0A%0A#%0A#%0A# def service_func_handler(proto, service_func, service_name, path_sig) :%0A#%0A#     def rest_handler(self, *args, **kwargs):%0A#         obj = http_handler(self, *args, **kwargs)%0A#%0A#         if not isinstance(obj, (list, tuple, DSetBase)):%0A#             obj = %5Bobj%5D if obj is not None else %5B%5D%0A#%0A#         if isinstance(obj, DSetBase) and hasattr(obj, '_page'):%0A#             content_range = obj._page.format_content_range()%0A#             self.set_header('Content-Range', content_range)%0A#             if obj._page.start != 0 or obj._page.limit is not None:%0A#                 self.set_status(206)%0A#%0A#         self.set_header('Content-Type', 'application/json; charset=UTF-8')%0A#         self.write(_json.dumps(obj))%0A#%0A#     if proto == 'REST':%0A#         return rest_handler%0A#     elif proto == 'HTTP':%0A#         return http_handler%0A#     else:%0A#         raise ValueError('Unknown')%0A

support redbean