Commits

Anonymous committed 44bad8d

Modifications for Python 3.

Comments (0)

Files changed (4)

     print('Cython.Distuils not found, not building C-extension')
 
 setup(name="ws_seq_type",
-      version="0.1.0",
+      version="0.1.1",
       description="fast isstring/sequence_type",
       url="http://bitbucket.org/wolfmanx/ws_seq_type",
 #      download_url="http://projects.bigasterisk.com/xtest-1.21.tar.gz",
 # :ide: COMPILE: sdist
 # . (progn (save-buffer) (compile (concat "python ./setup.py sdist")))
 
+# :ide: COMPILE: build3
+# . (progn (save-buffer) (compile (concat "python3 ./setup.py build")))
+
 # :ide: COMPILE: build
 # . (progn (save-buffer) (compile (concat "python ./setup.py build")))
 if globals().get('_is_main_', (__name__ == '__main__')):
     import os
     sys.path.insert(0, os.path.abspath(os.path.join(os.path.curdir)))
-    sys.path.insert(0, os.path.abspath(os.path.join('build', 'lib.linux-x86_64-2.7')))
+    py_ver = str(sys.version_info[0]) + '.' + str(sys.version_info[1])
+    machine = os.uname()[4]
+    build_path = os.path.abspath(os.path.join('build', 'lib.linux-' + machine + '-' + py_ver))
+    printe(sformat(
+        "{0}{3:^{1}} {4:<{2}s}: ]{5!s}[",
+        dbg_comm, dbg_twid, dbg_fwid, ':DBG:', 'build_path', build_path))
+    sys.path.insert(0, build_path)
 
 from ws_seq_type import p_isstring, p_issequence, p_sequence_type
 from ws_seq_type import c_isstring, c_issequence, c_sequence_type
 # along with this program. If not, see <http://www.gnu.org/licenses/>,
 # or write to Wolfgang Scherer, <Wolfgang.Scherer at gmx.de>
 
-# (progn (forward-line 1) (snip-insert-mode "py.f.isstring" t) (insert "\n"))
-# hide from 2to3
-# exec('''
-# def isstring(obj):
-#     return isinstance(obj, basestring)
-# ''')
-# try:
-#     isstring("")
-# except NameError:
-#     def isstring(obj):
-#         return isinstance(obj, str) or isinstance(obj, bytes)
-
-from cpython cimport PySequence_Check, PyUnicode_Check
-from cpython.string cimport PyString_Check
+from cpython cimport PySequence_Check, PyUnicode_Check, PyBytes_Check, PyString_Check
 
 def isstring(obj):
-    # PyString_Check aliased to PyBytes_Check in Py 3.x
-    return PyString_Check(obj) or PyUnicode_Check(obj)
+    '''String, i.e. bytes or unicode.'''
+    # PyBytes_Check aliased to PyString_Check in Py 2.x
+    return PyBytes_Check(obj) or PyUnicode_Check(obj)
 
 def issequence(obj, or_dict=False):                      # ||:fnc:||
     '''Not a string. Either a sequence (aka. list, tuple) or a mapping (aka. dict).'''
-    if not (PyString_Check(obj) or PyUnicode_Check(obj)):
+    if not (PyUnicode_Check(obj) or PyBytes_Check(obj)):
         if hasattr(obj, 'items'):
             return or_dict
         return PySequence_Check(obj)
 
 def sequence_type(obj):                                  # ||:fnc:||
     '''is_string, is_list, is_dict = sequence_type(obj).'''
-
-    if (PyString_Check(obj) or PyUnicode_Check(obj)):
+    if (PyUnicode_Check(obj) or PyBytes_Check(obj)):
         return _st_strg;
-
     if hasattr(obj, 'items'):
         return _st_dict
-
     if PySequence_Check(obj):
         return _st_list
-
-    # try:
-    #     for elt in obj:
-    #         break
-    #     return _st_list
-    # except TypeError:
-    #     pass
-
     return _st_none
 
 # :ide: COMPILE: Run w/o args
 # . (progn (save-buffer) (compile (concat "python ./" (file-name-nondirectory (buffer-file-name)) " ")))
 
-# :ide: COMPILE: install
-# . (progn (save-buffer) (compile (concat "python ./setup.py install")))
-
-# :ide: COMPILE: bdist_egg
-# . (progn (save-buffer) (compile (concat "python ./setup.py bdist_egg")))
-
-# :ide: COMPILE: sdist
-# . (progn (save-buffer) (compile (concat "python ./setup.py sdist")))
-
 # :ide: COMPILE: build
 # . (progn (save-buffer) (compile (concat "python ./setup.py build")))
 

ws_seq_type/__init__.py

     return _st_none
 
 try:
-    from ws_seq_type_ import isstring as c_isstring
-    from ws_seq_type_ import issequence as c_issequence
-    from ws_seq_type_ import sequence_type as c_sequence_type
+    from .ws_seq_type_ import isstring as c_isstring
+    from .ws_seq_type_ import issequence as c_issequence
+    from .ws_seq_type_ import sequence_type as c_sequence_type
+except ImportError:
+    pass
+
+if 'c_isstring' not in globals():
+    try:
+        from ws_seq_type_ import isstring as c_isstring
+        from ws_seq_type_ import issequence as c_issequence
+        from ws_seq_type_ import sequence_type as c_sequence_type
+    except ImportError:
+        pass
+
+if 'c_isstring' in globals():
     if globals().get('_is_main_', (__name__ == '__main__')):
         printf('using C')
     isstring = c_isstring
     issequence = c_issequence
     sequence_type = c_sequence_type
-except ImportError:
+else:
     if globals().get('_is_main_', (__name__ == '__main__')):
         printf('using Py')
     isstring = p_isstring