17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 from __future__ import print_function |
18 from __future__ import print_function |
19 |
19 |
20 import gc, types, weakref |
20 import gc, types, weakref |
21 |
21 |
|
22 from six import PY2 |
|
23 |
22 from cubicweb.schema import CubicWebRelationSchema, CubicWebEntitySchema |
24 from cubicweb.schema import CubicWebRelationSchema, CubicWebEntitySchema |
23 try: |
25 try: |
24 from cubicweb.web.request import _NeedAuthAccessMock |
26 from cubicweb.web.request import _NeedAuthAccessMock |
25 except ImportError: |
27 except ImportError: |
26 _NeedAuthAccessMock = None |
28 _NeedAuthAccessMock = None |
27 |
29 |
28 listiterator = type(iter([])) |
30 listiterator = type(iter([])) |
29 |
31 |
30 IGNORE_CLASSES = ( |
32 IGNORE_CLASSES = ( |
31 type, tuple, dict, list, set, frozenset, type(len), |
33 type, tuple, dict, list, set, frozenset, type(len), |
32 weakref.ref, weakref.WeakKeyDictionary, |
34 weakref.ref, |
33 listiterator, |
35 listiterator, |
34 property, classmethod, |
36 property, classmethod, |
35 types.ModuleType, types.FunctionType, types.MethodType, |
37 types.ModuleType, types.FunctionType, types.MethodType, |
36 types.MemberDescriptorType, types.GetSetDescriptorType, |
38 types.MemberDescriptorType, types.GetSetDescriptorType, |
37 ) |
39 ) |
|
40 if PY2: |
|
41 # weakref.WeakKeyDictionary fails isinstance check on Python 3.5. |
|
42 IGNORE_CLASSES += (weakref.WeakKeyDictionary, ) |
|
43 |
38 if _NeedAuthAccessMock is not None: |
44 if _NeedAuthAccessMock is not None: |
39 IGNORE_CLASSES = IGNORE_CLASSES + (_NeedAuthAccessMock,) |
45 IGNORE_CLASSES = IGNORE_CLASSES + (_NeedAuthAccessMock,) |
40 |
46 |
41 def _get_counted_class(obj, classes): |
47 def _get_counted_class(obj, classes): |
42 for cls in classes: |
48 for cls in classes: |