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


Python etree.XMLParser方法代码示例

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


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

示例1: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def __init__(self, filename, requests_and_responses=False):
        self._filename = filename
        self._requests_and_responses = requests_and_responses
        json_ext = '.json'
        yaml_ext = '.yaml'
        if filename[-len(json_ext):] == json_ext:
            self._scan = json.loads(open(filename).read().decode('utf-8-sig'), object_pairs_hook=UnsortableOrderedDict)
        elif filename[-len(yaml_ext):] == yaml_ext:
            self._scan = yaml_load(open(filename).read(), yaml.SafeLoader, UnsortableOrderedDict)
        else:
            # xml
            #self._xml = etree.parse(filename)
            etree_parser = etree.XMLParser(huge_tree=True)
            self._xml = etree.parse(filename, parser=etree_parser)
            root = self._xml.getroot()
            if root.tag == 'Sessions':
                self._webinspect_import()
            elif root.tag == 'issues':
                self._burp_import()
            elif root.tag == 'items':
                self._burp_items_import()
            else:
                raise Exception('Unknown scan format!') 
开发者ID:hvqzao,项目名称:report-ng,代码行数:25,代码来源:scan.py

示例2: get_form_collection

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def get_form_collection(self, list_name):

        # Build Request
        soap_request = Soap("GetFormCollection")
        soap_request.add_parameter("listName", list_name)
        self.last_request = str(soap_request)

        # Send Request
        response = post(self._session,
                        url=self._url("Forms"),
                        headers=self._headers("GetFormCollection"),
                        data=str(soap_request).encode("utf-8"),
                        verify=self._verify_ssl,
                        timeout=self.timeout)

        envelope = etree.fromstring(response.text.encode("utf-8"),
                                    parser=etree.XMLParser(huge_tree=self.huge_tree,
                                    recover=True))
        items = envelope[0][0][0][0]
        data = []
        for _item in items:
            data.append({k: v for (k, v) in _item.items()})

        return data 
开发者ID:jasonrollins,项目名称:shareplum,代码行数:26,代码来源:site.py

示例3: get_site

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def get_site(self):

        # Build Request
        soap_request = Soap("GetSite")
        soap_request.add_parameter("SiteUrl", self.site_url)
        self.last_request = str(soap_request)

        # Send Request
        response = post(self._session,
                        url=self._url("Sites"),
                        headers=self._headers("GetSite"),
                        data=str(soap_request).encode("utf-8"),
                        verify=self._verify_ssl,
                        timeout=self.timeout)

        envelope = etree.fromstring(response.text.encode("utf-8"),
                                    parser=etree.XMLParser(huge_tree=self.huge_tree,
                                    recover=True))
        data = envelope[0][0][0]

        # TODO: Not sure what to do with this, so just return the text
        return data.text 
开发者ID:jasonrollins,项目名称:shareplum,代码行数:24,代码来源:site.py

示例4: get_list_templates

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def get_list_templates(self):

        # Build Request
        soap_request = Soap("GetListTemplates")
        soap_request.add_parameter("GetListTemplates")
        self.last_request = str(soap_request)

        # Send Request
        response = post(self._session,
                        url=self._url("Webs"),
                        headers=self._headers("GetListTemplates"),
                        data=str(soap_request).encode("utf-8"),
                        verify=self._verify_ssl,
                        timeout=self.timeout)

        envelope = etree.fromstring(response.text.encode("utf-8"),
                                    parser=etree.XMLParser(huge_tree=self.huge_tree,
                                    recover=True))
        lists = envelope[0][0][0][0]
        data = []
        for _list in lists:
            data.append({k: v for (k, v) in _list.items()})

        return data 
开发者ID:jasonrollins,项目名称:shareplum,代码行数:26,代码来源:site.py

示例5: get_site_templates

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def get_site_templates(self, lcid="1033"):

        # Build Request
        soap_request = Soap("GetSiteTemplates")
        soap_request.add_parameter("LCID", lcid)
        self.last_request = str(soap_request)

        # Send Request
        response = post(self._session,
                        url=self._url("Sites"),
                        headers=self._headers("GetSiteTemplates"),
                        data=str(soap_request).encode("utf-8"),
                        verify=self._verify_ssl,
                        timeout=self.timeout)

        return response
        envelope = etree.fromstring(response.text.encode("utf-8"),
                                    parser=etree.XMLParser(huge_tree=self.huge_tree,
                                    recover=True))
        lists = envelope[0][0][1]
        data = []
        for _list in lists:
            data.append({k: v for (k, v) in _list.items()})

        return data 
开发者ID:jasonrollins,项目名称:shareplum,代码行数:27,代码来源:site.py

示例6: _canonicalize

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def _canonicalize(xml_string):
    '''
    Given an xml string, canonicalize the string per
    U{http://www.w3.org/2001/10/xml-exc-c14n#}

    @type  xml_string: C{str}
    @param xml_string: The XML string that needs to be canonicalized.

    @rtype: C{str}
    @return: Canonicalized string in Unicode.
    '''
    parser = etree.XMLParser(remove_blank_text=True)
    tree = etree.fromstring(xml_string, parser=parser).getroottree()
    string = BytesIO()
    tree.write_c14n(string, exclusive=True, with_comments=False)
    return string.getvalue().decode(UTF_8) 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:18,代码来源:sso.py

示例7: perform_romeo_query

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def perform_romeo_query(self, search_terms):
        search_terms = search_terms.copy()
        if self.api_key:
            search_terms['ak'] = self.api_key

        # Perform the query
        try:
            req = requests.get(self.base_url, params=search_terms, timeout=20)
        except requests.exceptions.RequestException as e:
            raise MetadataSourceException('Error while querying RoMEO.\n' +
                                          'URL was: '+self.base_url+'\n' +
                                          'Parameters were: '+str(search_terms)+'\n' +
                                          'Error is: '+str(e))

        # Parse it
        try:
            parser = ET.XMLParser(encoding='ISO-8859-1')
            root = ET.parse(BytesIO(req.content), parser)
        except ET.ParseError as e:
            raise MetadataSourceException('RoMEO returned an invalid XML response.\n' +
                                          'URL was: '+self.base_url+'\n' +
                                          'Parameters were: '+str(search_terms)+'\n' +
                                          'Error is: '+str(e))

        return root 
开发者ID:dissemin,项目名称:dissemin,代码行数:27,代码来源:romeo.py

示例8: get_new_status

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def get_new_status(self, identifier):
        """
        Unconditionnally fetch the new status of a deposit, by ID (e.g.
        hal-0001234)
        """
        deposit_url = '%s%s' % (self.api_url, identifier)
        req = requests.get(deposit_url,
                auth=requests.auth.HTTPBasicAuth(self.username,self.password))
        if req.status_code == 400:
            return 'deleted'
        req.raise_for_status()

        parser = etree.XMLParser(encoding='utf-8')
        receipt = etree.parse(BytesIO(req.text.encode('utf-8')), parser)
        receipt = receipt.getroot()

        hal_status = receipt.find('status').text
        if hal_status == 'accept' or hal_status == 'replace':
            return 'published'
        elif hal_status == 'verify' or hal_status == 'update':
            return 'pending'
        elif hal_status == 'delete':
            return 'refused' 
开发者ID:dissemin,项目名称:dissemin,代码行数:25,代码来源:protocol.py

示例9: iter_entry

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def iter_entry(self, data):
        """
        Get an iterator over rows extracted from the raw data body.

        Args:
            `data` (dict):
                As returned by prepare_data() (especially, its 'raw' item
                contains the raw data body).

        Returns:
            An iterator over xml tree:
        """
        raw_entry = StringIO(data['raw']).getvalue()
        parser = etree.XMLParser(ns_clean=True, remove_blank_text=True)
        tree = etree.fromstring(str(raw_entry), parser)
        return tree 
开发者ID:CERT-Polska,项目名称:n6,代码行数:18,代码来源:generic.py

示例10: download_default_transcript

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def download_default_transcript(self, url=None, language_code=None):  # pylint: disable=unused-argument
        """
        Download default transcript from Youtube API and format it to WebVTT-like unicode.

        Reference to `get_transcripts_from_youtube()`:
            https://github.com/edx/edx-platform/blob/ecc3473d36b3c7a360e260f8962e21cb01eb1c39/common/lib/xmodule/xmodule/video_module/transcripts_utils.py#L122
        """
        if url is None:
            raise VideoXBlockException(_('`url` parameter is required.'))
        utf8_parser = etree.XMLParser(encoding='utf-8')
        data = requests.get(url)
        xmltree = etree.fromstring(data.content, parser=utf8_parser)
        sub = [
            self.format_transcript_element(element, i)
            for i, element in enumerate(xmltree, 1)
        ]
        sub = "".join(sub)
        sub = u"WEBVTT\n\n" + unicode(sub) if "WEBVTT" not in sub else unicode(sub)
        return sub 
开发者ID:appsembler,项目名称:xblock-video,代码行数:21,代码来源:youtube.py

示例11: readXml

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def readXml(self, simType):
        path = os.path.dirname(__file__)
        if simType == types.TYPE_USIM:
            path = os.path.join(path, "sim_files_3g.xml")
        else:
            path = os.path.join(path, "sim_files_2g.xml")
        tree = etree.ElementTree()
        if not os.path.exists(path):
            logging.warning("File %s not exists" %path)
            logging.info("Create xml")
            if simType == types.TYPE_USIM:
                root = etree.Element('sim_3G')
            else:
                root = etree.Element('sim_2G')
        else:
            parser = etree.XMLParser(remove_blank_text=True)
            root = etree.parse(path, parser).getroot()
        return path, root 
开发者ID:kamwar,项目名称:simLAB,代码行数:20,代码来源:sim_files.py

示例12: transform_with_xsl

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def transform_with_xsl(xml_path, xsl_path, recover=False):
    try:
        xml_dom = etree.parse(xml_path)
    except etree.XMLSyntaxError as e:
        if recover:
            logger.error(e)
            parser = etree.XMLParser(recover=True)
            xml_dom = etree.parse(xml_path, parser=parser)
        else:
            raise
    xsl_transform = etree.XSLT(etree.parse(xsl_path))
    try:
        transformed_dom = xsl_transform(xml_dom)
    except Exception as err:
        logger.error(err)
        for xsl_error in xsl_transform.error_log:
            logger.error(xsl_error)
        if not recover:
            raise

    return transformed_dom 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:23,代码来源:files.py

示例13: findBodyType

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def findBodyType(request):
    bd_typ ="none"
    try:
        if request["body"]:
            try:
                json.loads(request["body"])
                bd_typ ="json"
            except:
                pass
            try:
                config = etree.XMLParser(remove_blank_text=True, resolve_entities=False)
                #Prevent Entity Expansion Attacks against the Framework
                etree.fromstring(request["body"],config)
                bd_typ ="xml"
            except:
                pass
            qs=parse_qs(request["body"])
            if qs:
                bd_typ="form"
        return bd_typ
    except:
        PrintException("[ERROR] Finding Request Body type") 
开发者ID:HackingLab,项目名称:MobileSF,代码行数:24,代码来源:views.py

示例14: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def __init__(self, rpc):
        if isinstance(rpc, str):
            self.rpc = ET.fromstring(rpc, parser=ET.XMLParser(remove_blank_text=True))
        else:
            self.rpc = rpc 
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:7,代码来源:ncparse.py

示例15: gen_rpc

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import XMLParser [as 别名]
def gen_rpc(username, payload):
        """
        Generate Netconf / Restconf RPC
        """
        if payload == '':
            logging.debug('gen_rpc: Rcvd: ' + 'None')
            return None

        logging.debug('gen_rpc: Rcvd: \n' + payload)

        request = ET.fromstring(payload)
        protocol = request.get('protocol', None)
        if protocol is None:
            logging.error('gen_rpc: Invalid payload, protocol missing !!')
            return None

        if protocol == 'restconf':
            res = Adapter._gen_rpc(username, request)
            ''' returns json '''
            return build_response(res)
        else:
            rpc = Adapter._gen_rpc(username, request)

        logging.debug('gen_rpc: Generated : \n' + rpc)

        ''' returns xml '''
        return ET.fromstring(rpc, parser=ET.XMLParser(remove_blank_text=True)) 
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:29,代码来源:adapter.py


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