Skip to content

Commit 4aae3ff

Browse files
committed
Fixed several places where files were not being closed. Commit ready for merge.
- Legacy-Id: 8209
1 parent be3d203 commit 4aae3ff

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

ietf/iesg/agenda.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import codecs
44
import datetime
55
from collections import OrderedDict
6+
from contextlib import closing
67

78
from django.conf import settings
89
from django.http import Http404
@@ -140,7 +141,7 @@ def fill_in_agenda_administrivia(date, sections):
140141

141142
for s, key, filename in extra_info_files:
142143
try:
143-
with codecs.open(filename, 'r', 'utf-8', 'replace') as f:
144+
with closing(codecs.open(filename, 'r', 'utf-8', 'replace')) as f:
144145
t = f.read().strip()
145146
except IOError:
146147
t = u"(Error reading %s)" % filename

ietf/ipr/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def patent_file_search(url, q):
3535
#print "*** Found file", fpath
3636
file = codecs.open(fpath, mode='r', encoding='utf-8', errors='replace')
3737
text = file.read()
38-
file.close
38+
file.close()
3939
return q in text
4040
return False
4141

ietf/meeting/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import debug # pyflakes:ignore
1111

12+
from contextlib import closing
13+
1214
from django import forms
1315
from django.shortcuts import render_to_response, redirect
1416
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404
@@ -362,7 +364,7 @@ def read_agenda_file(num, doc):
362364
# DOC_PATH_FORMAT = { "agenda": "/foo/bar/agenda-{meeting.number}/agenda-{meeting-number}-{doc.group}*", }
363365
path = os.path.join(settings.AGENDA_PATH, "%s/agenda/%s" % (num, doc.external_url))
364366
if os.path.exists(path):
365-
with open(path) as f:
367+
with closing(open(path)) as f:
366368
return f.read()
367369
else:
368370
return None
@@ -401,6 +403,7 @@ def convert_to_pdf(doc_name):
401403
return
402404

403405
t,tempname = mkstemp()
406+
os.close(t)
404407
tempfile = open(tempname, "w")
405408

406409
pageend = 0;
@@ -431,6 +434,7 @@ def convert_to_pdf(doc_name):
431434
infile.close()
432435
tempfile.close()
433436
t,psname = mkstemp()
437+
os.close(t)
434438
pipe("enscript --margins 76::76: -B -q -p "+psname + " " +tempname)
435439
os.unlink(tempname)
436440
pipe("ps2pdf "+psname+" "+outpath)
@@ -473,6 +477,7 @@ def session_draft_tarfile(request, num, session):
473477
response['Content-Disposition'] = 'attachment; filename=%s-drafts.tgz'%(session)
474478
tarstream = tarfile.open('','w:gz',response)
475479
mfh, mfn = mkstemp()
480+
os.close(mfh)
476481
manifest = open(mfn, "w")
477482

478483
for doc_name in drafts:
@@ -512,6 +517,7 @@ def session_draft_pdf(request, num, session):
512517
drafts = session_draft_list(num, session);
513518
curr_page = 1
514519
pmh, pmn = mkstemp()
520+
os.close(pmh)
515521
pdfmarks = open(pmn, "w")
516522
pdf_list = ""
517523

@@ -528,6 +534,7 @@ def session_draft_pdf(request, num, session):
528534

529535
pdfmarks.close()
530536
pdfh, pdfn = mkstemp()
537+
os.close(pdfh)
531538
pipe("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + pdfn + " " + pdf_list + " " + pmn)
532539

533540
pdf = open(pdfn,"r")

0 commit comments

Comments
 (0)