def getBounds(self, nElements): if isSequence(nElements): if len(nElements) != 2: raise CommandDefinitionError("nElements must be either integer or sequence of 2 integers") # verify, try to cast to correct types nElements = list(nElements) # make it mutable (incase of tuple) for ind in range(2): nElements[ind] = self.checkInt(nElements[ind]) if nElements[1] < nElements[0]: raise CommandDefinitionError("nElements[1] must be greater than nElements[0]") if nElements[0]==nElements[1]==int(0): raise CommandDefinitionError("may not specifiy nElement=(0,0)") if nElements[0]==inf: raise CommandDefinitionError("may not specify infinite lower bound for nElements") if True in [element<0 for element in nElements]: raise CommandDefinitionError("may not specify any negative value in nElements") lowerBound, upperBound = nElements else: # not a sequence, we expect an exact amount of values for this argument nElements = self.checkInt(nElements) if nElements <= 0: raise CommandDefinitionError("may not specify nElement<=0") if nElements == inf: raise CommandDefinitionError("may not specify nElement=inf, use range (lowerbound ,inf) instead") # set upper and lower bounds equal lowerBound, upperBound = [nElements]*2 return lowerBound, upperBound
def __init__(self, matchList, nElements=1, helpStr="", repString=None): if not isSequence(matchList): raise CommandDefinitionError("matchlist must be a sequence") self.matchList = matchList ArgumentBase.__init__(self, pyparseItems.uniqueMatch(matchList), nElements, helpStr, repString)