Skip to content

Commit

Permalink
Remove useless deallocation of tuple at the end of the function
Browse files Browse the repository at this point in the history
  • Loading branch information
rbu authored and Michael Howitz committed May 23, 2018
1 parent 7bdbc4c commit 1cd9f05
Showing 1 changed file with 68 additions and 72 deletions.
140 changes: 68 additions & 72 deletions src/Products/SiteErrorLog/SiteErrorLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
# Python 2
from thread import allocate_lock
from zope.event import notify
from Products.SiteErrorLog.interfaces import ErrorRaisedEvent
from .interfaces import ErrorRaisedEvent

from AccessControl.class_init import InitializeClass

from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.unauthorized import Unauthorized
Expand Down Expand Up @@ -165,80 +164,77 @@ def raising(self, info):
Called by SimpleItem's exception handler.
Returns the url to view the error log entry
"""
now = time.time()
try:
now = time.time()
tb_text = None
tb_html = None

strtype = str(getattr(info[0], '__name__', info[0]))
if strtype in self._ignored_exceptions:
return

if not isinstance(info[2], bstr):
tb_text = ''.join(
format_exception(*info, **{'as_html': 0}))
tb_html = ''.join(
format_exception(*info, **{'as_html': 1}))
else:
tb_text = info[2]

request = getattr(self, 'REQUEST', None)
url = None
username = None
userid = None
req_html = None
try:
tb_text = None
tb_html = None

strtype = str(getattr(info[0], '__name__', info[0]))
if strtype in self._ignored_exceptions:
return

if not isinstance(info[2], bstr):
tb_text = ''.join(
format_exception(*info, **{'as_html': 0}))
tb_html = ''.join(
format_exception(*info, **{'as_html': 1}))
else:
tb_text = info[2]

request = getattr(self, 'REQUEST', None)
url = None
username = None
userid = None
req_html = None
strv = str(info[1])
except:
strv = '<unprintable %s object>' % type(info[1]).__name__
if request:
url = request.get('URL', '?')
usr = getSecurityManager().getUser()
username = usr.getUserName()
userid = usr.getId()
try:
strv = str(info[1])
req_html = str(request)
except:
strv = '<unprintable %s object>' % type(info[1]).__name__
if request:
url = request.get('URL', '?')
usr = getSecurityManager().getUser()
username = usr.getUserName()
userid = usr.getId()
try:
req_html = str(request)
except:
pass
if strtype == 'NotFound':
strv = url
next = request['TraversalRequestNameStack']
if next:
next = list(next)
next.reverse()
strv = '%s [ /%s ]' % (strv, '/'.join(next))

log = self._getLog()
entry_id = str(now) + str(random()) # Low chance of collision
log.append({
'type': strtype,
'value': strv,
'time': now,
'id': entry_id,
'tb_text': tb_text,
'tb_html': tb_html,
'username': username,
'userid': userid,
'url': url,
'req_html': req_html})

cleanup_lock.acquire()
try:
if len(log) >= self.keep_entries:
del log[:-self.keep_entries]
finally:
cleanup_lock.release()
except:
LOG.error('Error while logging', exc_info=sys.exc_info())
else:
notify(ErrorRaisedEvent(log[-1]))
if self.copy_to_zlog:
self._do_copy_to_zlog(now, strtype, entry_id,
str(url), tb_text)
return '%s/showEntry?id=%s' % (self.absolute_url(), entry_id)
finally:
info = None
pass
if strtype == 'NotFound':
strv = url
next = request['TraversalRequestNameStack']
if next:
next = list(next)
next.reverse()
strv = '%s [ /%s ]' % (strv, '/'.join(next))

log = self._getLog()
entry_id = str(now) + str(random()) # Low chance of collision
log.append({
'type': strtype,
'value': strv,
'time': now,
'id': entry_id,
'tb_text': tb_text,
'tb_html': tb_html,
'username': username,
'userid': userid,
'url': url,
'req_html': req_html})

cleanup_lock.acquire()
try:
if len(log) >= self.keep_entries:
del log[:-self.keep_entries]
finally:
cleanup_lock.release()
except:
LOG.error('Error while logging', exc_info=sys.exc_info())
else:
notify(ErrorRaisedEvent(log[-1]))
if self.copy_to_zlog:
self._do_copy_to_zlog(now, strtype, entry_id,
str(url), tb_text)
return '%s/showEntry?id=%s' % (self.absolute_url(), entry_id)

def _do_copy_to_zlog(self, now, strtype, entry_id, url, tb_text):
when = _rate_restrict_pool.get(strtype, 0)
Expand Down

0 comments on commit 1cd9f05

Please sign in to comment.