コード例 #1
0
ファイル: downloadhandler.py プロジェクト: mahak/heron
  def get(self, path):
    """ get method """

    logging.debug("request to download: %s", path)
    # If the file is large, we want to abandon downloading
    # if user cancels the requests.
    # pylint: disable=attribute-defined-outside-init
    self.connection_closed = False

    self.set_header("Content-Disposition", "attachment")
    if not utils.check_path(path):
      self.write("Only relative paths are allowed")
      self.set_status(403)
      self.finish()
      return

    if path is None or not os.path.isfile(path):
      self.write("File %s  not found" % path)
      self.set_status(404)
      self.finish()
      return

    length = int(4 * 1024 * 1024)
    offset = int(0)
    while True:
      data = utils.read_chunk(path, offset=offset, length=length, escape_data=False)
      if self.connection_closed or 'data' not in data or len(data['data']) < length:
        break
      offset += length
      self.write(data['data'])
      self.flush()

    if 'data' in data:
      self.write(data['data'])
    self.finish()
コード例 #2
0
  def get(self, path):
    """ get method """

    logging.debug("request to download: %s", path)
    # If the file is large, we want to abandon downloading
    # if user cancels the requests.
    # pylint: disable=attribute-defined-outside-init
    self.connection_closed = False

    self.set_header("Content-Disposition", "attachment")
    if not utils.check_path(path):
      self.write("Only relative paths are allowed")
      self.set_status(403)
      self.finish()
      return

    if path is None or not os.path.isfile(path):
      self.write("File %s  not found" % path)
      self.set_status(404)
      self.finish()
      return

    length = int(4 * 1024 * 1024)
    offset = int(0)
    while True:
      data = utils.read_chunk(path, offset=offset, length=length, escape_data=False)
      if self.connection_closed or 'data' not in data or len(data['data']) < length:
        break
      offset += length
      self.write(data['data'])
      self.flush()

    if 'data' in data:
      self.write(data['data'])
    self.finish()
コード例 #3
0
ファイル: main.py プロジェクト: XBurnerAir/heron
 def get(self, path):
     if path is None:
         return {}
     if path.startswith("/"):
         self.write("Only relative paths are allowed")
         self.set_status(403)
         self.finish()
         return
     offset = self.get_argument("offset", default=-1)
     length = self.get_argument("length", default=-1)
     if not os.path.isfile(path):
         return {}
     data = utils.read_chunk(path, offset, length)
     self.write(json.dumps(data))
     self.finish()
コード例 #4
0
 def get(self, path):
     if path is None:
         return {}
     if path.startswith("/"):
         self.write("Only relative paths are allowed")
         self.set_status(403)
         self.finish()
         return
     offset = self.get_argument("offset", default=-1)
     length = self.get_argument("length", default=-1)
     if not os.path.isfile(path):
         return {}
     data = utils.read_chunk(path, offset, length)
     self.write(json.dumps(data))
     self.finish()
コード例 #5
0
ファイル: filedatahandler.py プロジェクト: nlu90/heron
  def get(self, path):
    """ get method """
    if path is None:
      return {}

    if not utils.check_path(path):
      self.write("Only relative paths are allowed")
      self.set_status(403)
      self.finish()
      return

    offset = self.get_argument("offset", default=-1)
    length = self.get_argument("length", default=-1)
    if not os.path.isfile(path):
      return {}
    data = utils.read_chunk(path, offset=offset, length=length, escape_data=True)
    self.write(json.dumps(data))
    self.finish()