本文整理汇总了Python中oslo_serialization.jsonutils.load方法的典型用法代码示例。如果您正苦于以下问题:Python jsonutils.load方法的具体用法?Python jsonutils.load怎么用?Python jsonutils.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_serialization.jsonutils
的用法示例。
在下文中一共展示了jsonutils.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: body_dict
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def body_dict(self):
"""
Returns the body content as a dictionary, deserializing per the
Content-Type header.
We add this method to ease future XML support, so the main code
is not hardcoded to call pecans "request.json" method.
"""
if self.content_type not in JSON_TYPES:
raise exceptions.UnsupportedContentType(
'Content-type must be application/json')
try:
json_dict = jsonutils.load(self.body_file)
if json_dict is None:
# NOTE(kiall): Somehow, json.load(fp) is returning None.
raise exceptions.EmptyRequestBody('Request Body is empty')
return json_dict
except ValueError as e:
if not self.body:
raise exceptions.EmptyRequestBody('Request Body is empty')
else:
raise exceptions.InvalidJson(six.text_type(e))
示例2: get_configuration
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def get_configuration(self, filename=None):
"""Check the json file for changes and load it if needed."""
if not filename:
filename = CONF.scheduler_json_config_location
if not filename:
return self.data
if self.last_checked:
now = self._get_time_now()
if now - self.last_checked < datetime.timedelta(minutes=5):
return self.data
last_modified = self._get_file_timestamp(filename)
if (not last_modified or not self.last_modified or
last_modified > self.last_modified):
self.data = self._load_file(self._get_file_handle(filename))
self.last_modified = last_modified
if not self.data:
self.data = {}
return self.data
示例3: main
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def main():
d = jsonutils.load(sys.stdin.buffer)
cni_conf = utils.CNIConfig(d)
args = (['--config-file', cni_conf.zun_conf] if 'zun_conf' in d
else [])
try:
if cni_conf.debug:
args.append('-d')
except AttributeError:
pass
config.init(args)
if os.environ.get('CNI_COMMAND') == 'VERSION':
CONF.set_default('use_stderr', True)
# Initialize o.vo registry.
os_vif.initialize()
runner = cni_api.CNIDaemonizedRunner()
def _timeout(signum, frame):
runner._write_dict(sys.stdout, {
'msg': 'timeout',
'code': consts.CNI_TIMEOUT_CODE,
})
LOG.debug('timed out')
sys.exit(1)
signal.signal(signal.SIGALRM, _timeout)
signal.alarm(_CNI_TIMEOUT)
status = runner.run(os.environ, cni_conf, sys.stdout)
LOG.debug("Exiting with status %s", status)
if status:
sys.exit(status)
示例4: test_playbook_persistence
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def test_playbook_persistence(self):
r_playbook = m.Playbook.query.first()
tmpfile = os.path.join(self.app.config['ARA_TMP_DIR'], 'ara.json')
with open(tmpfile, 'rb') as file:
data = jsonutils.load(file)
self.assertEqual(r_playbook.id, data['playbook']['id'])
示例5: run
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def run():
d = jsonutils.load(sys.stdin.buffer)
cni_conf = utils.CNIConfig(d)
args = (['--config-file', cni_conf.kuryr_conf] if 'kuryr_conf' in d
else [])
try:
if cni_conf.debug:
args.append('-d')
except AttributeError:
pass
config.init(args)
config.setup_logging()
# Initialize o.vo registry.
k_objects.register_locally_defined_vifs()
os_vif.initialize()
runner = cni_api.CNIDaemonizedRunner()
def _timeout(signum, frame):
runner._write_dict(sys.stdout, {
'msg': 'timeout',
'code': k_const.CNI_TIMEOUT_CODE,
})
LOG.debug('timed out')
sys.exit(1)
signal.signal(signal.SIGALRM, _timeout)
signal.alarm(_CNI_TIMEOUT)
status = runner.run(os.environ, cni_conf, sys.stdout)
LOG.debug("Exiting with status %s", status)
if status:
sys.exit(status)
示例6: _get_vhu_sock
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def _get_vhu_sock(config_file_path):
with open(config_file_path, 'r') as f:
conf = jsonutils.load(f)
return conf['vhostname']
示例7: load_json
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def load_json(input_string):
try:
# binary mode is needed due to bug/1515231
with open(input_string, 'r+b') as fh:
return jsonutils.load(fh)
except IOError:
return jsonutils.loads(input_string)
示例8: load
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def load(self, fp):
return jsonutils.load(fp, encoding=self._encoding)
示例9: test_load
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def test_load(self):
jsontext = u'{"a": "\u0442\u044d\u0441\u0442"}'
expected = {u'a': u'\u0442\u044d\u0441\u0442'}
for encoding in ('utf-8', 'cp1251'):
fp = io.BytesIO(jsontext.encode(encoding))
result = jsonutils.load(fp, encoding=encoding)
self.assertEqual(expected, result)
for key, val in result.items():
self.assertIsInstance(key, str)
self.assertIsInstance(val, str)
示例10: _modify_policy_file
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def _modify_policy_file(self, rules):
with open(self.policy_file, 'r+b') as policy_file:
existing_policy = jsonutils.load(policy_file)
existing_policy.update(rules)
with open(self.policy_file, 'w') as policy_file:
jsonutils.dump(existing_policy, policy_file)
time.sleep(2)
示例11: _load_fixture_data
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def _load_fixture_data(self, name):
base_dir = "searchlight/tests/functional/data"
# binary mode is needed due to bug/1515231
with open(os.path.join(base_dir, name), 'r+b') as f:
return jsonutils.load(f)
示例12: _get_glance_image_owner_and_count
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def _get_glance_image_owner_and_count(self):
with open(generate_load_data.IMAGES_FILE, "r+b") as file:
images_data = jsonutils.load(file)
if len(images_data) > 0:
return len(images_data), images_data[0]['owner']
示例13: _get_glance_metadefs_owner_and_count
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def _get_glance_metadefs_owner_and_count(self):
with open(generate_load_data.METADEFS_FILE, "r+b") as file:
metadefs_data = jsonutils.load(file)
if len(metadefs_data) > 0:
return len(metadefs_data), metadefs_data[0]['owner']
示例14: __init__
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def __init__(self):
# Load Images from file
self._images = []
with open(generate_load_data.IMAGES_FILE, "r+b") as file:
image_data = jsonutils.load(file)
for image in image_data:
fake_image = FakeImage(**image)
self._images.append(fake_image)
self.images = FakeImages(self._images)
# Load Images members from file
self._images_members_dict = dict()
self._image_members_list = []
with open(generate_load_data.IMAGE_MEMBERS_FILE, "r+b") as file:
image_members_data = jsonutils.load(file)
for image_id, image_members in image_members_data.items():
for image_member in image_members:
fake_image_member = FakeImageMember(**image_member)
self._image_members_list.append(fake_image_member)
self._images_members_dict[image_id] = self._image_members_list
self.image_members = FakeImageMembers(self._images_members_dict)
# Load Metadef namespaces from file
self._metadefs_namespace = []
self.metadefs_namespace = []
with open(generate_load_data.METADEFS_FILE, "r+b") as file:
metadefs_namespace_data = jsonutils.load(file)
for metadef_namespace in metadefs_namespace_data:
fake_namespace = FakeNamespace(**metadef_namespace)
self._metadefs_namespace.append(fake_namespace)
self.metadefs_namespace = FakeNamespaces(self._metadefs_namespace)
示例15: _load_file
# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import load [as 别名]
def _load_file(self, handle):
"""Decode the JSON file. Broken out for testing."""
try:
return jsonutils.load(handle)
except ValueError:
LOG.exception("Could not decode scheduler options.")
return {}