Exemplo n.º 1
0
    def _validate(self, value):
        """
        >>> uri = URI(__name__='test')
        >>> uri.validate(b("http://www.python.org/foo/bar"))
        >>> uri.validate(b("DAV:"))
        >>> uri.validate(b("www.python.org/foo/bar"))
        Traceback (most recent call last):
        ...
        InvalidURI: www.python.org/foo/bar
        """

        super(URI, self)._validate(value)
        if _isuri_bytes(value):
            return

        raise InvalidURI(value)
Exemplo n.º 2
0
    def __set__(self, instance, value):
        if instance is None:  # pragma: no cover
            return

        if not value:
            self._setattr(instance, self.file_attr_name, None)
            self._setattr(instance, self.url_attr_name, value)
            return

        if value.startswith('data:'):
            raw_bytes, mime_type = dataurl.decode(value)
            if self.max_file_size and len(raw_bytes) > self.max_file_size:
                raise ConstraintNotSatisfied("The uploaded file is too large.")
            major, minor, parms = ct_parse(mime_type)
            the_file = zfile.File(mimeType=major + '/' + minor,
                                  parameters=parms)
            fp = the_file.open('w')
            fp.write(raw_bytes)
            fp.close()
            the_file.__parent__ = instance
            the_file.__name__ = self.data_name

            # By keeping url in __dict__, toExternalDictionary
            # still does the right thing
            self._setattr(instance, self.url_attr_name, None)
            self._setattr(instance, self.file_attr_name, the_file)
        else:
            # Be sure it at least parses
            parsed = urlparse(value)
            if not parsed.netloc:
                if self.reject_url_with_missing_host:
                    raise InvalidURI(value)
                if self.ignore_url_with_missing_host:
                    return

            self._setattr(instance, self.file_attr_name, None)
            self._setattr(instance, self.url_attr_name, value)
Exemplo n.º 3
0
    def _validate(self, value):
        super(URI, self)._validate(value)
        if _isuri(value):
            return

        raise InvalidURI(value)
Exemplo n.º 4
0
    def _validate(self, value):
        super(URI, self)._validate(value)
        if _isuri(value):
            return

        raise InvalidURI(value).with_field_and_value(self, value)
Exemplo n.º 5
0
 def _validate(self, value):
     super(HTTPSURL, self)._validate(value)
     if not value.lower().startswith('https://'):
         raise InvalidURI(value).with_field_and_value(self, value)