本文整理汇总了Python中sublime.encode_value方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.encode_value方法的具体用法?Python sublime.encode_value怎么用?Python sublime.encode_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.encode_value方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_command
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import encode_value [as 别名]
def run_command(command, data=None, callback=None):
debug("run_command", [NODE_BIN, command, data])
json = sublime.encode_value({"command": command, "args": data})
err = None
out = None
try:
(err, out) = exec([NODE_BIN, "--no-warnings", RUN_PATH], json)
except Exception as e:
err = traceback.format_exc()
if bool(err):
if callback is not None:
return callback(err, None)
raise err
# debug('run_command: trying to decode', out)
result = sublime.decode_value(out)
if callback is not None:
return callback(None, result)
return result
示例2: load
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import encode_value [as 别名]
def load(self, default=[]):
self.fdir = os.path.dirname(self.fpath)
if not os.path.isdir(self.fdir):
os.makedirs(self.fdir)
if os.path.exists(self.fpath):
with open(self.fpath, mode='r', encoding=self.encoding) as f:
content = f.read()
try:
data = sublime.decode_value(content)
except Exception:
sublime.message_dialog('%s is bad!' % self.fpath)
raise
if not data:
data = default
else:
with open(self.fpath, mode='w', encoding=self.encoding, newline='\n') as f:
data = default
f.write(sublime.encode_value(data, True))
return data
示例3: getJsonOrGenerate
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import encode_value [as 别名]
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
示例4: save
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import encode_value [as 别名]
def save(self, data, indent=4):
self.fdir = os.path.dirname(self.fpath)
if not os.path.isdir(self.fdir):
os.makedirs(self.fdir)
f = codecs.open(self.fpath, "w+", encoding=self.encoding)
f.write(sublime.encode_value(data, True))
f.close()
示例5: save
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import encode_value [as 别名]
def save(self, data, indent=4):
self.fdir = os.path.dirname(self.fpath)
if not os.path.isdir(self.fdir):
os.makedirs(self.fdir)
with open(self.fpath, mode='w', encoding=self.encoding, newline='\n') as f:
f.write(sublime.encode_value(data, True))
示例6: write_new_theme
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import encode_value [as 别名]
def write_new_theme(self, name):
full_path = os.path.join(sublime.packages_path(), self.get_theme_path(name))
with util.file.safe_open(full_path, "wb", buffering=0) as out_f:
out_f.write(sublime.encode_value(self.dict, pretty=True).encode("utf-8"))
示例7: toggle
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import encode_value [as 别名]
def toggle():
preferences = sublime.load_settings("Preferences.sublime-settings")
color_scheme = os.path.basename(preferences.get("color_scheme"))
color_scheme_file = os.path.splitext(color_scheme)[0] + ".sublime-color-scheme"
user_color_scheme = get_user_color_scheme("Packages/User/" + color_scheme_file)
user_color_scheme_path = os.path.join(
sublime.packages_path(), "User", color_scheme_file
)
non_cfml_rules = [
row
for row in user_color_scheme["rules"]
if "scope" not in row or not row["scope"].endswith("cfml")
]
has_cfml_rules = len(user_color_scheme["rules"]) > len(non_cfml_rules)
if has_cfml_rules:
user_color_scheme["rules"] = non_cfml_rules
else:
user_color_scheme["rules"].extend(get_cfml_rules())
with open(user_color_scheme_path, "w") as f:
f.write(sublime.encode_value(user_color_scheme, True))
if len(user_color_scheme.keys()) == 1 and len(user_color_scheme["rules"]) == 0:
print("CFML: Packages/User/{} is now empty.".format(color_scheme_file))