Debian Codegraph @

rpython/rlib/rsre/test/targetrsre.py

raw symbols SCIP
1 #!/usr/bin/env python
2 from __future__ import print_function
3
4 from rpython.rlib.rarithmetic import intmask
5 from rpython.rlib.rsre import rsre_core
6 from rpython.rlib.rsre.rsre_char import MAXREPEAT
7 import os, time
8
9
10 # <item>\s*<title>(.*?)</title>
11 r_code1 = [17, 18, 1, 21, 131091, 6, 6, 60, 105, 116, 101, 109, 62, 0,
12 0, 0, 0, 0, 0, 19, 60, 19, 105, 19, 116, 19, 101, 19, 109, 19, 62, 29,
13 9, 0, MAXREPEAT, 15, 4, 9, 2, 0, 1, 19, 60, 19, 116, 19, 105, 19, 116, 19,
14 108, 19, 101, 19, 62, 21, 0, 31, 5, 0, MAXREPEAT, 2, 1, 21, 1, 19, 60, 19,
15 47, 19, 116, 19, 105, 19, 116, 19, 108, 19, 101, 19, 62, 1]
16
17
18 def read(filename):
19 fd = os.open(filename, os.O_RDONLY, 0666)
20 if fd < 0:
21 raise OSError
22 end = os.lseek(fd, 0, 2)
23 os.lseek(fd, 0, 0)
24 data = os.read(fd, intmask(end))
25 os.close(fd)
26 return data
27
28 def search_in_file(filename):
29 data = read(filename)
30 p = 0
31 while True:
32 res = rsre_core.search(r_code1, data, p)
33 if res is None:
34 break
35 matchstart, matchstop = res.span(1)
36 assert 0 <= matchstart <= matchstop
37 print('%s: %s' % (filename, data[matchstart:matchstop]))
38 p = res.span(0)[1]
39
40 # __________ Entry point __________
41
42 def entry_point(argv):
43 start = time.time()
44 for fn in argv[1:]:
45 search_in_file(fn)
46 stop = time.time()
47 print(stop - start)
48 return 0
49
50 # _____ Define and setup target ___
51
52 def target(*args):
53 return entry_point, None
54
55 # _____ Pure Python equivalent _____
56
57 if __name__ == '__main__':
58 import re, sys
59 r = re.compile(r"<item>\s*<title>(.*?)</title>")
60 start = time.time()
61 for fn in sys.argv[1:]:
62 f = open(fn, 'rb')
63 data = f.read()
64 f.close()
65 for title in r.findall(data):
66 print('%s: %s' % (fn, title))
67 stop = time.time()
68 print('%.4fs' % (stop - start,))