Пример #1
0
    def value(self, value, encoding='utf-8'):
        """Store binary content to applications's repository and update
        `self.meta['md5']`.

        :param:content: string, bytes, or any object with a `read()` method
        :param:encoding: encoding to use when content is Unicode
        """
        from abilian.services.repository import session_repository as repository
        repository.set(self, self.uuid, value)
        self.meta['md5'] = text_type(hashlib.md5(self.value).hexdigest())

        if hasattr(value, 'filename'):
            filename = getattr(value, 'filename')
            if isinstance(filename, bytes):
                filename = filename.decode('utf-8')
            self.meta['filename'] = filename

        if hasattr(value, 'content_type'):
            self.meta['mimetype'] = getattr(value, 'content_type')
Пример #2
0
    def value(self, value: bytes):
        """Store binary content to applications's repository and update
        `self.meta['md5']`.

        :param:content: bytes, or any object with a `read()` method
        :param:encoding: encoding to use when content is Unicode
        """
        from abilian.services.repository import session_repository as repository

        repository.set(self, self.uuid, value)
        self.meta["md5"] = str(hashlib.md5(self.value).hexdigest())

        if hasattr(value, "filename"):
            filename = value.filename
            if isinstance(filename, bytes):
                filename = filename.decode("utf-8")
            self.meta["filename"] = filename

        if hasattr(value, "content_type"):
            self.meta["mimetype"] = value.content_type
Пример #3
0
  def value(self, value, encoding='utf-8'):
    """
    Store binary content to applications's repository and update
    `self.meta['md5']`.

    :param:content: string, bytes, or any object with a `read()` method
    :param:encoding: encoding to use when content is unicode
    """
    from abilian.services.repository import session_repository as repository
    repository.set(self, self.uuid, value)
    self.meta['md5'] = unicode(hashlib.md5(self.value).hexdigest())

    if hasattr(value, 'filename'):
      filename = getattr(value, 'filename')
      if isinstance(filename, bytes):
        filename = filename.decode('utf-8')
      self.meta['filename'] = filename

    if hasattr(value, 'content_type'):
      self.meta['mimetype'] = getattr(value, 'content_type')