






# 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      __lowercase					( snake_case,  snake_case,  snake_case,  snake_case ):







				"""simple docstring"""






				__magic_name__		:List[Any]        =      multiprocessing.Manager()
				__magic_name__		:Union[str, Any]        =      manager.list()

				__magic_name__		:Dict        =      multiprocessing.Process(target=snake_case,  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      __lowercase					( snake_case,  snake_case,  snake_case ):







				"""simple docstring"""






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

								__magic_name__		:List[str]        =      shutil.rmtree
								__magic_name__		:Any        =      os.rmdir
								__magic_name__		:Optional[Any]        =      os.chdir

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

								# Run program.
								try:
												__magic_name__		:List[str]        =      {}
												with swallow_io():
																with time_limit(snake_case ):
																				exec(snake_case,  snake_case )
												result.append('''passed''' )
								except TimeoutException:
												result.append('''timed out''' )
								except BaseException as e:
												result.append(f'''failed: {e}''' )

								# Needed for cleaning up.
								__magic_name__		:int        =      rmtree
								__magic_name__		:Optional[int]        =      rmdir
								__magic_name__		:List[str]        =      chdir

@contextlib.contextmanager
def      __lowercase					( snake_case ):







				"""simple docstring"""






				def signal_handler(snake_case,  snake_case ):
								raise TimeoutException('''Timed out!''' )

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

@contextlib.contextmanager
def      __lowercase					( ):







				"""simple docstring"""






				__magic_name__		:Union[str, Any]        =      WriteOnlyStringIO()
				with contextlib.redirect_stdout(snake_case ):
								with contextlib.redirect_stderr(snake_case ):
												with redirect_stdin(snake_case ):
																yield

@contextlib.contextmanager
def      __lowercase					( ):







				"""simple docstring"""






				with tempfile.TemporaryDirectory() as dirname:
								with chdir(snake_case ):
												yield dirname
class 						lowerCamelCase_				(      lowerCamelCase ):
				pass







class 						lowerCamelCase_				(      io.StringIO ):







				def 			A	(						self       ,					*__lowerCAmelCase       ,					**__lowerCAmelCase     ):
								"""simple docstring"""
								raise OSError







				def 			A	(						self       ,					*__lowerCAmelCase       ,					**__lowerCAmelCase     ):
								"""simple docstring"""
								raise OSError







				def 			A	(						self       ,					*__lowerCAmelCase       ,					**__lowerCAmelCase     ):
								"""simple docstring"""
								raise OSError







				def 			A	(						self       ,					*__lowerCAmelCase       ,					**__lowerCAmelCase     ):
								"""simple docstring"""
								return False







class 						lowerCamelCase_				(      contextlib._RedirectStream ):  # type: ignore
				a__					       =  '''stdin'''







@contextlib.contextmanager
def      __lowercase					( snake_case ):







				"""simple docstring"""






				if root == ".":
								yield
								return
				__magic_name__		:str        =      os.getcwd()
				os.chdir(snake_case )
				try:
								yield
				except BaseException as exc:
								raise exc
				finally:
								os.chdir(snake_case )

def      __lowercase					( snake_case=None ):







				"""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

				__magic_name__		:Dict        =      None
				__magic_name__		:str        =      None

				import os

				__magic_name__		:Tuple        =      '''1'''

				__magic_name__		:Union[str, Any]        =      None
				__magic_name__		:Tuple        =      None
				__magic_name__		:List[str]        =      None
				__magic_name__		:List[Any]        =      None
				__magic_name__		:str        =      None
				__magic_name__		:Any        =      None
				__magic_name__		:List[str]        =      None
				__magic_name__		:str        =      None
				__magic_name__		:Tuple        =      None
				__magic_name__		:Optional[Any]        =      None
				__magic_name__		:Optional[int]        =      None
				__magic_name__		:Dict        =      None
				__magic_name__		:Dict        =      None
				__magic_name__		:Any        =      None
				__magic_name__		:Dict        =      None
				__magic_name__		:int        =      None
				__magic_name__		:int        =      None
				__magic_name__		:Optional[Any]        =      None
				__magic_name__		:int        =      None
				__magic_name__		:List[Any]        =      None
				__magic_name__		:List[str]        =      None
				__magic_name__		:Optional[int]        =      None
				__magic_name__		:Tuple        =      None
				__magic_name__		:List[str]        =      None
				__magic_name__		:Union[str, Any]        =      None
				__magic_name__		:Optional[int]        =      None
				__magic_name__		:List[str]        =      None

				import shutil

				__magic_name__		:str        =      None
				__magic_name__		:Any        =      None
				__magic_name__		:List[Any]        =      None

				import subprocess

				__magic_name__		:Union[str, Any]        =      None  # type: ignore

				__magic_name__		:Union[str, Any]        =      None

				import sys

				__magic_name__		:List[str]        =      None
				__magic_name__		:List[Any]        =      None
				__magic_name__		:str        =      None
				__magic_name__		:Optional[int]        =      None
				__magic_name__		:str        =      None














from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available


SCREAMING_SNAKE_CASE__      :			Union[str, Any]							=		{"""tokenization_herbert""": ["""HerbertTokenizer"""]}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE__      :			Optional[Any]							=		["""HerbertTokenizerFast"""]


if TYPE_CHECKING:
					from .tokenization_herbert import HerbertTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_herbert_fast import HerbertTokenizerFast

else:
					import sys

					SCREAMING_SNAKE_CASE__      :			Union[str, Any]							=		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






