X Tutup
Skip to content

Commit 97a3f53

Browse files
author
Dariusz Suchojad
committed
SESPRINGPYTHONPY-137: No need to duplicate stdlib's functionality (patch by Alan Franzoni).
git-svn-id: https://src.springframework.org/svn/se-springpython-py/trunk/springpython@741 ce8fead1-4192-4296-8608-a705134b927f
1 parent e73a3aa commit 97a3f53

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

src/springpython/context/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import atexit
1818
import logging
19+
from traceback import format_exc
1920

20-
from springpython.util import get_last_traceback
2121
from springpython.container import ObjectContainer
2222

2323
class ApplicationContext(ObjectContainer):
@@ -97,7 +97,7 @@ def shutdown_hook(self):
9797
destroy_method = getattr(obj, destroy_method_name)
9898

9999
except Exception, e:
100-
self.logger.error("Could not destroy object '%s', exception '%s'" % (obj_name, get_last_traceback(e)))
100+
self.logger.error("Could not destroy object '%s', exception '%s'" % (obj_name, format_exc()))
101101

102102
else:
103103
if callable(destroy_method):
@@ -106,7 +106,7 @@ def shutdown_hook(self):
106106
destroy_method()
107107
self.logger.debug("Successfully destroyed object '%s'" % obj_name)
108108
except Exception, e:
109-
self.logger.error("Could not destroy object '%s', exception '%s'" % (obj_name, get_last_traceback(e)))
109+
self.logger.error("Could not destroy object '%s', exception '%s'" % (obj_name, format_exc()))
110110
else:
111111
self.logger.error("Could not destroy object '%s', " \
112112
"the 'destroy_method' attribute it defines is not callable, " \

src/springpython/jms/factory.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from xml.sax.saxutils import escape
2424
from binascii import hexlify, unhexlify
2525
from time import time, mktime, strptime, altzone
26+
from traceback import format_exc
2627

2728
try:
2829
import cElementTree as etree
@@ -35,7 +36,7 @@
3536
# Spring Python
3637
from springpython.context import DisposableObject
3738
from springpython.jms.core import reserved_attributes, TextMessage
38-
from springpython.util import TRACE1, get_last_traceback, synchronized
39+
from springpython.util import TRACE1, synchronized
3940
from springpython.jms import JMSException, WebSphereMQJMSException, \
4041
NoMessageAvailableException, DELIVERY_MODE_NON_PERSISTENT, \
4142
DELIVERY_MODE_PERSISTENT
@@ -138,7 +139,7 @@ def destroy(self):
138139
self.logger.info("Caches cleared")
139140
except Exception, e:
140141
try:
141-
self.logger.error("Could not clear the caches. Exception [%s]" % get_last_traceback(e))
142+
self.logger.error("Could not clear the caches. Exception [%s]" % format_exc())
142143
except:
143144
pass
144145
try:
@@ -148,7 +149,7 @@ def destroy(self):
148149
except Exception, e:
149150
try:
150151
self.logger.error("Could not disconnect from queue manager [%s], exception [%s] " % (self.queue_manager,
151-
get_last_traceback(e)))
152+
format_exc()))
152153
except Exception:
153154
pass
154155

src/springpython/util.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,31 @@
1111
distributed under the License is distributed on an "AS IS" BASIS,
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
14-
limitations under the License.
14+
limitations under the License.
1515
"""
1616
import logging
1717
import traceback
18-
1918
from threading import RLock, currentThread
2019

2120
try:
2221
from cStringIO import StringIO
2322
except ImportError, e:
2423
from StringIO import StringIO
25-
26-
24+
25+
2726
TRACE1 = 6
2827
logging.addLevelName(TRACE1, "TRACE1")
2928

30-
31-
def get_last_traceback(exception):
32-
""" A utility function for better displaying exceptions.
33-
"""
34-
buff = StringIO()
35-
traceback.print_exc(file=buff)
36-
37-
return buff.getvalue()
38-
3929
# Original code by Anand Balachandran Pillai (abpillai at gmail.com)
4030
# http://code.activestate.com/recipes/533135/
4131
class synchronized(object):
4232
""" Class enapsulating a lock and a function allowing it to be used as
4333
a synchronizing decorator making the wrapped function thread-safe """
44-
34+
4535
def __init__(self, *args):
4636
self.lock = RLock()
4737
self.logger = logging.getLogger("springpython.util.synchronized")
48-
38+
4939
def __call__(self, f):
5040
def lockedfunc(*args, **kwargs):
5141
try:

0 commit comments

Comments
 (0)
X Tutup