Data Structures
Werkzeug provides some subclasses of common Python objects to extend them with additional features. Some of them are used to make them immutable, others are used to change some semantics to better work with HTTP.
General Purpose
在 0.6 版更改: The general purpose classes are now pickleable in each protocol as long as the contained objects are pickleable. This means that the werkzeug.datastructures.FileMultiDict" title="werkzeug.datastructures.FileMultiDict won’t be pickleable as soon as it contains a file.
- class werkzeug.datastructures.TypeConversionDict
- class werkzeug.datastructures.Headers([defaults])
- class werkzeug.datastructures.FileStorage(stream=None, filename=None, name=None, content_type=None, content_length=None, headers=None)
The werkzeug.datastructures.FileStorage" title="werkzeug.datastructures.FileStorage class is a thin wrapper over incoming files. It is used by the request object to represent uploaded files. All the attributes of the wrapper stream are proxied by the file storage so it’s possible to do storage.read() instead of the long form storage.stream.read().
- stream
The input stream for the uploaded file. This usually points to an open temporary file.
- filename
The filename of the file on the client.
- name
The name of the form field.
- headers
The multipart headers as werkzeug.datastructures.Headers" title="werkzeug.datastructures.Headers object. This usually contains irrelevant information but in combination with custom multipart requests the raw headers might be interesting.
0.6 新版功能.
- close()
Close the underlying file if possible.
- content_length
The content-length sent in the header. Usually not available
- content_type
The content-type sent in the header. Usually not available
- mimetype
Like werkzeug.datastructures.FileStorage.content_type" title="werkzeug.datastructures.FileStorage.content_type but without parameters (eg, without charset, type etc.). For example if the content type is text/html; charset=utf-8 the mimetype would be 'text/html'.
0.7 新版功能.
- mimetype_params
The mimetype parameters as dict. For example if the content type is text/html; charset=utf-8 the params would be {'charset': 'utf-8'}.
0.7 新版功能.
- save(dst, buffer_size=16384)
Save the file to a destination path or file object. If the destination is a file object you have to close it yourself after the call. The buffer size is the number of bytes held in memory during the copy process. It defaults to 16KB.
For secure file saving also have a look at secure_filename().
参数: - dst – a filename or open file object the uploaded file is saved to.
- buffer_size – the size of the buffer. This works the same as the length parameter of shutil.copyfileobj().