def finish(self, chunk=None):
     '''
     重写服务的finish, 并存储返回值
     '''
     
     RequestHandler.finish(self, chunk=chunk)
     self.return_value = chunk
示例#2
0
 def delete(self, *args, **kwargs):
     try:
         return orig_delete(self, *args, **kwargs)
     except Exception as e:
         RequestHandler.set_status(self, 500)
         RequestHandler.set_header(self, 'Content-Type', 'application/json')
         RequestHandler.set_header(self, 'Server', 'NeurDICOM')
         RequestHandler.write(self, json.dumps({'message': str(e)}))
         RequestHandler.finish(self)
示例#3
0
 def finish(self, chunk=None):
     self._chunk = chunk
     self.middleware_manager.run_response_hooks(self._chunk)
     rtn_content = b''.join(self._write_buffer)
     if chunk is not None:
         rtn_content += str(chunk)
     self.set_header("Content-Type", "application/json; charset=utf-8")
     if self._auto_finish and not self._finished:
         RequestHandler.finish(self, self._chunk)
示例#4
0
文件: base.py 项目: bufferx/twork
 def finish(self, chunk=None):
     if not self.request.connection.stream.closed():
         RequestHandler.finish(self, chunk)
         access_logger.info('',
                            extra={'version': 'V' + twork.version,
                                   'status': self.get_status(),
                                   'method': self.request.method,
                                   'remoteip': self.request.remote_ip,
                                   'uri': self.request.uri,
                                   'rt': '%.6f' % self.request.request_time()})
示例#5
0
文件: app.py 项目: jorviizheng/thr
 def finish(self, chunk=None):
     global running_exchanges
     if chunk is None or len(chunk) == 0:
         RequestHandler.finish(self)
     else:
         RequestHandler.finish(self, chunk)
     try:
         del(running_exchanges[self.__request_id])
     except KeyError:
         pass
示例#6
0
 def finish(self, chunk=None):
     if not self.request.connection.stream.closed():
         RequestHandler.finish(self, chunk)
         access_logger.info('',
                            extra={
                                'version': 'V' + twork.version,
                                'status': self.get_status(),
                                'method': self.request.method,
                                'remoteip': self.request.remote_ip,
                                'uri': self.request.uri,
                                'rt': '%.6f' % self.request.request_time()
                            })
示例#7
0
    async def send_file(h_request: RequestHandler,
                        fp: GridOut,
                        cache_time: int = 0):
        # If-Modified-Since header is only good to the second.
        modified = fp.upload_date.replace(microsecond=0)
        h_request.set_header("Last-Modified", modified)

        # MD5 is calculated on the MongoDB server when GridFS file is created
        h_request.set_header("Etag", f'"{fp.md5}"')

        mime_type = fp.content_type
        if not mime_type:
            mime_type = fp.metadata.get('contentType')

        # Starting from here, largely a copy of StaticFileHandler
        if mime_type:
            h_request.set_header("Content-Type", mime_type)

        if cache_time > 0:
            h_request.set_header(
                "Expires",
                datetime.utcnow() + timedelta(seconds=cache_time))
            h_request.set_header("Cache-Control", f"max-age={cache_time}")
        else:
            h_request.set_header("Cache-Control", "public")

        # Check the If-Modified-Since, and don't send the result if the
        # content has not been modified
        ims_value = h_request.request.headers.get("If-Modified-Since")
        if ims_value is not None:
            date_tuple = email.utils.parsedate(ims_value)

            # If our MotorClient is tz-aware, assume the naive ims_value is in
            # its time zone.
            if_since = datetime.fromtimestamp(
                time.mktime(date_tuple)).replace(tzinfo=modified.tzinfo)

            if if_since >= modified:
                h_request.set_status(304)
                return

        # Same for Etag
        etag = h_request.request.headers.get("If-None-Match")
        if etag is not None and etag.strip('"') == fp.md5:
            h_request.set_status(304)
            return

        h_request.set_header("Content-Length", fp.length)
        await fp.stream_to_handler(h_request)
        h_request.finish()
示例#8
0
async def trending(req: RequestHandler, start_url: str):
    lang = req.get_argument("lang", None)
    since = req.get_argument("since", None)
    url = start_url
    if lang is not None:
        lang = lang.replace('-shuo', '%23')
        url += lang
    params = None
    if since is not None:
        params = {'since': since}
    result = await get_trending(url=url, params=params)
    if result['count'] > 0:
        req.set_status(201)
    else:
        req.set_status(404)
    req.finish(result)
示例#9
0
    def send_file(handler: RequestHandler, file_name: str,
                  file_path: str) -> None:
        buf_size = 4096
        handler.set_header('Content-Type',
                           'application/octet-stream; charset=utf-8')
        handler.set_header(
            'Content-Disposition', "attachment; filename*=utf-8''{}".format(
                urllib.parse.quote(file_name, 'utf-8')))
        with open(file_path, 'rb') as f:
            while True:
                data = f.read(buf_size)
                if not data:
                    break
                handler.write(data)

        handler.finish()
示例#10
0
    def finish(self, chunk=None):

        commit_db()
        RequestHandler.finish(self, chunk=chunk)
 def done(self):
     RequestHandler.finish(self)
示例#12
0
 def finish(self, chunk=None):
     # add before-response hooks
     self._chunk = chunk
     self.tmiddleware.before_response_hooks(self._chunk)
     RequestHandler.finish(self, self._chunk)
示例#13
0
文件: base.py 项目: bufferx/tns
 def finish(self, chunk=None):
     if not self.request.connection.stream.closed():
         RequestHandler.finish(self, chunk)
示例#14
0
 def finish(self, chunk=None):
     if not self.request.connection.stream.closed():
         RequestHandler.finish(self, chunk)
示例#15
0
 def finish(self, chunk=None):
     
     commit_db()
     RequestHandler.finish(self, chunk=chunk)
示例#16
0
    def finish(self, chunk=None):
        self._chunk = chunk
        self.set_header("Content-Type", "application/json; charset=utf-8")

        if self._auto_finish and not self._finished:
            RequestHandler.finish(self, self._chunk)