Python sublime 模块,encode_value() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用sublime.encode_value()

项目:docphp    作者:garveen    | 项目源码 | 文件源码
def getJsonOrGenerate(name, callback):
    filename = getI18nCachePath() + name + '.json'
    if os.path.exists(filename):
        with open(filename, 'r', encoding='utf8') as f:
            json = f.read(10485760)
        content = sublime.decode_value(json)

    else:
        content = callback()

        dirname = os.path.dirname(filename)
        if not os.path.isdir(dirname):
            os.makedirs(dirname)
        with open(filename, 'w', encoding="utf8") as f:
            f.write(sublime.encode_value(content))

    return content
项目:ToolTip-Helper    作者:AvitanI    | 项目源码 | 文件源码
def save_stylesheets(self, style_sheets):
        """Save the stylesheet dictionary to file"""

        content = sublime.encode_value(style_sheets, True)

        with open(self.theme_file_path, "w") as f:
            f.write(content)

        self.style_sheets = style_sheets
项目:PyTest    作者:kaste    | 项目源码 | 文件源码
def tweak_theme():
    view = sublime.active_window().active_view()
    theme = view.settings().get('theme')
    if theme is None:
        print("Can't guess current theme.")
        return

    theme_path = os.path.join(sublime.packages_path(), 'User', theme)
    if os.path.exists(theme_path):
        with open(theme_path, mode='r', encoding='utf-8') as f:
            theme_text = f.read()

        if PYTEST_MARKERS.search(theme_text):
            print("Already patched")
            return

        safety_path = os.path.join(
            sublime.packages_path(), 'User', 'Original-' + theme)
        with open(safety_path, mode='w', encoding='utf-8') as f:
            f.write(theme_text)

        theme = sublime.decode_value(theme_text)
    else:
        theme = []

    theme.extend(PYTEST_RULES)

    tweaked_theme = sublime.encode_value(theme, True)
    with open(theme_path, mode='w', encoding='utf-8') as f:
        f.write(tweaked_theme)

    print('Done tweaking!')

    # sublime.active_window().open_file(theme_path)
项目:sublimeTextConfig    作者:luoye-fe    | 项目源码 | 文件源码
def send_command(self, callback: Callable, **data: Any) -> None:
        """Send the given command that should be handled bu the given callback
        """
        data['uid'] = self.add_callback(callback)

        try:
            self.push(
                bytes('{}\r\n'.format(sublime.encode_value(data)), 'utf8')
            )
        except NameError:
            self.push(bytes('{}\r\n'.format(json.dumps(data)), 'utf8'))
项目:ToolTip-Helper    作者:doobleweb    | 项目源码 | 文件源码
def save_stylesheets(self, style_sheets):
        """Save the stylesheet dictionary to file"""

        content = sublime.encode_value(style_sheets, True)

        with open(self.theme_file_path, "w") as f:
            f.write(content)

        self.style_sheets = style_sheets