def finish(self, chunk=None):
     '''
     重写服务的finish, 并存储返回值
     '''
     
     RequestHandler.finish(self, chunk=chunk)
     self.return_value = chunk
Example #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)
Example #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)
Example #4
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()})
Example #5
0
 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
Example #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()
                            })
Example #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()
Example #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)
Example #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()
Example #10
0
    def finish(self, chunk=None):

        commit_db()
        RequestHandler.finish(self, chunk=chunk)
 def done(self):
     RequestHandler.finish(self)
Example #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)
Example #13
0
File: base.py Project: bufferx/tns
 def finish(self, chunk=None):
     if not self.request.connection.stream.closed():
         RequestHandler.finish(self, chunk)
Example #14
0
 def finish(self, chunk=None):
     if not self.request.connection.stream.closed():
         RequestHandler.finish(self, chunk)
Example #15
0
 def finish(self, chunk=None):
     
     commit_db()
     RequestHandler.finish(self, chunk=chunk)
Example #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)