def check(st, regex_format = None): global case_num case_num += 1 print("case num:{}".format(case_num)) regex_format_info = detect_datetime_format(st, regex_format) if regex_format_info: regex_format_info["parser"] = "parser obj" # always change, it's an obj print(repr(regex_format_info)) print("")
def check(st, regex_format=None): global case_num case_num += 1 print("case num:{}".format(case_num)) regex_format_info = detect_datetime_format(st, regex_format) if regex_format_info: regex_format_info[ "parser"] = "parser obj" # always change, it's an obj print(repr(regex_format_info)) print("")
def do_binary_seek_pos(f, st, ed, cmp_pattern, regex_pattern): global dataset_index dataset_index += 1 regex_format_info = detect_datetime_format(cmp_pattern, None) file_order_info = detect_file_format(f, cmp_pattern, None, regex_format_info) print("\ndataset[{}]".format(dataset_index)) print("st={}, ed={}".format(st, ed)) pos = binary_seek_pos(f, st, ed, cmp_pattern, regex_format_info, file_order_info) if pos is None: print("binary search return None") else: print("pos=%d" % pos) f.seek(pos) print(f.readline())
def dofo(f, start, end, regex_format_info): global case_num case_num += 1 print("case {}".format(case_num)) res = detect_file_format(f, start, end, regex_format_info) if res is not None: res = {"order": res["order"]} print(repr(res)) print("") if __name__ == "__main__": ascending_log = "testbinary.log" with open(ascending_log) as f: # 1. ascending regex_format_info = detect_datetime_format("02/Oct/2016:20:13:14.666", None) dofo(f, "02/Oct/2016:20:13:14.666", "02/Dec/2017:20:13:14.666", regex_format_info) descending_log = "testbinary.log.reverse" with open(descending_log) as f: # 2. descending regex_format_info = detect_datetime_format("02/Oct/2016:20:13:14.666", None) dofo(f, "02/Oct/2016:20:13:14.666", "05/Aug/2016:20:13:14.666", regex_format_info) ascending_log = "testbinary.log" with open(ascending_log) as f: regex_format_info = detect_datetime_format("2015-12-13 12:13:20", None)
from timecat import detect_datetime_format from timecat import dtcmp case_num = 0 def docmp(lhs, rhs, regex_format_info, cmp_op): global case_num case_num += 1 print("case {}:".format(case_num)) print(repr(dtcmp(lhs, rhs, regex_format_info, cmp_op))) print("") if __name__ == "__main__": regex_format_info = detect_datetime_format("Oct 09 20:13:14", None) # 1. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, ">") # 2. True docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "<") # 3. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "=") # 4. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "==") # 5. True docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "!=") # 6. True docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "<=") # 7. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, ">=")
global case_num case_num += 1 print("case {}".format(case_num)) res = detect_file_format(f, start, end, regex_format_info) if res is not None: res = { "order": res["order"] } print(repr(res)) print("") if __name__ == "__main__": ascending_log = "testbinary.log" with open(ascending_log) as f: # 1. ascending regex_format_info = detect_datetime_format("02/Oct/2016:20:13:14.666", None) dofo(f, "02/Oct/2016:20:13:14.666", "02/Dec/2017:20:13:14.666", regex_format_info) descending_log = "testbinary.log.reverse" with open(descending_log) as f: # 2. descending regex_format_info = detect_datetime_format("02/Oct/2016:20:13:14.666", None) dofo(f, "02/Oct/2016:20:13:14.666", "05/Aug/2016:20:13:14.666", regex_format_info) ascending_log = "testbinary.log" with open(ascending_log) as f: regex_format_info = detect_datetime_format("2015-12-13 12:13:20", None) # 3. ascending
# -*- coding: utf-8 -*- from include import * from timecat import detect_datetime_format from timecat import dtcmp case_num = 0 def docmp(lhs, rhs, regex_format_info, cmp_op): global case_num case_num += 1 print("case {}:".format(case_num)) print(repr(dtcmp(lhs, rhs, regex_format_info, cmp_op))) print("") if __name__ == "__main__": regex_format_info = detect_datetime_format("Oct 09 20:13:14", None) # 1. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, ">") # 2. True docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "<") # 3. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "=") # 4. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "==") # 5. True docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "!=") # 6. True docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, "<=") # 7. False docmp("Oct 09 20:13:14", "Nov 08 19:12:13", regex_format_info, ">=")