當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。