[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:
parent
4d77130107
commit
b5caa70b83
|
@ -34,7 +34,6 @@ from osv import osv
|
||||||
from osv import fields
|
from osv import fields
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
from openerp.tools import html2text
|
from openerp.tools import html2text
|
||||||
from openerp.tools.func import wraps
|
|
||||||
import openerp.tools as tools
|
import openerp.tools as tools
|
||||||
|
|
||||||
# ustr was originally from tools.misc.
|
# ustr was originally from tools.misc.
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#.apidoc title: Objects Services (OSV)
|
#.apidoc title: Objects Services (OSV)
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
from psycopg2 import IntegrityError, errorcodes
|
from psycopg2 import IntegrityError, errorcodes
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@ import openerp
|
||||||
import openerp.netsvc as netsvc
|
import openerp.netsvc as netsvc
|
||||||
import openerp.pooler as pooler
|
import openerp.pooler as pooler
|
||||||
import openerp.sql_db as sql_db
|
import openerp.sql_db as sql_db
|
||||||
from openerp.tools.func import wraps
|
|
||||||
from openerp.tools.translate import translate
|
from openerp.tools.translate import translate
|
||||||
from openerp.osv.orm import MetaModel, Model, TransientModel, AbstractModel
|
from openerp.osv.orm import MetaModel, Model, TransientModel, AbstractModel
|
||||||
import openerp.exceptions
|
import openerp.exceptions
|
||||||
|
|
|
@ -35,13 +35,13 @@ See also: the `pooler` module
|
||||||
|
|
||||||
__all__ = ['db_connect', 'close_db']
|
__all__ = ['db_connect', 'close_db']
|
||||||
|
|
||||||
from threading import currentThread
|
from functools import wraps
|
||||||
import logging
|
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
|
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
|
import warnings
|
||||||
|
|
||||||
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
||||||
|
@ -66,7 +66,7 @@ psycopg2.extensions.register_type(psycopg2.extensions.new_type((700, 701, 1700,)
|
||||||
|
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
from tools.func import wraps, frame_codeinfo
|
from tools.func import frame_codeinfo
|
||||||
from datetime import datetime as mdt
|
from datetime import datetime as mdt
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import threading
|
import threading
|
||||||
|
|
|
@ -20,68 +20,10 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
__all__ = ['partial', 'wraps', 'update_wrapper', 'synchronized']
|
__all__ = ['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)
|
|
||||||
|
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
|
from inspect import getsourcefile
|
||||||
|
|
||||||
def synchronized(lock_attr='_lock'):
|
def synchronized(lock_attr='_lock'):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
|
@ -96,10 +38,6 @@ def synchronized(lock_attr='_lock'):
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from inspect import getsourcefile
|
|
||||||
|
|
||||||
def frame_codeinfo(fframe, back=0):
|
def frame_codeinfo(fframe, back=0):
|
||||||
""" Return a (filename, line) pair for a previous frame .
|
""" Return a (filename, line) pair for a previous frame .
|
||||||
@return (filename, lineno) where lineno is either int or string==''
|
@return (filename, lineno) where lineno is either int or string==''
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
Miscelleanous tools used by OpenERP.
|
Miscelleanous tools used by OpenERP.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
import inspect
|
import inspect
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
@ -50,10 +51,7 @@ from email import Encoders
|
||||||
from itertools import islice, izip
|
from itertools import islice, izip
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from which import which
|
from which import which
|
||||||
if sys.version_info[:2] < (2, 4):
|
from threading import local
|
||||||
from threadinglocal import local
|
|
||||||
else:
|
|
||||||
from threading import local
|
|
||||||
try:
|
try:
|
||||||
from html2text import html2text
|
from html2text import html2text
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -715,8 +713,6 @@ def human_size(sz):
|
||||||
return "%0.2f %s" % (s, units[i])
|
return "%0.2f %s" % (s, units[i])
|
||||||
|
|
||||||
def logged(f):
|
def logged(f):
|
||||||
from func import wraps
|
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
@ -742,8 +738,6 @@ class profile(object):
|
||||||
self.fname = fname
|
self.fname = fname
|
||||||
|
|
||||||
def __call__(self, f):
|
def __call__(self, f):
|
||||||
from func import wraps
|
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
class profile_wrapper(object):
|
class profile_wrapper(object):
|
||||||
|
|
Loading…
Reference in New Issue