Skip to content

2 bugs remain for python 3.10 #520

Open

Description

@retsyo
  1. cgi.escape is deprecated in python 3.4 #330
    as the post says, maybe we can change remi.gui.py:
    from
import cgi
escape = cgi.escape

to

try:
    import cgi
    escape = cgi.escape
except:
    import html
    escape = html.escape
  1. windows 10 + python 3.9: AttributeError: 'HTMLParser' object has no attribute 'unescape' #412
    now we should change remi.gui.py:
    from
except ImportError:
    # Python 3
    try:
        from html.parser import HTMLParser
        h = HTMLParser()
        unescape = h.unescape
    except ImportError:
        # Python 3.4+
        import html
        unescape = html.unescape

which says

  File "e:\prg\py\winpython\python-3.10.9.amd64\lib\site-packages\remi-1.2.2-py3.10.egg\remi\gui.py", line 30, in <module>
    from HTMLParser import HTMLParser
ModuleNotFoundError: No module named 'HTMLParser'

to

except ImportError:
    # Python 3
    try:
        from html.parser import HTMLParser
        h = HTMLParser()
        unescape = h.unescape
    except:
        # Python 3.4+
        import html
        unescape = html.unescape

Activity

  1. burnpanck commented on Apr 18, 2024

    @burnpanck

    There are very few cases where except: is a good solution, and even less of those where you are not going to re-raise the exception afterwards. Also, I suggest to reverse the order of trials; first check for the newer solution, then fall back to the old, rather than vice-versa. For the second problem, you could do, for example:

    except ImportError:
        # Python 3
        try:
            # Python 3.4+
            import html
            unescape = html.unescape
        except (AttributeError, ImportError):
            from html.parser import HTMLParser
            h = HTMLParser()
            unescape = h.unescape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions