Commit 9faa74f8 authored by Jérome Perrin's avatar Jérome Perrin

PortalTransforms: py3 WIP 🚧

parent 5bf8acc4
...@@ -35,7 +35,8 @@ class commandtransform: ...@@ -35,7 +35,8 @@ class commandtransform:
os.mkdir(tmpdir) os.mkdir(tmpdir)
filename = kwargs.get("filename", '') filename = kwargs.get("filename", '')
fullname = join(tmpdir, basename(filename)) fullname = join(tmpdir, basename(filename))
filedest = open(fullname , "wb").write(data) with open(fullname , "wb") as f:
f.write(data)
return tmpdir, fullname return tmpdir, fullname
def subObjects(self, tmpdir): def subObjects(self, tmpdir):
...@@ -51,7 +52,8 @@ class commandtransform: ...@@ -51,7 +52,8 @@ class commandtransform:
def fixImages(self, path, images, objects): def fixImages(self, path, images, objects):
for image in images: for image in images:
objects[image] = open(join(path, image), 'rb').read() with open(join(path, image), 'rb') as f:
objects[image] = f.read()
def cleanDir(self, tmpdir): def cleanDir(self, tmpdir):
shutil.rmtree(tmpdir) shutil.rmtree(tmpdir)
...@@ -99,7 +101,7 @@ class popentransform: ...@@ -99,7 +101,7 @@ class popentransform:
cin, couterr = os.popen4(command, 'b') cin, couterr = os.popen4(command, 'b')
if self.useStdin: if self.useStdin:
cin.write(str(data)) cin.write(bytes(data))
status = cin.close() status = cin.close()
......
...@@ -36,9 +36,7 @@ class ImageMagickTransforms: ...@@ -36,9 +36,7 @@ class ImageMagickTransforms:
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True) close_fds=True)
try: try:
# XXX: The only portable way is to pass what stdin.write can accept, image, err = p.communicate(bytes(orig))
# which is a string for PIPE.
image, err = p.communicate(str(orig))
finally: finally:
del p del p
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment