From 44553732cae7cb442462089d38a2336faba636a0 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sat, 8 Oct 2011 18:10:10 +0000 Subject: [PATCH] Fixed some bugs in write_tmpfile. --- cli/util.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/util.py b/cli/util.py index e207c46..81cd483 100644 --- a/cli/util.py +++ b/cli/util.py @@ -1,3 +1,6 @@ +import os +import tempfile + def make_result_dict(cursor, row): d = {} for i in xrange(len(row)): @@ -82,9 +85,9 @@ def run_editor(filename): else: exit("Error: %s: File does not exist!" % filename) -def write_tmpfile(pfix='', content=''): +def write_tmpfile(pfix, content, encoding='utf8'): file = tempfile.NamedTemporaryFile(prefix=pfix+'-', dir='/tmp', delete=False) - file.write(content.encode(file_encoding)) + file.write(content.encode(encoding)) name = file.name file.close() return name