Ejemplo n.º 1
0
    def render_json(self, obj, status_code):
        """
        returns json serialized objects
        :param obj: an object corresponding to a database entry.
        :return: json serialized objects.
        """

        return Response.get_formatted_response(Response(request=self.request, data=[obj]))
Ejemplo n.º 2
0
    def _handle_request(self, req: Request):
        uri = req.uri
        method = req.method
        filepath = self._static_dir + uri.split('?')[0]
        file = Path(filepath)
        status = ''
        if not file.exists():
            status = 404
        if file.is_dir() and filepath[-1:] == '/':
            filepath += 'index.html'
        elif file.is_dir():
            filepath += '/index.html'
        if req.method not in self._allowed_methods:
            status = 405
        i = filepath.rfind(".")

        if i != -1:
            file_type = filepath[i:]
        else:
            file_type = 'default'
        file_size = 0
        try:
            file_size = getsize(filepath)
            status = 200
        except FileNotFoundError:
            status = 404
            if filepath.split('/')[-1] == "index.html":
                status = 403
        if self._static_dir not in abspath(filepath):
            status = 403
        if method not in self._allowed_methods:
            status = 405
        #print(f'check response {Response(status=status, content_length=file_size, f_type=file_type, filename=filepath)}')
        return Response(status=status,
                        content_length=file_size,
                        f_type=file_type,
                        filename=filepath)
Ejemplo n.º 3
0
 def __init__(self):
     self.response = Response()
     # self.snmp_engine = SnmpEngine()
     self.context_data = ContextData()