[Python-checkins] Remove python2 support in logging cookbook example. (GH-32362)
vsajip
webhook-mailer at python.org
Wed Apr 6 12:57:58 EDT 2022
https://github.com/python/cpython/commit/f82f9ce3239b9a7e6ffa278658dd9858f64a3c14
commit: f82f9ce3239b9a7e6ffa278658dd9858f64a3c14
branch: main
author: Mathieu Dupuy <mathieu.dupuy at critizr.com>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022-04-06T17:57:54+01:00
summary:
Remove python2 support in logging cookbook example. (GH-32362)
files:
M Doc/howto/logging-cookbook.rst
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst
index f0d944940fc28..704279240b357 100644
--- a/Doc/howto/logging-cookbook.rst
+++ b/Doc/howto/logging-cookbook.rst
@@ -1788,22 +1788,15 @@ Python used.
If you need more specialised processing, you can use a custom JSON encoder,
as in the following complete example::
- from __future__ import unicode_literals
-
import json
import logging
- # This next bit is to ensure the script runs unchanged on 2.x and 3.x
- try:
- unicode
- except NameError:
- unicode = str
class Encoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, set):
return tuple(o)
- elif isinstance(o, unicode):
+ elif isinstance(o, str):
return o.encode('unicode_escape').decode('ascii')
return super().default(o)
More information about the Python-checkins
mailing list