






# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile



def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	str,					SCREAMING_SNAKE_CASE__:	Any,					SCREAMING_SNAKE_CASE__:	Tuple,					SCREAMING_SNAKE_CASE__:	Any    )  ->			List[str]:

   """simple docstring"""
   __a				     =    multiprocessing.Manager()
   __a				     =    manager.list()

   __a				     =    multiprocessing.Process(target=lowerCAmelCase__,					args=(check_program, result, timeout)    )
   p.start()
   p.join(timeout=timeout + 1    )
   if p.is_alive():
      p.kill()

   if not result:
      result.append('timed out'    )

   return {
       "task_id": task_id,
       "passed": result[0] == "passed",
       "result": result[0],
       "completion_id": completion_id,
   }



def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	List[str],					SCREAMING_SNAKE_CASE__:	Any,					SCREAMING_SNAKE_CASE__:	int    )  ->			Union[str, Any]:

   """simple docstring"""
   with create_tempdir():
      # These system calls are needed when cleaning up tempdir.
      import os
      import shutil

      __a				     =    shutil.rmtree
      __a				     =    os.rmdir
      __a				     =    os.chdir

      # Disable functionalities that can make destructive changes to the test.
      reliability_guard()

      # Run program.
      try:
         __a				     =    {}
         with swallow_io():
            with time_limit(lowerCAmelCase__    ):
               exec(lowerCAmelCase__,					lowerCAmelCase__    )
         result.append('passed'    )
      except TimeoutException:
         result.append('timed out'    )
      except BaseException as e:
         result.append(f"""failed: {e}"""    )

      # Needed for cleaning up.
      __a				     =    rmtree
      __a				     =    rmdir
      __a				     =    chdir



@contextlib.contextmanager
def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	str    )  ->			Optional[Any]:

   """simple docstring"""
   def signal_handler(SCREAMING_SNAKE_CASE__:	Union[str, Any],					SCREAMING_SNAKE_CASE__:	List[Any]    ):
      raise TimeoutException('Timed out!'    )

   signal.setitimer(signal.ITIMER_REAL,					lowerCAmelCase__    )
   signal.signal(signal.SIGALRM,					lowerCAmelCase__    )
   try:
      yield
   finally:
      signal.setitimer(signal.ITIMER_REAL,					0    )



@contextlib.contextmanager
def    __UpperCAmelCase	(				)  ->			List[str]:

   """simple docstring"""
   __a				     =    WriteOnlyStringIO()
   with contextlib.redirect_stdout(lowerCAmelCase__    ):
      with contextlib.redirect_stderr(lowerCAmelCase__    ):
         with redirect_stdin(lowerCAmelCase__    ):
            yield



@contextlib.contextmanager
def    __UpperCAmelCase	(				)  ->			str:

   """simple docstring"""
   with tempfile.TemporaryDirectory() as dirname:
      with chdir(lowerCAmelCase__    ):
         yield dirname
class 							__SCREAMING_SNAKE_CASE       (							__a     ):
      pass







class 							__SCREAMING_SNAKE_CASE       (							io.StringIO     ):




      def  __UpperCamelCase							(  self ,   *lowerCamelCase ,   **lowerCamelCase      )							->Optional[int]:



         '''simple docstring'''
         raise OSError




      def  __UpperCamelCase							(  self ,   *lowerCamelCase ,   **lowerCamelCase      )							->Optional[int]:



         '''simple docstring'''
         raise OSError




      def  __UpperCamelCase							(  self ,   *lowerCamelCase ,   **lowerCamelCase      )							->int:



         '''simple docstring'''
         raise OSError






      def  __UpperCamelCase							(  self ,   *lowerCamelCase ,   **lowerCamelCase      )							->str:



         '''simple docstring'''
         return False







class 							__SCREAMING_SNAKE_CASE       (							contextlib._RedirectStream     ):  # type: ignore
      __a  					='''stdin'''







@contextlib.contextmanager
def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	Optional[int]    )  ->			Optional[Any]:

   """simple docstring"""
   if root == ".":
      yield
      return
   __a				     =    os.getcwd()
   os.chdir(lowerCAmelCase__    )
   try:
      yield
   except BaseException as exc:
      raise exc
   finally:
      os.chdir(lowerCAmelCase__    )



def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	Optional[Any]=None    )  ->			Optional[int]:

   """simple docstring"""

   if maximum_memory_bytes is not None:
      import resource

      resource.setrlimit(resource.RLIMIT_AS,					(maximum_memory_bytes, maximum_memory_bytes)    )
      resource.setrlimit(resource.RLIMIT_DATA,					(maximum_memory_bytes, maximum_memory_bytes)    )
      if not platform.uname().system == "Darwin":
         resource.setrlimit(resource.RLIMIT_STACK,					(maximum_memory_bytes, maximum_memory_bytes)    )

   faulthandler.disable()

   import builtins

   __a				     =    None
   __a				     =    None

   import os

   __a				     =    '1'

   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None

   import shutil

   __a				     =    None
   __a				     =    None
   __a				     =    None

   import subprocess

   __a				     =    None  # type: ignore

   __a				     =    None

   import sys

   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None
   __a				     =    None







'''simple docstring'''



__UpperCamelCase      :       Optional[Any]      			=      [
    """DownloadConfig""",
    """DownloadManager""",
    """DownloadMode""",
    """StreamingDownloadManager""",
]

from .download_config import DownloadConfig
from .download_manager import DownloadManager, DownloadMode
from .streaming_download_manager import StreamingDownloadManager