Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 bugs remain for python 3.10 #520

Open
retsyo opened this issue Jul 18, 2023 · 1 comment
Open

2 bugs remain for python 3.10 #520

retsyo opened this issue Jul 18, 2023 · 1 comment

Comments

@retsyo
Copy link

retsyo commented Jul 18, 2023

  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
@burnpanck
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants