Suggested Fixes for Python 3
Opened this issue · 4 comments
I'm sure this has been out of production for a while, so I've rewritten some parts for my purposes, but for anyone coming across this who wants to use the code in Python3:
- in the init file, add a "." before the file names, i.e.
from .description import Description
. Also do this for all imports of files in the other files. - most of the URL-based packages have been split across various subpackages, so change things to the more modern
from urllib.request import urlopen
orurllib.request as Request
orimport urllib.parse as urlparse
(theas
in these examples makes it so you don't have to replace every individual issue). - strings associated with errors need to be in parenthetical now, such as
raise AttributeError("object has no attribute '%s'" % key)
. - the
<>
operator has been retired. Thank god for this one, but it took me a while to find out what the hell the operator is, since most modern documentation on operators doesn't even mention it... Anyway,<>
is equivalent to!=
so you can simply replace them. - When naming exceptions, the correct syntax is now
except Exception as e:
- Obviously, print statements now need parenthesis so add those where necessary.
sgmllib
doesn't exist for Python3 so tryfrom html.parser import HTMLParser as sgmllib
.rfc822
is nowemail.utils.getaddresses
.- change
StringIO
tofrom io import StringIO
... And that's the point where I gave up, wasn't quite able to mitigate all the issues with changing the SGMLParser to HTMLParser. If anyone figures out how to do it exactly, please post as a response. Otherwise, I'll just create a workaround this program for Python3 (and honestly that's probably what I'd suggest).
@Superraptor , how did you go creating a workaround ?
https://pypi.org/project/pyops/ by @devsf looks like a reasonable attempt at creating a new opensearch library.
Hi @jayvdb @Superraptor ! Yes, 'attempt' is the right word. Currently I'm using it, but it's not perfect and it can be improved a lot!
I was able to get this package to pass all of its tests on Python 3 by de-vendoring feedparser and using python-modernize
.
A pull request for that would be welcome.