[ Pobierz całość w formacie PDF ]
.13.7 Form Data ParsingWerkzeug provides the form parsing functions separately from the request object sothat 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-dataNested multipart is not currently supported (Werkzeug 0.9), but it isn t used by any ofthe 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 filesTrueNormally the WSGI environment is provided by the WSGI gateway with the incomingdata as part of it.If you want to generate such fake-WSGI environments for unittestingyou might want to use thecreate_environ()function or theEnvironBuilderinstead.classwerkzeug.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 itself it can parsemultipart and url encoded form data.It can be subclassed and extended but formost mimetypes it is a better idea to use the untouched stream and expose it asseparate attributes on a request object.New in version 0.8.105 Parameters" stream_factory  An optional callable that returns a new readand writeable file descriptor.This callable works the same as_get_file_stream()." charset  The character set for URL and url encoded form data." errors  The encoding error behavior." max_form_memory_size  the maximum number of bytes tobe accepted for in-memory stored form data.If the data ex-ceeds the value specified anRequestEntityTooLargeexceptionis raised." max_content_length  If this is provided and the transmitteddata is longer than this value anRequestEntityTooLargeex-ception is raised." cls  an optional dict class to use.If this is not specified or Nonethe defaultMultiDictis used." silent  If set to False parsing errors will not be caught.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 the transport method is POST,PUT, or PATCH.If the mimetype of the data transmitted is multipart/form-data the files multidictwill be filled with FileStorage objects.If the mimetype is unknown the inputstream is wrapped and returned as first argument, else the stream is empty.This is a shortcut for the common usage ofFormDataParser.Have a look at Dealing with Request Data for more details.New in version 0.5: Themax_form_memory_size, max_content_length and cls parameters were added.Newin version 0.5.1: The optional silent flag was added.Parameters" environ  the WSGI environment to be used for parsing." stream_factory  An optional callable that returns a new readand writeable file descriptor.This callable works the same as_get_file_stream()." charset  The character set for URL and url encoded form data." errors  The encoding error behavior." max_form_memory_size  the maximum number of bytes tobe accepted for in-memory stored form data.If the data ex-106 ceeds the value specified anRequestEntityTooLargeexceptionis raised." max_content_length  If this is provided and the transmitteddata is longer than this value anRequestEntityTooLargeex-ception is raised." cls  an optional dict class to use.If this is not specified or Nonethe defaultMultiDictis used." silent  If set to False parsing errors will not be caught.Returns A tuple in the form(stream, form, files).werkzeug.formparser.parse_multipart_headers(iterable)Parses multipart headers from an iterable that yields lines (including the trailingnewline symbol).The iterable has to be newline terminated.The iterable will stop at the line where the headers ended so it can be furtherconsumed.Parameters iterable  iterable of strings that are newline terminated107 108 CHAPTERFOURTEENDATA STRUCTURESWerkzeug provides some subclasses of common Python objects to extend them withadditional features.Some of them are used to make them immutable, others are usedto change some semantics to better work with HTTP.14.1 General PurposeChanged in version 0.6: The general purpose classes are now pickleable in each proto-col as long as the contained objects are pickleable.This means that theFileMultiDictwon t be pickleable as soon as it contains a file.classwerkzeug.datastructures.TypeConversionDictWorks like a regular dict but theget()method can perform type conversions.MultiDictandCombinedMultiDictare subclasses of this class and provide thesame feature.New in version 0.5.get(key, default=None, type=None)Return the default value if the requested data doesn t exist [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • gieldaklubu.keep.pl
  •