diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 4e1efd5..f50bf32 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -1200,12 +1200,18 @@ def load_file(): if request.data: file_data = json.loads(request.data, encoding='utf-8') - file_path = unquote(file_data['file_name']) + if hasattr(str, 'decode'): + file_path = unquote(file_data['file_name']).decode('utf-8') + else: + file_path = unquote(file_data['file_name']) # retrieve storage directory path storage_manager_path = get_storage_directory() if storage_manager_path: # generate full path of file - file_path = os.path.join(storage_manager_path, file_path.lstrip('/')) + file_path = os.path.join( + storage_manager_path, + file_path.lstrip('/') + ) file_data = None @@ -1224,7 +1230,10 @@ def load_file(): is_binary = is_binary_string(fileObj.read(1024)) if not is_binary: fileObj.seek(0) - file_data = fileObj.read() + if hasattr(str, 'decode'): + file_data = fileObj.read().decode('utf-8') + else: + file_data = fileObj.read() else: return internal_server_error( errormsg=gettext("File type not supported") @@ -1261,18 +1270,28 @@ def save_file(): storage_manager_path = get_storage_directory() # generate full path of file - file_path = unquote(file_data['file_name']) + if hasattr(str, 'decode'): + file_path = unquote(file_data['file_name']).decode('utf-8') + else: + file_path = unquote(file_data['file_name']) if storage_manager_path is not None: file_path = os.path.join( storage_manager_path, - unquote(file_data['file_name'].lstrip('/')) + file_path.lstrip('/') ) - file_content = file_data['file_content'] + + if hasattr(str, 'decode'): + file_content = file_data['file_content'] + else: + file_content = file_data['file_content'].encode() # write to file try: - with open(file_path, 'w') as output_file: - output_file.write(file_content) + with open(file_path, 'wb') as output_file: + if hasattr(str, 'decode'): + output_file.write(file_content.encode('utf-8')) + else: + output_file.write(file_content) except IOError as e: if e.strerror == 'Permission denied': err_msg = "Error: {0}".format(e.strerror)