1from__future__importannotations 2 3# 4# 5# This file is part of gunicorn released under the MIT license. 6# See the LICENSE for more information. 7# 8# Vendored and modified for Plain. 9importos10importplatform11importtempfile12importtime13fromtypingimportTYPE_CHECKING1415from..importutil1617ifTYPE_CHECKING:18from..configimportConfig1920PLATFORM=platform.system()21IS_CYGWIN=PLATFORM.startswith("CYGWIN")222324classWorkerTmp:25def__init__(self,cfg:Config)->None:26fd,name=tempfile.mkstemp(prefix="wplain-")2728# unlink the file so we don't leak temporary files29try:30ifnotIS_CYGWIN:31util.unlink(name)32# In Python 3.8, open() emits RuntimeWarning if buffering=1 for binary mode.33# Because we never write to this file, pass 0 to switch buffering off.34self._tmp=os.fdopen(fd,"w+b",0)35exceptException:36os.close(fd)37raise3839defnotify(self)->None:40new_time=time.monotonic()41os.utime(self._tmp.fileno(),(new_time,new_time))4243deflast_update(self)->float:44returnos.fstat(self._tmp.fileno()).st_mtime4546deffileno(self)->int:47returnself._tmp.fileno()4849defclose(self)->None:50returnself._tmp.close()