[IMP] tools: removed some functools functions (they were there for previous python versions).

bzr revid: vmt@openerp.com-20120118114109-txh1cjv503xautty
This commit is contained in:
Vo Minh Thu 2012-01-18 12:41:09 +01:00
parent 4d77130107
commit b5caa70b83
5 changed files with 13 additions and 82 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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==''

View File

@ -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:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: