本文整理汇总了Python中syck.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testBuggyNodesReduce
def testBuggyNodesReduce(self):
object = syck.load(BUGGY_NODES)
nodes = syck.parse(BUGGY_NODES)
output = syck.dump(nodes)
#print output
nodes2 = syck.load(output)
output2 = syck.emit(nodes2)
object2 = syck.load(output2)
self.assertEqual(object, object2)
示例2: testExtensions
def testExtensions(self):
source = EXTENSIONS[0]
object = EXTENSIONS[1]
object2 = syck.load(source, Loader=ExLoader)
for left, right in zip(object, object2):
self.assertEqual(left, right)
source2 = syck.dump(object2, Dumper=ExDumper)
object3 = syck.load(source2, Loader=ExLoader)
for left, right in zip(object, object3):
self.assertEqual(left, right)
示例3: __init__
def __init__(self, pref_string):
# Load default values first
from mallet.config import data_dir
default_pref = open(os.path.join(data_dir, 'default.yaml')).read()
default_data = syck.load(default_pref)
# Load from user preferences
self._data = syck.load(pref_string)
if self._data is None:
self._data = {}
self._data.update(default_data)
示例4: testNonsense
def testNonsense(self):
class MyFile1:
def read(self, max_length):
return ' '*(max_length+1)
class MyFile2:
def read(self, max_length):
return None
self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
self.assertRaises(TypeError, lambda: syck.load(MyFile2()))
示例5: testTimestamp
def testTimestamp(self):
# Again, Syck does not understand the latest two forms.
#self.assertEqual(syck.load(
# '- 2001-12-15T02:59:43.1Z\n'
# '- 2001-12-14t21:59:43.10-05:00\n'
# '- 2001-12-14 21:59:43.10 -5\n'
# '- 2001-12-15 2:59:43.10\n'),
# [datetime.datetime(2001, 12, 15, 2, 59, 43, 100000)]*4)
self.assertEqual(syck.load(
'- 2001-12-15T02:59:43.1Z\n'
'- 2001-12-14t21:59:43.10-05:00\n'
'- 2001-12-14 21:59:43.10 -05\n'
'- 2001-12-15 02:59:43.10 Z\n'),
[datetime.datetime(2001, 12, 15, 2, 59, 43, 100000)]*4)
self.assertEqual(syck.load('2002-12-14'), datetime.datetime(2002, 12, 14))
示例6: testLoad
def testLoad(self):
self._testWarning()
document, values = DOCUMENT
new_values = syck.load(document)
for string, new_string in zip(values, new_values):
self.assertEqual(string, new_string)
self.assertEqual(type(string), type(new_string))
示例7: prepare_data
def prepare_data(self, fast = False):
Diagnostic.prepare_data(self, fast)
from path import path
logdir = path(self.logfilename).parent
daigpath = logdir/'diag.yaml'
if daigpath.isfile():
with open(daigpath, 'r') as diagfile:
data = syck.load(diagfile)
# ensure that the process that crashed was the one that wrote the file
uniquekey = getattr(getattr(sys, 'opts', None), 'crashuniquekey', None)
if uniquekey is None:
return
try:
uniquekey = int(uniquekey)
except ValueError:
uniquekey = None
if data['uniquekey'] != uniquekey:
return
crun = data['args']['crun']
if self.crashuser is not None and crun != self.crashuser:
msg = 'ERROR: crash user does not match: %r and %r' % (self.crashuser, crun)
print >> sys.stderr, msg
return # don't update with YAML data
self.prepared_args.update(data['args'])
self.prepared_files.update(data['files'])
示例8: got_updateyaml
def got_updateyaml(self, req = None, fobj = None):
'''
an open fileobject that contains yaml with manifest locations in it.
'''
try:
data = fobj.read()
except Exception as e:
return self.manifest_path_error(e)
try:
ui = syck.load(data)
except Exception as e:
return self.manifest_path_error(e)
all = ui.get('all', {})
mine = ui.get(config.platform, None) or {}
merged = all.copy()
merged.update(mine)
manifest_path = merged.get(self.release_type, merged.get('release', None))
if manifest_path is None:
self.update_check_error(Exception("No manifest URL for %r in %r" % (self.release_type, all)))
else:
log.info("Got manifest path: %r", manifest_path)
self.remote_manifest_path = manifest_path
downloader.httpopen(self.remote_manifest_path, method = 'HEAD', success = self.check_manifest_integrity, error = self.manifest_check_error)
示例9: testMutableKey
def testMutableKey(self):
document = syck.load(MUTABLE_KEY)
self.assertEqual(type(document), list)
self.assertEqual(len(document), 1)
self.assertEqual(type(document[0]), tuple)
self.assertEqual(len(document[0]), 2)
self.assertEqual(document[0][0], document[0][1])
示例10: testDuplicateKey
def testDuplicateKey(self):
document = syck.load(DUPLICATE_KEY)
self.assertEqual(type(document), list)
self.assertEqual(len(document), 2)
self.assertEqual(len(document[0]), 2)
self.assertEqual(len(document[1]), 2)
self.assertEqual(document[0][0], document[1][0])
示例11: yaml
def yaml(self):
if self._yaml is None and has_yaml:
try:
self._yaml = yaml.load(self.data)
except yaml_error:
pass
return self._yaml
示例12: yaml_load
def yaml_load(filename):
"""Load and interpret a YAML file, using whichever library is
found. The following packages are tried:
pysyck
pyyaml (with C extensions if available)
"""
f = open(filename)
try:
import syck
s = f.read()
y = syck.load(s)
except:
import yaml
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
y = yaml.load(f, Loader=Loader)
f.close()
return y
示例13: __init__
def __init__(self, lang_override=None):
# L_O_G.info('init spellchecker')
self.spellengine = None
self.lang = None
self._need_to_download = None
self.currentDownloads = set()
self.expectedNext = None
# load YAML file describing the dictionaries
filename = program_dir() / "res" / ("dictionaries-%s.yaml" % Aspell.VERSION)
try:
with open(filename) as f:
self.dict_info = syck.load(f)
if not isinstance(self.dict_info, dict):
raise ValueError("invalid YAML in %s" % filename)
except Exception:
print_exc()
self.dict_info = {}
# load an engine using swap engine, if no engine is failed use the NullSpellEngine
if not self.SwapEngine(lang_override):
self.spellengine = NullSpellEngine()
profile.prefs.add_observer(
self.on_prefs_change, # @UndefinedVariable
"messaging.spellcheck.enabled",
"messaging.spellcheck.engineoptions.lang",
"messaging.spellcheck.engineoptions.encoding",
"messaging.spellcheck.engineoptions.keyboard",
"messaging.spellcheck.engineoptions.sug-mode",
) # @UndefinedVariable
示例14: load_soundset
def load_soundset(name):
set_name = set_dir = None
for set_name, set_dir in list_soundsets():
if set_name == name:
found = True
break
else:
found = False
if set_dir and found:
soundset_yaml = set_dir / DESC_FILENAME
else:
soundset_yaml = None
if soundset_yaml is None or not soundset_yaml.isfile():
raise SoundsetException('soundset %r is missing %r' % (name, DESC_FILENAME))
# load from YAML file in res dir
with file(soundset_yaml, 'r') as f:
soundset = syck.load(f)
if soundset is None:
raise SoundsetException('soundset %r is empty' % name)
# fix contact_signoff -> contact.signoff
underscores_to_dots(soundset)
# turn relative paths in YAML to actual paths
fix_paths(soundset, set_dir)
return Soundset(soundset)
示例15: updatesite
def updatesite(self):
if self._updatesite is None:
try:
self._updatesite = syck.load((self.local_path / 'index.yaml').open())['source']
except Exception:
raise Exception('Unknown source site for %r', self)
return self._updatesite