Exemple #1
0
    def get(self):
        """GET request; takes path as an argument."""
        path = self.get_path()
        base = util.get_base_path_adjustment()

        files = []
        try:
            file_list = os.listdir(os.path.join(base, path))
            for i in file_list:
                try:
                    filename = os.path.join(base, path, i)
                    is_file = os.path.isfile(filename)
                    confirm = ''
                    if is_file and os.path.getsize(filename) > 10485760:
                        confirm = 'large'
                    if is_file and not util.is_text_file(filename):
                        confirm = 'binary'
                    files.append({
                        'name': i,
                        'is_file': is_file,
                        'confirm': confirm
                    })
                except IOError as error:
                    log.warn(error)
        except Exception as error:  # pylint: disable=W0703
            log.warn(error)

        self.do_output(files, base)
Exemple #2
0
 def _search_file(self, filepath):
     if self.quit:
         raise SearchAborted()
     self.output.begin_file(self, filepath)
     if not is_text_file(filepath):
         return
     with open(filepath, "r") as f:
         matched_file = False
         for line_num, line in enumerate(f, 1):
             line = line.rstrip("\r\n")
             try:
                 line = line.decode(self.encoding)
             except UnicodeDecodeError:
                 line = line.decode("latin-1")
             if self.match(line):
                 if not matched_file:
                     self.output.add_file(self, filepath)
                     matched_file = True
                 self.output.add_line(self, line_num, line)
             if self.quit:
                 raise SearchAborted()
         if matched_file:
             self.output.end_file(self)
Exemple #3
0
    def get(self):
        """GET request; takes path as an argument."""
        path = self.get_path()
        base = util.get_base_path_adjustment()

        files = []
        try:
            file_list = os.listdir(os.path.join(base, path))
            for i in file_list:
                try:
                    filename = os.path.join(base, path, i)
                    is_file = os.path.isfile(filename)
                    confirm = ""
                    if is_file and os.path.getsize(filename) > 10485760:
                        confirm = "large"
                    if is_file and not util.is_text_file(filename):
                        confirm = "binary"
                    files.append({"name": i, "is_file": is_file, "confirm": confirm})
                except IOError as error:
                    log.warn(error)
        except Exception as error:  # pylint: disable=W0703
            log.warn(error)

        self.do_output(files, base)