Exemple #1
0
 def checker(cls, obj):
   assert isinstance(obj, String)
   if isinstance(obj._value, Compatibility.stringy):
     return TypeCheck.success()
   else:
     # TODO(wickman)  Perhaps we should mark uninterpolated Mustache objects as
     # intrinsically non-stringy, because String will never typecheck false given
     # its input constraints.
     return TypeCheck.failure("%s not a string" % repr(obj._value))
Exemple #2
0
 def check(self):
     assert ListContainer.isiterable(self._values)
     for element in self._values:
         assert isinstance(element, self.TYPE)
         typecheck = element.in_scope(*self.scopes()).provided(self.modulo()).check()
         if not typecheck.ok():
             return TypeCheck.failure(
                 "Element in %s failed check: %s" % (self.__class__.__name__, typecheck.message())
             )
     return TypeCheck.success()
Exemple #3
0
 def check(self):
   for name, signature in self.TYPEMAP.items():
     if self._schema_data[name] is Empty and signature.required:
       return TypeCheck.failure('%s[%s] is required.' % (self.__class__.__name__, name))
     elif self._schema_data[name] is not Empty:
       type_check = (self._schema_data[name].in_scope(*self.scopes())
                                            .provided(self.modulo())
                                            .check())
       if type_check.ok():
         continue
       else:
         return TypeCheck.failure('%s[%s] failed: %s' % (self.__class__.__name__, name,
           type_check.message()))
   return TypeCheck.success()
Exemple #4
0
 def check(self):
     assert isinstance(self._map, tuple)
     for key, value in self._map:
         assert isinstance(key, self.KEYTYPE)
         assert isinstance(value, self.VALUETYPE)
         keycheck = key.in_scope(*self.scopes()).provided(self.modulo()).check()
         valuecheck = value.in_scope(*self.scopes()).provided(self.modulo()).check()
         if not keycheck.ok():
             return TypeCheck.failure(
                 "%s key %s failed check: %s" % (self.__class__.__name__, key, keycheck.message())
             )
         if not valuecheck.ok():
             return TypeCheck.failure(
                 "%s[%s] value %s failed check: %s" % (self.__class__.__name__, key, value, valuecheck.message())
             )
     return TypeCheck.success()
Exemple #5
0
 def checker(cls, obj):
   assert isinstance(obj, Float)
   if isinstance(obj._value, Compatibility.real + Compatibility.integer):
     return TypeCheck.success()
   else:
     return TypeCheck.failure("%s not a float" % repr(obj._value))