本文整理匯總了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))