home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from contextlib import contextmanager
- import sys
- import traceback
-
- try:
- sentinel
- except NameError:
- sentinel = object()
-
-
- def try_this(func, default = sentinel, allow = (NameError,)):
- if not callable(func):
- raise TypeError('try_this takes a callable as its first argument')
-
-
- try:
- return func()
- except allow:
- raise
- except Exception:
- if default is sentinel:
- raise
- else:
- return default
- except:
- default is sentinel
-
-
-
- def syck_error_message(e, fpath):
- (msg, line, column) = e
- msg = '%s in %s:\n\n' % (msg, fpath)
- path = path
- import path
-
- try:
- error_line = path(fpath).lines()[line].strip()
- except:
- error_line = '(could not load line)'
-
- msg += 'line %d, column %d: "%s"' % (line, column, error_line)
- return msg
-
-
- def repr_exception(*args, **kwargs):
-
- try:
- yield None
- except:
- for item in args:
- found = False
- for k, v in sys._getframe(2).f_locals.iteritems():
- if v is item:
- print >>sys.stderr, k, '-->', repr(item)
- found = True
- break
- continue
-
- if not found:
- print >>sys.stderr, repr(item)
- continue
-
- for k, v in kwargs.iteritems():
- print >>sys.stderr, repr(k), repr(v)
-
- raise
-
-
- repr_exception = contextmanager(repr_exception)
-
- def with_traceback(func, *args, **kwargs):
-
- try:
- return func(*args, **kwargs)
- except Exception:
- traceback.print_exc()
-
-
-
- class traceguard:
-
- def __enter__(cls):
- pass
-
- __enter__ = classmethod(__enter__)
-
- def __exit__(cls, *a):
-
- try:
- if filter(None, a):
-
- try:
- print >>sys.stderr, 'The following exception has been squashed!'
- except Exception:
- pass
-
-
- try:
- exc_string = traceback.format_exc(a)
- except Exception:
- exc_string = '(Could not format exception.)'
- if hasattr(traceback, '_old_format_exc'):
-
- try:
- exc_string = traceback._old_format_exc(a)
- except Exception:
- pass
- except:
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
-
-
- try:
- if isinstance(exc_string, unicode):
-
- try:
- exc_string = exc_string.encode('utf-8')
- except Exception:
- exc_string = 'Error encoding this as utf8: %r' % (exc_string,)
- except:
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
- print >>sys.stderr, exc_string
- except Exception:
-
- try:
- print >>sys.stderr, 'could not print exception'
- except Exception:
- pass
- except:
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
- except Exception:
- pass
- finally:
- del a
-
- return True
-
- __exit__ = classmethod(__exit__)
-
-