1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import os
import sys
import re
def repl_fn(m):
ret = ''
ret = ret + m.groups()[0] + '('
for i in range(1, len(m.groups())):
if(m.groups()[i] != None):
ret = ret + m.groups()[i]
else:
break
ret = ret + ')'
print '\n' + m.group() + '\nwith\n' + ret + '\n'
return ret
def work_on(fname):
with open(fname) as f:
p = re.compile(r'((?:\b[^\s\(\),]+)|(?:\(\*[^\s\(\),]+\)))\s*' + # function name or function pointer
r'\(\s*' + # open brackets
r'(?:(?:exec_ctx)|(?:grpc_exec_ctx\s*\*\s*exec_ctx)|(?:&\s*exec_ctx))' + # first exec_ctx paramenter
r'\s*,?' + # comma after exec_ctx
r'(\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'(\s*,\s*[^\),]+)?' + # all but first argument
r'\s*\)') # close brackets
res = p.sub(repl_fn, f.read())
f = open(fname, 'w')
f.write(res)
f.close()
#print res
def main():
file_list = []
for line in sys.stdin:
work_on(line.strip())
if __name__ == '__main__':
main()
|