summaryrefslogtreecommitdiff
path: root/urwid/html_fragment.py
diff options
context:
space:
mode:
authorAlexey Stepanov <penguinolog@users.noreply.github.com>2023-03-31 17:08:50 +0200
committerGitHub <noreply@github.com>2023-03-31 17:08:50 +0200
commitea7e615ef5ee0897f66210f47ab6390889d7b313 (patch)
treed627570bacd90fb347f684c76c52b6c1065a9c41 /urwid/html_fragment.py
parent07621f1c8cc8bd88e55a3c3e48861c65f293b3f1 (diff)
downloadurwid-ea7e615ef5ee0897f66210f47ab6390889d7b313.tar.gz
Python 37+ initial migration (#522)
* Initial migration to the python 3.7: Semi-automatic changes CI related: Update `tox.ini` and `.travis.yml` to run python3 only tests Python 3.11 tests is commented-out on travis until #517 is not merged Manual changes: * `setup.py`: classifiers, remove python2 compatibility code * `docs/manual/wcur2.py`: looks like file was never completed, syntax is invalid * `urwid.compat`: removed `ord2`, `bytes3`, `text_type`, `xrange` and `text_types` Automatic changes (no manual editing, AST validated equality: * removed `u` prefix from all strings: not allowed in modern python code * `bytes()` -> `b''` * `== None` -> `is None` * subclassing of `object` * `super(<Class>`, self>)` ->`super()` * `from __future__ import ...` python3 compatibility imports * `set(<Iterable[Hashable]>)` -> `{<Hashable>}` * partial f-strings conversion * (`IOError`, `select.error`, `socket.error`) -> `OSError` * Switch to f-strings (automatic changes) * Remove `urwid.compat.B` * Remove `urwid.compat.with_metaclass` * use native `super()` instead of `self.__super` * Remove `urwid.compat.chr2` * Remove `urwid.split_repr.python3_repr` * Use native `@classmethod` and `@property` where overload is not possible * Add `from __future__ import annotations` * automatically sort imports * Add DeprecationWarning to the deprecated methods most IDE's will recognize it and annotate during new code usage call with "warnings as errors" mode will help to refactor other users * Address comments * replace homepage address in all files * remove outdated comments in compat.py * make wcur2.py correct python code. For example subclass * replace `self.__super` by `super()` in examples * fix asyncio_socket_server.py: magic with `asyncio` became wrong * Remove `widget.update_wrapper`: this was backport of python `functools.update_wrapper` * display_common.py: fix trivial typo in _colors calculation * use `sorted` method instead of list construction with later sorting * Address comments * `wcur2` include in docs * warning on `signals.Signals.emit` --------- Co-authored-by: Aleksei Stepanov <alekseis@nvidia.com>
Diffstat (limited to 'urwid/html_fragment.py')
-rwxr-xr-xurwid/html_fragment.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/urwid/html_fragment.py b/urwid/html_fragment.py
index 5df9273..b14c57f 100755
--- a/urwid/html_fragment.py
+++ b/urwid/html_fragment.py
@@ -17,18 +17,18 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# Urwid web site: http://excess.org/urwid/
+# Urwid web site: https://urwid.org/
-from __future__ import division, print_function
"""
HTML PRE-based UI implementation
"""
+from __future__ import annotations
+
from urwid import util
-from urwid.main_loop import ExitMainLoop
from urwid.display_common import AttrSpec, BaseScreen
-
+from urwid.main_loop import ExitMainLoop
# replace control characters with ?'s
_trans_table = "?" * 32 + "".join([chr(x) for x in range(32, 256)])
@@ -47,7 +47,7 @@ class HtmlGenerator(BaseScreen):
started = True
def __init__(self):
- super(HtmlGenerator, self).__init__()
+ super().__init__()
self.colors = 16
self.bright_is_bold = False # ignored
self.has_underline = True # ignored
@@ -124,7 +124,7 @@ class HtmlGenerator(BaseScreen):
l.append("\n")
# add the fragment to the list
- self.fragments.append( "<pre>%s</pre>" % "".join(l) )
+ self.fragments.append( f"<pre>{''.join(l)}</pre>" )
def clear(self):
"""
@@ -160,8 +160,8 @@ def html_span(s, aspec, cursor = -1):
fg_r, fg_g, fg_b = _d_fg_r, _d_fg_g, _d_fg_b
if bg_r is None:
bg_r, bg_g, bg_b = _d_bg_r, _d_bg_g, _d_bg_b
- html_fg = "#%02x%02x%02x" % (fg_r, fg_g, fg_b)
- html_bg = "#%02x%02x%02x" % (bg_r, bg_g, bg_b)
+ html_fg = f"#{fg_r:02x}{fg_g:02x}{fg_b:02x}"
+ html_bg = f"#{bg_r:02x}{bg_g:02x}{bg_b:02x}"
if aspec.standout:
html_fg, html_bg = html_bg, html_fg
extra = (";text-decoration:underline" * aspec.underline +