Пример #1
0
 def _find_right(self, opened_file):
     left = 0
     right = ReadUtils.size_of_opened_file(opened_file)
     while left + 1 < right:
         curr = (left + right) // 2
         line, line_begin, line_end = ReadUtils.get_line_containing_offset(
             opened_file, curr, ReadUtils.STANDARD_BUFFER_SIZE
         )
         groups = self._super_parser.get_ordered_groups(line)
         assert len(groups) <= 1
         if self._investigation_step.compare_with_bound(InvestigationStep.RIGHT_BOUND, groups)\
                 in [CompareResult.LT, CompareResult.EQ]:
             # go to the end of current line, maybe it will be returned
             left = line_end
         else:
             # going left, current line is not interesting
             right = line_begin - 1
     if right == 0:
         return 0
     _, _, end_offset = ReadUtils.get_line_containing_offset(
         opened_file, right - 1, ReadUtils.STANDARD_BUFFER_SIZE
     )
     return end_offset + 1
Пример #2
0
 def _find_left(self, opened_file):
     left = 0
     right = ReadUtils.size_of_opened_file(opened_file)
     while left + 1 < right:
         curr = (left + right) // 2
         line, line_begin, line_end = ReadUtils.get_line_containing_offset(
             opened_file, curr, ReadUtils.STANDARD_BUFFER_SIZE
         )
         groups = self._super_parser.get_ordered_groups(line)
         assert len(groups) <= 1
         if self._investigation_step.compare_with_bound(
             InvestigationStep.LEFT_BOUND, groups
         ) == CompareResult.LT:
             # omit actual line and go right
             left = line_end + 1
         else:
             # going left, omit actual line, but maybe it will be returned
             right = line_begin
     return right
Пример #3
0
 def test_getting_line_by_offset_huge(self):
     with open(TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)) as fh:
         for j in six.moves.range(1, 120, 7):
             for i in six.moves.range(100):
                 assert ReadUtils.get_line_containing_offset(fh, i, j) == \
                        AFewLinesLogParams.get_line_with_borders(i)
Пример #4
0
 def test_getting_line_by_offset_huge(self):
     with open(TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)) as fh:
         for j in six.moves.range(1, 120, 7):
             for i in six.moves.range(100):
                 assert ReadUtils.get_line_containing_offset(fh, i, j) == \
                        AFewLinesLogParams.get_line_with_borders(i)