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


Python objectify.parse方法代码示例

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


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

示例1: _get_profiles_from_one_file

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def _get_profiles_from_one_file(path):
    logger.info("Loading profiles from file", path=path.name)

    with path.open() as f:
        xml = objectify.parse(f)

    hostentries = xml.xpath(
        "//enc:AnyConnectProfile/enc:ServerList/enc:HostEntry", namespaces=ns
    )

    profiles = []
    for entry in hostentries:
        profiles.append(
            HostProfile(
                name=entry.HostName,
                address=entry.HostAddress,
                user_group=entry.UserGroup,
            )
        )

    logger.debug("AnyConnect profiles parsed", path=path.name, profiles=profiles)
    return profiles 
开发者ID:vlaci,项目名称:openconnect-sso,代码行数:24,代码来源:profile.py

示例2: generate_rows

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def generate_rows(self, dataset_schema=None, dataset_partitioning=None,
                            partition_id=None, records_limit = -1):
        """
        The main reading method.

        Returns a generator over the rows of the dataset (or partition)
        Each yielded row must be a dictionary, indexed by column name.

        The dataset schema and partitioning are given for information purpose.
        """
        limit_mode = False
        if records_limit != -1 or self.test_mode:
            limit_mode = True
        ### We hard force limit to 100 because of the time required for parsing ...

        if not self.all_years and partition_id not in self.list_partitions(None):
            raise ValueError("Unexpected partition id: '%s' - expected one of %s" % (partition_id, ",".join(self.list_partitions(None))))

        count = 0
        for (url, filename, year) in self.files(partition_id):
            print filename
            fullname = self.get_filename(url, filename)
            if not fullname:
                continue
            if limit_mode and count > 100:
                break
            for doc in extract_xml_strings(fullname):
                count = count + 1
                if count % 1000 == 0:
                    print "Patents : parsed", count, " lines"
                if limit_mode and count > 100:
                    break
                emptyDict = {}
                from lxml import objectify
                from StringIO import StringIO
                o = objectify.parse(StringIO(doc))
                iterNodes(o.getroot(), emptyDict)
                s = json.dumps(emptyDict)
                yield { "patent" : s, "year" : year[0], "filename" : filename} 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:41,代码来源:connector.py

示例3: get_test_context

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def get_test_context(self):
        """
        Run the shell command generated by `list_command` in a subprocess,
        parse and return the stdout generated via `parse_test_context`.

        :return: Result returned by `parse_test_context`.
        :rtype: ``list`` of ``list``
        """
        cmd = self.list_command()  # pylint: disable=assignment-from-none
        if cmd is None:
            return [(self._DEFAULT_SUITE_NAME, ())]

        proc = subprocess_popen(
            cmd,
            cwd=self.cfg.proc_cwd,
            env=self.cfg.proc_env,
            stdout=subprocess.PIPE,
        )

        test_list_output = proc.communicate()[0]

        # with python3, stdout is bytes so need to decode.
        if not isinstance(test_list_output, six.string_types):
            test_list_output = test_list_output.decode(sys.stdout.encoding)

        return self.parse_test_context(test_list_output) 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:28,代码来源:base.py

示例4: read_test_data

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def read_test_data(self):
        """
        Parse `report.xml` generated by the 3rd party testing tool and return
        the root node.

        You can override this if the test is generating a JSON file and you
        need custom logic to parse its contents for example.

        :return: Root node of parsed raw test data
        :rtype: ``xml.etree.Element``
        """
        with self.result.report.logged_exceptions(), open(
            self.report_path
        ) as report_file:
            return objectify.parse(report_file).getroot() 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:17,代码来源:base.py

示例5: sml_import

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def sml_import(xmlfile, user, request_form):
    filename = xmlfile.name
    tree = objectify.parse(xmlfile).getroot()
    move = parse_move(tree)
    move.source = os.path.abspath(filename)
    move.import_module = __name__
    device = parse_device(tree)
    persistent_device = Device.query.filter_by(serial_number=device.serial_number).scalar()
    if persistent_device:
        if not persistent_device.name:
            flash("update device name to '%s'" % device.name)
            persistent_device.name = device.name
        else:
            assert device.name == persistent_device.name
        device = persistent_device
    else:
        db.session.add(device)

    if Move.query.filter_by(user=user, date_time=move.date_time, device=device).scalar():
        flash("%s at %s already exists" % (move.activity, move.date_time), 'warning')
    else:
        move.user = user
        move.device = device
        db.session.add(move)

        samples = tree.DeviceLog.Samples.iterchildren()
        for sample in parse_samples(samples, move):
            db.session.add(sample)

        postprocess_move(move)

        db.session.commit()
        return move 
开发者ID:bwaldvogel,项目名称:openmoves,代码行数:35,代码来源:sml_import.py

示例6: _read_config_to_json

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def _read_config_to_json(sysmon_config):
    parser = etree.XMLParser(remove_comments=True)
    tree = objectify.parse(sysmon_config, parser=parser)
    root = tree.getroot()
    event_filtering = root.find('EventFiltering')

    configuration = []
    for rule in event_filtering.getchildren():
        rule_type = rule.tag
        on_match = rule.get('onmatch')
        single_rule = {
            'rule_type': rule_type,
            'on_match': on_match,
            'conditions': []
        }
        for condition in rule.iterchildren():
            cond_operator = condition.get('condition')
            cond_content = condition.text
            cond_type = condition.tag
            single_rule['conditions'].append({
                'operator': cond_operator,
                'content': cond_content,
                'condition_type': cond_type
            })
        configuration.append(single_rule)
    return configuration 
开发者ID:mkorman90,项目名称:sysmon-config-bypass-finder,代码行数:28,代码来源:main.py

示例7: make_model_from_file

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def make_model_from_file(self, path):
        obj = objectify.parse(path)
        root = obj.getroot()
        self._make_model(root) 
开发者ID:beeond,项目名称:opcua-modeling-tool,代码行数:6,代码来源:structures_generator.py

示例8: parse

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def parse(fileobject, schema=None):
    """Parses a file object
    
    This functon parses a KML file object, and optionally validates it against 
    a provided schema.
    """
    if schema:
        # with validation
        parser = objectify.makeparser(schema = schema.schema, strip_cdata=False)
        return objectify.parse(fileobject, parser=parser)
    else:
        # without validation
        return objectify.parse(fileobject) 
开发者ID:grst,项目名称:geos,代码行数:15,代码来源:parser.py

示例9: gpx_import

# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import parse [as 别名]
def gpx_import(xmlfile, user, request_form):
    # Get users options
    import_options = get_gpx_import_options(request_form)
    if import_options == None:
        return

    filename = xmlfile.filename
    try:
        tree = objectify.parse(xmlfile).getroot()
    except Exception as e:
        flash("Failed to parse the GPX file! %s" % e.msg)
        return

    for namespace in GPX_NAMESPACES.values():
        if tree.tag.startswith(namespace):
            gpx_namespace = namespace
            break
    else:
        flash("Unsupported GPX format version: %s" % tree.tag)
        return

    device = create_device()
    persistent_device = Device.query.filter_by(serial_number=device.serial_number).scalar()
    if persistent_device:
        if not persistent_device.name:
            flash("update device name to '%s'" % device.name)
            persistent_device.name = device.name
        else:
            assert device.name == persistent_device.name
        device = persistent_device
    else:
        db.session.add(device)

    move = create_move()
    move.source = os.path.abspath(filename)
    move.import_module = __name__

    # Parse samples
    all_samples = parse_samples(tree, move, gpx_namespace, import_options)

    derive_move_infos_from_samples(move, all_samples)

    if Move.query.filter_by(user=user, date_time=move.date_time, device=device).scalar():
        flash("%s at %s already exists" % (move.activity, move.date_time), 'warning')
    else:
        move.user = user
        move.device = device
        db.session.add(move)

        for sample in all_samples:
            db.session.add(sample)

        postprocess_move(move)

        db.session.commit()
        return move 
开发者ID:bwaldvogel,项目名称:openmoves,代码行数:58,代码来源:gpx_import.py


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