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


Python cElementTree.parse方法代码示例

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


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

示例1: isUpdatesAvailable

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def isUpdatesAvailable(cls, path):
        if sys.version_info < (3, 0):
            return False
        # pylint: disable=broad-except
        if not os.path.isfile(os.path.join(path, "files.xml")):
            return True
        try:
            available = dict()
            for it in ET.parse(os.path.join(path, "files.xml")).iter():
                if it.tag == "File":
                    available[it.text] = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")

            path = NamedTemporaryFile()
            path.close()
            urllib.request.urlretrieve("https://www.gurux.fi/obis/files.xml", path.name)
            for it in ET.parse(path.name).iter():
                if it.tag == "File":
                    tmp = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")
                    if not it.text in available or available[it.text] != tmp:
                        return True
        except Exception as e:
            print(e)
            return True
        return False 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:26,代码来源:GXManufacturerCollection.py

示例2: updateManufactureSettings

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def updateManufactureSettings(cls, directory):
        #
        # Update manufacturer settings from the Gurux www server.
        #
        # directory: Target directory.
        #
        if sys.version_info >= (3, 0):
            return
        if not os.path.isdir(directory):
            os.mkdir(directory)
            if not os.path.isdir(directory):
                return
        path = os.path.join(directory, "files.xml")
        urllib.request.urlretrieve("https://www.gurux.fi/obis/files.xml", path)
        for it in ET.parse(path).iter():
            if it.tag == "File":
                path = os.path.join(directory, it.text)
                urllib.request.urlretrieve("https://www.gurux.fi/obis/" + it.text, path) 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:20,代码来源:GXManufacturerCollection.py

示例3: pull_item

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def pull_item(self, index):
        img_id = self.ids[index]

        target = ET.parse(self._annopath % img_id).getroot()
        img = cv2.imread(self._imgpath % img_id)
        height, width, channels = img.shape

        if self.target_transform is not None:
            target = self.target_transform(target, width, height)

        if self.transform is not None:
            target = np.array(target)
            img, boxes, labels = self.transform(img, target[:, :4], target[:, 4])
            # to rgb
            img = img[:, :, (2, 1, 0)]
            # img = img.transpose(2, 0, 1)
            target = np.hstack((boxes, np.expand_dims(labels, axis=1)))
        return torch.from_numpy(img).permute(2, 0, 1), target, height, width
        # return torch.from_numpy(img), target, height, width 
开发者ID:soo89,项目名称:CSD-SSD,代码行数:21,代码来源:voc0712.py

示例4: pull_anno

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def pull_anno(self, index):
        '''Returns the original annotation of image at index

        Note: not using self.__getitem__(), as any transformations passed in
        could mess up this functionality.

        Argument:
            index (int): index of img to get annotation of
        Return:
            list:  [img_id, [(label, bbox coords),...]]
                eg: ('001718', [('dog', (96, 13, 438, 332))])
        '''
        img_id = self.ids[index]
        anno = ET.parse(self._annopath % img_id).getroot()
        gt = self.target_transform(anno, 1, 1)
        return img_id[1], gt 
开发者ID:soo89,项目名称:CSD-SSD,代码行数:18,代码来源:voc0712.py

示例5: pull_item

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def pull_item(self, index):
        img_id = self.ids[index]

        target = ET.parse(self._annopath % img_id).getroot()
        img = cv2.imread(self._imgpath % img_id)
        height, width, channels = img.shape

        if self.target_transform is not None:
            target = self.target_transform(target, width, height)

        if self.transform is not None:
            target = np.array(target)
            img, boxes, labels = self.transform(img, target[:, :4], target[:, 4])
            # to rgb
            img = img[:, :, (2, 1, 0)]
            # img = img.transpose(2, 0, 1)
            target = np.hstack((boxes, np.expand_dims(labels, axis=1)))

        if(img_id[0][(len(img_id[0]) - 7):]=='VOC2007'):
            semi = np.array([1])
        else:
            semi = np.array([0])
            target = np.zeros([1, 5])
        return torch.from_numpy(img).permute(2, 0, 1), target, height, width, semi
        # return torch.from_numpy(img), target, height, width 
开发者ID:soo89,项目名称:CSD-SSD,代码行数:27,代码来源:voc07_consistency_init.py

示例6: parse_rec

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def parse_rec(filename):
    """ Parse a PASCAL VOC xml file """
    tree = ET.parse(filename)
    objects = []
    for obj in tree.findall('object'):
        obj_struct = {}
        obj_struct['name'] = obj.find('name').text
        obj_struct['pose'] = obj.find('pose').text
        obj_struct['truncated'] = int(obj.find('truncated').text)
        obj_struct['difficult'] = int(obj.find('difficult').text)
        bbox = obj.find('bndbox')
        obj_struct['bbox'] = [int(bbox.find('xmin').text) - 1,
                              int(bbox.find('ymin').text) - 1,
                              int(bbox.find('xmax').text) - 1,
                              int(bbox.find('ymax').text) - 1]
        objects.append(obj_struct)

    return objects 
开发者ID:soo89,项目名称:CSD-SSD,代码行数:20,代码来源:eval512.py

示例7: parse

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def parse(stream):
        """Parse a stream containing XML into an ``InputDefinition``.

        :param stream: stream containing XML to parse.
        :return: definition: an ``InputDefinition`` object.
        """
        definition = InputDefinition()

        # parse XML from the stream, then get the root node
        root = ET.parse(stream).getroot()

        for node in root:
            if node.tag == "configuration":
                # get config for each stanza
                definition.inputs = parse_xml_data(node, "stanza")
            else:
                definition.metadata[node.tag] = node.text

        return definition 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:input_definition.py

示例8: __getitem__

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def __getitem__(self, index):
        img_id = self.ids[index]
        target = ET.parse(self._annopath % img_id).getroot()
        img = cv2.imread(self._imgpath % img_id, cv2.IMREAD_COLOR)
        height, width, _ = img.shape

        if self.target_transform is not None:
            target = self.target_transform(target)


        if self.preproc is not None:
            img, target = self.preproc(img, target)
            #print(img.size())

                    # target = self.target_transform(target, width, height)
        #print(target.shape)

        return img, target 
开发者ID:ShuangXieIrene,项目名称:ssds.pytorch,代码行数:20,代码来源:voc.py

示例9: pull_anno

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def pull_anno(self, index):
        '''Returns the original annotation of image at index

        Note: not using self.__getitem__(), as any transformations passed in
        could mess up this functionality.

        Argument:
            index (int): index of img to get annotation of
        Return:
            list:  [img_id, [(label, bbox coords),...]]
                eg: ('001718', [('dog', (96, 13, 438, 332))])
        '''
        img_id = self.ids[index]
        anno = ET.parse(self._annopath % img_id).getroot()
        # gt = self.target_transform(anno, 1, 1)
        # gt = self.target_transform(anno)
        # return img_id[1], gt
        if self.target_transform is not None:
            anno = self.target_transform(anno)
        return anno 
开发者ID:ShuangXieIrene,项目名称:ssds.pytorch,代码行数:22,代码来源:voc.py

示例10: pull_img_anno

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def pull_img_anno(self, index):
        '''Returns the original annotation of image at index

        Note: not using self.__getitem__(), as any transformations passed in
        could mess up this functionality.

        Argument:
            index (int): index of img to get annotation of
        Return:
            list:  [img_id, [(label, bbox coords),...]]
                eg: ('001718', [('dog', (96, 13, 438, 332))])
        '''
        img_id = self.ids[index]
        img = cv2.imread(self._imgpath % img_id, cv2.IMREAD_COLOR)
        anno = ET.parse(self._annopath % img_id).getroot()
        gt = self.target_transform(anno)
        height, width, _ = img.shape
        boxes = gt[:,:-1]
        labels = gt[:,-1]
        boxes[:, 0::2] /= width
        boxes[:, 1::2] /= height
        labels = np.expand_dims(labels,1)
        targets = np.hstack((boxes,labels))
        
        return img, targets 
开发者ID:ShuangXieIrene,项目名称:ssds.pytorch,代码行数:27,代码来源:voc.py

示例11: test_bulk_construction

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def test_bulk_construction(self):
        " Test XsdFile construction for a bulk. "
        filename = path + "/bulk.xsd"
        xsd = XsdFile(filename)

        # Check the default coordinate value for the Atom3d tag without XYZ.
        ref_origin_coord = [0.0, 0.0, 0.0]
        ret_origin_coord = xsd.data[0].tolist()
        self.assertListEqual(ref_origin_coord, ret_origin_coord)

        # Check atom info update in new xsd file.
        temp_file = "{}/temp.xsd".format(path)
        xsd.tofile(temp_file)
        tree = ET.parse(temp_file)
        for atom3d in tree.iter('Atom3d'):
            break
        self.assertEqual(atom3d.get('XYZ'), '0.0,0.0,0.0')
        os.remove(temp_file) 
开发者ID:PytLab,项目名称:VASPy,代码行数:20,代码来源:xsd_test.py

示例12: bug_owner

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def bug_owner(apiurl, package, entity='person'):
    query = {
        'binary': package,
    }
    url = osc.core.makeurl(apiurl, ('search', 'owner'), query=query)
    root = ET.parse(osc.core.http_GET(url)).getroot()

    bugowner = root.find('.//{}[@role="bugowner"]'.format(entity))
    if bugowner is not None:
        return entity_email(apiurl, bugowner.get('name'), entity)
    maintainer = root.find('.//{}[@role="maintainer"]'.format(entity))
    if maintainer is not None:
        return entity_email(apiurl, maintainer.get('name'), entity)
    if entity == 'person':
        return bug_owner(apiurl, package, 'group')

    return None 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:19,代码来源:issue-diff.py

示例13: binaries_of_product

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def binaries_of_product(self, project, product, repo=None, arch=None):
        if repo is None:
            repo = self.project.product_repo
        if arch is None:
            arch = self.project.product_arch

        url = self.api.makeurl(['build', project, repo, arch, product])
        try:
            f = self.api.retried_GET(url)
        except HTTPError:
            return []

        ret = []
        root = ET.parse(f).getroot()
        for binary in root.findall('binary'):
            ret.append(binary.get('filename'))

        return ret 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:20,代码来源:manager.py

示例14: get_comments

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def get_comments(self, request_id=None, project_name=None,
                     package_name=None):
        """Get the list of comments of an object in OBS.

        :param request_id: Request where to get comments.
        :param project_name: Project name where to get comments.
        :param package_name: Package name where to get comments.
        :returns: A list of comments (as a dictionary).
        """
        url = self._prepare_url(request_id, project_name, package_name)
        root = root = ET.parse(http_GET(url)).getroot()
        comments = {}
        for c in root.findall('comment'):
            c = self._comment_as_dict(c)
            comments[c['id']] = c
        return comments 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:18,代码来源:comments.py

示例15: package_source_hash

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import parse [as 别名]
def package_source_hash(apiurl, project, package, revision=None):
    query = {}
    if revision:
        query['rev'] = revision

    # Will not catch packages that previous had a link, but no longer do.
    if package_source_link_copy(apiurl, project, package):
        query['expand'] = 1

    try:
        url = makeurl(apiurl, ['source', project, package], query)
        root = ETL.parse(http_GET(url)).getroot()
    except HTTPError as e:
        if e.code == 400 or e.code == 404:
            # 400: revision not found, 404: package not found.
            return None

        raise e

    if revision and root.find('error') is not None:
        # OBS returns XML error instead of HTTP 404 if revision not found.
        return None

    from osclib.util import sha1_short
    return sha1_short(root.xpath('entry[@name!="_link"]/@md5')) 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:27,代码来源:core.py


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