当前位置: 首页>>代码示例>>Python>>正文


Python jsonpath_rw.parse方法代码示例

本文整理汇总了Python中jsonpath_rw.parse方法的典型用法代码示例。如果您正苦于以下问题:Python jsonpath_rw.parse方法的具体用法?Python jsonpath_rw.parse怎么用?Python jsonpath_rw.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonpath_rw的用法示例。


在下文中一共展示了jsonpath_rw.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _parse_json

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def _parse_json(source, json_path_expr=None):
    if not source:
        _logger.debug('Unable to parse JSON from empty source, return empty.')
        return {}

    if json_path_expr:
        _logger.debug(
            'Try to extract JSON from source with JSONPATH expression: %s, ',
            json_path_expr
        )
        source = json_path(source, json_path_expr)

    elif isinstance(source, six.string_types):
        source = json.loads(source)

    return source 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:ext.py

示例2: main

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def main():
    args = parse_args()
    response = urlopen(args.url)
    data = json.loads(response.read().decode('utf-8'))

    template = args.prefix + '.{} {} ' + str(int(time()))

    if args.keys:
        for key, value in data.items():
            if key in args.keys:
                print(template.format(key, value))

    if args.jsonpaths:
        from jsonpath_rw import parse

        for path in args.jsonpaths:
            for match in parse(path).find(data):
                # Graphite text protocol can not process square brackets
                graphite_path = str(match.full_path).replace('[', '').replace(
                    ']', '')
                print(template.format(graphite_path, match.value)) 
开发者ID:innogames,项目名称:igcollect,代码行数:23,代码来源:url_json.py

示例3: job_directory

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def job_directory(cluster, job, user_home='.'):
    """
    Returns the job directory for a given job.

    :param cluster: The job the cluster is running on.
    :param job: The job to return the directory for.

    """
    # First try the job parameters
    output_root = parse('params.jobOutputDir').find(job)
    if output_root:
        output_root = output_root[0].value
    else:
        # Try the cluster
        output_root = parse('config.jobOutputDir').find(cluster)
        if output_root:
            output_root = output_root[0].value
        else:
            output_root = user_home

    return os.path.join(output_root, job['_id']) 
开发者ID:Kitware,项目名称:cumulus,代码行数:23,代码来源:job.py

示例4: download_job_input

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def download_job_input(cluster, job, log_write_url=None, girder_token=None):
    job_url = '%s/jobs/%s/log' % (cumulus.config.girder.baseUrl, job['_id'])
    log = get_post_logger(job['_id'], girder_token, job_url)

    # Create job directory
    with get_connection(girder_token, cluster) as conn:
        conn.makedirs(job_directory(cluster, job))

    log.info('Downloading input for "%s"' % job['name'])

    if parse('input.itemId').find(job):
        download_job_input_items(cluster, job, log_write_url=log_write_url,
                                 girder_token=girder_token)
    else:
        download_job_input_folders(cluster, job, log_write_url=log_write_url,
                                   girder_token=girder_token) 
开发者ID:Kitware,项目名称:cumulus,代码行数:18,代码来源:job.py

示例5: __enter__

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def __enter__(self):

        # Do we need to get the session id for this user
        if not self._newt_session_id:
            headers = {'Girder-Token':  self._girder_token}
            url = '%s/newt/sessionId' % cumulus.config.girder.baseUrl
            r = requests.get(url, headers=headers)
            check_status(r)

            session_id = parse('sessionId').find(r.json())

            if not session_id:
                raise Exception('No NEWT session ID present')

            self._session = requests.Session()
            self._newt_session_id = session_id[0].value
            self._session.cookies.set('newt_sessionid', self._newt_session_id)

        return self 
开发者ID:Kitware,项目名称:cumulus,代码行数:21,代码来源:newt.py

示例6: get_queue_adapter

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def get_queue_adapter(cluster, cluster_connection=None):
    global type_to_adapter

    # Special case for nersc clusters. They use SLURM ( at the moment ) but the
    # submission is done using the NEWT REST API. So the scheduler is set the
    # SLURM but we want to use the NEWT adapter.
    if cluster['type'] == ClusterType.NEWT:
        system = QueueType.NEWT
    else:
        system = parse('config.scheduler.type').find(cluster)
        if system:
            system = system[0].value
        # Default to SGE
        else:
            system = QueueType.SGE

    if system not in type_to_adapter:
        raise Exception('Unsupported queuing system: %s' % system)
    else:
        cls = type_to_adapter[system]

    return cls(cluster, cluster_connection) 
开发者ID:Kitware,项目名称:cumulus,代码行数:24,代码来源:__init__.py

示例7: job_statuses

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def job_statuses(self, jobs):
        user = parse('config.user').find(self._cluster)

        if not user:
            raise Exception('Unable to extract user from cluster '
                            'configuration.')

        user = user[0].value
        url = '%s/queue/%s?user=%s' % (NEWT_BASE_URL, self._machine, user)
        r = self._session.get(url)
        check_status(r)
        json_response = r.json()

        states = []
        for job in jobs:
            slurm_state = self._extract_job_status(json_response, job)
            state = self.to_job_queue_state(slurm_state)
            states.append((job, state))

        return states 
开发者ID:Kitware,项目名称:cumulus,代码行数:22,代码来源:newt.py

示例8: _validate_region

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def _validate_region(self, client, doc):
        try:
            response = client.describe_regions(RegionNames=[doc['regionName']])
            endpoint = parse('Regions[0].Endpoint').find(response)
            if endpoint:
                endpoint = endpoint[0].value
            else:
                raise ValidationException('Unable to extract region endpoint.')

            doc['regionHost'] = endpoint
        except ClientError as ce:
            code = parse('Error.Code').find(ce.response)
            if code:
                code = code[0].value
            else:
                raise

            if code == ClientErrorCode.InvalidParameterValue:
                raise ValidationException('Invalid region', 'regionName')
        except EndpointConnectionError as ece:
            raise ValidationException(ece.message) 
开发者ID:Kitware,项目名称:cumulus,代码行数:23,代码来源:aws.py

示例9: _validate_zone

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def _validate_zone(self, client, doc):
        try:
            client = get_ec2_client(doc)
            client.describe_availability_zones(
                ZoneNames=[doc['availabilityZone']])

        except ClientError as ce:
            code = parse('Error.Code').find(ce.response)
            if code:
                code = code[0].value
            else:
                raise

            if code == ClientErrorCode.InvalidParameterValue:
                raise ValidationException(
                    'Invalid zone', 'availabilityZone')
        except EndpointConnectionError as ece:
            raise ValidationException(ece.message) 
开发者ID:Kitware,项目名称:cumulus,代码行数:20,代码来源:aws.py

示例10: retrieve_credentials

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def retrieve_credentials(event):
    cluster_id = event.info['authKey']
    user = event.info['user']
    model = ModelImporter.model('cluster', 'cumulus')
    cluster = model.load(cluster_id, user=getCurrentUser(),
                         level=AccessType.READ)
    event.stopPropagation()

    if not cluster:
        return

    username = parse('config.ssh.user').find(cluster)[0].value
    key_name = parse('config.ssh.key').find(cluster)[0].value
    key_path = os.path.join(cumulus.config.ssh.keyStore, key_name)
    passphrase = get_property('config.ssh.passphrase', cluster)

    if user != username:
        raise Exception('User doesn\'t match cluster user id ')

    event.addResponse((key_path, passphrase)) 
开发者ID:Kitware,项目名称:cumulus,代码行数:22,代码来源:credentials.py

示例11: jpath_selector

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def jpath_selector(self, query: str):
        """Query JSON with jpath query

        `Reference <https://goessner.net/articles/JsonPath/index.html#e2>`__
        
        Args:
            query (str): Required. Query. For reference, see the help
        
        Returns:
            Chepy: The Chepy object. 

        Examples:
            >>> c = Chepy("tests/files/test.json")
            >>> c.load_file()
            >>> c.jpath_selector("[*].name.first")
            >>> c.get_by_index(2)
            >>> c.o
            "Long"
        """
        self.state = list(
            j.value
            for j in jsonpath_rw.parse(query).find(ujson.loads(self._convert_to_str()))
        )
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:26,代码来源:extractors.py

示例12: _process_inline

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def _process_inline(expression, data):
    if not expression:
        raise JSONTemplateParseException("Empty expression found")

    try:
        parsed = parse_json_path(expression)
    except JsonPathLexerError as jple:
        raise JSONTemplateParseException("For expression `%s`: %s" % (expression, jple))
    except Exception as ex:
        raise JSONTemplateParseException("For expression `%s`: %s" % (expression, ex))

    try:
        found = parsed.find(data)
        if not found:
            return None

        if len(found) > 1:
            return [f.data for f in found]

        return found[0].value
    except IndexError:
        return None 
开发者ID:quay,项目名称:quay,代码行数:24,代码来源:jsontemplate.py

示例13: step_impl

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def step_impl(context, jsonpath, thing, value):
    if not context.content_json :
        ## Apparently no JSON at all...
        assert True is False
    else:
        jsonpath_expr = jsonpath_rw.parse(jsonpath)
        res = jsonpath_expr.find(context.content_json)
        if not res[0] :
            assert True is False
        else:
            if thing == "string":
                assert res[0].value == value
            elif thing == "integer":
                assert res[0].value == int(value)
            elif thing == "float":
                assert res[0].value == float(value)
            else:
                ## Not a thing we know how to deal with yet.
                assert True is False 
开发者ID:biolink,项目名称:biolink-api,代码行数:21,代码来源:route-data.py

示例14: jsonpath_query

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def jsonpath_query(value, query):
    """Extracts data from an object `value` using a JSONPath `query`.
    :link: https://github.com/kennknowles/python-jsonpath-rw
    :param value: a object (dict, array, etc) to query
    :param query: a JSONPath query expression (string)
    :returns: the result of the query executed on the value
    :rtype: dict, array, int, string, bool
    """
    expr = jsonpath_rw.parse(query)

    matches = [match.value for match in expr.find(value)]

    if not matches:
        return None

    return matches 
开发者ID:StackStorm,项目名称:st2,代码行数:18,代码来源:data.py

示例15: additional_global_fields

# 需要导入模块: import jsonpath_rw [as 别名]
# 或者: from jsonpath_rw import parse [as 别名]
def additional_global_fields(config, raw_json):
    if config.additional_global_fields:
        for field in config.additional_global_fields:
            jp = parse(field['path'])
            matches = jp.find(raw_json)
            if matches:
                for match in matches:
                    jsonpath_expr = get_path(match)
                    raw_json = update_json(raw_json, jsonpath_expr, field['value'])
            else:
                fields = []
                recurse(jp, fields)
                temp_json = raw_json
                for idx, f in enumerate(fields):
                    if f in temp_json:
                        temp_json = temp_json[f]
                    elif idx == len(fields) - 1:
                        temp_json[f] = field['value']
                    else:
                        print('path is not valid! : %s', '.'.join(fields))
    return raw_json 
开发者ID:blockchain-certificates,项目名称:cert-tools,代码行数:23,代码来源:jsonpath_helpers.py


注:本文中的jsonpath_rw.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。