You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/changelog.rst
+8-4
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,19 @@ Release Notes
8
8
Release 0.14 (in development)
9
9
=============================
10
10
11
-
.. rubric:: Removed APIs (deprecated since 0.13)
11
+
.. rubric:: Removed APIs
12
12
13
-
* Dropped support for Python 2 and removed helpers and workarounds that only make sense in a Python 2/3 dual codebase (e.g. ``tonat()`` or the ``py3k`` flag).
13
+
* Dropped support for Python 2 and removed workarounds or helpers that only make sense in a Python 2/3 dual codebase.
14
14
* Removed the ``RouteReset`` exception and associated logic.
15
15
* Removed the `bottle.py` console script entrypoint in favour of the new `bottle` script. You can still execute `bottle.py` directly or via `python -m bottle`. The only change is that the command installed by pip or similar tools into the bin/Scripts folder of the (virtual) environment is now called `bottle` to avoid circular import errors.
16
16
17
-
.. rubric:: Changes
17
+
.. rubric:: Changed APIs
18
+
19
+
* ``bottle.FormsDict`` no longer translates between PEP-3333 `latin1` and the correct `utf8` encoding on demand. The `getunicode()` and `decode()` methods are deprecated and do nothing, as all values are already decoded correctly.
20
+
21
+
.. rubric:: New features
18
22
19
-
* ``bottle.HTTPError`` raised on Invalid JSON now include the underlying exception in their ``exception`` field.
23
+
* ``bottle.HTTPError`` raised on Invalid JSON now include the underlying exception in the ``exception`` field.
Copy file name to clipboardexpand all lines: docs/tutorial.rst
+3-13
Original file line number
Diff line number
Diff line change
@@ -552,28 +552,18 @@ Property Data source
552
552
553
553
Bottle uses a special type of dictionary to store those parameters. :class:`FormsDict` behaves like a normal dictionary, but has some additional features to make your life easier.
554
554
555
-
First of all, :class:`FormsDict` is a subclass of :class:`MultiDict` and can store more than one value per key. The standard dictionary access methods will only return the first of many values, but the :meth:`MultiDict.getall` method returns a (possibly empty) list of all values for a specific key::
555
+
First of all, :class:`FormsDict` is a subclass of :class:`MultiDict` and can store more than one value per key. Only the first value is returned by default, but :meth:`MultiDict.getall` can be used to get a (possibly empty) list of all values for a specific key::
556
556
557
557
for choice in request.forms.getall('multiple_choice'):
558
558
do_something(choice)
559
559
560
-
To simplify dealing with lots of unreliable user input, :class:`FormsDict` exposes all its values as attributes, but with a twist: These virtual attributes always return properly encoded unicode strings, even if the value is missing or character decoding fails. They never return ``None`` or throw an exception, but return an empty string instead::
560
+
Attribute-like access is also supported, returning empty strings for missing values. This simplifies code a lot whend ealing with lots of optional attributes::
561
561
562
562
name = request.query.name # may be an empty string
563
563
564
564
.. rubric:: A word on unicode and character encodings
565
565
566
-
HTTP is a byte-based wire protocol. The server has to decode byte strings somehow before they are passed to the application. To be on the safe side, WSGI suggests ISO-8859-1 (aka latin1), a reversible single-byte codec that can be re-encoded with a different encoding later. Bottle does that for :meth:`FormsDict.getunicode` and attribute access, but not for :meth:`FormsDict.get` or item-access. These return the unchanged values as provided by the server implementation, which is probably not what you want.
567
-
568
-
::
569
-
570
-
>>> request.query['city']
571
-
'Göttingen' # An utf8 string provisionally decoded as ISO-8859-1 by the server
572
-
>>> request.query.city
573
-
'Göttingen' # The same string correctly re-encoded as utf8 by bottle
574
-
575
-
If you need the whole dictionary with correctly decoded values (e.g. for WTForms), you can call :meth:`FormsDict.decode` to get a fully re-encoded copy.
576
-
566
+
Unicode characters in the request path, query parameters or cookies are a bit tricky. HTTP is a very old byte-based protocol that predates unicode and lacks explicit encoding information. This is why WSGI servers have to fall back on `ISO-8859-1` (aka `latin1`, a reversible input encoding) for those estrings. Modern browsers default to `utf8`, though. It's a bit much to ask application developers to translate every single user input string to the correct encoding manually. Bottle makes this easy and just assumes `utf8` for everything. All strings returned by Bottle APIs support the full range of unicode characters, as long as the webpage or HTTP client follows best practices and does not break with established standards.
0 commit comments