Ejemplo n.º 1
0
 def checkValue(self, context, value):
     container = self.collection.interpret(context)
     if isinstance(container, IContainer):
         if not container.hasItem(context, value):
             raise InvalidValueError("Value:" + str(value) +
                                     " is not in range: " +
                                     str(self.collection))
     else:
         raise InvalidValueError("Not a collection: " +
                                 self.collection.toString())
Ejemplo n.º 2
0
 def getMemberValue(self, context, name, autoCreate=False):
     if "count" == name:
         return IntegerValue(len(self))
     elif "totalCount" == name:
         return IntegerValue(self.totalLength())
     else:
         raise InvalidValueError("No such member:" + name)
Ejemplo n.º 3
0
 def nativeCast(self, context, value):
     from prompto.type.TextType import TextType
     if isinstance(value.itype, TextType) and len(value.value)>=1:
         from prompto.value.CharacterValue import CharacterValue
         return CharacterValue(value.value[0:1])
     else:
         raise InvalidValueError("Cannot convert " + str(value) + " to Character")
Ejemplo n.º 4
0
 def getMatchOp(self):
     if self.operator in [CmpOp.GT, CmpOp.LTE]:
         return MatchOp.GREATER
     elif self.operator in [CmpOp.GTE, CmpOp.LT]:
         return MatchOp.LESSER
     else:
         raise InvalidValueError(str(self.operator))
Ejemplo n.º 5
0
 def interpretLimit(self, context, exp):
     if exp is None:
         return None
     value = exp.interpret(context).getStorableData()
     if not isinstance(value, (int, long)):
         raise InvalidValueError("Expecting an Integer, got:" + value.type.typeName)
     return value
Ejemplo n.º 6
0
 def checkValue(self, context, value):
     if self.pattern is None:
         toMatch = self.expression.interpret(context)
         self.pattern = re.compile(str(toMatch))
     if not re.match(self.pattern, str(value)):
         raise InvalidValueError(
             str(value) + " does not match:" + str(self.pattern))
Ejemplo n.º 7
0
 def checkValue(self, context, value):
     child = context.newChildContext()
     child.registerValue(TransientVariable("value", AnyType.instance))
     child.setValue("value", value)
     test = self.expression.interpret(child)
     if not BooleanValue.TRUE == test:
         raise InvalidValueError(str(value) + " does not match:" + str(self.expression))
Ejemplo n.º 8
0
 def getItem(self, context, index):
     from prompto.value.CharacterValue import CharacterValue
     try:
         if isinstance(index, IntegerValue):
             return CharacterValue(self.value[index.IntegerValue() - 1])
         else:
             raise InvalidValueError("No such item:" + str(index))
     except IndexError:
         raise IndexOutOfRangeError()
Ejemplo n.º 9
0
 def interpretCondition(self, context):
     value = self.condition.interpret(context)
     if not isinstance(value, BooleanValue):
         raise InvalidValueError("Expected a Boolean, got:" +
                                 type(value).__name__)
     return value.value
Ejemplo n.º 10
0
    def Parse(text):
        try:
            data = [0]*8
            steps = "YMWDHM.S"
            value = None
            lastStep = -1
            isNeg = False
            inPeriod = False
            inTime = False
            inMillis = False

            for c in text:
                # leading 'P' is mandatory
                if not inPeriod:
                    if c == 'P':
                        inPeriod = True
                        continue
                    else:
                        raise Exception()
                # check for time section
                if c == 'T':
                    if not inTime:
                        inTime = True
                        continue
                    else:
                        raise Exception()
                # check for value type
                step = steps.find(c, 4) if inTime else steps.find(c)
                if step >= 0:
                    if step <= lastStep:
                        raise Exception()
                    if step > 3 and not inTime:
                        raise Exception()
                    if value is None:
                        raise Exception()
                    if step == 6: # millis '.'
                        inMillis = True
                    if step == 7 and not inMillis:
                        step = 6
                    data[step] = value
                    lastStep = step
                    value = None
                    continue
                if c == '-':
                    if value is not None:
                        raise Exception()
                    if isNeg or inMillis:
                        raise Exception()
                    isNeg = True
                if c < '0' or c > '9':
                    raise Exception()
                if value is not None:
                    value *= 10
                    value += ord(c) - ord('0')
                else:
                    value = ord(c) - ord('0')
                    if isNeg:
                        value = -value
                        isNeg = False
            # must terminate by a value type
            if value is not None:
                raise Exception()
            return PeriodValue(years=data[0], months=data[1], weeks=data[2], days=data[3], hours=data[4], minutes=data[5], seconds=data[6], millis=data[7])
        except Exception, e:
            from prompto.store.InvalidValueError import InvalidValueError
            raise InvalidValueError("\"" + text + "\" is not a valid ISO 8601 period!")