summaryrefslogtreecommitdiff
path: root/pygments/lexers/_mapping.py
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 /pygments/lexers/_mapping.py
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 'pygments/lexers/_mapping.py')
-rw-r--r--pygments/lexers/_mapping.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index a714941b..80b4da4a 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -388,19 +388,15 @@ if __name__ == '__main__':
found_lexers.sort()
# extract useful sourcecode from this file
- f = open(__file__)
- try:
- content = f.read()
- finally:
- f.close()
+ with open(__file__) as fp:
+ content = fp.read()
header = content[:content.find('LEXERS = {')]
footer = content[content.find("if __name__ == '__main__':"):]
# write new file
- f = open(__file__, 'w')
- f.write(header)
- f.write('LEXERS = {\n %s,\n}\n\n' % ',\n '.join(found_lexers))
- f.write(footer)
- f.close()
+ with open(__file__, 'w') as fp:
+ fp.write(header)
+ fp.write('LEXERS = {\n %s,\n}\n\n' % ',\n '.join(found_lexers))
+ fp.write(footer)
print ('=== %d lexers processed.' % len(found_lexers))