Beispiel #1
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
Beispiel #2
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
Beispiel #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