Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ProtoText/hook_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import types
import __builtin__
import builtins
import logging

HOOK_TABLE_NAME = '__ZX_PY_HOOK_TABLE__'
Expand All @@ -14,11 +14,11 @@ def register_class_hook(cls, strategy='safe', skip_buildin=True):
:param skip_buildin: determine if we skip the build in object
:return:
"""
assert isinstance(cls, (type, types.ClassType)), \
assert isinstance(cls, type), \
"The input object must be a class object"
base_classes = cls.__bases__
for base_class in base_classes:
if skip_buildin and base_class.__name__ in __builtin__.__dict__:
if skip_buildin and base_class.__name__ in builtins.__dict__:
logger.warn("Skip hooking build-in base class '%s' in sub-class '%s' ..." %
(base_class.__name__, cls.__name__))
continue
Expand Down Expand Up @@ -49,7 +49,7 @@ def deregister_class_hook(cls):
:param cls: the class object of the class to unhook
:return:
"""
assert isinstance(cls, (type, types.ClassType)), \
assert isinstance(cls, type), \
"The input object must be a class object"
base_classes = cls.__bases__
for base_class in base_classes:
Expand All @@ -63,4 +63,4 @@ def deregister_class_hook(cls):
setattr(base_class, x, _hook_table[x])
else:
delattr(base_class, x)
delattr(base_class, HOOK_TABLE_NAME)
delattr(base_class, HOOK_TABLE_NAME)