예제 #1
0
 def Validate(self, value):
   if self._regex and not re.match(self._regex, self.Display(value)):
     raise exceptions.ValidationError(
         self.GetPresentationName(),
         'Value [{}] does not match [{}].'.format(
             self.Display(value),
             self._regex))
예제 #2
0
 def Validate(self, value):
   value = self._convert_value(value)
   invalid = None
   if self._min_endpoint:
     endpoint = self._min_endpoint.value
     if self._min_endpoint.closed:
       if value < endpoint:
         invalid = 'greater than or equal to'
     elif value <= endpoint:
       invalid = 'greater than'
   if not invalid and self._max_endpoint:
     endpoint = self._max_endpoint.value
     if self._max_endpoint.closed:
       if value > endpoint:
         invalid = 'less than or equal to'
     elif value >= endpoint:
       invalid = 'less than'
   if invalid:
     raise exceptions.ValidationError(
         self.GetPresentationName(),
         '{}{} [{}] must be {} [{}].'.format(
             self._kind[0].upper(),
             self._kind[1:],
             self._display_endpoint(value),
             invalid,
             self._display_endpoint(endpoint)))