Example #1
0
    def _validate_type_ip(self, field, value):
        """ Enables validation for `ip` schema attribute.

        :param field: field name.
        :param value: field value.
        """
        if self._ip_re is None:
            self._ip_re = re.compile(
                r'^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$'
            )

        # Run regular expression
        m = re.match(self._ip_re, value)

        # Check general format
        if m is None:
            self._error(
                field, ERROR_BAD_TYPE.format('Ip'),
            )
            return

        # Check parts
        for i in range(1, 4):
            part = int(m.group(i))
            if part < 0 or part > 255:
                self._error(
                    field, ERROR_BAD_TYPE.format('Ip'),
                )
 def _validate_type_objectid(self, field, value):
     """ Enables validation for `objectid` schema attribute.
 
     :param field: field name.
     :param value: field value.
     """
     if not re.match('[a-f0-9]{16}', value):
         self._error(field, ERROR_BAD_TYPE.format('ObjectId'))
Example #3
0
 def _validate_type_email(self, field, value):
     if not _EMAIL_REGEX.match(value):
         self._error(field, ERROR_BAD_TYPE.format('Email'))
Example #4
0
 def _validate_type_url(self, field, value):
     if not _URL_REGEX.match(value):
         self._error(field, ERROR_BAD_TYPE.format('Url'))
Example #5
0
 def _validate_type_location(self, field, value):
     try:
         all([isinstance(value[0], float), isinstance(value[1], float)])
     except Exception as e:
         self._error(field, ERROR_BAD_TYPE.format('Location'))
Example #6
0
 def _validate_type_object_id(self, field, value):
     if not isinstance(value, ObjectId):
         self._error(field, ERROR_BAD_TYPE.format('ObjectId'))