comparison MoinMoin/support/werkzeug/test.py @ 6129:7f12cf241d5e

update werkzeug to 0.12.1, update CHANGES
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 11 Apr 2017 22:42:23 +0200
parents 9f12f41504fc
children
comparison
equal deleted inserted replaced
6128:561b7a9c2bd9 6129:7f12cf241d5e
190 U2Request(get_current_url(environ)), 190 U2Request(get_current_url(environ)),
191 ) 191 )
192 192
193 193
194 def _iter_data(data): 194 def _iter_data(data):
195 """Iterates over a dict or multidict yielding all keys and values. 195 """Iterates over a `dict` or :class:`MultiDict` yielding all keys and
196 values.
196 This is used to iterate over the data passed to the 197 This is used to iterate over the data passed to the
197 :class:`EnvironBuilder`. 198 :class:`EnvironBuilder`.
198 """ 199 """
199 if isinstance(data, MultiDict): 200 if isinstance(data, MultiDict):
200 for key, values in iterlists(data): 201 for key, values in iterlists(data):
224 other with the :attr:`form` and :attr:`files` attributes, but are 225 other with the :attr:`form` and :attr:`files` attributes, but are
225 passed with the same argument to the constructor: `data`. 226 passed with the same argument to the constructor: `data`.
226 227
227 `data` can be any of these values: 228 `data` can be any of these values:
228 229
229 - a `str`: If it's a string it is converted into a :attr:`input_stream`, 230 - a `str` or `bytes` object: The object is converted into an
230 the :attr:`content_length` is set and you have to provide a 231 :attr:`input_stream`, the :attr:`content_length` is set and you have to
231 :attr:`content_type`. 232 provide a :attr:`content_type`.
232 - a `dict`: If it's a dict the keys have to be strings and the values 233 - a `dict` or :class:`MultiDict`: The keys have to be strings. The values
233 any of the following objects: 234 have to be either any of the following objects, or a list of any of the
234 235 following objects:
235 - a :class:`file`-like object. These are converted into 236
237 - a :class:`file`-like object: These are converted into
236 :class:`FileStorage` objects automatically. 238 :class:`FileStorage` objects automatically.
237 - a tuple. The :meth:`~FileMultiDict.add_file` method is called 239 - a `tuple`: The :meth:`~FileMultiDict.add_file` method is called
238 with the tuple items as positional arguments. 240 with the key and the unpacked `tuple` items as positional
241 arguments.
242 - a `str`: The string is set as form data for the associated key.
243 - a file-like object: The object content is loaded in memory and then
244 handled like a regular `str` or a `bytes`.
239 245
240 .. versionadded:: 0.6 246 .. versionadded:: 0.6
241 `path` and `base_url` can now be unicode strings that are encoded using 247 `path` and `base_url` can now be unicode strings that are encoded using
242 the :func:`iri_to_uri` function. 248 the :func:`iri_to_uri` function.
243 249
264 `wsgi.errors`. Defaults to :data:`stderr`. 270 `wsgi.errors`. Defaults to :data:`stderr`.
265 :param multithread: controls `wsgi.multithread`. Defaults to `False`. 271 :param multithread: controls `wsgi.multithread`. Defaults to `False`.
266 :param multiprocess: controls `wsgi.multiprocess`. Defaults to `False`. 272 :param multiprocess: controls `wsgi.multiprocess`. Defaults to `False`.
267 :param run_once: controls `wsgi.run_once`. Defaults to `False`. 273 :param run_once: controls `wsgi.run_once`. Defaults to `False`.
268 :param headers: an optional list or :class:`Headers` object of headers. 274 :param headers: an optional list or :class:`Headers` object of headers.
269 :param data: a string or dict of form data. See explanation above. 275 :param data: a string or dict of form data or a file-object.
276 See explanation above.
270 :param environ_base: an optional dict of environment defaults. 277 :param environ_base: an optional dict of environment defaults.
271 :param environ_overrides: an optional dict of environment overrides. 278 :param environ_overrides: an optional dict of environment overrides.
272 :param charset: the charset used to encode unicode data. 279 :param charset: the charset used to encode unicode data.
273 """ 280 """
274 281
323 self.closed = False 330 self.closed = False
324 331
325 if data: 332 if data:
326 if input_stream is not None: 333 if input_stream is not None:
327 raise TypeError('can\'t provide input stream and data') 334 raise TypeError('can\'t provide input stream and data')
335 if hasattr(data, 'read'):
336 data = data.read()
328 if isinstance(data, text_type): 337 if isinstance(data, text_type):
329 data = data.encode(self.charset) 338 data = data.encode(self.charset)
330 if isinstance(data, bytes): 339 if isinstance(data, bytes):
331 self.input_stream = BytesIO(data) 340 self.input_stream = BytesIO(data)
332 if self.content_length is None: 341 if self.content_length is None:
431 return rv 440 return rv
432 441
433 def setter(self, value): 442 def setter(self, value):
434 self._input_stream = None 443 self._input_stream = None
435 setattr(self, key, value) 444 setattr(self, key, value)
436 return property(getter, setter, doc) 445 return property(getter, setter, doc=doc)
437 446
438 form = form_property('form', MultiDict, doc=''' 447 form = form_property('form', MultiDict, doc='''
439 A :class:`MultiDict` of form values.''') 448 A :class:`MultiDict` of form values.''')
440 files = form_property('files', FileMultiDict, doc=''' 449 files = form_property('files', FileMultiDict, doc='''
441 A :class:`FileMultiDict` of uploaded files. You can use the 450 A :class:`FileMultiDict` of uploaded files. You can use the
677 scheme, netloc, script_root, qs, anchor = url_parse(new_location) 686 scheme, netloc, script_root, qs, anchor = url_parse(new_location)
678 base_url = url_unparse((scheme, netloc, '', '', '')).rstrip('/') + '/' 687 base_url = url_unparse((scheme, netloc, '', '', '')).rstrip('/') + '/'
679 688
680 cur_server_name = netloc.split(':', 1)[0].split('.') 689 cur_server_name = netloc.split(':', 1)[0].split('.')
681 real_server_name = get_host(environ).rsplit(':', 1)[0].split('.') 690 real_server_name = get_host(environ).rsplit(':', 1)[0].split('.')
691 if cur_server_name == ['']:
692 # this is a local redirect having autocorrect_location_header=False
693 cur_server_name = real_server_name
694 base_url = EnvironBuilder(environ).base_url
682 695
683 if self.allow_subdomain_redirects: 696 if self.allow_subdomain_redirects:
684 allowed = cur_server_name[-len(real_server_name):] == real_server_name 697 allowed = cur_server_name[-len(real_server_name):] == real_server_name
685 else: 698 else:
686 allowed = cur_server_name == real_server_name 699 allowed = cur_server_name == real_server_name