本文整理汇总了Python中sublime.decode_value方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.decode_value方法的具体用法?Python sublime.decode_value怎么用?Python sublime.decode_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.decode_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_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):
f = codecs.open(self.fpath, "r+", encoding=self.encoding)
try:
content = f.read()
data = sublime.decode_value(content)
except Exception:
print("%s is bad!" % self.fpath)
f.close()
raise
if not data:
data = default
f.close()
else:
f = codecs.open(self.fpath, "w+", encoding=self.encoding)
data = default
f.close()
return data
示例2: run_command
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_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
示例3: load
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_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
示例4: getJsonOrGenerate
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_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
示例5: on_post_save_async
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def on_post_save_async(self, view):
file_name = utils.normalize_path(view.file_name())
# check to see if the updated file was a .sublime-project
if file_name.lower().endswith(".sublime-project"):
project_name = file_name
project_data = sublime.decode_value(
view.substr(sublime.Region(0, view.size()))
)
self.project_updated(project_name, project_data)
else:
project_name = utils.get_project_name(view)
if project_name:
self.project_file_changed(
project_name, file_name, "project_file_updated"
)
示例6: read_config
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def read_config(package, key, default=None):
try:
context = sublime.load_resource(
"Packages/{}/.package_reloader.json".format(package))
value = sublime.decode_value(context).get(key, default)
except Exception:
value = default
return value
示例7: find_errors
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def find_errors(self, output):
"""
Override find_errors, parsing output json into json_object.
Calls parse_message for each error found.
"""
output_json = sublime.decode_value(output)
logger.debug('output_json:"%s", file: "%s"', output_json, self.filename)
for file in output_json:
for message in file["messages"]:
yield self.parse_message(message)
示例8: read_json
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def read_json(file):
if not os.path.isfile(file):
return None
fo = open(file, "r")
data = fo.read()
fo.close()
return sublime.decode_value(data)
示例9: __init__
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def __init__(self, original_color_scheme):
super().__init__(original_color_scheme)
self.dict = OrderedDict(sublime.decode_value(self.color_scheme_string))
示例10: getAllLanguages
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def getAllLanguages():
return sublime.decode_value(sublime.load_resource('Packages/' + package_name + '/languages.json'))
示例11: decodeEntity
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def decodeEntity(xml, category='iso'):
global entities
if not isinstance(xml, str):
return xml
if entities[category]:
forward, reverse = entities[category]
else:
resourceMap = {
"iso": "IsoEntities.json",
"html": "HtmlEntities.json",
}
forward = sublime.decode_value(sublime.load_resource('Packages/' + package_name + '/' + resourceMap[category]))
reverse = dict((v, k) for k, v in forward.items())
entities[category] = (forward, reverse)
def parseEntity(match):
entity = match.group(1)
try:
if entity.isdigit():
return reverse[int(entity)]
else:
return chr(forward[entity])
except:
return match.group(0)
xml = re.sub('&([a-zA-Z0-9]+);', parseEntity, xml)
return xml
示例12: get_user_color_scheme
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def get_user_color_scheme(color_scheme_file):
try:
src_str = sublime.load_resource(color_scheme_file)
user_color_scheme = sublime.decode_value(src_str)
if "rules" not in user_color_scheme:
user_color_scheme["rules"] = []
return user_color_scheme
except IOError:
return {"rules": []}
示例13: load_tag_list
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def load_tag_list():
tags_to_filter = [
'abort',
'admin',
'case',
'catch',
'component',
'continue',
'defaultcase',
'else',
'elseif',
'exit',
'finally',
'function',
'if',
'interface',
'print',
'rethrow',
'retry',
'return',
'script',
'servlet',
'servletparam',
'set',
'sleep',
'switch',
'try',
'while',
]
tags = sublime.load_resource(
"Packages/CFML/src/plugins_/basecompletions/json/cfml_tags.json"
)
tags = sublime.decode_value(tags).keys()
return [t.lower()[2:] for t in tags if t.lower()[2:] not in tags_to_filter]
示例14: load_member_functions
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def load_member_functions():
member_functions = set()
data = sublime.load_resource(
"Packages/CFML/src/plugins_/basecompletions/json/cfml_member_functions.json"
)
data = sublime.decode_value(data)
for member_type in data:
methods = [m.lower() for m in data[member_type].keys()]
member_functions.update(methods)
return list(member_functions)
示例15: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import decode_value [as 别名]
def run(self, theme=None, remove=False, force=False):
settings = sublime.load_settings("Terminus.sublime-settings")
if not theme:
theme = settings.get("theme", "default")
if theme == "user":
variables = settings.get("user_theme_colors", {})
for key, value in list(variables.items()):
if key.isdigit():
variables[ANSI_COLORS[int(key)]] = value
del variables[key]
elif theme == "default":
variables = {}
else:
content = sublime.load_resource("Packages/Terminus/themes/{}.json".format(theme))
theme_data = sublime.decode_value(content)
variables = theme_data["theme_colors"]
path = os.path.join(
sublime.packages_path(),
"User",
"Terminus",
"Terminus.hidden-color-scheme"
)
path256 = os.path.join(
sublime.packages_path(),
"User",
"Terminus.hidden-color-scheme"
)
if remove:
if os.path.isfile(path):
os.unlink(path)
print("Theme removed: {}".format(path))
if os.path.isfile(path256):
os.unlink(path256)
print("Theme removed: {}".format(path256))
sublime.status_message("Theme {} removed".format(theme))
else:
if settings.get("256color", False):
if force or not os.path.isfile(path256):
generate_theme_file(
path256, ansi_scopes=True, color256_scopes=True, pretty=False)
print("Theme {} generated: {}".format(theme, path256))
else:
if os.path.isfile(path256):
os.unlink(path256)
generate_theme_file(path, variables=variables, ansi_scopes=False, color256_scopes=False)
print("Theme {} generated: {}".format(theme, path))
sublime.status_message("Theme generated")