diff --git a/openerp/addons/base/ir/ir_mail_server.py b/openerp/addons/base/ir/ir_mail_server.py index 3cb1446a146..aca4778830f 100644 --- a/openerp/addons/base/ir/ir_mail_server.py +++ b/openerp/addons/base/ir/ir_mail_server.py @@ -34,7 +34,6 @@ from osv import osv from osv import fields from openerp.tools.translate import _ from openerp.tools import html2text -from openerp.tools.func import wraps import openerp.tools as tools # ustr was originally from tools.misc. diff --git a/openerp/osv/osv.py b/openerp/osv/osv.py index 85df3e7e219..44597bf6507 100644 --- a/openerp/osv/osv.py +++ b/openerp/osv/osv.py @@ -21,6 +21,7 @@ #.apidoc title: Objects Services (OSV) +from functools import wraps import logging from psycopg2 import IntegrityError, errorcodes @@ -29,7 +30,6 @@ import openerp import openerp.netsvc as netsvc import openerp.pooler as pooler import openerp.sql_db as sql_db -from openerp.tools.func import wraps from openerp.tools.translate import translate from openerp.osv.orm import MetaModel, Model, TransientModel, AbstractModel import openerp.exceptions diff --git a/openerp/sql_db.py b/openerp/sql_db.py index 82851abd034..a268cfd3b2e 100644 --- a/openerp/sql_db.py +++ b/openerp/sql_db.py @@ -35,13 +35,13 @@ See also: the `pooler` module __all__ = ['db_connect', 'close_db'] -from threading import currentThread +from functools import wraps import logging -from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_REPEATABLE_READ -from psycopg2.psycopg1 import cursor as psycopg1cursor -from psycopg2.pool import PoolError - import psycopg2.extensions +from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_REPEATABLE_READ +from psycopg2.pool import PoolError +from psycopg2.psycopg1 import cursor as psycopg1cursor +from threading import currentThread import warnings psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) @@ -66,7 +66,7 @@ psycopg2.extensions.register_type(psycopg2.extensions.new_type((700, 701, 1700,) import tools -from tools.func import wraps, frame_codeinfo +from tools.func import frame_codeinfo from datetime import datetime as mdt from datetime import timedelta import threading diff --git a/openerp/tools/func.py b/openerp/tools/func.py index 9f52f1da956..d1797e30b9a 100644 --- a/openerp/tools/func.py +++ b/openerp/tools/func.py @@ -20,68 +20,10 @@ # ############################################################################## -__all__ = ['partial', 'wraps', 'update_wrapper', 'synchronized'] - -try: - from functools import partial, wraps, update_wrapper -except ImportError: - # The functools module doesn't exist in python < 2.5 - # Code taken from python 2.5 - # http://svn.python.org/view/python/tags/r254/Lib/functools.py?view=markup - - def partial(fun, *args, **kwargs): - """ Partial implementation - - See: http://svn.python.org/view/python/tags/r254/Lib/functools.py - """ - def _partial(*args2, **kwargs2): - return fun(*(args+args2), **dict(kwargs, **kwargs2)) - return _partial - - ### --- code from python 2.5 - - # update_wrapper() and wraps() are tools to help write - # wrapper functions that can handle naive introspection - - WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__') - WRAPPER_UPDATES = ('__dict__',) - def update_wrapper(wrapper, - wrapped, - assigned = WRAPPER_ASSIGNMENTS, - updated = WRAPPER_UPDATES): - """Update a wrapper function to look like the wrapped function - - wrapper is the function to be updated - wrapped is the original function - assigned is a tuple naming the attributes assigned directly - from the wrapped function to the wrapper function (defaults to - functools.WRAPPER_ASSIGNMENTS) - updated is a tuple naming the attributes off the wrapper that - are updated with the corresponding attribute from the wrapped - function (defaults to functools.WRAPPER_UPDATES) - """ - for attr in assigned: - setattr(wrapper, attr, getattr(wrapped, attr)) - for attr in updated: - getattr(wrapper, attr).update(getattr(wrapped, attr, {})) - # Return the wrapper so this can be used as a decorator via partial() - return wrapper - - def wraps(wrapped, - assigned = WRAPPER_ASSIGNMENTS, - updated = WRAPPER_UPDATES): - """Decorator factory to apply update_wrapper() to a wrapper function - - Returns a decorator that invokes update_wrapper() with the decorated - function as the wrapper argument and the arguments to wraps() as the - remaining arguments. Default arguments are as for update_wrapper(). - This is a convenience function to simplify applying partial() to - update_wrapper(). - """ - return partial(update_wrapper, wrapped=wrapped, - assigned=assigned, updated=updated) - +__all__ = ['synchronized'] +from functools import wraps +from inspect import getsourcefile def synchronized(lock_attr='_lock'): def decorator(func): @@ -96,10 +38,6 @@ def synchronized(lock_attr='_lock'): return wrapper return decorator - - -from inspect import getsourcefile - def frame_codeinfo(fframe, back=0): """ Return a (filename, line) pair for a previous frame . @return (filename, lineno) where lineno is either int or string=='' diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index 7fdb2f07386..b888c898e40 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -26,6 +26,7 @@ Miscelleanous tools used by OpenERP. """ +from functools import wraps import inspect import subprocess import logging @@ -50,10 +51,7 @@ from email import Encoders from itertools import islice, izip from lxml import etree from which import which -if sys.version_info[:2] < (2, 4): - from threadinglocal import local -else: - from threading import local +from threading import local try: from html2text import html2text except ImportError: @@ -715,8 +713,6 @@ def human_size(sz): return "%0.2f %s" % (s, units[i]) def logged(f): - from func import wraps - @wraps(f) def wrapper(*args, **kwargs): from pprint import pformat @@ -742,8 +738,6 @@ class profile(object): self.fname = fname def __call__(self, f): - from func import wraps - @wraps(f) def wrapper(*args, **kwargs): class profile_wrapper(object): @@ -1200,4 +1194,4 @@ class UnquoteEvalContext(defaultdict): def __missing__(self, key): return unquote(key) -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: