We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
WeasyPrint import error Python 3.7
## 🐛 Bug

When importing weasyprint with python 3.7 I have an error: `AttributeError: 'OutStream' object has no attribute 'buffer'`*


## To Reproduce

Steps to reproduce the behavior:

`from doctr.models import ocr_predictor`

leads to:

```
AttributeError                            Traceback (most recent call last)

<ipython-input-4-19f78ebc9b57> in <module>()
----> 1 from doctr.models import ocr_predictor
      2 
      3 # Load predictor
      4 model = ocr_predictor(pretrained=True)

7 frames

/usr/local/lib/python3.7/dist-packages/doctr/__init__.py in <module>()
      1 from .file_utils import is_tf_available, is_torch_available
      2 from .version import __version__  # noqa: F401
----> 3 from . import documents
      4 from . import transforms
      5 from . import utils

/usr/local/lib/python3.7/dist-packages/doctr/documents/__init__.py in <module>()
      1 from .elements import *
----> 2 from .reader import *

/usr/local/lib/python3.7/dist-packages/doctr/documents/reader.py in <module>()
      8 from pathlib import Path
      9 import fitz
---> 10 from weasyprint import HTML
     11 from typing import List, Tuple, Optional, Any, Union, Sequence, Dict
     12 

/usr/local/lib/python3.7/dist-packages/weasyprint/__init__.py in <module>()
    321 # Work around circular imports.
    322 from .css import preprocess_stylesheet  # noqa isort:skip
--> 323 from .html import (  # noqa isort:skip
    324     HTML5_UA_COUNTER_STYLE, HTML5_UA_STYLESHEET, HTML5_PH_STYLESHEET,
    325     find_base_url)

/usr/local/lib/python3.7/dist-packages/weasyprint/html.py in <module>()
     21 from .css.counters import CounterStyle
     22 from .formatting_structure import boxes
---> 23 from .images import SVGImage
     24 from .logger import LOGGER
     25 from .urls import get_url_attribute

/usr/local/lib/python3.7/dist-packages/weasyprint/images.py in <module>()
     11 from itertools import cycle
     12 
---> 13 import pydyf
     14 from PIL import Image
     15 

/usr/local/lib/python3.7/dist-packages/pydyf/__init__.py in <module>()
    402 
    403 
--> 404 class PDF:
    405     """PDF document."""
    406     def __init__(self):

/usr/local/lib/python3.7/dist-packages/pydyf/__init__.py in PDF()
    506         self.write_line(b'%%EOF', output)
    507 
--> 508     def write(self, output=sys.stdout.buffer):
    509         """Write PDF to output.
    510 

AttributeError: 'OutStream' object has no attribute 'buffer'

```


## Expected behavior

Nothing, special

## Environment
```
DocTR version: 0.3.0
TensorFlow version: 2.5.0
PyTorch version: 1.9.0+cu102 (torchvision 0.10.0+cu102)
OpenCV version: 4.5.3
OS: Ubuntu 18.04.5 LTS
Python version: 3.7
Is CUDA available (TensorFlow): No
Is CUDA available (PyTorch): No
CUDA runtime version: 11.0.221
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 # Copyright (C) 2021, Mindee.
2 
3 # This program is licensed under the Apache License version 2.
4 # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.
5 
6 """
7 Package installation setup
8 """
9 
10 import os
11 import re
12 from pathlib import Path
13 import subprocess
14 
15 from setuptools import find_packages, setup
16 
17 
18 version = "0.3.1a0"
19 sha = 'Unknown'
20 package_name = 'doctr'
21 
22 cwd = Path(__file__).parent.absolute()
23 
24 if os.getenv('BUILD_VERSION'):
25     version = os.getenv('BUILD_VERSION')
26 elif sha != 'Unknown':
27     try:
28         sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()
29     except Exception:
30         pass
31     version += '+' + sha[:7]
32 print(f"Building wheel {package_name}-{version}")
33 
34 with open(cwd.joinpath(package_name, 'version.py'), 'w') as f:
35     f.write(f"__version__ = '{version}'\n")
36 
37 with open('README.md', 'r') as f:
38     readme = f.read()
39 
40 # Borrowed from https://github.com/huggingface/transformers/blob/master/setup.py
41 _deps = [
42     "importlib_metadata",
43     "numpy>=1.16.0",
44     "scipy>=1.4.0",
45     "opencv-python>=4.2",
46     "tensorflow>=2.4.0",
47     "PyMuPDF>=1.16.0,<1.18.11",
48     "pyclipper>=1.2.0",
49     "shapely>=1.6.0",
50     "matplotlib>=3.1.0",
51     "mplcursors>=0.3",
52     "weasyprint>=52.2",
53     "unidecode>=1.0.0",
54     "tensorflow-cpu>=2.4.0",
55     "torch>=1.8.0",
56     "torchvision>=0.9.0",
57     "Pillow>=8.0.0,<8.3.0",  # cf. https://github.com/python-pillow/Pillow/issues/5571
58     "tqdm>=4.30.0",
59     "tensorflow-addons>=0.13.0"
60 ]
61 
62 deps = {b: a for a, b in (re.findall(r"^(([^!=<>]+)(?:[!=<>].*)?$)", x)[0] for x in _deps)}
63 
64 
65 def deps_list(*pkgs):
66     return [deps[pkg] for pkg in pkgs]
67 
68 
69 install_requires = [
70     deps["importlib_metadata"] + ";python_version<'3.8'",  # importlib_metadata for Python versions that don't have it
71     deps["numpy"],
72     deps["scipy"],
73     deps["opencv-python"],
74     deps["PyMuPDF"],
75     deps["pyclipper"],
76     deps["shapely"],
77     deps["matplotlib"],
78     deps["mplcursors"],
79     deps["weasyprint"],
80     deps["unidecode"],
81     deps["Pillow"],
82     deps["tqdm"],
83 ]
84 
85 extras = {}
86 extras["tf"] = deps_list("tensorflow", "tensorflow-addons")
87 extras["tf-cpu"] = deps_list("tensorflow-cpu", "tensorflow-addons")
88 extras["torch"] = deps_list("torch", "torchvision")
89 extras["all"] = (
90     extras["tf"]
91     + extras["torch"]
92 )
93 
94 setup(
95     # Metadata
96     name=os.getenv('PKG_INDEX') if os.getenv('PKG_INDEX') else package_name,
97     version=version,
98     author='François-Guillaume Fernandez, Charles Gaillard',
99     author_email='fg@mindee.co',
100     description='Extract valuable text information from your documents',
101     long_description=readme,
102     long_description_content_type="text/markdown",
103     url='https://github.com/mindee/doctr',
104     download_url='https://github.com/mindee/doctr/tags',
105     license='Apache',
106     classifiers=[
107         'Development Status :: 4 - Beta',
108         'Intended Audience :: Developers',
109         "Intended Audience :: Education",
110         'Intended Audience :: Science/Research',
111         'License :: OSI Approved :: Apache Software License',
112         'Natural Language :: English',
113         'Operating System :: OS Independent',
114         'Programming Language :: Python :: 3',
115         'Programming Language :: Python :: 3.6',
116         'Programming Language :: Python :: 3.7',
117         'Topic :: Scientific/Engineering :: Artificial Intelligence',
118     ],
119     keywords=['OCR', 'deep learning', 'computer vision', 'tensorflow', 'pytorch', 'text detection', 'text recognition'],
120 
121     # Package info
122     packages=find_packages(exclude=('test',)),
123     zip_safe=True,
124     python_requires='>=3.6.0',
125     include_package_data=True,
126     install_requires=install_requires,
127     extras_require=extras,
128     package_data={'': ['LICENSE']}
129 )
130
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -49,7 +49,7 @@
     "shapely>=1.6.0",
     "matplotlib>=3.1.0",
     "mplcursors>=0.3",
-    "weasyprint>=52.2",
+    "weasyprint>=52.2,<53.0",
     "unidecode>=1.0.0",
     "tensorflow-cpu>=2.4.0",
     "torch>=1.8.0",

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -49,7 +49,7 @@\n     \"shapely>=1.6.0\",\n     \"matplotlib>=3.1.0\",\n     \"mplcursors>=0.3\",\n-    \"weasyprint>=52.2\",\n+    \"weasyprint>=52.2,<53.0\",\n     \"unidecode>=1.0.0\",\n     \"tensorflow-cpu>=2.4.0\",\n     \"torch>=1.8.0\",\n", "issue": "WeasyPrint import error Python 3.7\n## \ud83d\udc1b Bug\r\n\r\nWhen importing weasyprint with python 3.7 I have an error: `AttributeError: 'OutStream' object has no attribute 'buffer'`*\r\n\r\n\r\n## To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\n`from doctr.models import ocr_predictor`\r\n\r\nleads to:\r\n\r\n```\r\nAttributeError                            Traceback (most recent call last)\r\n\r\n<ipython-input-4-19f78ebc9b57> in <module>()\r\n----> 1 from doctr.models import ocr_predictor\r\n      2 \r\n      3 # Load predictor\r\n      4 model = ocr_predictor(pretrained=True)\r\n\r\n7 frames\r\n\r\n/usr/local/lib/python3.7/dist-packages/doctr/__init__.py in <module>()\r\n      1 from .file_utils import is_tf_available, is_torch_available\r\n      2 from .version import __version__  # noqa: F401\r\n----> 3 from . import documents\r\n      4 from . import transforms\r\n      5 from . import utils\r\n\r\n/usr/local/lib/python3.7/dist-packages/doctr/documents/__init__.py in <module>()\r\n      1 from .elements import *\r\n----> 2 from .reader import *\r\n\r\n/usr/local/lib/python3.7/dist-packages/doctr/documents/reader.py in <module>()\r\n      8 from pathlib import Path\r\n      9 import fitz\r\n---> 10 from weasyprint import HTML\r\n     11 from typing import List, Tuple, Optional, Any, Union, Sequence, Dict\r\n     12 \r\n\r\n/usr/local/lib/python3.7/dist-packages/weasyprint/__init__.py in <module>()\r\n    321 # Work around circular imports.\r\n    322 from .css import preprocess_stylesheet  # noqa isort:skip\r\n--> 323 from .html import (  # noqa isort:skip\r\n    324     HTML5_UA_COUNTER_STYLE, HTML5_UA_STYLESHEET, HTML5_PH_STYLESHEET,\r\n    325     find_base_url)\r\n\r\n/usr/local/lib/python3.7/dist-packages/weasyprint/html.py in <module>()\r\n     21 from .css.counters import CounterStyle\r\n     22 from .formatting_structure import boxes\r\n---> 23 from .images import SVGImage\r\n     24 from .logger import LOGGER\r\n     25 from .urls import get_url_attribute\r\n\r\n/usr/local/lib/python3.7/dist-packages/weasyprint/images.py in <module>()\r\n     11 from itertools import cycle\r\n     12 \r\n---> 13 import pydyf\r\n     14 from PIL import Image\r\n     15 \r\n\r\n/usr/local/lib/python3.7/dist-packages/pydyf/__init__.py in <module>()\r\n    402 \r\n    403 \r\n--> 404 class PDF:\r\n    405     \"\"\"PDF document.\"\"\"\r\n    406     def __init__(self):\r\n\r\n/usr/local/lib/python3.7/dist-packages/pydyf/__init__.py in PDF()\r\n    506         self.write_line(b'%%EOF', output)\r\n    507 \r\n--> 508     def write(self, output=sys.stdout.buffer):\r\n    509         \"\"\"Write PDF to output.\r\n    510 \r\n\r\nAttributeError: 'OutStream' object has no attribute 'buffer'\r\n\r\n```\r\n\r\n\r\n## Expected behavior\r\n\r\nNothing, special\r\n\r\n## Environment\r\n```\r\nDocTR version: 0.3.0\r\nTensorFlow version: 2.5.0\r\nPyTorch version: 1.9.0+cu102 (torchvision 0.10.0+cu102)\r\nOpenCV version: 4.5.3\r\nOS: Ubuntu 18.04.5 LTS\r\nPython version: 3.7\r\nIs CUDA available (TensorFlow): No\r\nIs CUDA available (PyTorch): No\r\nCUDA runtime version: 11.0.221\r\nGPU models and configuration: Could not collect\r\nNvidia driver version: Could not collect\r\n```\r\n\n", "before_files": [{"content": "# Copyright (C) 2021, Mindee.\n\n# This program is licensed under the Apache License version 2.\n# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.\n\n\"\"\"\nPackage installation setup\n\"\"\"\n\nimport os\nimport re\nfrom pathlib import Path\nimport subprocess\n\nfrom setuptools import find_packages, setup\n\n\nversion = \"0.3.1a0\"\nsha = 'Unknown'\npackage_name = 'doctr'\n\ncwd = Path(__file__).parent.absolute()\n\nif os.getenv('BUILD_VERSION'):\n    version = os.getenv('BUILD_VERSION')\nelif sha != 'Unknown':\n    try:\n        sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()\n    except Exception:\n        pass\n    version += '+' + sha[:7]\nprint(f\"Building wheel {package_name}-{version}\")\n\nwith open(cwd.joinpath(package_name, 'version.py'), 'w') as f:\n    f.write(f\"__version__ = '{version}'\\n\")\n\nwith open('README.md', 'r') as f:\n    readme = f.read()\n\n# Borrowed from https://github.com/huggingface/transformers/blob/master/setup.py\n_deps = [\n    \"importlib_metadata\",\n    \"numpy>=1.16.0\",\n    \"scipy>=1.4.0\",\n    \"opencv-python>=4.2\",\n    \"tensorflow>=2.4.0\",\n    \"PyMuPDF>=1.16.0,<1.18.11\",\n    \"pyclipper>=1.2.0\",\n    \"shapely>=1.6.0\",\n    \"matplotlib>=3.1.0\",\n    \"mplcursors>=0.3\",\n    \"weasyprint>=52.2\",\n    \"unidecode>=1.0.0\",\n    \"tensorflow-cpu>=2.4.0\",\n    \"torch>=1.8.0\",\n    \"torchvision>=0.9.0\",\n    \"Pillow>=8.0.0,<8.3.0\",  # cf. https://github.com/python-pillow/Pillow/issues/5571\n    \"tqdm>=4.30.0\",\n    \"tensorflow-addons>=0.13.0\"\n]\n\ndeps = {b: a for a, b in (re.findall(r\"^(([^!=<>]+)(?:[!=<>].*)?$)\", x)[0] for x in _deps)}\n\n\ndef deps_list(*pkgs):\n    return [deps[pkg] for pkg in pkgs]\n\n\ninstall_requires = [\n    deps[\"importlib_metadata\"] + \";python_version<'3.8'\",  # importlib_metadata for Python versions that don't have it\n    deps[\"numpy\"],\n    deps[\"scipy\"],\n    deps[\"opencv-python\"],\n    deps[\"PyMuPDF\"],\n    deps[\"pyclipper\"],\n    deps[\"shapely\"],\n    deps[\"matplotlib\"],\n    deps[\"mplcursors\"],\n    deps[\"weasyprint\"],\n    deps[\"unidecode\"],\n    deps[\"Pillow\"],\n    deps[\"tqdm\"],\n]\n\nextras = {}\nextras[\"tf\"] = deps_list(\"tensorflow\", \"tensorflow-addons\")\nextras[\"tf-cpu\"] = deps_list(\"tensorflow-cpu\", \"tensorflow-addons\")\nextras[\"torch\"] = deps_list(\"torch\", \"torchvision\")\nextras[\"all\"] = (\n    extras[\"tf\"]\n    + extras[\"torch\"]\n)\n\nsetup(\n    # Metadata\n    name=os.getenv('PKG_INDEX') if os.getenv('PKG_INDEX') else package_name,\n    version=version,\n    author='Fran\u00e7ois-Guillaume Fernandez, Charles Gaillard',\n    author_email='fg@mindee.co',\n    description='Extract valuable text information from your documents',\n    long_description=readme,\n    long_description_content_type=\"text/markdown\",\n    url='https://github.com/mindee/doctr',\n    download_url='https://github.com/mindee/doctr/tags',\n    license='Apache',\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Intended Audience :: Developers',\n        \"Intended Audience :: Education\",\n        'Intended Audience :: Science/Research',\n        'License :: OSI Approved :: Apache Software License',\n        'Natural Language :: English',\n        'Operating System :: OS Independent',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Topic :: Scientific/Engineering :: Artificial Intelligence',\n    ],\n    keywords=['OCR', 'deep learning', 'computer vision', 'tensorflow', 'pytorch', 'text detection', 'text recognition'],\n\n    # Package info\n    packages=find_packages(exclude=('test',)),\n    zip_safe=True,\n    python_requires='>=3.6.0',\n    include_package_data=True,\n    install_requires=install_requires,\n    extras_require=extras,\n    package_data={'': ['LICENSE']}\n)\n", "path": "setup.py"}], "after_files": [{"content": "# Copyright (C) 2021, Mindee.\n\n# This program is licensed under the Apache License version 2.\n# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.\n\n\"\"\"\nPackage installation setup\n\"\"\"\n\nimport os\nimport re\nfrom pathlib import Path\nimport subprocess\n\nfrom setuptools import find_packages, setup\n\n\nversion = \"0.3.1a0\"\nsha = 'Unknown'\npackage_name = 'doctr'\n\ncwd = Path(__file__).parent.absolute()\n\nif os.getenv('BUILD_VERSION'):\n    version = os.getenv('BUILD_VERSION')\nelif sha != 'Unknown':\n    try:\n        sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()\n    except Exception:\n        pass\n    version += '+' + sha[:7]\nprint(f\"Building wheel {package_name}-{version}\")\n\nwith open(cwd.joinpath(package_name, 'version.py'), 'w') as f:\n    f.write(f\"__version__ = '{version}'\\n\")\n\nwith open('README.md', 'r') as f:\n    readme = f.read()\n\n# Borrowed from https://github.com/huggingface/transformers/blob/master/setup.py\n_deps = [\n    \"importlib_metadata\",\n    \"numpy>=1.16.0\",\n    \"scipy>=1.4.0\",\n    \"opencv-python>=4.2\",\n    \"tensorflow>=2.4.0\",\n    \"PyMuPDF>=1.16.0,<1.18.11\",\n    \"pyclipper>=1.2.0\",\n    \"shapely>=1.6.0\",\n    \"matplotlib>=3.1.0\",\n    \"mplcursors>=0.3\",\n    \"weasyprint>=52.2,<53.0\",\n    \"unidecode>=1.0.0\",\n    \"tensorflow-cpu>=2.4.0\",\n    \"torch>=1.8.0\",\n    \"torchvision>=0.9.0\",\n    \"Pillow>=8.0.0,<8.3.0\",  # cf. https://github.com/python-pillow/Pillow/issues/5571\n    \"tqdm>=4.30.0\",\n    \"tensorflow-addons>=0.13.0\"\n]\n\ndeps = {b: a for a, b in (re.findall(r\"^(([^!=<>]+)(?:[!=<>].*)?$)\", x)[0] for x in _deps)}\n\n\ndef deps_list(*pkgs):\n    return [deps[pkg] for pkg in pkgs]\n\n\ninstall_requires = [\n    deps[\"importlib_metadata\"] + \";python_version<'3.8'\",  # importlib_metadata for Python versions that don't have it\n    deps[\"numpy\"],\n    deps[\"scipy\"],\n    deps[\"opencv-python\"],\n    deps[\"PyMuPDF\"],\n    deps[\"pyclipper\"],\n    deps[\"shapely\"],\n    deps[\"matplotlib\"],\n    deps[\"mplcursors\"],\n    deps[\"weasyprint\"],\n    deps[\"unidecode\"],\n    deps[\"Pillow\"],\n    deps[\"tqdm\"],\n]\n\nextras = {}\nextras[\"tf\"] = deps_list(\"tensorflow\", \"tensorflow-addons\")\nextras[\"tf-cpu\"] = deps_list(\"tensorflow-cpu\", \"tensorflow-addons\")\nextras[\"torch\"] = deps_list(\"torch\", \"torchvision\")\nextras[\"all\"] = (\n    extras[\"tf\"]\n    + extras[\"torch\"]\n)\n\nsetup(\n    # Metadata\n    name=os.getenv('PKG_INDEX') if os.getenv('PKG_INDEX') else package_name,\n    version=version,\n    author='Fran\u00e7ois-Guillaume Fernandez, Charles Gaillard',\n    author_email='fg@mindee.co',\n    description='Extract valuable text information from your documents',\n    long_description=readme,\n    long_description_content_type=\"text/markdown\",\n    url='https://github.com/mindee/doctr',\n    download_url='https://github.com/mindee/doctr/tags',\n    license='Apache',\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Intended Audience :: Developers',\n        \"Intended Audience :: Education\",\n        'Intended Audience :: Science/Research',\n        'License :: OSI Approved :: Apache Software License',\n        'Natural Language :: English',\n        'Operating System :: OS Independent',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Topic :: Scientific/Engineering :: Artificial Intelligence',\n    ],\n    keywords=['OCR', 'deep learning', 'computer vision', 'tensorflow', 'pytorch', 'text detection', 'text recognition'],\n\n    # Package info\n    packages=find_packages(exclude=('test',)),\n    zip_safe=True,\n    python_requires='>=3.6.0',\n    include_package_data=True,\n    install_requires=install_requires,\n    extras_require=extras,\n    package_data={'': ['LICENSE']}\n)\n", "path": "setup.py"}]}