"""
Utility class for working with temporary files
"""

import os

from contextlib import contextmanager
from tempfile import mkstemp


class MixedModeTemporaryFile:
    """
    Temporary file that can be opened multiple times in different modes
    """

    def __init__(self):
        self._fd, self._filename = mkstemp()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, traceback):
        self.close()

    @contextmanager
    def open(self, mode):
        """
        Open the file in the specified mode
        """
        with os.fdopen(self._fd, mode, closefd=False) as fileobj:
            yield fileobj
        os.lseek(self._fd, 0, os.SEEK_SET)

    def close(self):
        """
        Close the temporary file (and delete it)
        """
        os.close(self._fd)
        os.unlink(self._filename)

    def size(self):
        """
        Return the size of the file
        """
        return os.stat(self._fd).st_size

@@ -64,46 +64,8 @@
 os%0A%0A
-from contextlib import contextmanager%0A
 from
@@ -406,28 +406,8 @@
 ()%0A%0A
-    @contextmanager%0A
     
@@ -504,20 +504,22 @@
         
-with
+return
  os.fdop
@@ -555,89 +555,8 @@
 lse)
- as fileobj:%0A            yield fileobj%0A        os.lseek(self._fd, 0, os.SEEK_SET)
 %0A%0A  
@@ -705,24 +705,156 @@
 _filename)%0A%0A
+    def rewind(self):%0A        %22%22%22%0A        Seek to the beginning of the file%0A        %22%22%22%0A        os.lseek(self._fd, 0, os.SEEK_SET)%0A%0A
     def size

Switch to using rewind() method explicitly for seeking within the file.