diff options
Diffstat (limited to 'docs/_ext')
| -rw-r--r-- | docs/_ext/applyxrefs.py | 27 | ||||
| -rw-r--r-- | docs/_ext/djangodocs.py | 9 | ||||
| -rw-r--r-- | docs/_ext/literals_to_xrefs.py | 6 |
3 files changed, 14 insertions, 28 deletions
diff --git a/docs/_ext/applyxrefs.py b/docs/_ext/applyxrefs.py index 14d18bd856..7181480e0f 100644 --- a/docs/_ext/applyxrefs.py +++ b/docs/_ext/applyxrefs.py @@ -18,33 +18,18 @@ def process_file(fn, lines): lines.insert(0, '\n') lines.insert(0, '.. %s:\n' % target_name(fn)) try: - f = open(fn, 'w') + with open(fn, 'w') as fp: + fp.writelines(lines) except IOError: print("Can't open %s for writing. Not touching it." % fn) - return - try: - f.writelines(lines) - except IOError: - print("Can't write to %s. Not touching it." % fn) - finally: - f.close() def has_target(fn): try: - f = open(fn, 'r') + with open(fn, 'r') as fp: + lines = fp.readlines() except IOError: - print("Can't open %s. Not touching it." % fn) + print("Can't open or read %s. Not touching it." % fn) return (True, None) - readok = True - try: - lines = f.readlines() - except IOError: - print("Can't read %s. Not touching it." % fn) - readok = False - finally: - f.close() - if not readok: - return (True, None) #print fn, len(lines) if len(lines) < 1: @@ -82,7 +67,7 @@ def main(argv=None): print("Adding xref to %s" % fn) process_file(fn, lines) else: - print "Skipping %s: already has a xref" % fn + print("Skipping %s: already has a xref" % fn) if __name__ == '__main__': sys.exit(main()) diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py index d4b0b43ca7..3d85147952 100644 --- a/docs/_ext/djangodocs.py +++ b/docs/_ext/djangodocs.py @@ -210,8 +210,7 @@ class DjangoStandaloneHTMLBuilder(StandaloneHTMLBuilder): if t == "templatefilter" and l == "ref/templates/builtins"], } outfilename = os.path.join(self.outdir, "templatebuiltins.js") - f = open(outfilename, 'wb') - f.write('var django_template_builtins = ') - json.dump(templatebuiltins, f) - f.write(';\n') - f.close(); + with open(outfilename, 'wb') as fp: + fp.write('var django_template_builtins = ') + json.dump(templatebuiltins, fp) + fp.write(';\n') diff --git a/docs/_ext/literals_to_xrefs.py b/docs/_ext/literals_to_xrefs.py index d1487ca729..d7b3cfc549 100644 --- a/docs/_ext/literals_to_xrefs.py +++ b/docs/_ext/literals_to_xrefs.py @@ -38,7 +38,8 @@ ALWAYS_SKIP = [ ] def fixliterals(fname): - data = open(fname).read() + with open(fname) as fp: + data = fp.read() last = 0 new = [] @@ -101,7 +102,8 @@ def fixliterals(fname): lastvalues[m.group(1)] = replace_value new.append(data[last:]) - open(fname, "w").write("".join(new)) + with open(fname, "w") as fp: + fp.write("".join(new)) storage["lastvalues"] = lastvalues storage.close() |
