コード例 #1
0
    def write_response(req: Request, res: Response) -> None:
        res.content_type = 'application/cbor'
        res.set_header('Access-Control-Allow-Origin', '*')

        if req.path.endswith('/_entry-names'):
            path = root_dir / req.path[1:-len('/_entry-names')]
            if path.is_file(): raise HTTPStatus(HTTP_404)
            res.data = cbor2.dumps(dict(
                type='plain-object',
                content=sorted([
                    re.sub(r'\.h5$', '', p.name) + ('/' if p.is_dir() else '')
                    for p in path.glob('[!_]*')
                ])
            ))

        elif req.path.endswith('/_meta'):
            key = req.path[1:-len('/_meta')]
            res.data = cbor2.dumps(_read_meta(root_dir, key))

        else:
            t_last = float(req.get_param('t_last') or 0) / 1000
            entry = _read(root_dir, req.path[1:], t_last)
            if entry['type'] == 'file':
                res.data = (root_dir / entry['content']).read_bytes()
            else:
                res.data = cbor2.dumps(entry)

        res.status = HTTP_200
コード例 #2
0
    def on_get(self, req: Request, resp: Response):
        consent = MessageApiCall.consent(req)

        self.req_to_message(req, resp, consent=consent)

        self.set_retargeting_segment(req, resp, consent=consent)

        resp.content_type = falcon.MEDIA_GIF
        resp.content_length = self.pixel_size
        resp.data = self.pixel_bytes
        resp.status = falcon.HTTP_200
コード例 #3
0
    def on_post(self, req: Request, resp: Response, *, eid: int = 0) -> None:
        if not eid == 0:
            raise ValueError()
        e = Estimator(self._lm)
        eid = id(e)
        self._estimators[eid] = e

        resp.data = json.dumps(
            {'eid': eid}
        ).encode('utf-8')
        resp.content_type = MEDIA_JSON
        resp.status = HTTP_201
        return
コード例 #4
0
    def on_get(self, req: Request, resp: Response, *, eid: int) -> None:
        self._root[eid].finish()

        words = self._root[eid].result

        if words is None:
            raise Exception()

        resp.data = json.dumps({
            'id': eid,
            'result': Word.to_str(words)
        }).encode('utf-8')

        resp.content_type = MEDIA_JSON
        resp.status = HTTP_200
コード例 #5
0
    def on_post(self, req: Request, resp: Response, *, eid: int) -> None:
        try:
            key_str = req.params['key']
        except Exception:
            raise Exception(req.params)

        klass = TagWord if TagWord.is_include(key_str) else int
        key: Key = Key([klass(key_str)])

        self._root[eid].add(key)
        words = self._root[eid].result

        resp.data = json.dumps({
            'eid': eid,
            'result': Word.to_str(words),
        }).encode('utf-8')
        resp.content_type = MEDIA_JSON
        resp.status = HTTP_200
コード例 #6
0
 def fetch(self, response: falcon.Response, identifier: str) -> None:
     response.data = self.__contents[identifier]
     response.content_type = "image/png"
     response.status = falcon.HTTP_OK