本文整理汇总了Python中pyaml.dump函数的典型用法代码示例。如果您正苦于以下问题:Python dump函数的具体用法?Python dump怎么用?Python dump使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dump函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeConfig
def writeConfig(self):
log.info("Writing config...")
trigs = {}
for i in self.triggers:
trigs[i.trigger] = i.text
log.info("Saving : {}".format(trigs))
settings = {
"bot": {
"name": self.botname,
"version": self.bot_version,
"msg_prefix": self.bot_prefix,
"cmd_prefix": self.cmd_prefix,
"debug_logging": False
},
"modules": {
"path": self.path,
"load": self.init_modules
},
"triggers": trigs,
"admins": self.admins,
"ai":{"model_directory":"models"}
}
log.info(pyaml.dump(settings))
with open("discord-config.conf", "w") as f:
f.write(pyaml.dump(settings))
log.info("Written")
示例2: do_list
def do_list(self):
"""
Usage: list
"""
archives = self.cache._for_adf('archives')
if len(archives):
for n, archive in enumerate(archives.iteritems()):
archive = archive[1]
status = "LOCAL"
cert = ""
if 'signature' in archive:
status = "COMPLETE"
cert = archive['signature'].aid
elif 'links' in archive and archive['links'].upload:
status = "UPLOADED"
if self.verbose:
cert = archive['links'].upload
title = archive['archive'].title
size = archive_size(archive['archive'])
print "{:03d} {:>6} {:>20} {:>10} {:>10}".format(
n+1, size, title, status, cert)
if self.debug > 2:
for doc in archive.itervalues():
pyaml.dump(doc, sys.stdout)
print
else:
print "No available archives."
示例3: write_settings_file
def write_settings_file(self, eps_values):
eps_values['min_samples'] = self.min_samples
eps_values['only_core_samples'] = self.only_core_samples
settingspath = self.pm.blotchfile.parent / 'clustering_settings.yaml'
settingspath.parent.mkdir(exist_ok=True, parents=True)
logger.info("Writing settings file at %s", str(settingspath))
with open(settingspath, 'w') as fp:
pyaml.dump(eps_values, fp)
示例4: test_str_style_pick
def test_str_style_pick(self):
a = pyaml.dump(data_str_multiline)
b = pyaml.dump(data_str_multiline, string_val_style='|')
self.assertEqual(a, b)
b = pyaml.dump(data_str_multiline, string_val_style='plain')
self.assertNotEqual(a, b)
self.assertTrue(pyaml.dump('waka waka', string_val_style='|').startswith('|-\n'))
self.assertEqual(pyaml.dump(dict(a=1), string_val_style='|'), 'a: 1\n')
示例5: type_diff
def type_diff(a, b):
s = StringIO.StringIO()
pyaml.dump(a, s, safe = True)
a = s.getvalue().splitlines()
s = StringIO.StringIO()
pyaml.dump(b, s, safe = True)
b = s.getvalue().splitlines()
return '\n'.join(difflib.Differ().compare(a, b))
示例6: test_str_style_pick
def test_str_style_pick(self):
a = pyaml.dump(data_str_multiline)
b = pyaml.dump(data_str_multiline, string_val_style="|")
self.assertEqual(a, b)
b = pyaml.dump(data_str_multiline, string_val_style="plain")
self.assertNotEqual(a, b)
self.assertTrue(pyaml.dump("waka waka", string_val_style="|").startswith("|-\n"))
self.assertEqual(pyaml.dump(dict(a=1), string_val_style="|"), "a: 1\n")
示例7: test_colons_in_strings
def test_colons_in_strings(self):
val1 = {'foo': ['bar:', 'baz', 'bar:bazzo', 'a: b'], 'foo:': 'yak:'}
val1_str = pyaml.dump(val1)
val2 = yaml.safe_load(val1_str)
val2_str = pyaml.dump(val2)
val3 = yaml.safe_load(val2_str)
self.assertEqual(val1, val2)
self.assertEqual(val1_str, val2_str)
self.assertEqual(val2, val3)
示例8: test_colons_in_strings
def test_colons_in_strings(self):
val1 = {"foo": ["bar:", "baz", "bar:bazzo", "a: b"], "foo:": "yak:"}
val1_str = pyaml.dump(val1)
val2 = yaml.safe_load(val1_str)
val2_str = pyaml.dump(val2)
val3 = yaml.safe_load(val2_str)
self.assertEqual(val1, val2)
self.assertEqual(val1_str, val2_str)
self.assertEqual(val2, val3)
示例9: test_empty_strings
def test_empty_strings(self):
val1 = {"key": ["", "stuff", "", "more"], "": "value", "k3": ""}
val1_str = pyaml.dump(val1)
val2 = yaml.safe_load(val1_str)
val2_str = pyaml.dump(val2)
val3 = yaml.safe_load(val2_str)
self.assertEqual(val1, val2)
self.assertEqual(val1_str, val2_str)
self.assertEqual(val2, val3)
示例10: dump
def dump(self, data, path):
"""dump data to file
"""
with open(path, "w") as f:
if isinstance(data, MergeableDict):
pyaml.dump(data.convert_to(data), f)
else:
pyaml.dump(data, f)
示例11: dump
def dump(self, content, filepath, indent=4):
"""
Dump settings content to filepath.
Args:
content (str): Settings content.
filepath (str): Settings file location.
"""
with open(filepath, 'w') as fp:
pyaml.dump(content, dst=fp, indent=indent)
示例12: main
def main(argv=None):
import argparse
parser = argparse.ArgumentParser(
description='Process and dump prettified YAML to stdout.')
parser.add_argument('path', nargs='?', metavar='path',
help='Path to YAML to read (default: use stdin).')
opts = parser.parse_args(argv or sys.argv[1:])
src = open(opts.path) if opts.path else sys.stdin
try: data = yaml.load(src)
finally: src.close()
pyaml.dump(data, sys.stdout)
示例13: do_list
def do_list(self):
"""
Usage: list
"""
archives = list(self.cache._for_adf('archives').iteritems())
if len(archives):
ui.print_archives_header()
bydate = sorted(archives,
key=compose(creation, operator.itemgetter(1)))
for n, docs in enumerate(bydate):
fname = docs[0]
archive = docs[1]
status = self.cache.archive_status(fname, archive)
cert = ""
if status == ArchiveStatus.Completed:
status = "COMPLETE"
cert = archive['signature'].aid
elif status == ArchiveStatus.InProgress:
status = "IN PROGRESS"
if self.verbose:
cert = archive['links'].upload
elif status == ArchiveStatus.Failed:
status = "FAILED"
if self.verbose:
cert = archive['links'].upload
elif status == ArchiveStatus.Local:
status = "LOCAL"
elif status == ArchiveStatus.Paused:
status = "PAUSED"
else:
status = "UNKNOWN"
title = archive['archive'].title
size = archive_size(archive['archive'])
ui.print_archives_line(archive={
'num': n+1,
'size': size,
'title': title,
'status': status,
'cert': cert,
'created': archive['archive'].meta.created,
'capsule': archive_capsule(archive) or '-'
})
if self.debug > 2:
for doc in archive.itervalues():
pyaml.dump(doc, sys.stdout)
print
print
else:
print "No available archives."
示例14: test_multiple_docs
def test_multiple_docs(self):
docs = [yaml.safe_load(large_yaml), dict(a=1, b=2, c=3)]
docs_str = pyaml.dump_all(docs, vspacing=[3, 2])
self.assertTrue(docs_str.startswith('---'))
self.assertIn('---\n\n\n\na: 1\n\n\n\nb: 2\n\n\n\nc: 3\n', docs_str)
docs_str2 = pyaml.dump(docs, vspacing=[3, 2], multiple_docs=True)
self.assertEqual(docs_str, docs_str2)
docs_str2 = pyaml.dump(docs, vspacing=[3, 2])
self.assertNotEqual(docs_str, docs_str2)
docs_str2 = pyaml.dump_all(docs, explicit_start=False)
self.assertFalse(docs_str2.startswith('---'))
self.assertNotEqual(docs_str, docs_str2)
docs_str = pyaml.dump(docs, multiple_docs=True, explicit_start=False)
self.assertEqual(docs_str, docs_str2)
示例15: test_print
def test_print(self):
self.assertIs(pyaml.print, pyaml.pprint)
self.assertIs(pyaml.print, pyaml.p)
buff = io.BytesIO()
b = pyaml.dump(data_str_multiline, dst=bytes)
pyaml.print(data_str_multiline, file=buff)
self.assertEqual(b, buff.getvalue())