def __init__(self): path = str("") if (platform.system() == "Windows"): path = self.winPath() else: path = self.unixPath() self.settingsPath = path if (exists(str(path)) == False): gen_settings.generate_settings() self.parser = XmlParser(path)
def startDocument(self): XmlParser.startDocument(self) # Where to store the parsed tables, keyed by their names self.res = {} # The currently walked table self.currentTable = None # The currently walked data row, as list of strings (cell content) self.currentRow = None # The initial parsing state self.state = self.PARSING
class RepoMdParser: def __init__(self): self.parser = XmlParser() self.handler = RepoMdSaxHandler() self.parser.setContentHandler(self.handler) def parse(self, fileName): if self.parser.parse(fileName): return self.handler.repomd Log.cout(Log.ERROR, 'Parse repomd [%s] failed' % fileName) return None
class RepoMdParser: def __init__(self): self.parser = XmlParser() self.handler = RepoMdSaxHandler() self.parser.setContentHandler(self.handler) def parse(self, fileName): if self.parser.parse(fileName): return self.handler.repomd Log.cout(Log.ERROR, "Parse repomd [%s] failed" % fileName) return None
def test_xml_parser_with_blank_file(): global test_file # value missing with open(test_file, "w") as f: f.write("") y = XmlParser(test_file) y.load_file() y.parse_file() y.process_file() assert (y.get_value() == 0)
def test_xml_parser_with_no_child_nodes(): global test_file # value missing with open(test_file, "w") as f: f.write("""<?xml version="1.0" encoding="UTF-8" ?> <users>""") y = XmlParser(test_file) y.load_file() y.parse_file() y.process_file() assert (y.get_value() == 0)
def test_xml_parser_with_xml_dtd(): global test_file # value missing with open(test_file, "w") as f: f.write("""<?xml version="1.0" encoding="UTF-8" ?>""") y = XmlParser(test_file) y.load_file() y.parse_file() y.process_file() assert (y.get_value() == 0) # delete the test file as not required os.remove(test_file)
def get_parse(ann_fname, input_size): parser = XmlParser() WIDTH = parser.get_width(ann_fname) HEIGHT = parser.get_height(ann_fname) filename = parser.get_fname(ann_fname) labels = parser.get_labels(ann_fname) boxes = parser.get_boxes(ann_fname) for i in range(len(boxes)): boxes[i][0] = boxes[i][0] / WIDTH * input_size boxes[i][1] = boxes[i][1] / WIDTH * input_size boxes[i][2] = boxes[i][2] / HEIGHT * input_size boxes[i][3] = boxes[i][3] / HEIGHT * input_size return filename, labels, boxes
def test_xml_parser_with_malformed_xml(): global test_file # value missing with open(test_file, "w") as f: f.write("""<?xml version="1.0" encoding="UTF-8" ?> <users> <user <name>John</name> <active>true</active> /user> <user> <name>Mark</name> active>false</active> <value>250</value </user> </users>""") y = XmlParser(test_file) y.load_file() y.parse_file() y.process_file() assert (y.get_value() == 0)
class Settings(): settingsPath = str("") parser = 0 def winPath(self): path = str(getenv("USERPROFILE")) path += str("\.py-editor\settings.xml") return path def unixPath(self): path = str(getenv("HOME")) path += str("/.py-editor/settings.xml") return path def __init__(self): path = str("") if (platform.system() == "Windows"): path = self.winPath() else: path = self.unixPath() self.settingsPath = path if (exists(str(path)) == False): gen_settings.generate_settings() self.parser = XmlParser(path) def getSetting(self, ID, defaultSetting): setting = str("") try: setting = self.parser.getElementData(ID) except Exception: setting = defaultSetting return setting def getAttributeSetting(self, ID, attrID, defaultSetting): setting = str("") try: setting = self.parser.getElementAttribute(ID, attrID) except Exception: setting = defaultSetting if (setting == None): setting = defaultSetting return setting def writeSetting(self, ID, value): self.parser.setElementValue(ID, value) def writeAttributeSetting(self, ID, attr, attrValue): self.parser.setElementAttribute(ID, attr, attrValue)
def __init__(self): self.parser = XmlParser() self.handler = RepoMdSaxHandler() self.parser.setContentHandler(self.handler)
class FileHandling: def __init__(self, Filename, FilePath): self.Filename = Filename self.FilePath = FilePath def creatFileObject(self): s = '\\' filename = s.join([self.FilePath, self.Filename]) print(filename) fileObj = open(filename, 'r') return fileObj def CreateListOfFileObj(self): fileObj = self.creatFileObject() listOfVMNames = [] for i in fileObj: listOfVMNames.append(i.rstrip()) return listOfVMNames if __name__ == '__main__': obj1 = XmlParser(Fake_Path) listOfElements = obj1.ParseXML() filename = listOfElements[0] filepath = listOfElements[1] obj = FileHandling(filename, filepath) print(obj.CreateListOfFileObj())
def main(): #build ipcam list from config.xml config = 'config.xml' parser = XmlParser(config) cam_list = parser.build_cam_list() print 'Full List' for item in cam_list: print item.get_name() default = 0 current_proc = subprocess.Popen(['omxplayer', cam_list[default].get_rem_addr()] , stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) #ir input section blocking = 0; if(pylirc.init("pylirc", "./pylirc/conf", blocking)): code = {"config" : ""} while (code["config"] != "0"): # Very intuitive indeed if(not blocking): print "." # Delay... sleep(0.5) # Read next code s = pylirc.nextcode(1) # Loop as long as there are more on the queue # (dont want to wait a second if the user pressed many buttons...) while(s): # Print all the configs... for (code) in s: char = code["config"] print "Command: %s, Repeat: %d" % (code["config"], code["repeat"]) # Read next code? if(not blocking): s = pylirc.nextcode(1) else: s = [] # if 0 pressed exit close player and pylirc # if int(char) == 0: # subprocess.Popen(['killall', 'omxplayer.bin']) # pylirc.exit() # break if (int(char) <= len(cam_list) and int(char) != 0): index = int(char)-1 url = cam_list[index].get_rem_addr() print url #comment try: next_proc = subprocess.Popen(['omxplayer', url], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #current_proc.communicate('p') #current_proc.stdin.flush() #print next_proc.stdout current_proc.communicate('q') temp = current_proc current_proc = next_proc next_proc = temp except: out, err = current_proc.communicate() print ("Error: " + err.rstrip()) else: print ("there are no cam corresponding to this number") sleep(0.1) subprocess.Popen(['killall', 'omxplayer.bin']) pylirc.exit()
def main(): #build ipcam list from config.xml config = 'config.xml' parser = XmlParser(config) cam_list = parser.build_cam_list() print 'Full List' for item in cam_list: print item.get_name() default = 0 current_proc = subprocess.Popen( ['omxplayer', cam_list[default].get_rem_addr()], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #input section cec_proc = subprocess.Popen('cec-client', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) # wrap p.stdout with a NonBlockingStreamReader object: nbsr = NBSR(cec_proc.stdout) while True: output = nbsr.readline() # 0.1 secs to let the shell output the result if output: if (output.startswith('waiting')): print "Ready for input" if (output.startswith('TRAFFIC:')): sub = output.split('>>') if (len(sub) > 1): if (sub[1].startswith(' 01:44:2')): code = sub[1].split(':2') print code[1] char = int(code[1]) #while True: #char = raw_input("choose camera [1 - %s ]: " % len(cam_list)) if char == 0: subprocess.Popen(['killall', 'omxplayer.bin']) break if (int(char) <= len(cam_list)): index = int(char) - 1 url = cam_list[index].get_rem_addr() print url #comment try: next_proc = subprocess.Popen( ['omxplayer', url], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #current_proc.communicate('p') #current_proc.stdin.flush() #print next_proc.stdout current_proc.communicate('q') temp = current_proc current_proc = next_proc next_proc = temp except: out, err = current_proc.communicate() print("Error: " + err.rstrip()) else: print( "there are no cam corresponding to this number" ) sleep(0.1)
def endDocument(self): XmlParser.endDocument(self)