-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, we were using Nengo core's Python 2/3 compatibility module, but Nengo core has dropped Python 2 support. Since we have not yet dropped Python 2 support, we add a `compat.py` module to handle the things that we use in Nengo GUI.
- Loading branch information
Showing
6 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import absolute_import | ||
|
||
import collections | ||
import sys | ||
|
||
import numpy as np | ||
|
||
# Only test for Python 2 so that we have less changes for Python 4 | ||
PY2 = sys.version_info[0] == 2 | ||
|
||
# If something's changed from Python 2 to 3, we handle that here | ||
if PY2: | ||
from cgi import escape as cgi_escape | ||
from StringIO import StringIO | ||
|
||
escape = lambda s, quote=True: cgi_escape(s, quote=quote) | ||
iteritems = lambda d: d.iteritems() | ||
|
||
string_types = (str, unicode) | ||
int_types = (int, long) | ||
range = xrange | ||
|
||
else: | ||
from html import escape | ||
from io import StringIO | ||
|
||
iteritems = lambda d: iter(d.items()) | ||
|
||
|
||
def is_iterable(obj): | ||
if isinstance(obj, np.ndarray): | ||
return obj.ndim > 0 # 0-d arrays give error if iterated over | ||
else: | ||
return isinstance(obj, collections.Iterable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters