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

Use of IterableUserDict and basestring incompatible with Python 3 #3

Open
SpotlightKid opened this issue Apr 16, 2014 · 0 comments
Open

Comments

@SpotlightKid
Copy link

flask_zodb.py uses the UserDict.IterableUserDict class, which is replaced by collections.UserDict in Python 3.

Also, the ZODB.create_db method uses basestring, which is unavailable in Python.

This can be fixed easily with the following patch (I'll also make a pull request), making Flask-ZODB work with Python 3:

diff --git a/flask_zodb.py b/flask_zodb.py
index a950cf1..5c9f582 100644
--- a/flask_zodb.py
+++ b/flask_zodb.py
@@ -2,7 +2,11 @@ import flask
 import transaction
 import zodburi

-from UserDict import IterableUserDict
+try:
+    from collections import UserDict
+except ImportError: # for Python 2
+    from UserDict import IterableUserDict as UserDict
+
 from ZODB.DB import DB
 from contextlib import contextmanager, closing
 from werkzeug.utils import cached_property
@@ -12,11 +16,17 @@ from persistent import Persistent as Object
 from persistent.list import PersistentList as List
 from persistent.mapping import PersistentMapping as Dict

+# Python 3 compatibility
+try:
+    basestring
+except NameError:
+    basestring = str
+

 __all__ = ['ZODB', 'Object', 'List', 'Dict', 'BTree']


-class ZODB(IterableUserDict):
+class ZODB(UserDict):
     """Extension object.  Behaves as the root object of the storage during
     requests, i.e. a `~persistent.mapping.PersistentMapping`.
@SpotlightKid SpotlightKid changed the title Use of IterableUserDict and basestring incompatible with Python 3 Use of IterableUserDict and basestring incompatible with Python 3 Apr 16, 2014
SpotlightKid added a commit to SpotlightKid/flask-zodb that referenced this issue Apr 16, 2014
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

1 participant