import os
import sys
import string

def parse_xml(string, substring):
    output = ""
    retA = string.find("<" + substring + ">")
    if retA > 0:
        retB = string.find("</" + substring + ">")
        output = string[retA + len(substring) + 2:retB]
    return output    

def parse_xml_defined(string, substringA, substringB):
    output = ""
    retA = string.find(substringA)
    if retA > 0:
        retB = string.find(substringB)
        output = string[retA + len(substringA):retB]
    return output   

def open_file_return_base64encoded(filename):
    fd = open(filename, "rb")
    fileData = fd.read()
    fd.close()
    encodedData = base64.b64encode(fileData)
    return encodedData

def getIPlist(filename):
    iplist = []
    fd = open(filename, 'r')
    while True:
        try:
            temp = fd.readline()
            if temp == '':
                break
            iplist.append(temp[:len(temp)-1])
        except Exception, e:
            break
    fd.close()
    return iplist

def getConfigList(filename):
    cfglist = []
    fd = open(filename, 'r')
    while True:
        try:
            temp = fd.readline()
            if temp == '':
                break            
            cfglist.append(temp)
        except Exception, e:
            break
    fd.close()
    return cfglist
