コード例 #1
0
 def parseXML(self, res, device):
    descr={'location': 'Unknown',
           'manufacturer': 'Unknown',
           'manufacturerURL': 'Unknown',
           'modelDescription': 'Unknown',
           'modelName': 'Unknown',
           'modelNumber': 'Unknown',
           'deviceType': 'Unknown',
           'host': 'Unknown'}
    try:
       xmlstring=xml.parseXMLString(res)
    except:
       log.info("Cannot parse XML for "+str(device))
       return
    log.debug('RAW DEVICE XML: '+str(res)+' FOR DEVICE: '+str(device))
    xmldev=xml.getElementsByTagName(xmlstring, 'device')[0]
    for k in descr.keys():
       try:
          descr[k] = xml.getElementsByTagName(xmlstring, k)[0].firstChild().toxml()
       except:
          try:
             descr[k] = getattr(device, k, None)
          except:
             descr[k] = 'Unknown'
    log.debug('DEVICE DATA: '+str(descr))
    if 'Network Camera' in descr['deviceType']:
       log.debug("FOUND A CAMERA TO ADD")
       self.core.addMediaSource(descr)
コード例 #2
0
 def test_encode_decode(self):
     # FIXME: this test is rather weak
     fixture_xml = self.fixtures.get_fixture('client_sync_init.xml')
     wbxml = yield xml2wbxml(fixture_xml)
     xml = yield wbxml2xml(wbxml)
     dom = microdom.parseXMLString(xml)
     [ver_proto] = dom.getElementsByTagName('VerProto')
     self.assertEqual(ver_proto.firstChild().value, 'SyncML/1.1')
コード例 #3
0
    def deserialize_body(cls, body):
        document = microdom.parseXMLString(body.decode(cls.ENCODING))
        root = document.firstChild()

        params = dict((node.nodeName, cls._xml_node_text(node))
                      for node in root.childNodes)

        return root.nodeName, params
コード例 #4
0
ファイル: xml_over_tcp.py プロジェクト: areski/vumi
    def deserialize_body(cls, body):
        document = microdom.parseXMLString(body.decode(cls.ENCODING))
        root = document.firstChild()

        params = dict(
            (node.nodeName, cls._xml_node_text(node))
            for node in root.childNodes)

        return root.nodeName, params
コード例 #5
0
 def testDeferredModel(self):
     channel = FakeHTTPChannel()
     channel.site = FakeSite(_TestPage())
     request = channel.makeFakeRequest('/')
     while not request.finished:
         reactor.iterate()
     dom = microdom.parseXMLString(request.written.getvalue())
     spanElems = domhelpers.findNodesNamed(dom, 'span')
     for spanElem in spanElems:
         self.failUnlessEqual('The Result', spanElem.childNodes[0].data)
コード例 #6
0
    def testDeferredModel(self):
        # Test that multiple uses of a deferred model work correctly.
        channel = FakeHTTPChannel()
        channel.site = FakeSite(_TestPage())
        request = channel.makeFakeRequest('/')

        while not request.finished:
            reactor.iterate()
        
        dom = microdom.parseXMLString(request.written.getvalue())
        spanElems = domhelpers.findNodesNamed(dom, 'span')
        for spanElem in spanElems:
            self.failUnlessEqual('The Result', spanElem.childNodes[0].data)
コード例 #7
0
ファイル: utils.py プロジェクト: BackupTheBerlios/remusic-svn
def parse_propfind(xml_doc):
    """ parse an propfind xml file and return a list of props 

    returns:
        
        request_type            -- ALLPROP, PROPNAME, PROP
        proplist            -- list of properties found
        namespaces            -- list of namespaces found
    
    """

    print xml_doc
    doc = microdom.parseXMLString(xml_doc)
    

    return doc
    ###
    doc = PyExpat.Reader().fromString(xml_doc)
    snit = doc.createNodeIterator(doc, NodeFilter.NodeFilter.SHOW_ELEMENT, None, None)

    request_type=None
    props={}
    namespaces=[]

    while 1:
        curr_elem = snit.nextNode()
        if not curr_elem: break
        ename=fname=lower(curr_elem.nodeName)
        if ":" in fname:
            ename=split(fname,":")[1]
        if ename=="prop": request_type=RT_PROP; continue
        if ename=="propfind": continue
        if ename=="allprop": request_type=RT_ALLPROP; continue
        if ename=="propname": request_type=RT_PROPNAME; continue

        # rest should be names of attributes

        ns = curr_elem.namespaceURI
        if props.has_key(ns):
            props[ns].append(ename)
        else:
            props[ns]=[ename]
            namespaces.append(ns)

    #ReleaseNode(doc)
    return request_type,props,namespaces
コード例 #8
0
ファイル: test_woven.py プロジェクト: hitzjd/Balance-Simulate
 def check(_):
     dom = microdom.parseXMLString(request.written.getvalue())
     spanElems = domhelpers.findNodesNamed(dom, 'span')
     for spanElem in spanElems:
         self.failUnlessEqual('The Result', spanElem.childNodes[0].data)
コード例 #9
0
ファイル: txml.py プロジェクト: russellhaering/twitty-twister
def parseXML(xml):
    return microdom.parseXMLString(xml)
コード例 #10
0
 def _setIOConfig(self, res):
    xmlsha = sha1()
    xmlsha.update(res)
    self.iohash = xmlsha.hexdigest()
    self.ioXML = xml.parseXMLString(res)
    return defer.succeed(True)   
コード例 #11
0
 def _setBoardConfig(self, res):
    self.boardXML = xml.parseXMLString(res)
    return defer.succeed(True)
コード例 #12
0
ファイル: test_woven.py プロジェクト: AnthonyNystrom/YoGoMee
 def check(_):
     dom = microdom.parseXMLString(request.written.getvalue())
     spanElems = domhelpers.findNodesNamed(dom, 'span')
     for spanElem in spanElems:
         self.failUnlessEqual('The Result', spanElem.childNodes[0].data)
コード例 #13
0
def parseXML(xml):
    return microdom.parseXMLString(xml)
コード例 #14
0
ファイル: test_codecs.py プロジェクト: smn/txsyncml
 def test_decode(self):
     wbxml = self.fixtures.get_fixture('client_sync_init.wbxml')
     xml = yield self.codec.decode(wbxml)
     dom = microdom.parseXMLString(xml)
     [ver_proto] = dom.getElementsByTagName('VerProto')
     self.assertEqual(ver_proto.firstChild().value, 'SyncML/1.1')
コード例 #15
0
ファイル: pyicqt2spectrum.py プロジェクト: mikerCZ/spectrum
def start():
	if len(sys.argv) != 6 and len(sys.argv) != 7 and len(sys.argv) != 3 and len(sys.argv) != 4:
		print "Usage for MySQL: " + sys.argv[0] + " pyicqt_directory database username password host [mysql_prefix]"
		print "Usage for SQLite: " + sys.argv[0] + " pyicqt_directory database [prefix]"
		reactor.stop()
		return
	maindir = sys.argv[1]
	
	prefix = ""
	if len(sys.argv) == 7:
		prefix = sys.argv[6]
	elif len(sys.argv) == 4:
		prefix = sys.argv[3]
	dict = {}
	if len(sys.argv) == 3 or len(sys.argv) == 4:
		if not os.path.exists(sys.argv[2]):
			print "Run Spectrum to create this DB file first and then run this script again with the DB file created by Spectrum."
			reactor.stop()
			return
		db = adbapi.ConnectionPool('sqlite3', sys.argv[2])
	else:
		db = adbapi.ConnectionPool('MySQLdb', db = sys.argv[2], user = sys.argv[3], passwd = sys.argv[4], host = sys.argv[5], cp_min=1, cp_max=1)
	c = 0
	for dr in os.listdir(maindir):
		if os.path.isdir(maindir+dr):
			for f in os.listdir(maindir+dr):
				if os.path.isfile(maindir+dr+'/'+f) and not f in ['pubsub', 'avatars']:
					fp = open(maindir+dr+'/'+f, 'r')
					c += 1
					buff = fp.read()
					fp.close()
					try:
						x = dom.parseXMLString(buff)
					except:
						print "Can't parse", maindir+dr+'/'+dr2+'/'+f, ". Skipping..."
						continue
					jid = f.replace('%','@')[:-4]
					p = x.getElementsByTagName('password')
					if len(p) != 1:
						print "No password for jid", jid, ". Skipping..."
						continue
					password =  gatherTextNodes(p[0])
					u = x.getElementsByTagName('username')
					uin = gatherTextNodes(u[0])
					print "Adding", jid
					
					def done2(res, x2):
						user_id = int(res[0][0])
						print "user_id =", user_id
						print "Adding buddies of", jid
						items = x2.getElementsByTagName('item')
						for j in items:
							if len(sys.argv) == 3 or len(sys.argv) == 4:
								db.runQuery('insert or ignore into ' + prefix + 'buddies (uin, user_id, nickname, groups, subscription) values ("%s", "%s", "%s","Buddies", "both")'%(s(j.getAttribute('jid')), s(str(user_id)), s(j.getAttribute('jid')))).addErrback(error)
							else:
								db.runQuery('insert ignore into ' + prefix + 'buddies (uin, user_id, nickname, groups, subscription) values ("%s", "%s", "%s","Buddies", "both")'%(s(j.getAttribute('jid')), s(str(user_id)), s(j.getAttribute('jid')))).addErrback(error)
						print "done!"

					if len(sys.argv) == 3 or len(sys.argv) == 4:
						db.runQuery('insert or ignore into ' + prefix + 'users (jid, uin, password, language) values ("%s", "%s", "%s", "en")'%(s(jid), s(uin),s(password))).addErrback(error)
					else:
						db.runQuery('insert ignore into ' + prefix + 'users (jid, uin, password, language) values ("%s", "%s", "%s", "en")'%(s(jid), s(uin),s(password))).addErrback(error)
					db.runQuery('select id from users WHERE jid = "'+jid+'";').addCallback(done2, x).addErrback(error)
コード例 #16
0
 def test_decode(self):
     wbxml = self.fixtures.get_fixture('client_sync_init.wbxml')
     xml = yield self.codec.decode(wbxml)
     dom = microdom.parseXMLString(xml)
     [ver_proto] = dom.getElementsByTagName('VerProto')
     self.assertEqual(ver_proto.firstChild().value, 'SyncML/1.1')