Beispiel #1
0
def decode_from_base64(editor, data, pos):
    """
    Decodes base64 string back to file.
    @requires: zen_editor.prompt
    @requires: zen_file

    @type editor: ZenEditor
    @param data: Base64-encoded file content
    @type data: str
    @param pos: Caret position where image is located in the editor
    @type pos: int
    """
    # ask user to enter path to file
    file_path = editor.prompt('Enter path to file (absolute or relative)')
    if not file_path:
        return False

    abs_path = zen_file.create_path(editor.get_file_path(), file_path)
    if not abs_path:
        raise zencoding.utils.ZenError("Can't save file")


    zen_file.save(abs_path, base64.b64decode( re.sub(r'^data\:.+?;.+?,', '', data) ))
    editor.replace_content('$0' + file_path, pos, pos + len(data))
    return True
Beispiel #2
0
def decode_from_base64(editor, data, pos):
    """
    Decodes base64 string back to file.
    @requires: zen_editor.prompt
    @requires: zen_file

    @type editor: ZenEditor
    @param data: Base64-encoded file content
    @type data: str
    @param pos: Caret position where image is located in the editor
    @type pos: int
    """
    # ask user to enter path to file
    file_path = editor.prompt('Enter path to file (absolute or relative)')
    if not file_path:
        return False

    abs_path = zen_file.create_path(editor.get_file_path(), file_path)
    if not abs_path:
        raise zencoding.utils.ZenError("Can't save file")


    zen_file.save(abs_path, base64.b64decode( re.sub(r'^data\:.+?;.+?,', '', data) ))
    editor.replace_content('$0' + file_path, pos, pos + len(data))
    return True