3939import functools
4040import io
4141import logging
42- import marshal
4342import os
4443import pathlib
4544import random
@@ -124,16 +123,15 @@ def run_python_container_command(self, command: str) -> dict:
124123 mode = "r" ,
125124 encoding = "utf-8"
126125 ) as memfile :
127- code_object = compile (memfile .read () + command , filename = nonce , mode = "exec" )
128- pyc_file = io .BytesIO ()
129- pyc_file .write (b'o\r \r \n \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 ' )
130- marshal .dump (code_object , pyc_file )
131- self .upload_file (content = pyc_file .getvalue (), remote_file_path = f'/opt/{ nonce } .pyc' )
132- _ , stdout , stderr = self .ssh_client .exec_command (f"python3 /opt/{ nonce } .pyc" )
133- return {
126+ source = memfile .read () + command
127+ self .upload_file (content = source , remote_file_path = f'/opt/{ nonce } .py' )
128+ _ , stdout , stderr = self .ssh_client .exec_command (f"python3 /opt/{ nonce } .py" )
129+ result = {
134130 "output" : stdout .read ().decode (),
135131 "error" : stderr .read ().decode ()
136132 }
133+ self .ssh_client .exec_command (f"rm -f /opt/{ nonce } .py" )
134+ return result
137135
138136 def upload_directory (self , local_directory_path : str , remote_directory_path : str ) -> None :
139137 stack = [(local_directory_path , remote_directory_path )]
@@ -152,7 +150,7 @@ def upload_directory(self, local_directory_path: str, remote_directory_path: str
152150 self .sftp_client .put (local_item_path , remote_item_path )
153151
154152 def create_directory (self , remote_directory_path : str ) -> None :
155- self .sftp_client . mkdir ( remote_directory_path )
153+ self .ssh_client . exec_command ( f"mkdir -p { remote_directory_path } " )
156154
157155 def upload_file (self , content : str | bytes , remote_file_path : str ) -> None :
158156 if isinstance (content , str ):
0 commit comments