def open_file(self, name: str, mode: str = 'r') -> File: with self.conn() as soc: send_request( soc, encode_parameter('fs', 'open_file', self.path(), name, mode)) return RemoteFile(self.conn, asserttype(File, pickle.loads(get_request(soc))))
def _start(self): with network.create_server_connection(network.get_local_ip(), self.port) as soc: while True: self.request = None try: soc.listen() if soc: c_soc, _ = soc.accept() code = self.execute( network.decode_parameter( notnone(network.get_request(c_soc)))) if code is not None: print(f'=> {code}') network.send_request(c_soc, pickle.dumps(code)) c_soc.close() except (OSError, AssertionError) as e: print(f"Error occurred: {e}") with open('log_server.log', 'a+') as f: f.write( f'[{datetime.datetime.now()}] ERROR {type(e)}: {e}\n' )
def delete_file(self, name: str) -> None: with self.conn() as soc: send_request( soc, encode_parameter('fs', 'delete_file', self.path(), name))
def memory_map(self) -> Memory: with self.__create_connection() as soc: send_request(soc, encode_parameter('fs', 'memory_map')) return asserttype(Memory, pickle.loads(get_request(soc)))
def current(self): with self.__create_connection() as soc: send_request(soc, encode_parameter('fs', 'current')) return RemoteFolder( self.__create_connection, asserttype(Folder, pickle.loads(get_request(soc))))
def delete(self, path: str) -> None: with self.__create_connection() as soc: send_request(soc, encode_parameter('fs', 'delete', path))
def save(self): with self.__create_connection() as soc: send_request(soc, encode_parameter('fs', 'save'))
def create_directory(self, path: str) -> None: with self.__create_connection() as soc: send_request(soc, encode_parameter('fs', 'create_directory', path))
def move(self, src: str, dest: str) -> None: with self.__create_connection() as soc: send_request(soc, encode_parameter('fs', 'move', src, dest))
def change_directory(self, path: str) -> Folder: with self.__create_connection() as soc: send_request(soc, encode_parameter('fs', 'change_directory', path)) return RemoteFolder( self.__create_connection, asserttype(Folder, pickle.loads(get_request(soc))))
def truncate(self, end: int) -> None: with self.conn() as soc: send_request(soc, encode_parameter( 'fs', 'truncate_contents', self.parent.path(), self.name, str(end) ))
def move(self, start: int, end: int, target: int) -> None: with self.conn() as soc: send_request(soc, encode_parameter( 'fs', 'move_contents', self.parent.path(), self.name, str(start), str(end), str(target) ))
def read(self, start: int = 0, end: int = -1) -> Union[str, bytes]: with self.conn() as soc: send_request(soc, encode_parameter( 'fs', 'read_contents', self.parent.path(), self.name, str(start), str(end) )) return ''.join(pickle.loads(get_request(soc)))
def _write(self, contents: str, start: int = 0, append: bool = False) -> None: with self.conn() as soc: send_request(soc, encode_parameter( 'fs', 'write_contents', self.parent.path(), self.name, contents, str(start), str(append) ))