コード例 #1
0
ファイル: resources.py プロジェクト: yuanbosdu/Kotti
    def _save_data(cls, target, value, oldvalue, initiator):
        """ Refresh metadata and save the binary data to the data field.

        :param target: The File instance
        :type target: :class:`kotti.resources.File` or subclass
        :param value: The container for binary data
        :type value: A :class:`cgi.FieldStorage` instance
        """

        if isinstance(value, bytes):
            value = _to_fieldstorage(fp=StringIO(value),
                                     filename=target.filename,
                                     mimetype=target.mimetype,
                                     size=len(value))

        newvalue = _SQLAMutationTracker._field_set(
            target, value, oldvalue, initiator)

        if newvalue is None:
            return

        target.filename = newvalue.filename
        target.mimetype = newvalue.content_type
        target.size = newvalue.file.content_length

        return newvalue
コード例 #2
0
ファイル: resources.py プロジェクト: castaf/Kotti
    def _save_data(target: 'File',
                   value: Optional[Union[FieldStorage, bytes, UploadedFile, BufferedReader]],  # noqa
                   oldvalue: Optional[Union[UploadedFile, _symbol]],
                   initiator: Event) -> Optional[UploadedFile]:
        """ Refresh metadata and save the binary data to the data field.

        :param target: The File instance
        :type target: :class:`kotti.resources.File` or subclass

        :param value: The container for binary data
        :type value: A :class:`cgi.FieldStorage` instance
        """

        if isinstance(value, bytes):
            fp = BytesIO(value)
            value = _to_fieldstorage(fp=fp,
                                     filename=target.filename,
                                     mimetype=target.mimetype,
                                     size=len(value))

        newvalue = _SQLAMutationTracker._field_set(
            target, value, oldvalue, initiator)

        if newvalue is None:
            return

        target.filename = newvalue.filename
        target.mimetype = newvalue.content_type
        target.size = newvalue.file.content_length

        return newvalue
コード例 #3
0
    def _set_data(cls, target, value, oldvalue, initiator):
        # Ref #384 : enforce this method
        if isinstance(value, (cStringIO.InputType, file)):
            value.seek(0)
            value = value.read()

        if isinstance(value, bytes):
            value = _to_fieldstorage(
                fp=cStringIO.StringIO(value),
                filename=target.name,
                size=len(value)
            )
        newvalue = _SQLAMutationTracker._field_set(
            target,
            value,
            oldvalue,
            initiator
        )

        if newvalue is None:
            return
        target.filename = newvalue.filename
        target.mimetype = detect_file_headers(newvalue.filename)
        target.size = newvalue.file.content_length

        return newvalue
コード例 #4
0
    def _set_data(cls, target, value, oldvalue, initiator):
        if isinstance(value, bytes):
            value = _to_fieldstorage(fp=StringIO(value),
                                     filename=target.filename,
                                     size=len(value))

        newvalue = _SQLAMutationTracker._field_set(
            target, value, oldvalue, initiator)

        if newvalue is None:
            return
        target.filename = newvalue.filename
        target.mimetype = detect_file_headers(newvalue.filename)
        target.size = newvalue.file.content_length

        return newvalue
コード例 #5
0
ファイル: files.py プロジェクト: tonthon/autonomie
    def _set_data(cls, target, value, oldvalue, initiator):
        # Ref #384 : enforce this method
        if hasattr(value, "seek"):
            value.seek(0)
            value = value.read()

        if isinstance(value, bytes):
            value = _to_fieldstorage(fp=cStringIO.StringIO(value),
                                     filename=target.name,
                                     size=len(value))
        newvalue = _SQLAMutationTracker._field_set(target, value, oldvalue,
                                                   initiator)

        if newvalue is None:
            return
        target.filename = newvalue.filename
        target.mimetype = detect_file_headers(newvalue.filename)
        target.size = newvalue.file.content_length

        return newvalue
コード例 #6
0
ファイル: resources.py プロジェクト: rkx-forks/Kotti
    def _save_data(
        target: "File",
        value: Optional[Union[FieldStorage, bytes, UploadedFile,
                              BufferedReader]],  # noqa
        oldvalue: Optional[Union[UploadedFile, _symbol]],
        initiator: Event,
    ) -> Optional[UploadedFile]:
        """ Refresh metadata and save the binary data to the data field.

        :param target: The File instance
        :type target: :class:`kotti.resources.File` or subclass

        :param value: The container for binary data
        :type value: A :class:`cgi.FieldStorage` instance
        """

        if isinstance(value, bytes):
            fp = BytesIO(value)
            value = _to_fieldstorage(
                fp=fp,
                filename=target.filename,
                mimetype=target.mimetype,
                size=len(value),
            )

        newvalue = _SQLAMutationTracker._field_set(target, value, oldvalue,
                                                   initiator)

        if newvalue is None:
            return

        target.filename = newvalue.filename
        target.mimetype = newvalue.content_type
        target.size = newvalue.file.content_length

        return newvalue