diff --git a/scripts/analyze_memdump.py b/scripts/analyze_memdump.py
index 62649964..3f0f9cf9 100755
--- a/scripts/analyze_memdump.py
+++ b/scripts/analyze_memdump.py
@@ -23,6 +23,7 @@ import codecs
import html
from linkcheck import strformat
+
def main(filename):
om = print_memorydump(filename)
dirname, basename = os.path.split(filename)
@@ -32,13 +33,16 @@ def main(filename):
os.mkdir(basedir)
write_htmlfiles(om, basedir)
+
def print_memorydump(filename):
from meliae import loader
+
om = loader.load(filename, collapse=True)
om.remove_expensive_references()
print om.summarize()
return om
+
def write_htmlfiles(om, basedir):
om.compute_parents()
open_files = {}
@@ -47,21 +51,24 @@ def write_htmlfiles(om, basedir):
write_html_obj(fp, obj, om.objs)
close_files(open_files)
+
def get_file(type_str, open_files, basedir):
"""Get already opened file, or open and initialize a new one."""
if type_str not in open_files:
- filename = type_str+".html"
- encoding = 'utf-8'
- fd = codecs.open(os.path.join(basedir, filename), 'w', encoding)
+ filename = type_str + ".html"
+ encoding = "utf-8"
+ fd = codecs.open(os.path.join(basedir, filename), "w", encoding)
open_files[type_str] = fd
write_html_header(fd, type_str, encoding)
return open_files[type_str]
+
def close_files(open_files):
for fp in open_files.values():
write_html_footer(fp)
fp.close()
+
HtmlHeader = """
@@ -70,10 +77,14 @@ HtmlHeader = """
"""
+
def write_html_header(fp, type_str, encoding):
fp.write(HtmlHeader % encoding)
fp.write("Type %s
\n" % type_str)
- fp.write("| Address | Name | Size | Parents | References |
\n")
+ fp.write(
+ "| Address | Name | Size | Parents | References |
\n"
+ )
+
def get_children(obj, objs):
res = []
@@ -89,6 +100,7 @@ def get_children(obj, objs):
res.append(entry)
return res
+
def get_parents(obj, objs):
res = []
for address in obj.parents:
@@ -103,6 +115,7 @@ def get_parents(obj, objs):
res.append(entry)
return res
+
def write_html_obj(fp, obj, objs):
if obj.value is None:
value = "None"
@@ -115,11 +128,16 @@ def write_html_obj(fp, obj, objs):
parents=",".join(get_parents(obj, objs)),
value=value,
)
- fp.write("| %(address)d | %(value)s | %(size)s | %(children)s |
\n" % attrs)
+ fp.write(
+ "| %(address)d | %(value)s | %(size)s | %(children)s |
\n"
+ % attrs
+ )
+
def write_html_footer(fp):
fp.write("
")
-if __name__ == '__main__':
+
+if __name__ == "__main__":
filename = sys.argv[1]
main(filename)
diff --git a/scripts/removeafter.py b/scripts/removeafter.py
index 1c0fab70..f6386d0b 100755
--- a/scripts/removeafter.py
+++ b/scripts/removeafter.py
@@ -6,6 +6,7 @@ from __future__ import print_function
import fileinput
import sys
+
def main(args):
"""Remove lines after marker."""
filename = args[0]
@@ -15,5 +16,6 @@ def main(args):
if line.startswith(marker):
break
-if __name__ == '__main__':
+
+if __name__ == "__main__":
main(sys.argv[1:])
diff --git a/scripts/update_iana_uri_schemes.py b/scripts/update_iana_uri_schemes.py
index c54c31d3..967f0a77 100644
--- a/scripts/update_iana_uri_schemes.py
+++ b/scripts/update_iana_uri_schemes.py
@@ -5,17 +5,23 @@ import requests
iana_uri_schemes = "https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml"
# CSV format: URI Scheme,Template,Description,Reference
-csv_iana_uri_schemes_permanent = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-1.csv'
-csv_iana_uri_schemes_provisional = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-2.csv'
-csv_iana_uri_schemes_historical = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-3.csv'
+csv_iana_uri_schemes_permanent = (
+ "https://www.iana.org/assignments/uri-schemes/uri-schemes-1.csv"
+)
+csv_iana_uri_schemes_provisional = (
+ "https://www.iana.org/assignments/uri-schemes/uri-schemes-2.csv"
+)
+csv_iana_uri_schemes_historical = (
+ "https://www.iana.org/assignments/uri-schemes/uri-schemes-3.csv"
+)
iana_uri_schemes_permanent = {}
iana_uri_schemes_provisional = {}
iana_uri_schemes_historical = {}
iana_uri_schemes_other = {
- "clsid": "Microsoft specific",
- "find" : "Mozilla specific",
- "isbn" : "ISBN (int. book numbers)",
+ "clsid": "Microsoft specific",
+ "find": "Mozilla specific",
+ "isbn": "ISBN (int. book numbers)",
"javascript": "JavaScript",
}
@@ -58,24 +64,27 @@ ignored_schemes_re = re.compile(ignored_schemes, re.VERBOSE)
is_unknown_scheme = ignored_schemes_re.match
'''
+
def main(args):
parse_csv_file(csv_iana_uri_schemes_permanent, iana_uri_schemes_permanent)
parse_csv_file(csv_iana_uri_schemes_provisional, iana_uri_schemes_provisional)
parse_csv_file(csv_iana_uri_schemes_historical, iana_uri_schemes_historical)
for scheme in iana_uri_schemes_other:
- if (scheme in iana_uri_schemes_permanent or
- scheme in iana_uri_schemes_provisional or
- scheme in iana_uri_schemes_historical):
+ if (
+ scheme in iana_uri_schemes_permanent
+ or scheme in iana_uri_schemes_provisional
+ or scheme in iana_uri_schemes_historical
+ ):
raise ValueError(scheme)
for scheme in filter_uri_schemes_permanent:
if scheme in iana_uri_schemes_permanent:
del iana_uri_schemes_permanent[scheme]
args = dict(
- uri = iana_uri_schemes,
- permanent = get_regex(iana_uri_schemes_permanent),
- provisional = get_regex(iana_uri_schemes_provisional),
- historical = get_regex(iana_uri_schemes_historical),
- other = get_regex(iana_uri_schemes_other),
+ uri=iana_uri_schemes,
+ permanent=get_regex(iana_uri_schemes_permanent),
+ provisional=get_regex(iana_uri_schemes_provisional),
+ historical=get_regex(iana_uri_schemes_historical),
+ other=get_regex(iana_uri_schemes_other),
)
res = template % args
print res
@@ -83,8 +92,10 @@ def main(args):
def get_regex(schemes):
- expr = ["|%s # %s" % (re.escape(scheme).ljust(10), description)
- for scheme, description in sorted(schemes.items())]
+ expr = [
+ "|%s # %s" % (re.escape(scheme).ljust(10), description)
+ for scheme, description in sorted(schemes.items())
+ ]
return "\n".join(expr)
@@ -102,5 +113,5 @@ def parse_csv_file(url, res):
res[scheme] = description
-if __name__ == '__main__':
+if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
diff --git a/scripts/viewprof.py b/scripts/viewprof.py
index 2c604a97..4220f96a 100755
--- a/scripts/viewprof.py
+++ b/scripts/viewprof.py
@@ -7,6 +7,7 @@ Usage: $0
import sys
import yappi
+
def main(args):
filename = args[0]
stats = yappi.YFuncStats()
@@ -14,6 +15,5 @@ def main(args):
stats.print_all()
-if __name__ == '__main__':
- main(sys.argv[1:])
-
+if __name__ == "__main__":
+ main(sys.argv[1:])