提交 3748f19a 编写于 作者: HansBug's avatar HansBug 😆

dev(hansbug): put constraint into it

上级 db5c6bc7
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from libcpp cimport bool from libcpp cimport bool
from .constraint cimport Constraint
from ..common.delay cimport DelayedProxy from ..common.delay cimport DelayedProxy
from ..common.storage cimport TreeStorage from ..common.storage cimport TreeStorage
...@@ -11,6 +12,7 @@ cdef class _CObject: ...@@ -11,6 +12,7 @@ cdef class _CObject:
cdef class TreeValue: cdef class TreeValue:
cdef readonly TreeStorage _st cdef readonly TreeStorage _st
cdef readonly Constraint _constraint
cdef readonly type _type cdef readonly type _type
cpdef TreeStorage _detach(self) cpdef TreeStorage _detach(self)
...@@ -20,7 +22,7 @@ cdef class TreeValue: ...@@ -20,7 +22,7 @@ cdef class TreeValue:
cpdef _getitem_extern(self, object key) cpdef _getitem_extern(self, object key)
cpdef _setitem_extern(self, object key, object value) cpdef _setitem_extern(self, object key, object value)
cpdef _delitem_extern(self, object key) cpdef _delitem_extern(self, object key)
cdef void _update(self, object d, dict kwargs) except * cdef void _update(self, object d, dict kwargs) except*
cpdef public get(self, str key, object default= *) cpdef public get(self, str key, object default= *)
cpdef public pop(self, str key, object default= *) cpdef public pop(self, str key, object default= *)
cpdef public popitem(self) cpdef public popitem(self)
......
...@@ -8,6 +8,7 @@ from operator import itemgetter ...@@ -8,6 +8,7 @@ from operator import itemgetter
import cython import cython
from hbutils.design import SingletonMark from hbutils.design import SingletonMark
from .constraint cimport Constraint, to_constraint, EmptyConstraint
from ..common.delay cimport undelay, _c_delayed_partial, DelayedProxy from ..common.delay cimport undelay, _c_delayed_partial, DelayedProxy
from ..common.storage cimport TreeStorage, create_storage, _c_undelay_data from ..common.storage cimport TreeStorage, create_storage, _c_undelay_data
from ...utils import format_tree from ...utils import format_tree
...@@ -56,12 +57,13 @@ cdef class TreeValue: ...@@ -56,12 +57,13 @@ cdef class TreeValue:
The `TreeValue` class is a light-weight framework just for DIY. The `TreeValue` class is a light-weight framework just for DIY.
""" """
def __cinit__(self, object data): def __cinit__(self, object data, Constraint constraint=None):
self._st = _DEFAULT_STORAGE self._st = _DEFAULT_STORAGE
self._constraint = EmptyConstraint() if constraint is None else constraint
self._type = type(self) self._type = type(self)
@cython.binding(True) @cython.binding(True)
def __init__(self, object data): def __init__(self, object data, object constraint=None):
""" """
Constructor of :class:`TreeValue`. Constructor of :class:`TreeValue`.
...@@ -100,6 +102,8 @@ cdef class TreeValue: ...@@ -100,6 +102,8 @@ cdef class TreeValue:
"Unknown initialization type for tree value - {type}.".format( "Unknown initialization type for tree value - {type}.".format(
type=repr(type(data).__name__))) type=repr(type(data).__name__)))
self._constraint = to_constraint(constraint)
def __getnewargs_ex__(self): # for __cinit__, when pickle.loads def __getnewargs_ex__(self): # for __cinit__, when pickle.loads
return ({},), {} return ({},), {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册