diff options
author | Emilio Pozuelo Monfort <pochu@debian.org> | 2020-07-16 13:16:14 +0200 |
---|---|---|
committer | Emilio Pozuelo Monfort <pochu@debian.org> | 2020-07-29 10:20:33 +0200 |
commit | 37e775cc5d145a4e5c573278c694a098b6c10066 (patch) | |
tree | 8fcba54391f63a94754cda64eeec6c598548e662 /lib/python/web_support.py | |
parent | 98dbd1d464037d7e15773c28ec93075d75213be2 (diff) |
lib/python: use isinstance rather than types
types.TypeFoo are gone in python3.
Diffstat (limited to 'lib/python/web_support.py')
-rw-r--r-- | lib/python/web_support.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/python/web_support.py b/lib/python/web_support.py index 116cbec2be..37d36d037b 100644 --- a/lib/python/web_support.py +++ b/lib/python/web_support.py @@ -24,12 +24,13 @@ import struct import sys import grp import traceback -import types import urllib import threading import SocketServer import BaseHTTPServer +from helpers import isstring + class ServinvokeError(Exception): pass @@ -164,7 +165,7 @@ class URLFactory: for (key, value) in args.items(): if value is None: continue - if type(value) not in (types.ListType, types.TupleType): + if not isinstance(value, (list, tuple)): value = (value,) for v in value: arglist.append("%s=%s" % (urllib.quote(key), @@ -268,8 +269,6 @@ class VerbatimHTML(HTMLBase): def flatten(self, write): write(self.__contents) -_string_types = (types.StringType, types.UnicodeType) - class Compose(HTMLBase): """Glues a sequence of HTML snippets together, without enclosing it in a tag.""" @@ -278,7 +277,7 @@ class Compose(HTMLBase): def flatten(self, write): for x in self.__contents: - if type(x) in _string_types: + if isstring(x): write(escapeHTML(x)) else: x.flatten(write) @@ -325,7 +324,7 @@ class Tag(HTMLBase): closing = "</%s>" % self.__name try: for x in self.contents: - if type(x) in _string_types: + if isstring(x): write(escapeHTML(x)) else: x.flatten(write) @@ -494,7 +493,7 @@ def make_menu(convert, *entries): ul = [] append = ul.append for e in entries: - if type(e) == types.TupleType: + if isinstance(e, tuple): (relurl, label) = e append(LI(A(convert(relurl), label))) else: @@ -512,7 +511,7 @@ def make_numbered_list(entries): def make_list(lst, separator=", "): """Creates a list of HTML elements.""" - assert type(lst) != types.StringType + assert not isstring(lst) c = [] if lst: append = c.append @@ -657,9 +656,12 @@ class HTMLResult(Result): buf.write(self.doctype) buf.write('\n') def write_both(s): - if type(s) == types.UnicodeType: - buf.write(s.encode('UTF-8')) - else: + try: + if isinstance(s, unicode): + s = s.encode('UTF-8') + except: + pass + finally: buf.write(s) self.contents.flatten(write_both) buf = buf.getvalue() |