Ejemplo n.º 1
0
    def _xmlparserwithspecificxpath(self, datafile, xpathe):
        # type: () -> object
        """
        Custom parser for xml using specific xpath
        USAGE:
        _xmlparserwithspecificxpath(datafile,xpathe)

        datafile : file containing actual xml data
        xpath : provide the specific xpath which needs to be parsed

        NOTE:
        This method/function can be used for any test involving xml parsing using specific xpath
        """
        self.datafile = datafile
        self.xpathe = xpathe
        loaddatafile = xmlparse(datafile)

        try:
            response = xpath.find(xpathe, loaddatafile)
            for xpathee in response:
                for xchild in xpathee.childNodes:
                    if xchild.nodeType == xchild.TEXT_NODE:
                        xvalue = xchild.nodeValue
                        print(xvalue)

        except TypeError:
            raise Exception('None')

        except Exception as e:
            raise Exception("Error Occurred : %s" % e)
def parse_source_xml(src):
    def getElemValue(root, tag):
        return root.getElementsByTagName(tag)[0].childNodes[0].nodeValue

    sira_xml = xmlparse(src)
    root_node = sira_xml.childNodes[0]

    config = {}
    # url template
    config[KEY_URL_FOR_CSV] = getElemValue(root_node, KEY_URL_FOR_CSV)

    # istat codes
    items_node = root_node.getElementsByTagName(KEY_ISTAT_VALUE)
    config[KEY_ISTAT_VALUES] = [item.childNodes[0].nodeValue for item in items_node]

    # where to save downloads
    tmp_dir = getElemValue(root_node, KEY_TEMP_DIR)
    config[KEY_TEMP_DIR] = abspath_here_if_not(tmp_dir)

    # sql model file name
    sql_model = getElemValue(root_node, KEY_SQL_MODEL)
    config[KEY_SQL_MODEL] = abspath_here_if_not(sql_model)

    # sql output file name
    sql_output = getElemValue(root_node, KEY_SQL_OUTPUT)
    config[KEY_SQL_OUTPUT] = abspath_here_if_not(sql_output)

    return config
Ejemplo n.º 3
0
    def _xmlparser(self, datafile, xpathfile):
        # type: () -> object
        """
        Custom parser for xml using xpath
        USAGE:
        _xmlparser(datafile,xpathfile)

        datafile : file containing actual xml data
        xpathfile : file containing all the xpath's mentioned in a file

        NOTE:
        This method/function can be used for any test involving xml parsing using xpath's
        """
        self.datafile = datafile
        self.xpathfile = xpathfile

        loaddatafile = xmlparse(datafile)
        xpaths = open(xpathfile, 'r+')

        for xpathlist in xpaths:
            try:
                response = xpath.find(xpathlist, loaddatafile)
                for xpathe in response:
                    for xchild in xpathe.childNodes:
                        if xchild.nodeType == xchild.TEXT_NODE:
                            xvalue = xchild.nodeValue
                            print('%s : %s' % (xpathe, xvalue))
                            # print('%s' % xvalue)

            except TypeError:
                raise Exception('TypeError')

            except Exception as e:
                raise Exception("Error Occurred : %s" % e)
Ejemplo n.º 4
0
def prettyformatxml(path, encoding=None):
    """
    Takes a one line xml file and splits it into many.
    Formats the xml to be more readable.
    :param path: path to file as a string.
    :return: the prettier xml.
    """
    return xmlparse(path, encoding).toprettyxml(indent=' ' * 2)
Ejemplo n.º 5
0
 def loadxml(self, xml):
     dom = xmlparse(xml)
     root = dom.documentElement
     try:
         # 默认取第一个取得的值
         self.url = root.getElementsByTagName('url')[0].firstChild.data
         self.id = root.getElementsByTagName('id')[0].firstChild.data
     except BaseException, ex:
         print 'loadXml error : ', ex
Ejemplo n.º 6
0
def _execute_request(args):
    """
    Executes the register/remove request.

    @param args: Request payload.
    """
    host = args.pop('ec2stack_server_address')
    response = requests.post(host, args)
    response = xmlparse(response.text)
    message = response.getElementsByTagName('Message')[0].firstChild.nodeValue
    print message
Ejemplo n.º 7
0
def _execute_request(args):
    """
    Executes the register/remove request.

    @param args: Request payload.
    """
    host = args.pop("ec2stack_server_address")
    response = requests.post(host, args)
    response = xmlparse(response.text)
    message = response.getElementsByTagName("Message")[0].firstChild.nodeValue
    print message
Ejemplo n.º 8
0
    def setUp(self):
        xml = xmlparse("""<node>
            <interface name='non.sysd.interface'></interface>
            <interface name='org.freebeer.obj1.I1'>
                <property name='prop1' type='s'></property>
                <method name='meth1'>
                    <arg direction="in" type="s"/>
                </method>
            </interface>
            </node>""").firstChild

        self.introspect_path_xml = xml
Ejemplo n.º 9
0
    def __init__(self, session):
        self.session = session
        Screen.__init__(self, session)

        self["actions"] = ActionMap(["OkCancelActions"], {
            "ok": self.ok,
            "cancel": self.close
        }, -1)
        self.urls = []
        list = []
        file = None

        fileName = configDir + "feedly.opml"

        try:
            if fileExists(fileName):
                file = open(fileName)
            else:
                list.append(_("No Feedly configuration"))
        except:
            pass

        if file:
            # check if file is just a proxy to an external XML
            head = file.readline()

            try:
                if head.startswith("http"):
                    file.close
                    source = urllib2.urlopen(head)
                else:
                    file.close
                    source = open(fileName)
            except:
                pass

            if source:
                dom = xmlparse(source)
                for item in dom.getElementsByTagName("outline"):
                    if str(item.getAttribute("title")) == "PodcastPlugin":
                        for podcast in item.getElementsByTagName("outline"):
                            list.append(str(podcast.getAttribute("title")))
                            self.urls.append(
                                str(podcast.getAttribute("xmlUrl")))

        self["list"] = MenuList(list)
Ejemplo n.º 10
0
	def __init__(self, session):
		self.session = session
		Screen.__init__(self, session)
		
		self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.ok, "cancel": self.close}, -1)
		self.urls = []
		list = []
		file = None
		
		fileName = configDir + "feedly.opml"

		try:
			if fileExists(fileName):
				file = open(fileName)
			else:
				list.append(_("No Feedly configuration"))
		except:
			pass

		if file:
			# check if file is just a proxy to an external XML
			head = file.readline()

			try:
				if head.startswith("http"):
					file.close
					source = urllib2.urlopen(head)
				else:
					file.close
					source = open(fileName)
			except:
				pass
			
			if source:	
				dom = xmlparse(source)
				for item in dom.getElementsByTagName("outline"):
					if str(item.getAttribute("title")) == "PodcastPlugin":
						for podcast in item.getElementsByTagName("outline"):
							list.append(str(podcast.getAttribute("title")))
							self.urls.append(str(podcast.getAttribute("xmlUrl")))

		self["list"] = MenuList(list)
Ejemplo n.º 11
0
 def __init__(self, xml=None, tree=None, path=None):
     self.__path = path or []
     self.__tree = tree
     if xml is not None:
         self.__tree = xmlparse(xml)
Ejemplo n.º 12
0
    def loadxml(self, xmlfile=None):
        localnotfound = False
        includepath = './include'
        libpath = './lib'
        packaging = 'tar'
        local = None
        tmpxml = self.xml
        if xmlfile:
            tmpxml = xmlfile

        dom = xmlparse(tmpxml)
        root = dom.documentElement
        try:
            # 默认取第一个取得的值
            self.groupid = root.getElementsByTagName('groupId')[0].firstChild.data
            self.artifactid = root.getElementsByTagName('artifactId')[0].firstChild.data
            self.version = root.getElementsByTagName('version')[0].firstChild.data
            self.packaging = root.getElementsByTagName('packaging')[0].firstChild.data

            # 上传Maven库,需要file,源tar包
            files = root.getElementsByTagName('file')
            if files is not None and len(files) > 0:
                self.file = files[0].firstChild.data

            # 下载Maven库,需要dependices,依赖
            dependencies = root.getElementsByTagName('dependencies')[0]
            locals = root.getElementsByTagName('local')

            if locals is None or len(locals) <= 0:
                localnotfound = True
            else:
                # 查找default的local地址
                local = locals[0]
                defaultlocals = local.getElementsByTagName('default')
                if defaultlocals is None or len(defaultlocals) <= 0:
                    localnotfound = True
                else:
                    includepath = defaultlocals[0].getElementsByTagName('include')[0].firstChild.data
                    libpath = defaultlocals[0].getElementsByTagName('lib')[0].firstChild.data

            for depend in dependencies.getElementsByTagName('dependency'):
                try:
                    tmpinclude = includepath
                    tmplib = libpath
                    groupid = depend.getElementsByTagName('groupId')[0].firstChild.data
                    artifactid = depend.getElementsByTagName('artifactId')[0].firstChild.data
                    version = depend.getElementsByTagName('version')[0].firstChild.data
                    types = depend.getElementsByTagName('type')
                    if types and len(types) > 0:
                        # type非必须,因此有默认值tar
                        packaging = types[0].firstChild.data
                    if groupid is None or artifactid is None or version is None or \
                                    len(groupid) <= 0 or len(artifactid) <= 0 or len(version) <= 0:
                        continue
                    # 寻找path
                    if not localnotfound and local:
                        # 检查下是否有特定设置
                        speclocals = local.getElementsByTagName(artifactid)
                        if speclocals and len(speclocals) > 0:
                            tmpinclude = speclocals[0].getElementsByTagName('include')[0].firstChild.data
                            tmplib = speclocals[0].getElementsByTagName('lib')[0].firstChild.data

                    arti = CMavenArtifact(groupid, artifactid, version, tmpinclude, tmplib, packaging)
                    self.dependencies.append(arti)
                except BaseException, ex:
                    print 'loadXml depend error : ', ex
                    continue
        except BaseException, ex:
            print 'loadXml error : ', ex
Ejemplo n.º 13
0
 def __init__(self, xml=None, tree=None, path=None):
     self.__path = path or []
     self.__tree = tree
     if xml is not None:
         self.__tree = xmlparse(xml)
Ejemplo n.º 14
0
def _execute_request(args):
    host = args.pop('ec2stack_server_address')
    response = requests.post(host, args)
    response = xmlparse(response.text)
    message = response.getElementsByTagName('Message')[0].firstChild.nodeValue
    print message
Ejemplo n.º 15
0
def _execute_request(args):
    host = args.pop('ec2stack_server_address')
    response = requests.post(host, args)
    response = xmlparse(response.text)
    message = response.getElementsByTagName('Message')[0].firstChild.nodeValue
    print message