Commit 1161ec14 authored by Eckhart Arnold's avatar Eckhart Arnold

cython compatibility

parent e1092e1b
......@@ -9,7 +9,7 @@ cdef class Node:
cdef public object _result
cdef public tuple children
cdef public str tag_name
cdef object _xml_attr
cdef public object _xml_attr
# cpdef equals(self, other, ignore_attr_order)
# cpdef get(self, index_or_tagname, surrogate)
......
......@@ -36,7 +36,6 @@ from DHParser.error import Error, ErrorCode, linebreaks, line_col
from DHParser.stringview import StringView # , real_indices
from DHParser.toolkit import re, cython
__all__ = ('WHITESPACE_PTYPE',
'TOKEN_PTYPE',
'REGEXP_PTYPE',
......@@ -486,8 +485,6 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
existence of any attributes.
"""
try:
if self._xml_attr is None: # cython compatibility
return False
return attr in self._xml_attr if bool(attr) else bool(self._xml_attr)
except (AttributeError, TypeError):
return False
......
......@@ -581,26 +581,15 @@ def swap_attributes(node: Node, other: Node):
NA = node.has_attr()
OA = other.has_attr()
if NA or OA:
try:
save = node._xml_attr if NA else None
if OA:
node._xml_attr = other._xml_attr
elif NA:
node._xml_attr = None
if NA:
other._xml_attr = save
elif OA:
other._xml_attr = None
except AttributeError: # cython compatibility
save = node.attr if NA else None
if OA:
node.attr = other.attr
elif NA:
node.attr = None
if NA:
other.attr = save
elif OA:
other.attr = None
save = node._xml_attr if NA else None
if OA:
node._xml_attr = other._xml_attr
elif NA:
node._xml_attr = None
if NA:
other._xml_attr = save
elif OA:
other._xml_attr = None
def _replace_by(node: Node, child: Node):
......
......@@ -15,17 +15,17 @@ setup(
name='DHParser',
version=__version__,
packages=['DHParser', 'DHParser.scripts'],
ext_modules=cythonize([#'DHParser/stringview.py',
#'DHParser/toolkit.py',
#'DHParser/preprocess.py',
#'DHParser/error.py',
ext_modules=cythonize(['DHParser/stringview.py',
'DHParser/toolkit.py',
'DHParser/preprocess.py',
'DHParser/error.py',
'DHParser/syntaxtree.py',
#'DHParser/log.py',
#'DHParser/parse.py',
#'DHParser/trace.py',
'DHParser/log.py',
'DHParser/parse.py',
'DHParser/trace.py',
'DHParser/transform.py',
#'DHParser/compile.py',
#'DHParser/ebnf.py',
'DHParser/compile.py',
'DHParser/ebnf.py',
],
nthreads=0, annotate=False),
url='https://gitlab.lrz.de/badw-it/DHParser',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment