summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-10-07 14:10:28 +0200
committerGeorg Brandl <georg@python.org>2014-10-07 14:10:28 +0200
commit9a51e6a6df8a56aebede133687e91e519a186122 (patch)
treeffebef0e0f0b63c2749e2858fdc50972a336fc2b /scripts
parent9cbc7803dd8e7826393721fe4acbd702843e131c (diff)
downloadpygments-9a51e6a6df8a56aebede133687e91e519a186122.tar.gz
Closes #980: fix DeprecationWarnings (mostly due to files closed by __del__) on Py3.
Also fix a bunch of other uses of open() to use the with statement.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/find_codetags.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/scripts/find_codetags.py b/scripts/find_codetags.py
index f8204e6e..5063f61f 100755
--- a/scripts/find_codetags.py
+++ b/scripts/find_codetags.py
@@ -39,12 +39,12 @@ def escape_html(text):
def process_file(store, filename):
try:
- f = open(filename, 'r')
+ fp = open(filename, 'r')
except (IOError, OSError):
return False
llmatch = 0
- try:
- for lno, line in enumerate(f):
+ with fp:
+ for lno, line in enumerate(fp):
# just some random heuristics to filter out binary files
if lno < 100 and binary_re.search(line):
return False
@@ -69,8 +69,6 @@ def process_file(store, filename):
continue
llmatch = 0
return True
- finally:
- f.close()
def main():
@@ -198,13 +196,13 @@ td { padding: 2px 5px 2px 5px;
'<td class="tag %%(tag)s">%%(tag)s</td>'
'<td class="who">%%(who)s</td><td class="what">%%(what)s</td></tr>')
- f = open(output, 'w')
table = '\n'.join(TABLE % fname +
'\n'.join(TR % (no % 2,) % entry
for no, entry in enumerate(store[fname]))
for fname in sorted(store))
- f.write(HTML % (', '.join(map(abspath, args)), table))
- f.close()
+
+ with open(output, 'w') as fp:
+ fp.write(HTML % (', '.join(map(abspath, args)), table))
print("Report written to %s." % output)
return 0