[windows] fix probleme using NamedTemporaryFile on windows

This commit is contained in:
Bezleputh 2014-11-25 13:56:07 +01:00
commit c3b5dbc316

View file

@ -777,21 +777,30 @@ class Keyring(object):
""" """
gpgv = self.find_gpgv() gpgv = self.find_gpgv()
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
with NamedTemporaryFile(suffix='.sig') as sigfile: with NamedTemporaryFile(suffix='.sig', delete=False) as sigfile:
sigfile.write(sigdata) temp_filename = sigfile.name
sigfile.flush() # very important return_code = None
assert isinstance(data, basestring) out = ''
# Yes, all of it is necessary err = ''
proc = subprocess.Popen([gpgv, try:
'--status-fd', '1', sigfile.write(sigdata)
'--keyring', os.path.realpath(self.path), sigfile.flush() # very important
os.path.realpath(sigfile.name), assert isinstance(data, basestring)
'-'], # Yes, all of it is necessary
stdin=subprocess.PIPE, proc = subprocess.Popen([gpgv,
stdout=subprocess.PIPE, '--status-fd', '1',
stderr=subprocess.PIPE) '--keyring', os.path.realpath(self.path),
out, err = proc.communicate(data) os.path.realpath(sigfile.name),
if proc.returncode or 'GOODSIG' not in out or 'VALIDSIG' not in out: '-'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate(data)
return_code = proc.returncode
finally:
os.unlink(temp_filename)
if return_code or 'GOODSIG' not in out or 'VALIDSIG' not in out:
print(out, err, file=sys.stderr) print(out, err, file=sys.stderr)
return False return False
return True return True