def Validate(self, value, key=None):
   """Validates a schedule."""
   if value is None:
     raise validation.MissingAttribute('schedule must be specified')
   if not isinstance(value, basestring):
     raise TypeError('schedule must be a string, not \'%r\''%type(value))
   try:
     groctimespecification.GrocTimeSpecification(value)
   except groc.GrocException, e:
     raise validation.ValidationError('schedule \'%s\' failed to parse: %s'%(
         value, e.args[0]))
Exemplo n.º 2
0
    def Validate(self, value, unused_key=None):
        """Validates a subnet."""
        if value is None:
            raise validation.MissingAttribute('subnet must be specified')
        if not isinstance(value, basestring):
            raise validation.ValidationError(
                'subnet must be a string, not \'%r\'' % type(value))
        try:
            ipaddr.IPNetwork(value)
        except ValueError:
            raise validation.ValidationError(
                '%s is not a valid IPv4 or IPv6 subnet' % value)

        # Extra validation check since ipaddr accepts quad-dotted subnet masks.
        parts = value.split('/')
        if len(parts) == 2 and not re.match('^[0-9]+$', parts[1]):
            raise validation.ValidationError(
                'Prefix length of subnet %s must be an '
                'integer (quad-dotted masks are not '
                'supported)' % value)

        return value
Exemplo n.º 3
0
    def Validate(self, value, unused_key=None):
        """Validates an URL pattern."""
        if value is None:
            raise validation.MissingAttribute('url must be specified')
        if not isinstance(value, basestring):
            raise validation.ValidationError(
                'url must be a string, not \'%r\'' % type(value))

        url_holder = ParsedURL(value)
        if url_holder.host_exact:
            _ValidateMatch(_URL_HOST_EXACT_PATTERN_RE, url_holder.host,
                           'invalid host_pattern \'%s\'' % url_holder.host)
            # Explicitly disallow IpV4 #.#.#.# addresses. These will match
            # _URL_HOST_EXACT_PATTERN_RE above.
            _ValidateNotIpV4Address(url_holder.host)
        else:
            _ValidateMatch(
                _URL_HOST_SUFFIX_PATTERN_RE, url_holder.host_pattern,
                'invalid host_pattern \'%s\'' % url_holder.host_pattern)

        #TODO(user): validate path_pattern and lengths of both patterns.
        #                also validate hostname label lengths 63 charn max)
        return value