|
11 | 11 | from typing import Any, Optional, TextIO, Union |
12 | 12 |
|
13 | 13 | # third-party |
14 | | -import aiofiles |
15 | 14 | from vcorelib import DEFAULT_ENCODING |
16 | 15 | from vcorelib.io import IndentedFileWriter, JsonObject |
17 | 16 | from vcorelib.paths import Pathlike, find_file, normalize |
|
26 | 25 | from runtimepy.net.server.html import HtmlApp, HtmlApps, get_html, html_handler |
27 | 26 | from runtimepy.net.server.json import encode_json, json_handler |
28 | 27 | from runtimepy.net.tcp.http import HttpConnection |
29 | | -from runtimepy.util import normalize_root, path_has_part |
| 28 | +from runtimepy.util import normalize_root, path_has_part, read_binary |
30 | 29 |
|
31 | 30 | MIMETYPES_INIT = False |
32 | 31 |
|
@@ -158,10 +157,9 @@ async def render_markdown_file( |
158 | 157 | ) -> bytes: |
159 | 158 | """Render a markdown file as HTML and return the result.""" |
160 | 159 |
|
161 | | - async with aiofiles.open(path, mode="r") as path_fd: |
162 | | - return self.render_markdown( |
163 | | - await path_fd.read(), response, **kwargs |
164 | | - ) |
| 160 | + return self.render_markdown( |
| 161 | + (await read_binary(path)).decode(), response, **kwargs |
| 162 | + ) |
165 | 163 |
|
166 | 164 | async def try_file( |
167 | 165 | self, path: PathMaybeQuery, response: ResponseHeader |
@@ -195,8 +193,7 @@ async def try_file( |
195 | 193 | self.logger.info("Serving '%s' (MIME: %s)", candidate, mime) |
196 | 194 |
|
197 | 195 | # Return the file data. |
198 | | - async with aiofiles.open(candidate, mode="rb") as path_fd: |
199 | | - result = await path_fd.read() |
| 196 | + result = await read_binary(candidate) |
200 | 197 |
|
201 | 198 | break |
202 | 199 |
|
|
0 commit comments