ยปCore Development>Code coverage>Modules/_sha3/cleanup.py

Python code coverage for Modules/_sha3/cleanup.py

#countcontent
1n/a#!/usr/bin/env python
2n/a# Copyright (C) 2012 Christian Heimes (christian@python.org)
3n/a# Licensed to PSF under a Contributor Agreement.
4n/a#
5n/a# cleanup Keccak sources
6n/a
7n/aimport os
8n/aimport re
9n/a
10n/aCPP1 = re.compile("^//(.*)")
11n/aCPP2 = re.compile("\ //(.*)")
12n/a
13n/aSTATICS = ("void ", "int ", "HashReturn ",
14n/a "const UINT64 ", "UINT16 ", " int prefix##")
15n/a
16n/aHERE = os.path.dirname(os.path.abspath(__file__))
17n/aKECCAK = os.path.join(HERE, "kcp")
18n/a
19n/adef getfiles():
20n/a for name in os.listdir(KECCAK):
21n/a name = os.path.join(KECCAK, name)
22n/a if os.path.isfile(name):
23n/a yield name
24n/a
25n/adef cleanup(f):
26n/a buf = []
27n/a for line in f:
28n/a # mark all functions and global data as static
29n/a #if line.startswith(STATICS):
30n/a # buf.append("static " + line)
31n/a # continue
32n/a # remove UINT64 typedef, we have our own
33n/a if line.startswith("typedef unsigned long long int"):
34n/a buf.append("/* %s */\n" % line.strip())
35n/a continue
36n/a ## remove #include "brg_endian.h"
37n/a if "brg_endian.h" in line:
38n/a buf.append("/* %s */\n" % line.strip())
39n/a continue
40n/a # transform C++ comments into ANSI C comments
41n/a line = CPP1.sub(r"/*\1 */\n", line)
42n/a line = CPP2.sub(r" /*\1 */\n", line)
43n/a buf.append(line)
44n/a return "".join(buf)
45n/a
46n/afor name in getfiles():
47n/a with open(name) as f:
48n/a res = cleanup(f)
49n/a with open(name, "w") as f:
50n/a f.write(res)