diff --git a/newsfragments/4044.minor b/newsfragments/4044.minor new file mode 100644 index 000000000..e69de29bb diff --git a/src/allmydata/client.py b/src/allmydata/client.py index fefd29657..13909d5ca 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -1030,14 +1030,14 @@ class _Client(node.Node, pollmixin.PollMixin): def init_web(self, webport): self.log("init_web(webport=%s)", args=(webport,)) - from allmydata.webish import WebishServer, anonymous_tempfile + from allmydata.webish import WebishServer, anonymous_tempfile_factory nodeurl_path = self.config.get_config_path("node.url") staticdir_config = self.config.get_config("node", "web.static", "public_html") staticdir = self.config.get_config_path(staticdir_config) ws = WebishServer( self, webport, - anonymous_tempfile(self._get_tempdir()), + anonymous_tempfile_factory(self._get_tempdir()), nodeurl_path, staticdir, ) diff --git a/src/allmydata/test/web/test_web.py b/src/allmydata/test/web/test_web.py index bd7ca3f7f..42be0f50d 100644 --- a/src/allmydata/test/web/test_web.py +++ b/src/allmydata/test/web/test_web.py @@ -341,7 +341,7 @@ class WebMixin(TimezoneMixin): self.ws = webish.WebishServer( self.s, "0", - webish.anonymous_tempfile(tempdir.path), + webish.anonymous_tempfile_factory(tempdir.path), staticdir=self.staticdir, clock=self.clock, now_fn=lambda:self.fakeTime, diff --git a/src/allmydata/test/web/test_webish.py b/src/allmydata/test/web/test_webish.py index d444df436..523dfc878 100644 --- a/src/allmydata/test/web/test_webish.py +++ b/src/allmydata/test/web/test_webish.py @@ -6,9 +6,6 @@ import tempfile from uuid import ( uuid4, ) -from errno import ( - EACCES, -) from io import ( BytesIO, ) @@ -30,9 +27,6 @@ from testtools.matchers import ( HasLength, ) -from twisted.python.runtime import ( - platform, -) from twisted.python.filepath import ( FilePath, ) @@ -50,7 +44,7 @@ from ..common import ( from ...webish import ( TahoeLAFSRequest, TahoeLAFSSite, - anonymous_tempfile, + anonymous_tempfile_factory, ) @@ -179,7 +173,7 @@ class TahoeLAFSSiteTests(SyncTestCase): FilePath(tempdir).makedirs() site = TahoeLAFSSite( - anonymous_tempfile(tempdir), + anonymous_tempfile_factory(tempdir), Resource(), logPath=logPath, ) diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 2bae7f8a5..ec5ad64c0 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -4,7 +4,7 @@ General web server-related utilities. from __future__ import annotations from six import ensure_str -from typing import BinaryIO, Callable, Optional +from typing import IO, Callable, Optional import re, time, tempfile from urllib.parse import parse_qsl, urlencode @@ -217,7 +217,7 @@ def censor(queryargs: bytes) -> bytes: return urlencode(result, safe="[]").encode("ascii") -def anonymous_tempfile(tempdir: bytes) -> BinaryIO: +def anonymous_tempfile_factory(tempdir: bytes) -> Callable[[], IO[bytes]]: """ Create a no-argument callable for creating a new temporary file in the given directory. @@ -243,14 +243,14 @@ class TahoeLAFSSite(Site, object): """ requestFactory = TahoeLAFSRequest - def __init__(self, make_tempfile: Callable[[], BinaryIO], *args, **kwargs): + def __init__(self, make_tempfile: Callable[[], IO[bytes]], *args, **kwargs): Site.__init__(self, *args, logFormatter=_logFormatter, **kwargs) assert callable(make_tempfile) with make_tempfile(): pass self._make_tempfile = make_tempfile - def getContentFile(self, length: Optional[int]) -> BinaryIO: + def getContentFile(self, length: Optional[int]) -> IO[bytes]: if length is None or length >= 1024 * 1024: return self._make_tempfile() return BytesIO()