2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-12-12 11:49:45 +00:00
|
|
|
##############################################################################
|
2010-11-09 16:57:39 +00:00
|
|
|
#
|
2009-01-05 11:56:08 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2009-10-14 12:32:15 +00:00
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2010-11-09 16:57:39 +00:00
|
|
|
# Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
|
2008-12-12 11:49:45 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2008-12-12 11:49:45 +00:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-12-12 11:49:45 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-11-09 16:57:39 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-12 11:49:45 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-01-18 11:41:09 +00:00
|
|
|
__all__ = ['synchronized']
|
2010-11-09 16:57:39 +00:00
|
|
|
|
2012-01-18 11:41:09 +00:00
|
|
|
from functools import wraps
|
|
|
|
from inspect import getsourcefile
|
2010-11-09 16:57:39 +00:00
|
|
|
|
|
|
|
def synchronized(lock_attr='_lock'):
|
|
|
|
def decorator(func):
|
|
|
|
@wraps(func)
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
lock = getattr(self, lock_attr)
|
|
|
|
try:
|
|
|
|
lock.acquire()
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
finally:
|
|
|
|
lock.release()
|
|
|
|
return wrapper
|
|
|
|
return decorator
|
|
|
|
|
2010-11-23 13:57:42 +00:00
|
|
|
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==''
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
if not fframe:
|
2012-12-14 12:38:03 +00:00
|
|
|
return "<unknown>", ''
|
2010-11-23 13:57:42 +00:00
|
|
|
for i in range(back):
|
|
|
|
fframe = fframe.f_back
|
|
|
|
try:
|
|
|
|
fname = getsourcefile(fframe)
|
|
|
|
except TypeError:
|
|
|
|
fname = '<builtin>'
|
|
|
|
lineno = fframe.f_lineno or ''
|
2012-12-14 12:38:03 +00:00
|
|
|
return fname, lineno
|
2010-11-23 13:57:42 +00:00
|
|
|
except Exception:
|
2012-12-14 12:38:03 +00:00
|
|
|
return "<unknown>", ''
|
2011-11-22 08:58:48 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|