o Fdl @sddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl Z de de de de fddZ ejd e fd d Zejd d ZejddZGdddeZGdddejZGdddejZejddZddeefddZdS))OptionalDictNprompt completiontesttimeoutcsnfdd}t}|tj|d}||jdd|r,|s3ddS)z: Get the output of a testcases against a solution c stddl}ddl}|j}|j}|j}td}d}gd}|D]}|vr-|}q%|dkr8d|nd|dd} z7i} t(t t | |  | dWdn1sgwYWdn1svwYWn/t y d Yn"t y} zt| j}  d | d | WYd} ~ nd} ~ ww||_||_||_WddS1swYdS) Nrdef)z def is_palindrome(string: str) -> bool: """ Test if given string is a palindrome """ return string == string[::-1] zimport math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) a def encode_cyclic(s: str): """ returns encoded string by cycling groups of three characters. """ # split string to groups. Each of length 3. groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)] # cycle elements in each group. Unless group has fewer elements than 3. groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups] return "".join(groups) z def encode_shift(s: str): """ returns encoded string by shifting every character by 5 in the alphabet. """ return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in s])  z result = resultzFAILURE: timed outz FAILURE: z: )create_tempdirosshutilrmtreermdirchdirreliability_guardfind swallow_io time_limitexecappendTimeoutException BaseExceptiontype__name__) rrrrrimport_packages_end_index helper_funchelper_funcs_to_be_includedhelper check_program exec_globalse error_typerrr rr?/home/bjwang/projects/factool/factool/code/helper/_execution.pyunsafe_executesL  ,    ""z2test_case_against_solution..unsafe_execute)target)rz timed outr) multiprocessingManagerlistProcessstartjoinis_alivekillr)rrrrr(managerpr&r%r'test_case_against_solutionsM  r5secondsc csRdd}ttj|ttj|z dVWttjddSttjdw)NcSstd)Nz Timed out!)r)signumframer&r&r'signal_handlerpsz"time_limit..signal_handlerr)signal setitimer ITIMER_REALSIGALRM)r6r9r&r&r'rns"rc cst}t|=t|t| dVWdn1s"wYWdn1s1wYWddSWddS1sIwYdSN)WriteOnlyStringIO contextlibredirect_stdoutredirect_stderrredirect_stdin)streamr&r&r'rzs   "rc csnt(}t| |VWdn1swYWddSWddS1s0wYdSr>)tempfileTemporaryDirectoryr)dirnamer&r&r'r s  "r c@s eZdZdS)rN)r __module__ __qualname__r&r&r&r'rsrc@s0eZdZdZddZddZddZdd Zd S) r?z7 StringIO that throws an exception when it's read from cOtr>IOErrorselfargskwargsr&r&r'readzWriteOnlyStringIO.readcOrJr>rKrMr&r&r'readlinerRzWriteOnlyStringIO.readlinecOrJr>rKrMr&r&r' readlinesrRzWriteOnlyStringIO.readlinescOsdS)z, Returns True if the IO object can be read. Fr&rMr&r&r'readableszWriteOnlyStringIO.readableN)rrHrI__doc__rQrSrTrUr&r&r&r'r?s  r?c@seZdZdZdS)rCstdinN)rrHrI_streamr&r&r&r'rCsrCc csl|dkr dVdSt}t|zzdVWnty'}z|d}~wwWt|dSt|w)N.)rgetcwdrr)rootcwdexcr&r&r'rs  rmaximum_memory_bytescCs|dur*ddl}||j||f||j||ftjdks*||j||ft ddl }d|_ d|_ ddl }d|jd<d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_!d|_"d|_d|_#d|_$d|_%d|_&d|_'ddl(}d|_)d|_*d|_!ddl+}d|_,dt-d<ddl.}d|j/d<d|j/d<d|j/d <d|j/d <d|j/d <dS) a This disables various destructive functions and prevents the generated code from interfering with the test (e.g. fork bomb, killing other processes, removing filesystem files, etc.) WARNING This function is NOT a security sandbox. Untrusted code, including, model- generated code, should not be blindly executed outside of one. See the Codex paper for more information about OpenAI's code sandbox, and proceed with caution. NrDarwin1OMP_NUM_THREADShelpipdbjoblibresourcepsutiltkinter)0re setrlimit RLIMIT_AS RLIMIT_DATAplatformunamesystem RLIMIT_STACK faulthandlerdisablebuiltinsexitquitrenvironr2putenvremove removedirsrfchdirsetuidforkforkptykillpgrenamerenamestruncatereplaceunlinkfchmodfchownchmodchownchrootlchflagslchmodlchownrZrrrmove subprocessPopen __builtins__sysmodules)r^rerqrrrrr&r&r'rst      rr>)typingrrr@roiorr+rkr:rEstrfloatr5contextmanagerrrr ExceptionrStringIOr?_RedirectStreamrCrintrr&r&r&r's,`