prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  deprecate posixemulation
  It's called out as "not a public interface" in the docstring, and looks like it was only there to support `contrib.sessions`, which has moved to `secure-cookie` now. Move it there if it's still needed, remove it here.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/werkzeug/posixemulation.py`
  Content:
  ```
  1 """A ``rename`` function that follows POSIX semantics. If the target
  2 file already exists it will be replaced without asking.
  3 
  4 This is not a public interface.
  5 """
  6 import errno
  7 import os
  8 import random
  9 import sys
  10 import time
  11 
  12 from ._internal import _to_str
  13 from .filesystem import get_filesystem_encoding
  14 
  15 can_rename_open_file = False
  16 
  17 if os.name == "nt":
  18     try:
  19         import ctypes
  20 
  21         _MOVEFILE_REPLACE_EXISTING = 0x1
  22         _MOVEFILE_WRITE_THROUGH = 0x8
  23         _MoveFileEx = ctypes.windll.kernel32.MoveFileExW  # type: ignore
  24 
  25         def _rename(src, dst):
  26             src = _to_str(src, get_filesystem_encoding())
  27             dst = _to_str(dst, get_filesystem_encoding())
  28             if _rename_atomic(src, dst):
  29                 return True
  30             retry = 0
  31             rv = False
  32             while not rv and retry < 100:
  33                 rv = _MoveFileEx(
  34                     src, dst, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH
  35                 )
  36                 if not rv:
  37                     time.sleep(0.001)
  38                     retry += 1
  39             return rv
  40 
  41         # new in Vista and Windows Server 2008
  42         _CreateTransaction = ctypes.windll.ktmw32.CreateTransaction  # type: ignore
  43         _CommitTransaction = ctypes.windll.ktmw32.CommitTransaction  # type: ignore
  44         _MoveFileTransacted = ctypes.windll.kernel32.MoveFileTransactedW  # type: ignore
  45         _CloseHandle = ctypes.windll.kernel32.CloseHandle  # type: ignore
  46         can_rename_open_file = True
  47 
  48         def _rename_atomic(src, dst):
  49             ta = _CreateTransaction(None, 0, 0, 0, 0, 1000, "Werkzeug rename")
  50             if ta == -1:
  51                 return False
  52             try:
  53                 retry = 0
  54                 rv = False
  55                 while not rv and retry < 100:
  56                     rv = _MoveFileTransacted(
  57                         src,
  58                         dst,
  59                         None,
  60                         None,
  61                         _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH,
  62                         ta,
  63                     )
  64                     if rv:
  65                         rv = _CommitTransaction(ta)
  66                         break
  67                     else:
  68                         time.sleep(0.001)
  69                         retry += 1
  70                 return rv
  71             finally:
  72                 _CloseHandle(ta)
  73 
  74     except Exception:
  75 
  76         def _rename(src, dst):
  77             return False
  78 
  79         def _rename_atomic(src, dst):
  80             return False
  81 
  82     def rename(src, dst):
  83         # Try atomic or pseudo-atomic rename
  84         if _rename(src, dst):
  85             return
  86         # Fall back to "move away and replace"
  87         try:
  88             os.rename(src, dst)
  89         except OSError as e:
  90             if e.errno != errno.EEXIST:
  91                 raise
  92             old = f"{dst}-{random.randint(0, sys.maxsize):08x}"
  93             os.rename(dst, old)
  94             os.rename(src, dst)
  95             try:
  96                 os.unlink(old)
  97             except Exception:
  98                 pass
  99 
  100 
  101 else:
  102     rename = os.rename
  103     can_rename_open_file = True
  104
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/src/werkzeug/posixemulation.py b/src/werkzeug/posixemulation.py
  deleted file mode 100644
  --- a/src/werkzeug/posixemulation.py
  +++ /dev/null
  @@ -1,103 +0,0 @@
  -"""A ``rename`` function that follows POSIX semantics. If the target
  -file already exists it will be replaced without asking.
  -
  -This is not a public interface.
  -"""
  -import errno
  -import os
  -import random
  -import sys
  -import time
  -
  -from ._internal import _to_str
  -from .filesystem import get_filesystem_encoding
  -
  -can_rename_open_file = False
  -
  -if os.name == "nt":
  -    try:
  -        import ctypes
  -
  -        _MOVEFILE_REPLACE_EXISTING = 0x1
  -        _MOVEFILE_WRITE_THROUGH = 0x8
  -        _MoveFileEx = ctypes.windll.kernel32.MoveFileExW  # type: ignore
  -
  -        def _rename(src, dst):
  -            src = _to_str(src, get_filesystem_encoding())
  -            dst = _to_str(dst, get_filesystem_encoding())
  -            if _rename_atomic(src, dst):
  -                return True
  -            retry = 0
  -            rv = False
  -            while not rv and retry < 100:
  -                rv = _MoveFileEx(
  -                    src, dst, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH
  -                )
  -                if not rv:
  -                    time.sleep(0.001)
  -                    retry += 1
  -            return rv
  -
  -        # new in Vista and Windows Server 2008
  -        _CreateTransaction = ctypes.windll.ktmw32.CreateTransaction  # type: ignore
  -        _CommitTransaction = ctypes.windll.ktmw32.CommitTransaction  # type: ignore
  -        _MoveFileTransacted = ctypes.windll.kernel32.MoveFileTransactedW  # type: ignore
  -        _CloseHandle = ctypes.windll.kernel32.CloseHandle  # type: ignore
  -        can_rename_open_file = True
  -
  -        def _rename_atomic(src, dst):
  -            ta = _CreateTransaction(None, 0, 0, 0, 0, 1000, "Werkzeug rename")
  -            if ta == -1:
  -                return False
  -            try:
  -                retry = 0
  -                rv = False
  -                while not rv and retry < 100:
  -                    rv = _MoveFileTransacted(
  -                        src,
  -                        dst,
  -                        None,
  -                        None,
  -                        _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH,
  -                        ta,
  -                    )
  -                    if rv:
  -                        rv = _CommitTransaction(ta)
  -                        break
  -                    else:
  -                        time.sleep(0.001)
  -                        retry += 1
  -                return rv
  -            finally:
  -                _CloseHandle(ta)
  -
  -    except Exception:
  -
  -        def _rename(src, dst):
  -            return False
  -
  -        def _rename_atomic(src, dst):
  -            return False
  -
  -    def rename(src, dst):
  -        # Try atomic or pseudo-atomic rename
  -        if _rename(src, dst):
  -            return
  -        # Fall back to "move away and replace"
  -        try:
  -            os.rename(src, dst)
  -        except OSError as e:
  -            if e.errno != errno.EEXIST:
  -                raise
  -            old = f"{dst}-{random.randint(0, sys.maxsize):08x}"
  -            os.rename(dst, old)
  -            os.rename(src, dst)
  -            try:
  -                os.unlink(old)
  -            except Exception:
  -                pass
  -
  -
  -else:
  -    rename = os.rename
  -    can_rename_open_file = True
  
verification_info: {"golden_diff": "diff --git a/src/werkzeug/posixemulation.py b/src/werkzeug/posixemulation.py\ndeleted file mode 100644\n--- a/src/werkzeug/posixemulation.py\n+++ /dev/null\n@@ -1,103 +0,0 @@\n-\"\"\"A ``rename`` function that follows POSIX semantics. If the target\n-file already exists it will be replaced without asking.\n-\n-This is not a public interface.\n-\"\"\"\n-import errno\n-import os\n-import random\n-import sys\n-import time\n-\n-from ._internal import _to_str\n-from .filesystem import get_filesystem_encoding\n-\n-can_rename_open_file = False\n-\n-if os.name == \"nt\":\n-    try:\n-        import ctypes\n-\n-        _MOVEFILE_REPLACE_EXISTING = 0x1\n-        _MOVEFILE_WRITE_THROUGH = 0x8\n-        _MoveFileEx = ctypes.windll.kernel32.MoveFileExW  # type: ignore\n-\n-        def _rename(src, dst):\n-            src = _to_str(src, get_filesystem_encoding())\n-            dst = _to_str(dst, get_filesystem_encoding())\n-            if _rename_atomic(src, dst):\n-                return True\n-            retry = 0\n-            rv = False\n-            while not rv and retry < 100:\n-                rv = _MoveFileEx(\n-                    src, dst, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH\n-                )\n-                if not rv:\n-                    time.sleep(0.001)\n-                    retry += 1\n-            return rv\n-\n-        # new in Vista and Windows Server 2008\n-        _CreateTransaction = ctypes.windll.ktmw32.CreateTransaction  # type: ignore\n-        _CommitTransaction = ctypes.windll.ktmw32.CommitTransaction  # type: ignore\n-        _MoveFileTransacted = ctypes.windll.kernel32.MoveFileTransactedW  # type: ignore\n-        _CloseHandle = ctypes.windll.kernel32.CloseHandle  # type: ignore\n-        can_rename_open_file = True\n-\n-        def _rename_atomic(src, dst):\n-            ta = _CreateTransaction(None, 0, 0, 0, 0, 1000, \"Werkzeug rename\")\n-            if ta == -1:\n-                return False\n-            try:\n-                retry = 0\n-                rv = False\n-                while not rv and retry < 100:\n-                    rv = _MoveFileTransacted(\n-                        src,\n-                        dst,\n-                        None,\n-                        None,\n-                        _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH,\n-                        ta,\n-                    )\n-                    if rv:\n-                        rv = _CommitTransaction(ta)\n-                        break\n-                    else:\n-                        time.sleep(0.001)\n-                        retry += 1\n-                return rv\n-            finally:\n-                _CloseHandle(ta)\n-\n-    except Exception:\n-\n-        def _rename(src, dst):\n-            return False\n-\n-        def _rename_atomic(src, dst):\n-            return False\n-\n-    def rename(src, dst):\n-        # Try atomic or pseudo-atomic rename\n-        if _rename(src, dst):\n-            return\n-        # Fall back to \"move away and replace\"\n-        try:\n-            os.rename(src, dst)\n-        except OSError as e:\n-            if e.errno != errno.EEXIST:\n-                raise\n-            old = f\"{dst}-{random.randint(0, sys.maxsize):08x}\"\n-            os.rename(dst, old)\n-            os.rename(src, dst)\n-            try:\n-                os.unlink(old)\n-            except Exception:\n-                pass\n-\n-\n-else:\n-    rename = os.rename\n-    can_rename_open_file = True\n", "issue": "deprecate posixemulation\nIt's called out as \"not a public interface\" in the docstring, and looks like it was only there to support `contrib.sessions`, which has moved to `secure-cookie` now. Move it there if it's still needed, remove it here.\n", "before_files": [{"content": "\"\"\"A ``rename`` function that follows POSIX semantics. If the target\nfile already exists it will be replaced without asking.\n\nThis is not a public interface.\n\"\"\"\nimport errno\nimport os\nimport random\nimport sys\nimport time\n\nfrom ._internal import _to_str\nfrom .filesystem import get_filesystem_encoding\n\ncan_rename_open_file = False\n\nif os.name == \"nt\":\n    try:\n        import ctypes\n\n        _MOVEFILE_REPLACE_EXISTING = 0x1\n        _MOVEFILE_WRITE_THROUGH = 0x8\n        _MoveFileEx = ctypes.windll.kernel32.MoveFileExW  # type: ignore\n\n        def _rename(src, dst):\n            src = _to_str(src, get_filesystem_encoding())\n            dst = _to_str(dst, get_filesystem_encoding())\n            if _rename_atomic(src, dst):\n                return True\n            retry = 0\n            rv = False\n            while not rv and retry < 100:\n                rv = _MoveFileEx(\n                    src, dst, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH\n                )\n                if not rv:\n                    time.sleep(0.001)\n                    retry += 1\n            return rv\n\n        # new in Vista and Windows Server 2008\n        _CreateTransaction = ctypes.windll.ktmw32.CreateTransaction  # type: ignore\n        _CommitTransaction = ctypes.windll.ktmw32.CommitTransaction  # type: ignore\n        _MoveFileTransacted = ctypes.windll.kernel32.MoveFileTransactedW  # type: ignore\n        _CloseHandle = ctypes.windll.kernel32.CloseHandle  # type: ignore\n        can_rename_open_file = True\n\n        def _rename_atomic(src, dst):\n            ta = _CreateTransaction(None, 0, 0, 0, 0, 1000, \"Werkzeug rename\")\n            if ta == -1:\n                return False\n            try:\n                retry = 0\n                rv = False\n                while not rv and retry < 100:\n                    rv = _MoveFileTransacted(\n                        src,\n                        dst,\n                        None,\n                        None,\n                        _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH,\n                        ta,\n                    )\n                    if rv:\n                        rv = _CommitTransaction(ta)\n                        break\n                    else:\n                        time.sleep(0.001)\n                        retry += 1\n                return rv\n            finally:\n                _CloseHandle(ta)\n\n    except Exception:\n\n        def _rename(src, dst):\n            return False\n\n        def _rename_atomic(src, dst):\n            return False\n\n    def rename(src, dst):\n        # Try atomic or pseudo-atomic rename\n        if _rename(src, dst):\n            return\n        # Fall back to \"move away and replace\"\n        try:\n            os.rename(src, dst)\n        except OSError as e:\n            if e.errno != errno.EEXIST:\n                raise\n            old = f\"{dst}-{random.randint(0, sys.maxsize):08x}\"\n            os.rename(dst, old)\n            os.rename(src, dst)\n            try:\n                os.unlink(old)\n            except Exception:\n                pass\n\n\nelse:\n    rename = os.rename\n    can_rename_open_file = True\n", "path": "src/werkzeug/posixemulation.py"}], "after_files": [{"content": null, "path": "src/werkzeug/posixemulation.py"}]}