From 912f27d4bf52da52a68b8e696f15df9ea523df76 Mon Sep 17 00:00:00 2001 From: Yann Date: Mon, 15 Feb 2016 09:52:04 +0100 Subject: [PATCH] Disabled wrapper in default settings + some little modifications Modified Makefile (it was outdated) Modified the way of checking caller in _LeCrud.__new__ Modified the way the method is called by ACL wrapper --- Makefile | 4 ++-- leapi/lecrud.py | 10 +++++++--- libs/transwrap/transwrap.py | 17 +++++++++++++---- settings.py | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 6da0814..6f4feae 100644 --- a/Makefile +++ b/Makefile @@ -35,13 +35,13 @@ cleandoc: -rm -Rf ./doc/html ./doc/doxygen_sqlite3.db cleandocimages: - cd $(graphviz_images_path); make clean + $(MAKE) -C $(graphviz_images_path) clean # Python cleaning cleanpyc: -find ./ |grep -E "\.pyc$$" |xargs rm -f 2>/dev/null cleanpycache: cleanpyc - -find ./ -type d |grep '__pycache__' | xargs rmdir -f 2>/dev/null + -find ./ -type d |grep '__pycache__' | xargs rmdir 2>/dev/null cleandyn: -rm leapi/dyn.py diff --git a/leapi/lecrud.py b/leapi/lecrud.py index 63ef2d3..4744a13 100644 --- a/leapi/lecrud.py +++ b/leapi/lecrud.py @@ -8,7 +8,8 @@ import copy import warnings import importlib import re -import inspect +#import inspect +import sys from Lodel.settings import Settings from libs.transwrap.transwrap import get_class_wrapper @@ -60,13 +61,16 @@ class _LeCrud(object): _query_re = None ## @brief Stores Query filters operators _query_operators = ['=', '<=', '>=', '!=', '<', '>', ' in ', ' not in ', ' like ', ' not like '] - + ## @brief Returns a wrapped object def __new__(cls, *args, **kwargs): - if Settings.acl_bypass or inspect.stack()[2][3] == '__init__': + # differents ways of checking the caller + #if Settings.acl_bypass or inspect.stack()[2][3] == '__init__': + if Settings.acl_bypass or sys._getframe().f_back.f_code.co_name == '__do_call__': return super().__new__(cls) else: return get_class_wrapper(cls)(*args, **kwargs) + ## @brief Asbtract constructor for every child classes # @param uid int : lodel_id if LeObject, id_relation if its a LeRelation diff --git a/libs/transwrap/transwrap.py b/libs/transwrap/transwrap.py index b93132e..7b1e32a 100644 --- a/libs/transwrap/transwrap.py +++ b/libs/transwrap/transwrap.py @@ -33,7 +33,7 @@ class DefaultCallCatcher(object): # @param kwargs dict : method call named arguments # @return the call returned value @classmethod - def method_call(self, obj, method, args, kwargs): + def method_call(cls, obj, method, args, kwargs): if obj is method: print("\tCatched ! %s(%s %s)" % (obj.__name__, args, kwargs)) else: @@ -42,7 +42,16 @@ class DefaultCallCatcher(object): else: print("\tCatched ! %s.%s(%s %s)" % (obj, method.__name__, args,kwargs)) print("\t\tCallobject = %s method = %s with %s %s" % (obj, method, args, kwargs)) - + return cls.__do_call__(method, args, kwargs) + + ## @brief Do the method call + # @note You have to use this method to make the call, because the __new__ method test caller method name to know if it has to return a real instance or a wrapped one + # @param method : the python bounded method + # @param args tuple : positional arguments + # @param kwargs dict : keywords arguments + # @return method returned value + @classmethod + def __do_call__(cls, method, args, kwargs): return method(*args, **kwargs) ## @brief Generate a wrapper @@ -64,7 +73,7 @@ def get_wrapper(module_name, class_name, call_catcher_cls = DefaultCallCatcher): # @param call_catcher_cls : A child class of DefaultCallCatcher designed to be called by the wrapper # @return A class that is a wrapper for towrap def get_class_wrapper(towrap, call_catcher_cls = DefaultCallCatcher): - + ## @brief Function wrapper # # In fact this class will only be a wrapper for methods @@ -150,5 +159,5 @@ def get_class_wrapper(towrap, call_catcher_cls = DefaultCallCatcher): setattr(wrap, name, make_instance_magix(name)) if name not in class_ex: setattr(metawrap, name, make_class_magix(name)) - + return wrap diff --git a/settings.py b/settings.py index e27a0e5..c4e9a2f 100644 --- a/settings.py +++ b/settings.py @@ -28,4 +28,4 @@ migration_options = { em_graph_format = 'png' em_graph_output = '/tmp/em_%s_graph.png' -acl_bypass = False +acl_bypass = True