本文整理汇总了Python中plistlib.readPlistFromBytes方法的典型用法代码示例。如果您正苦于以下问题:Python plistlib.readPlistFromBytes方法的具体用法?Python plistlib.readPlistFromBytes怎么用?Python plistlib.readPlistFromBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plistlib
的用法示例。
在下文中一共展示了plistlib.readPlistFromBytes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def run(self, *args, **kwargs):
view = sublime.active_window().active_view()
#settings = sublime.load_settings('KSP.sublime-settings')
#scheme_file = settings.get('color_scheme', 'Packages/SublimeKSP/KScript Light.tmTheme')
scheme_file = 'Packages/SublimeKSP/KScript Light.tmTheme'
plist = readPlistFromBytes(sublime.load_binary_resource(scheme_file))
result = ['[pre]']
start, end = view.sel()[0].a, view.sel()[0].b
if start == end:
start, end = 0, view.size()
for a, b, scopes in get_ranges(view.scope_name(i) for i in range(start, end)):
result.append(self.apply_style(scopes, plist, view.substr(sublime.Region(start+a, start+b))))
result.append('[/pre]')
sublime.set_clipboard(''.join(result))
示例2: test_dataobject_deprecated
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def test_dataobject_deprecated(self):
in_data = { 'key': plistlib.Data(b'hello') }
out_data = { 'key': b'hello' }
buf = plistlib.dumps(in_data)
cur = plistlib.loads(buf)
self.assertEqual(cur, out_data)
self.assertNotEqual(cur, in_data)
cur = plistlib.loads(buf, use_builtin_types=False)
self.assertNotEqual(cur, out_data)
self.assertEqual(cur, in_data)
with self.assertWarns(DeprecationWarning):
cur = plistlib.readPlistFromBytes(buf)
self.assertNotEqual(cur, out_data)
self.assertEqual(cur, in_data)
示例3: test_dataobject_deprecated
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def test_dataobject_deprecated(self):
in_data = { 'key': plistlib.Data(b'hello') }
out_data = { 'key': b'hello' }
buf = plistlib.dumps(in_data)
cur = plistlib.loads(buf)
self.assertEqual(cur, out_data)
self.assertEqual(cur, in_data)
cur = plistlib.loads(buf, use_builtin_types=False)
self.assertEqual(cur, out_data)
self.assertEqual(cur, in_data)
with self.assertWarns(DeprecationWarning):
cur = plistlib.readPlistFromBytes(buf)
self.assertEqual(cur, out_data)
self.assertEqual(cur, in_data)
示例4: handle_tm_language_files
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def handle_tm_language_files():
# type: () -> None
syntax_files = sublime.find_resources("*.tmLanguage")
for syntax_file in syntax_files:
try:
resource = sublime.load_binary_resource(syntax_file)
except Exception:
print("GitSavvy: could not load {}".format(syntax_file))
continue
try:
extensions = plistlib.readPlistFromBytes(resource).get("fileTypes", [])
except Exception:
print("GitSavvy: could not parse {}".format(syntax_file))
continue
for extension in extensions:
syntax_file_map[extension].append(syntax_file)
示例5: parse
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def parse(self, xml, pvars):
#tmp = minidom.parseString(xml)
if sys.version_info >= (3, 0):
pl = plistlib.readPlistFromBytes(xml.encode());
else:
pl = plistlib.readPlistFromString(xml);
parsed= {}
pvars = self.getVars(pvars)
for k,v in pvars.items():
parsed[k] = pl[k] if k in pl else None
return parsed;
示例6: get_color_scheme
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def get_color_scheme(view=None):
if int(sublime.version()) > 3153:
return view.style()
setting = sublime.load_settings("Preferences.sublime-settings").get("color_scheme")
color_scheme_bytes = sublime.load_binary_resource(setting)
color_scheme = {"scopes": []}
for setting in plistlib.readPlistFromBytes(color_scheme_bytes)["settings"]:
if "scope" in setting:
this_scope = {"scope": setting["scope"], "style": {}}
for key in ["foreground", "background"]:
if key in setting["settings"]:
this_scope["style"][key] = setting["settings"][key]
for key in ["italic", "bold"]:
this_scope["style"][key] = (
"fontStyle" in setting["settings"]
and key in setting["settings"]["fontStyle"].lower()
)
color_scheme["scopes"].append(this_scope)
elif "settings" in setting:
for key in ["foreground", "background"]:
if key in setting["settings"]:
color_scheme[key] = setting["settings"][key]
return color_scheme
示例7: test_bytes_deprecated
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def test_bytes_deprecated(self):
pl = {
'key': 42,
'sub': {
'key': 9,
'alt': 'value',
'data': b'buffer',
}
}
with self.assertWarns(DeprecationWarning):
data = plistlib.writePlistToBytes(pl)
with self.assertWarns(DeprecationWarning):
pl2 = plistlib.readPlistFromBytes(data)
self.assertIsInstance(pl2, plistlib._InternalDict)
self.assertEqual(pl2, plistlib._InternalDict(
key=42,
sub=plistlib._InternalDict(
key=9,
alt='value',
data=plistlib.Data(b'buffer'),
)
))
with self.assertWarns(DeprecationWarning):
data2 = plistlib.writePlistToBytes(pl2)
self.assertEqual(data, data2)
示例8: test_gh463
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def test_gh463(self):
"""https://github.com/IronLanguages/ironpython2/issues/463"""
import plistlib
x = b'<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>A</key><string>B</string></dict></plist>'
self.assertEqual(plistlib.readPlistFromBytes(x), {'A': 'B'})
示例9: __init__
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def __init__(self, scheme_file, color_filter=None):
"""Initialize."""
if color_filter is None:
color_filter = self.filter
self.color_scheme = scheme_file.replace('\\', '/')
self.scheme_file = path.basename(self.color_scheme)
if NEW_SCHEMES and scheme_file.endswith(('.sublime-color-scheme', '.hidden-color-scheme')):
self.legacy = False
self.scheme_obj = {
'variables': {},
GLOBAL_OPTIONS: {},
'rules': []
}
else:
try:
content = sublime.load_binary_resource(sublime_format_path(self.color_scheme))
except IOError:
# Fallback if file was created manually and not yet found in resources
with open(packages_path(self.color_scheme), 'rb') as f:
content = f.read()
self.legacy = True
self.convert_format(readPlistFromBytes(XML_COMMENT_RE.sub(b'', content)))
self.overrides = []
if NEW_SCHEMES:
self.merge_overrides()
self.scheme_file = scheme_file
self.matched = {}
self.variables = {}
self.parse_scheme()
self.scheme_obj = color_filter(self.scheme_obj)
self.setup_matcher()
示例10: test_bytes_deprecated
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import readPlistFromBytes [as 别名]
def test_bytes_deprecated(self):
pl = {
'key': 42,
'sub': {
'key': 9,
'alt': 'value',
'data': b'buffer',
}
}
with self.assertWarns(DeprecationWarning):
data = plistlib.writePlistToBytes(pl)
with self.assertWarns(DeprecationWarning):
pl2 = plistlib.readPlistFromBytes(data)
self.assertIsInstance(pl2, dict)
self.assertEqual(pl2, dict(
key=42,
sub=dict(
key=9,
alt='value',
data=plistlib.Data(b'buffer'),
)
))
with self.assertWarns(DeprecationWarning):
data2 = plistlib.writePlistToBytes(pl2)
self.assertEqual(data, data2)