ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# HTTP Utilities Werkzeug provides a couple of functions to parse and generate HTTP headersthat are useful when implementing WSGI middlewares or whenever you areoperating on a lower level layer. All this functionality is also exposedfrom request and response objects. ### Date Functions The following functions simplify working with times in an HTTP context.Werkzeug uses offset-naive [datetime](http://docs.python.org/dev/library/datetime.html#datetime.datetime "(在 Python v3.5)") [http://docs.python.org/dev/library/datetime.html#datetime.datetime] objects internallythat store the time in UTC. If you're working with timezones in yourapplication make sure to replace the tzinfo attribute with a UTC timezoneinformation before processing the values. werkzeug.http.cookie_date(*expires=None*) Formats the time to ensure compatibility with Netscape's cookiestandard. Accepts a floating point number expressed in seconds since the epoch in, adatetime object or a timetuple. All times in UTC. The [parse_date()](# "werkzeug.http.parse_date")function can be used to parse such a date. Outputs a string in the format Wdy,DD-Mon-YYYYHH:MM:SSGMT. | 参数: | **expires** – If provided that date is used, otherwise the current. | |-----|-----| werkzeug.http.http_date(*timestamp=None*) Formats the time to match the RFC1123 date format. Accepts a floating point number expressed in seconds since the epoch in, adatetime object or a timetuple. All times in UTC. The [parse_date()](# "werkzeug.http.parse_date")function can be used to parse such a date. Outputs a string in the format Wdy,DDMonYYYYHH:MM:SSGMT. | 参数: | **timestamp** – If provided that date is used, otherwise the current. | |-----|-----| werkzeug.http.parse_date(*value*) Parse one of the following date formats into a datetime object: ~~~ Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format ~~~ If parsing fails the return value is None. | 参数: | **value** – a string with a supported date format. | |-----|-----| | 返回: | a [datetime.datetime](http://docs.python.org/dev/library/datetime.html#datetime.datetime "(在 Python v3.5)") [http://docs.python.org/dev/library/datetime.html#datetime.datetime] object. | ### Header Parsing The following functions can be used to parse incoming HTTP headers.Because Python does not provide data structures with the semantics requiredby [**RFC 2616**](http://tools.ietf.org/html/rfc2616.html) [http://tools.ietf.org/html/rfc2616.html], Werkzeug implements some custom data structures that are[*documented separately*](#). werkzeug.http.parse_options_header(*value*) Parse a Content-Type like header into a tuple with the contenttype and the options: ~~~ >>> parse_options_header('text/html; charset=utf8') ('text/html', {'charset': 'utf8'}) ~~~ This should not be used to parse Cache-Control like headers that usea slightly different format. For these headers use the[parse_dict_header()](# "werkzeug.http.parse_dict_header") function. 0.5 新版功能. | 参数: | **value** – the header to parse. | |-----|-----| | 返回: | (str, options) | werkzeug.http.parse_set_header(*value*, *on_update=None*) Parse a set-like header and return a[HeaderSet](# "werkzeug.datastructures.HeaderSet") object: ~~~ >>> hs = parse_set_header('token, "quoted value"') ~~~ The return value is an object that treats the items case-insensitivelyand keeps the order of the items: ~~~ >>> 'TOKEN' in hs True >>> hs.index('quoted value') 1 >>> hs HeaderSet(['token', 'quoted value']) ~~~ To create a header from the HeaderSet again, use the[dump_header()](# "werkzeug.http.dump_header") function. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple"><li><strong>value</strong> – a set header to be parsed.</li><li><strong>on_update</strong> – an optional callable that is called every time avalue on the <a class="reference internal" href="datastructures.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><tt class="xref py py-class docutils literal"><span class="pre">HeaderSet</span></tt></a>object is changed.</li></ul></td></tr><tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">a <a class="reference internal" href="datastructures.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><tt class="xref py py-class docutils literal"><span class="pre">HeaderSet</span></tt></a></p></td></tr></tbody></table> werkzeug.http.parse_list_header(*value*) Parse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements ofthe list may include quoted-strings. A quoted-string couldcontain a comma. A non-quoted string could have quotes in themiddle. Quotes are removed automatically after parsing. It basically works like [parse_set_header()](# "werkzeug.http.parse_set_header") just that itemsmay appear multiple times and case sensitivity is preserved. The return value is a standard [list](http://docs.python.org/dev/library/stdtypes.html#list "(在 Python v3.5)") [http://docs.python.org/dev/library/stdtypes.html#list]: ~~~ >>> parse_list_header('token, "quoted value"') ['token', 'quoted value'] ~~~ To create a header from the [list](http://docs.python.org/dev/library/stdtypes.html#list "(在 Python v3.5)") [http://docs.python.org/dev/library/stdtypes.html#list] again, use the[dump_header()](# "werkzeug.http.dump_header") function. | 参数: | **value** – a string with a list header. | |-----|-----| | 返回: | [list](http://docs.python.org/dev/library/stdtypes.html#list "(在 Python v3.5)") [http://docs.python.org/dev/library/stdtypes.html#list] | werkzeug.http.parse_dict_header(*value*, *cls=<type 'dict'>*) Parse lists of key, value pairs as described by RFC 2068 Section 2 andconvert them into a python dict (or any other mapping object created fromthe type with a dict like interface provided by the cls arugment): ~~~ >>> d = parse_dict_header('foo="is a fish", bar="as well"') >>> type(d) is dict True >>> sorted(d.items()) [('bar', 'as well'), ('foo', 'is a fish')] ~~~ If there is no value for a key it will be None: ~~~ >>> parse_dict_header('key_without_value') {'key_without_value': None} ~~~ To create a header from the [dict](http://docs.python.org/dev/library/stdtypes.html#dict "(在 Python v3.5)") [http://docs.python.org/dev/library/stdtypes.html#dict] again, use the[dump_header()](# "werkzeug.http.dump_header") function. 在 0.9 版更改: Added support for cls argument. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple"><li><strong>value</strong> – a string with a dict header.</li><li><strong>cls</strong> – callable to use for storage of parsed results.</li></ul></td></tr><tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">an instance of <cite>cls</cite></p></td></tr></tbody></table> werkzeug.http.parse_accept_header(*value*[, *class*]) Parses an HTTP Accept-* header. This does not implement a completevalid algorithm but one that supports at least value and qualityextraction. Returns a new Accept object (basically a list of (value,quality)tuples sorted by the quality with some additional accessor methods). The second parameter can be a subclass of Accept that is createdwith the parsed values and returned. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple"><li><strong>value</strong> – the accept header string to be parsed.</li><li><strong>cls</strong> – the wrapper class for the return value (can be<tt class="xref py py-class docutils literal"><span class="pre">Accept</span></tt> or a subclass thereof)</li></ul></td></tr><tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">an instance of <cite>cls</cite>.</p></td></tr></tbody></table> werkzeug.http.parse_cache_control_header(*value*, *on_update=None*, *cls=None*) Parse a cache control header. The RFC differs between response andrequest cache control, this method does not. It's your responsibilityto not use the wrong control statements. 0.5 新版功能: The cls was added. If not specified an immutable[RequestCacheControl](# "werkzeug.datastructures.RequestCacheControl") is returned. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple"><li><strong>value</strong> – a cache control header to be parsed.</li><li><strong>on_update</strong> – an optional callable that is called every time a valueon the <tt class="xref py py-class docutils literal"><span class="pre">CacheControl</span></tt>object is changed.</li><li><strong>cls</strong> – the class for the returned object. By default<a class="reference internal" href="datastructures.html#werkzeug.datastructures.RequestCacheControl" title="werkzeug.datastructures.RequestCacheControl"><tt class="xref py py-class docutils literal"><span class="pre">RequestCacheControl</span></tt></a> is used.</li></ul></td></tr><tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">a <cite>cls</cite> object.</p></td></tr></tbody></table> werkzeug.http.parse_authorization_header(*value*) Parse an HTTP basic/digest authorization header transmitted by the webbrowser. The return value is either None if the header was invalid ornot given, otherwise an [Authorization](# "werkzeug.datastructures.Authorization")object. | 参数: | **value** – the authorization header to parse. | |-----|-----| | 返回: | a [Authorization](# "werkzeug.datastructures.Authorization") object or None. | werkzeug.http.parse_www_authenticate_header(*value*, *on_update=None*) Parse an HTTP WWW-Authenticate header into a[WWWAuthenticate](# "werkzeug.datastructures.WWWAuthenticate") object. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple"><li><strong>value</strong> – a WWW-Authenticate header to parse.</li><li><strong>on_update</strong> – an optional callable that is called every time a valueon the <a class="reference internal" href="datastructures.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><tt class="xref py py-class docutils literal"><span class="pre">WWWAuthenticate</span></tt></a>object is changed.</li></ul></td></tr><tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">a <a class="reference internal" href="datastructures.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><tt class="xref py py-class docutils literal"><span class="pre">WWWAuthenticate</span></tt></a> object.</p></td></tr></tbody></table> werkzeug.http.parse_if_range_header(*value*) Parses an if-range header which can be an etag or a date. Returnsa [IfRange](# "werkzeug.datastructures.IfRange") object. 0.7 新版功能. werkzeug.http.parse_range_header(*value*, *make_inclusive=True*) Parses a range header into a [Range](# "werkzeug.datastructures.Range")object. If the header is missing or malformed None is returned.ranges is a list of (start,stop) tuples where the ranges arenon-inclusive. 0.7 新版功能. werkzeug.http.parse_content_range_header(*value*, *on_update=None*) Parses a range header into a[ContentRange](# "werkzeug.datastructures.ContentRange") object or None ifparsing is not possible. 0.7 新版功能. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>value</strong> – a content range header to be parsed.</li><li><strong>on_update</strong> – an optional callable that is called every time a valueon the <a class="reference internal" href="datastructures.html#werkzeug.datastructures.ContentRange" title="werkzeug.datastructures.ContentRange"><tt class="xref py py-class docutils literal"><span class="pre">ContentRange</span></tt></a>object is changed.</li></ul></td></tr></tbody></table> ### Header Utilities The following utilities operate on HTTP headers well but do not parsethem. They are useful if you're dealing with conditional responses or ifyou want to proxy arbitrary requests but want to remove WSGI-unsupportedhop-by-hop headers. Also there is a function to create HTTP headerstrings from the parsed data. werkzeug.http.is_entity_header(*header*) Check if a header is an entity header. 0.5 新版功能. | 参数: | **header** – the header to test. | |-----|-----| | 返回: | True if it's an entity header, False otherwise. | werkzeug.http.is_hop_by_hop_header(*header*) Check if a header is an HTTP/1.1 “Hop-by-Hop” header. 0.5 新版功能. | 参数: | **header** – the header to test. | |-----|-----| | 返回: | True if it's an entity header, False otherwise. | werkzeug.http.remove_entity_headers(*headers*, *allowed=('expires'*, *'content-location')*) Remove all entity headers from a list or Headers object. Thisoperation works in-place. Expires and Content-Location headers areby default not removed. The reason for this is [**RFC 2616**](http://tools.ietf.org/html/rfc2616.html) [http://tools.ietf.org/html/rfc2616.html] section10.3.5 which specifies some entity headers that should be sent. 在 0.5 版更改: added allowed parameter. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>headers</strong> – a list or <tt class="xref py py-class docutils literal"><span class="pre">Headers</span></tt> object.</li><li><strong>allowed</strong> – a list of headers that should still be allowed even thoughthey are entity headers.</li></ul></td></tr></tbody></table> werkzeug.http.remove_hop_by_hop_headers(*headers*) Remove all HTTP/1.1 “Hop-by-Hop” headers from a list orHeaders object. This operation works in-place. 0.5 新版功能. | 参数: | **headers** – a list or Headers object. | |-----|-----| werkzeug.http.is_byte_range_valid(*start*, *stop*, *length*) Checks if a given byte content range is valid for the given length. 0.7 新版功能. werkzeug.http.quote_header_value(*value*, *extra_chars=''*, *allow_token=True*) Quote a header value if necessary. 0.5 新版功能. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>value</strong> – the value to quote.</li><li><strong>extra_chars</strong> – a list of extra characters to skip quoting.</li><li><strong>allow_token</strong> – if this is enabled token values are returnedunchanged.</li></ul></td></tr></tbody></table> werkzeug.http.unquote_header_value(*value*, *is_filename=False*) Unquotes a header value. (Reversal of [quote_header_value()](# "werkzeug.http.quote_header_value")).This does not use the real unquoting but what browsers are actuallyusing for quoting. 0.5 新版功能. | 参数: | **value** – the header value to unquote. | |-----|-----| werkzeug.http.dump_header(*iterable*, *allow_token=True*) Dump an HTTP header again. This is the reversal of[parse_list_header()](# "werkzeug.http.parse_list_header"), [parse_set_header()](# "werkzeug.http.parse_set_header") and[parse_dict_header()](# "werkzeug.http.parse_dict_header"). This also quotes strings that include anequals sign unless you pass it as dict of key, value pairs. ~~~ >>> dump_header({'foo': 'bar baz'}) 'foo="bar baz"' >>> dump_header(('foo', 'bar baz')) 'foo, "bar baz"' ~~~ <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>iterable</strong> – the iterable or dict of values to quote.</li><li><strong>allow_token</strong> – if set to <cite>False</cite> tokens as values are disallowed.See <a class="reference internal" href="#werkzeug.http.quote_header_value" title="werkzeug.http.quote_header_value"><tt class="xref py py-func docutils literal"><span class="pre">quote_header_value()</span></tt></a> for more details.</li></ul></td></tr></tbody></table> ### Cookies werkzeug.http.parse_cookie(*header*, *charset='utf-8'*, *errors='replace'*, *cls=None*) Parse a cookie. Either from a string or WSGI environ. Per default encoding errors are ignored. If you want a different behavioryou can set errors to 'replace' or 'strict'. In strict mode aHTTPUnicodeError is raised. 在 0.5 版更改: This function now returns a TypeConversionDict instead of aregular dict. The cls parameter was added. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>header</strong> – the header to be used to parse the cookie. Alternativelythis can be a WSGI environment.</li><li><strong>charset</strong> – the charset for the cookie values.</li><li><strong>errors</strong> – the error behavior for the charset decoding.</li><li><strong>cls</strong> – an optional dict class to use. If this is not specifiedor <cite>None</cite> the default <tt class="xref py py-class docutils literal"><span class="pre">TypeConversionDict</span></tt> isused.</li></ul></td></tr></tbody></table> werkzeug.http.dump_cookie(*key*, *value=''*, *max_age=None*, *expires=None*, *path='/'*, *domain=None*, *secure=False*, *httponly=False*, *charset='utf-8'*, *sync_expires=True*) Creates a new Set-Cookie header without the Set-Cookie prefixThe parameters are the same as in the cookie Morsel object in thePython standard library but it accepts unicode data, too. On Python 3 the return value of this function will be a unicodestring, on Python 2 it will be a native string. In both cases thereturn value is usually restricted to ascii as the vast majority ofvalues are properly escaped, but that is no guarantee. If a unicodestring is returned it's tunneled through latin1 as required byPEP 3333. The return value is not ASCII safe if the key contains unicodecharacters. This is technically against the specification buthappens in the wild. It's strongly recommended to not usenon-ASCII values for the keys. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>max_age</strong> – should be a number of seconds, or <cite>None</cite> (default) ifthe cookie should last only as long as the client'sbrowser session. Additionally <cite>timedelta</cite> objectsare accepted, too.</li><li><strong>expires</strong> – should be a <cite>datetime</cite> object or unix timestamp.</li><li><strong>path</strong> – limits the cookie to a given path, per default it willspan the whole domain.</li><li><strong>domain</strong> – Use this if you want to set a cross-domain cookie. Forexample, <tt class="docutils literal"><span class="pre">domain=".example.com"</span></tt> will set a cookiethat is readable by the domain <tt class="docutils literal"><span class="pre">www.example.com</span></tt>,<tt class="docutils literal"><span class="pre">foo.example.com</span></tt> etc. Otherwise, a cookie will onlybe readable by the domain that set it.</li><li><strong>secure</strong> – The cookie will only be available via HTTPS</li><li><strong>httponly</strong> – disallow JavaScript to access the cookie. This is anextension to the cookie standard and probably notsupported by all browsers.</li><li><strong>charset</strong> – the encoding for unicode values.</li><li><strong>sync_expires</strong> – automatically set expires if max_age is definedbut expires not.</li></ul></td></tr></tbody></table> ### Conditional Response Helpers For conditional responses the following functions might be useful: werkzeug.http.parse_etags(*value*) Parse an etag header. | 参数: | **value** – the tag header to parse | |-----|-----| | 返回: | an [ETags](# "werkzeug.datastructures.ETags") object. | werkzeug.http.quote_etag(*etag*, *weak=False*) Quote an etag. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>etag</strong> – the etag to quote.</li><li><strong>weak</strong> – set to <cite>True</cite> to tag it “weak”.</li></ul></td></tr></tbody></table> werkzeug.http.unquote_etag(*etag*) Unquote a single etag: ~~~ >>> unquote_etag('w/"bar"') ('bar', True) >>> unquote_etag('"bar"') ('bar', False) ~~~ | 参数: | **etag** – the etag identifier to unquote. | |-----|-----| | 返回: | a (etag,weak) tuple. | werkzeug.http.generate_etag(*data*) Generate an etag for some data. werkzeug.http.is_resource_modified(*environ*, *etag=None*, *data=None*, *last_modified=None*) Convenience method for conditional requests. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple"><li><strong>environ</strong> – the WSGI environment of the request to be checked.</li><li><strong>etag</strong> – the etag for the response for comparison.</li><li><strong>data</strong> – or alternatively the data of the response to automaticallygenerate an etag using <a class="reference internal" href="#werkzeug.http.generate_etag" title="werkzeug.http.generate_etag"><tt class="xref py py-func docutils literal"><span class="pre">generate_etag()</span></tt></a>.</li><li><strong>last_modified</strong> – an optional date of the last modification.</li></ul></td></tr><tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last"><cite>True</cite> if the resource was modified, otherwise <cite>False</cite>.</p></td></tr></tbody></table> ### Constants werkzeug.http.HTTP_STATUS_CODES A dict of status code -> default status message pairs. This is usedby the wrappers and other places where an integer status code is expandedto a string throughout Werkzeug. ### Form Data Parsing Werkzeug provides the form parsing functions separately from the requestobject so that you can access form data from a plain WSGI environment. The following formats are currently supported by the form data parser: - application/x-www-form-urlencoded - multipart/form-data Nested multipart is not currently supported (Werkzeug 0.9), but it isn't usedby any of the modern web browsers. Usage example: ~~~ >>> from cStringIO import StringIO >>> data = '--foo\r\nContent-Disposition: form-data; name="test"\r\n' \ ... '\r\nHello World!\r\n--foo--' >>> environ = {'wsgi.input': StringIO(data), 'CONTENT_LENGTH': str(len(data)), ... 'CONTENT_TYPE': 'multipart/form-data; boundary=foo', ... 'REQUEST_METHOD': 'POST'} >>> stream, form, files = parse_form_data(environ) >>> stream.read() '' >>> form['test'] u'Hello World!' >>> not files True ~~~ Normally the WSGI environment is provided by the WSGI gateway with theincoming data as part of it. If you want to generate such fake-WSGIenvironments for unittesting you might want to use thecreate_environ() function or the EnvironBuilder instead. *class *werkzeug.formparser.FormDataParser(*stream_factory=None*, *charset='utf-8'*, *errors='replace'*, *max_form_memory_size=None*, *max_content_length=None*, *cls=None*, *silent=True*) This class implements parsing of form data for Werkzeug. By itselfit can parse multipart and url encoded form data. It can be subclassedand extended but for most mimetypes it is a better idea to use theuntouched stream and expose it as separate attributes on a requestobject. 0.8 新版功能. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>stream_factory</strong> – An optional callable that returns a new read andwriteable file descriptor. This callable worksthe same as <tt class="xref py py-meth docutils literal"><span class="pre">_get_file_stream()</span></tt>.</li><li><strong>charset</strong> – The character set for URL and url encoded form data.</li><li><strong>errors</strong> – The encoding error behavior.</li><li><strong>max_form_memory_size</strong> – the maximum number of bytes to be accepted forin-memory stored form data. If the dataexceeds the value specified an<tt class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></tt>exception is raised.</li><li><strong>max_content_length</strong> – If this is provided and the transmitted datais longer than this value an<tt class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></tt>exception is raised.</li><li><strong>cls</strong> – an optional dict class to use. If this is not specifiedor <cite>None</cite> the default <tt class="xref py py-class docutils literal"><span class="pre">MultiDict</span></tt> is used.</li><li><strong>silent</strong> – If set to False parsing errors will not be caught.</li></ul></td></tr></tbody></table> werkzeug.formparser.parse_form_data(*environ*, *stream_factory=None*, *charset='utf-8'*, *errors='replace'*, *max_form_memory_size=None*, *max_content_length=None*, *cls=None*, *silent=True*) Parse the form data in the environ and return it as tuple in the form(stream,form,files). You should only call this method if thetransport method is POST, PUT, or PATCH. If the mimetype of the data transmitted is multipart/form-data thefiles multidict will be filled with FileStorage objects. If themimetype is unknown the input stream is wrapped and returned as firstargument, else the stream is empty. This is a shortcut for the common usage of [FormDataParser](# "werkzeug.formparser.FormDataParser"). Have a look at [*Dealing with Request Data*](#) for more details. 0.5 新版功能: The max_form_memory_size, max_content_length andcls parameters were added. 0.5.1 新版功能: The optional silent flag was added. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple"><li><strong>environ</strong> – the WSGI environment to be used for parsing.</li><li><strong>stream_factory</strong> – An optional callable that returns a new read andwriteable file descriptor. This callable worksthe same as <tt class="xref py py-meth docutils literal"><span class="pre">_get_file_stream()</span></tt>.</li><li><strong>charset</strong> – The character set for URL and url encoded form data.</li><li><strong>errors</strong> – The encoding error behavior.</li><li><strong>max_form_memory_size</strong> – the maximum number of bytes to be accepted forin-memory stored form data. If the dataexceeds the value specified an<tt class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></tt>exception is raised.</li><li><strong>max_content_length</strong> – If this is provided and the transmitted datais longer than this value an<tt class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></tt>exception is raised.</li><li><strong>cls</strong> – an optional dict class to use. If this is not specifiedor <cite>None</cite> the default <tt class="xref py py-class docutils literal"><span class="pre">MultiDict</span></tt> is used.</li><li><strong>silent</strong> – If set to False parsing errors will not be caught.</li></ul></td></tr><tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">A tuple in the form <tt class="docutils literal"><span class="pre">(stream,</span> <span class="pre">form,</span> <span class="pre">files)</span></tt>.</p></td></tr></tbody></table> werkzeug.formparser.parse_multipart_headers(*iterable*) Parses multipart headers from an iterable that yields lines (includingthe trailing newline symbol). The iterable has to be newline terminated. The iterable will stop at the line where the headers ended so it can befurther consumed. | 参数: | **iterable** – iterable of strings that are newline terminated | |-----|-----|