python类YAMLError()的实例源码

client.py 文件源码 项目:chkit.old 作者: containerum 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_json_from_file(self):
        file_name = os.path.join(self.path, self.args['file'])
        try:
            with open(file_name, 'r', encoding='utf-8') as f:
                body = json.load(f)
                return body
        except FileNotFoundError:
            self.parser.error('no such file: {}'.format(
                file_name
            ))
        except json.decoder.JSONDecodeError as e:
            pass

        try:
            with open(file_name, 'r', encoding='utf-8') as f:
                body = yaml.load(f)
                return body
        except FileNotFoundError:
            self.parser.error('no such file: {}'.format(
                file_name
            ))
        except yaml.YAMLError as e:
            self.parser.error('bad json or yaml: {}'.format(
                e
            ))
sysctl.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
yaml_api.py 文件源码 项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def post(self, **params):
        user = self.get_current_user()
        data = params.get('data')
        if data is None:
            raise InsufficientData('No "data" provided')
        try:
            parsed_data = list(yaml.safe_load_all(data))
        except yaml.YAMLError as e:
            raise PredefinedAppExc.UnparseableTemplate(
                'Incorrect yaml, parsing failed: "{0}"'.format(str(e)))

        try:
            res = start_pod_from_yaml(parsed_data, user=user)
        except APIError as e:  # pass as is
            raise
        except Exception as e:
            raise PredefinedAppExc.InternalPredefinedAppError(
                details={'message': str(e)})
        send_event_to_user('pod:change', res, user.id)
        return res
sysctl.py 文件源码 项目:charm-neutron-api 作者: openstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-neutron-api 作者: openstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-ceph-mon 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-ceph-mon 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-openstack-dashboard 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-openstack-dashboard 作者: openstack 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
http_codes.py 文件源码 项目:os-api-ref 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _load_status_file(self, fpath):
        global HTTP_YAML_CACHE
        if fpath in HTTP_YAML_CACHE:
            return HTTP_YAML_CACHE[fpath]

        # self.app.info("Fpath: %s" % fpath)
        try:
            with open(fpath, 'r') as stream:
                lookup = yaml.safe_load(stream)
        except IOError:
            self.app.warn(
                "Parameters file %s not found" % fpath,
                (self.env.docname, None))
            return
        except yaml.YAMLError as exc:
            self.app.warn(exc)
            raise

        HTTP_YAML_CACHE[fpath] = lookup
        return lookup
sysctl.py 文件源码 项目:charm-ceilometer 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-ceilometer 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-ceilometer 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-hacluster 作者: openstack 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-hacluster 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-neutron-openvswitch 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])
sysctl.py 文件源码 项目:charm-neutron-openvswitch 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def create(sysctl_dict, sysctl_file):
    """Creates a sysctl.conf file from a YAML associative array

    :param sysctl_dict: a YAML-formatted string of sysctl options eg "{ 'kernel.max_pid': 1337 }"
    :type sysctl_dict: str
    :param sysctl_file: path to the sysctl file to be saved
    :type sysctl_file: str or unicode
    :returns: None
    """
    try:
        sysctl_dict_parsed = yaml.safe_load(sysctl_dict)
    except yaml.YAMLError:
        log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
            level=ERROR)
        return

    with open(sysctl_file, "w") as fd:
        for key, value in sysctl_dict_parsed.items():
            fd.write("{}={}\n".format(key, value))

    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict_parsed),
        level=DEBUG)

    check_call(["sysctl", "-p", sysctl_file])


问题


面经


文章

微信
公众号

扫码关注公众号