diff --git a/weasyprint/fonts.py b/weasyprint/fonts.py
index 5e95c4aec..b61555cf6 100644
--- a/weasyprint/fonts.py
+++ b/weasyprint/fonts.py
@@ -225,9 +225,9 @@ def add_font_face(self, rule_descriptors, url_fetcher):
**font_features).items():
features_string += '%s %s' % (
key, value)
- _, filename = tempfile.mkstemp()
- with open(filename, 'wb') as fd:
- fd.write(font)
+ fd, filename = tempfile.mkstemp()
+ os.write(fd, font)
+ os.close(fd)
self._filenames.append(filename)
xml = '''
@@ -266,10 +266,10 @@ def add_font_face(self, rule_descriptors, url_fetcher):
FONTCONFIG_STRETCH_CONSTANTS[
rule_descriptors.get('font_stretch', 'normal')],
filename, features_string)
- _, conf_filename = tempfile.mkstemp()
- with open(conf_filename, 'wb') as fd:
- # TODO: coding is OK for but what about ?
- fd.write(xml.encode(FILESYSTEM_ENCODING))
+ fd, conf_filename = tempfile.mkstemp()
+ # TODO: coding is OK for but what about ?
+ os.write(fd, xml.encode(FILESYSTEM_ENCODING))
+ os.close(fd)
self._filenames.append(conf_filename)
fontconfig.FcConfigParseAndLoad(
config, conf_filename.encode(FILESYSTEM_ENCODING),