1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-04-01 16:47:16 +02:00

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
This commit is contained in:
Yann 2016-02-15 09:52:04 +01:00
commit 912f27d4bf
4 changed files with 23 additions and 10 deletions

View file

@ -35,13 +35,13 @@ cleandoc:
-rm -Rf ./doc/html ./doc/doxygen_sqlite3.db -rm -Rf ./doc/html ./doc/doxygen_sqlite3.db
cleandocimages: cleandocimages:
cd $(graphviz_images_path); make clean $(MAKE) -C $(graphviz_images_path) clean
# Python cleaning # Python cleaning
cleanpyc: cleanpyc:
-find ./ |grep -E "\.pyc$$" |xargs rm -f 2>/dev/null -find ./ |grep -E "\.pyc$$" |xargs rm -f 2>/dev/null
cleanpycache: cleanpyc cleanpycache: cleanpyc
-find ./ -type d |grep '__pycache__' | xargs rmdir -f 2>/dev/null -find ./ -type d |grep '__pycache__' | xargs rmdir 2>/dev/null
cleandyn: cleandyn:
-rm leapi/dyn.py -rm leapi/dyn.py

View file

@ -8,7 +8,8 @@ import copy
import warnings import warnings
import importlib import importlib
import re import re
import inspect #import inspect
import sys
from Lodel.settings import Settings from Lodel.settings import Settings
from libs.transwrap.transwrap import get_class_wrapper from libs.transwrap.transwrap import get_class_wrapper
@ -63,11 +64,14 @@ class _LeCrud(object):
## @brief Returns a wrapped object ## @brief Returns a wrapped object
def __new__(cls, *args, **kwargs): 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) return super().__new__(cls)
else: else:
return get_class_wrapper(cls)(*args, **kwargs) return get_class_wrapper(cls)(*args, **kwargs)
## @brief Asbtract constructor for every child classes ## @brief Asbtract constructor for every child classes
# @param uid int : lodel_id if LeObject, id_relation if its a LeRelation # @param uid int : lodel_id if LeObject, id_relation if its a LeRelation
# @param **kwargs : datas ! # @param **kwargs : datas !

View file

@ -33,7 +33,7 @@ class DefaultCallCatcher(object):
# @param kwargs dict : method call named arguments # @param kwargs dict : method call named arguments
# @return the call returned value # @return the call returned value
@classmethod @classmethod
def method_call(self, obj, method, args, kwargs): def method_call(cls, obj, method, args, kwargs):
if obj is method: if obj is method:
print("\tCatched ! %s(%s %s)" % (obj.__name__, args, kwargs)) print("\tCatched ! %s(%s %s)" % (obj.__name__, args, kwargs))
else: else:
@ -42,7 +42,16 @@ class DefaultCallCatcher(object):
else: else:
print("\tCatched ! %s.%s(%s %s)" % (obj, method.__name__, args,kwargs)) print("\tCatched ! %s.%s(%s %s)" % (obj, method.__name__, args,kwargs))
print("\t\tCallobject = %s method = %s with %s %s" % (obj, method, 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) return method(*args, **kwargs)
## @brief Generate a wrapper ## @brief Generate a wrapper

View file

@ -28,4 +28,4 @@ migration_options = {
em_graph_format = 'png' em_graph_format = 'png'
em_graph_output = '/tmp/em_%s_graph.png' em_graph_output = '/tmp/em_%s_graph.png'
acl_bypass = False acl_bypass = True