Skip to content

Commit 300a6c3

Browse files
committed
Add parsing
1 parent a756c85 commit 300a6c3

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

safeexecute/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def install_docker_image():
2727
return client
2828

2929

30-
async def execute_python_code(self, code: str, working_directory: str) -> str:
30+
async def execute_python_code(code: str, working_directory: str) -> str:
3131
# Create working directory if it doesn't exist
3232
if not os.path.exists(working_directory):
3333
os.makedirs(working_directory)
@@ -40,7 +40,8 @@ async def execute_python_code(self, code: str, working_directory: str) -> str:
4040
subprocess.check_output(["pip", "install", package])
4141
except:
4242
pass
43-
code = await self.get_python_code_from_response(code)
43+
if "```python" in code:
44+
code = code.split("```python")[1].split("```")[0]
4445
# Create a temporary Python file in the WORKSPACE directory
4546
temp_file = os.path.join(working_directory, "temp.py")
4647
with open(temp_file, "w") as f:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="safeexecute",
11-
version="0.0.1",
11+
version="0.0.2",
1212
description="Safe way to execute Python code with containerization.",
1313
long_description=long_description,
1414
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)