Go to the documentation of this file.00001 import json
00002 class selectionParser(object):
00003 def __init__(self,selectStr):
00004 self.__result={}
00005 self.__strresult={}
00006 strresult=json.loads(selectStr)
00007 for k,v in strresult.items():
00008 expandedvalues=[]
00009 for w in v:
00010 if len(w)==0:
00011 self.__result[int(k)]=expandedvalues
00012 self.__strresult[k]=[]
00013 continue
00014
00015 elif len(w)==1:
00016 expandedvalues.append(w[0])
00017
00018 elif len(w)==2 and w[0]==w[1]:
00019 expandedvalues.append(w[0])
00020 else:
00021 for i in range(w[0],w[1]+1):
00022 expandedvalues.append(i)
00023 self.__result[int(k)]=expandedvalues
00024 self.__strresult[k]=[str(x) for x in expandedvalues]
00025 def runs(self):
00026 return self.__result.keys()
00027 def runsandls(self):
00028 '''return expanded {run:lslist}
00029 '''
00030 return self.__result
00031 def runsandlsStr(self):
00032 '''return expanded {'run':lslist}
00033 '''
00034 return self.__strresult
00035 def numruns(self):
00036 return len(self.__result.keys())
00037 def numls(self,run):
00038 return len(self.__result[run])
00039 if __name__ == "__main__":
00040 s=selectionParser('{"1":[[3,45]],"2":[[4,8],[10,10]],"3":[[]]}')
00041 print 'runs : ',s.runs()
00042 print 'full result : ',s.runsandls()
00043 print 'str result : ',s.runsandlsStr()
00044 print 'num runs : ',s.numruns()
00045 print 'numls in run : ',s.numls(1)