Beispiel #1
0
    def test_find_date_spans(self):
        raw_date_regex = r"\d+/[a-zA-z]+/\d+:\d+:\d+:\d+ \+\d+"
        date_regexes = {re.compile(raw_date_regex): raw_date_regex}

        text = r'2015-12-03 or [10/Oct/1999:21:15:05 +0500] "GET /index.html HTTP/1.0" 200 1043'
        spans = find_date_spans(text, date_regexes)
        assert len(spans) == 2
        spans = spans.sort_by_start_and_end()
        dates = [text[s.start:s.end] for s in spans]
        assert dates[0] == '2015-12-03'
        assert dates[1] == '10/Oct/1999:21:15:05 +0500'
Beispiel #2
0
    def test_find_date_spans(self):
        raw_date_regex = r"\d+/[a-zA-z]+/\d+:\d+:\d+:\d+ \+\d+"
        date_regexes = {re.compile(raw_date_regex): raw_date_regex}

        text = r'2015-12-03 or [10/Oct/1999:21:15:05 +0500] "GET /index.html HTTP/1.0" 200 1043'
        spans = find_date_spans(text, date_regexes)
        assert len(spans) == 2
        spans = spans.sort_by_start_and_end()
        dates = [text[s.start:s.end] for s in spans]
        assert dates[0] == '2015-12-03'
        assert dates[1] == '10/Oct/1999:21:15:05 +0500'
Beispiel #3
0
def guess_pattern_match_with_dates(text):
    group_spans = find_date_spans(text)
    regex = regex_from_group_spans(group_spans, text)
    groups = _groups_from_spans(group_spans, regex, text)
    return PatternMatch(text, regex, groups)
Beispiel #4
0
def guess_pattern_match_with_dates(text):
    group_spans = find_date_spans(text)
    regex = regex_from_group_spans(group_spans, text)
    groups = _groups_from_spans(group_spans, regex, text)
    return PatternMatch(text, regex, groups)