From dda7753580d1dfb0d793280aae9a0f09c5e92c26 Mon Sep 17 00:00:00 2001 From: Philip Jenvey <pjenvey@underboss.org> Date: Sat, 19 Jan 2008 18:56:39 +0000 Subject: [PATCH] defer temp file creation until after any potential lexer exceptions fixes #69 --- CHANGES | 3 +++ lib/mako/template.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 9db4722..ea10bcc 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ - fixed bug in python generation when variable names are used with identifiers like "else", "finally", etc. inside them [ticket:68] +- fixed lexer exceptions not cleaning up temporary files, which + could lead to a maximum number of file descriptors used in the + process [ticket:69] 0.1.10 - fixed propagation of 'caller' such that nested %def calls diff --git a/lib/mako/template.py b/lib/mako/template.py index 52725b0..fc28c03 100644 --- a/lib/mako/template.py +++ b/lib/mako/template.py @@ -200,10 +200,10 @@ def _compile_text(template, text, filename): def _compile_module_file(template, text, filename, outputpath): identifier = template.module_id - (dest, name) = tempfile.mkstemp() lexer = Lexer(text, filename, input_encoding=template.input_encoding, preprocessor=template.preprocessor) node = lexer.parse() source = codegen.compile(node, template.uri, filename, default_filters=template.default_filters, buffer_filters=template.buffer_filters, imports=template.imports, source_encoding=lexer.encoding) + (dest, name) = tempfile.mkstemp() os.write(dest, source) os.close(dest) shutil.move(name, outputpath) -- GitLab