當前位置: 首頁>>代碼示例>>Python>>正文


Python jsonutils.load方法代碼示例

本文整理匯總了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)) 
開發者ID:openstack,項目名稱:designate,代碼行數:25,代碼來源:patches.py

示例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 
開發者ID:openstack,項目名稱:manila,代碼行數:22,代碼來源:scheduler_options.py

示例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) 
開發者ID:openstack,項目名稱:zun,代碼行數:36,代碼來源:cni.py

示例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']) 
開發者ID:dmsimard,項目名稱:ara-archive,代碼行數:9,代碼來源:test_callback.py

示例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) 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:36,代碼來源:main.py

示例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'] 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:6,代碼來源:vhostuser.py

示例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) 
開發者ID:openstack,項目名稱:python-mistralclient,代碼行數:9,代碼來源:utils.py

示例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) 
開發者ID:openstack,項目名稱:oslo.serialization,代碼行數:4,代碼來源:json_serializer.py

示例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) 
開發者ID:openstack,項目名稱:oslo.serialization,代碼行數:14,代碼來源:test_jsonutils.py

示例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) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:12,代碼來源:test_api.py

示例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) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:7,代碼來源:__init__.py

示例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'] 
開發者ID:openstack,項目名稱:searchlight,代碼行數:7,代碼來源:test_glance_plugins.py

示例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'] 
開發者ID:openstack,項目名稱:searchlight,代碼行數:7,代碼來源:test_glance_plugins.py

示例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) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:33,代碼來源:mock_glance_pyclient.py

示例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 {} 
開發者ID:openstack,項目名稱:manila,代碼行數:9,代碼來源:scheduler_options.py


注:本文中的oslo_serialization.jsonutils.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。