mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
Python 3 conversion failure on Windows
Windows is not able to create a tempfile with NamedTemporaryFile and then open it with a second file handle without closing the first one. Added code to close the handle, and keep the file around a little longer so it can be reopened and rewritten to again.
This commit is contained in:
parent
ed42746027
commit
e3095edad3
|
@ -1,4 +1,5 @@
|
|||
# testutils.py - utility module for psycopg2 testing.
|
||||
|
||||
#
|
||||
# Copyright (C) 2010-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||
#
|
||||
|
@ -190,21 +191,24 @@ def script_to_py3(script):
|
|||
return script
|
||||
|
||||
import tempfile
|
||||
f = tempfile.NamedTemporaryFile(suffix=".py")
|
||||
f = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
|
||||
f.write(script.encode())
|
||||
f.flush()
|
||||
filename = f.name
|
||||
f.close()
|
||||
|
||||
# 2to3 is way too chatty
|
||||
import logging
|
||||
logging.basicConfig(filename=os.devnull)
|
||||
|
||||
from lib2to3.main import main
|
||||
if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', f.name]):
|
||||
if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', filename]):
|
||||
raise Exception('py3 conversion failed')
|
||||
|
||||
f2 = open(f.name)
|
||||
f2 = open(filename)
|
||||
try:
|
||||
return f2.read()
|
||||
finally:
|
||||
f2.close()
|
||||
os.remove(filename)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user