Esempio n. 1
0
  def testNoHits(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("foo bar quux")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_regex_match.regex = "\\d+"
    params.contents_regex_match.mode = "FIRST_HIT"
    condition = client_file_finder.RegexMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertFalse(results)
Esempio n. 2
0
  def testFirstHit(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("4 8 15 16 23 42 foo 108 bar")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_regex_match.regex = "[a-z]+"
    params.contents_regex_match.mode = "FIRST_HIT"
    condition = client_file_finder.RegexMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertEqual(len(results), 1)
    self.assertEqual(results[0].data, "foo")
    self.assertEqual(results[0].offset, 16)
    self.assertEqual(results[0].length, 3)
Esempio n. 3
0
  def testStartOffset(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("ooooooo")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_regex_match.regex = "o+"
    params.contents_regex_match.mode = "FIRST_HIT"
    params.contents_regex_match.start_offset = 3
    condition = client_file_finder.RegexMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertEqual(len(results), 1)
    self.assertEqual(results[0].data, "oooo")
    self.assertEqual(results[0].offset, 3)
    self.assertEqual(results[0].length, 4)
Esempio n. 4
0
  def testContext(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("foobarbazbaaarquux")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_regex_match.regex = "ba+r"
    params.contents_regex_match.mode = "ALL_HITS"
    params.contents_regex_match.bytes_before = 3
    params.contents_regex_match.bytes_after = 4
    condition = client_file_finder.RegexMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertEqual(len(results), 2)
    self.assertEqual(results[0].data, "foobarbazb")
    self.assertEqual(results[0].offset, 0)
    self.assertEqual(results[0].length, 10)
    self.assertEqual(results[1].data, "bazbaaarquux")
    self.assertEqual(results[1].offset, 6)
    self.assertEqual(results[1].length, 12)
Esempio n. 5
0
  def testSomeHits(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("foo 7 bar 49 baz343")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_regex_match.regex = "\\d+"
    params.contents_regex_match.mode = "ALL_HITS"
    condition = client_file_finder.RegexMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertEqual(len(results), 3)
    self.assertEqual(results[0].data, "7")
    self.assertEqual(results[0].offset, 4)
    self.assertEqual(results[0].length, 1)
    self.assertEqual(results[1].data, "49")
    self.assertEqual(results[1].offset, 10)
    self.assertEqual(results[1].length, 2)
    self.assertEqual(results[2].data, "343")
    self.assertEqual(results[2].offset, 16)
    self.assertEqual(results[2].length, 3)