Specify the encoding when generate snippet images.

master v0.7a
Pacman Ghost 5 years ago
parent de27daed25
commit 7bd6e9504d
  1. 14
      vasl_templates/webapp/utils.py
  2. 3
      vasl_templates/webapp/webdriver.py

@ -52,15 +52,25 @@ class MsgStore:
class TempFile: class TempFile:
"""Manage a temp file that can be closed while it's still being used.""" """Manage a temp file that can be closed while it's still being used."""
def __init__( self, mode="wb", extn=None ): def __init__( self, mode="wb", extn=None, encoding=None ):
self.mode = mode self.mode = mode
self.extn = extn self.extn = extn
self.encoding = encoding
self.temp_file = None self.temp_file = None
self.name = None self.name = None
def __enter__( self ): def __enter__( self ):
"""Allocate a temp file.""" """Allocate a temp file."""
self.temp_file = tempfile.NamedTemporaryFile( mode=self.mode, suffix=self.extn, delete=False ) if self.encoding:
encoding = self.encoding
else:
encoding = "utf-8" if "b" not in self.mode else None
self.temp_file = tempfile.NamedTemporaryFile(
mode = self.mode,
encoding = encoding,
suffix = self.extn,
delete = False
)
self.name = self.temp_file.name self.name = self.temp_file.name
return self return self

@ -117,7 +117,8 @@ class WebDriver:
bbox = diff.getbbox() bbox = diff.getbbox()
return img.crop( bbox ) return img.crop( bbox )
with TempFile(extn=".html",mode="w") as html_tempfile, TempFile(extn=".png") as screenshot_tempfile: with TempFile( extn=".html", mode="w", encoding="utf-8" ) as html_tempfile, \
TempFile( extn=".png" ) as screenshot_tempfile:
# NOTE: We could do some funky Javascript stuff to load the browser directly from the string, # NOTE: We could do some funky Javascript stuff to load the browser directly from the string,
# but using a temp file is straight-forward and pretty much guaranteed to work :-/ # but using a temp file is straight-forward and pretty much guaranteed to work :-/

Loading…
Cancel
Save