コード例 #1
0
def try_call(func, self, *args, **kw):
    """Call function, catch and dispatch any resulting exception."""
    # turbogears.database import here to avoid circular imports
    from turbogears.database import restart_transaction
    try:
        return func(self, *args, **kw)
    except Exception, e:
        if isinstance(e, cherrypy.HTTPRedirect) or \
                call_on_stack("dispatch_error",
                    {"tg_source": func, "tg_exception": e}, 4):
            raise
        else:
            exc_type, exc_value, exc_trace = sys.exc_info()
            remove_keys(kw, ("tg_source", "tg_errors", "tg_exceptions"))
            if 'tg_format' in cherrypy.request.params:
                kw['tg_format'] = 'json'
            if getattr(cherrypy.request, "in_transaction", None):
                restart_transaction(1)
            try:
                output = dispatch_error(self, func, None, e, *args, **kw)
            except NoApplicableMethods:
                raise exc_type, exc_value, exc_trace
            else:
                del exc_trace
                return output
コード例 #2
0
ファイル: errorhandling.py プロジェクト: thraxil/gtreed
def try_call(func, self, *args, **kw):
    """Call function, catch and dispatch any resulting exception."""
    # turbogears.database import here to avoid circular imports
    from turbogears.database import _use_sa
    try:
        return func(self, *args, **kw)
    except Exception, e:
        if isinstance(e, cherrypy.HTTPRedirect) or \
           call_on_stack("dispatch_error",
                         {"tg_source":func, "tg_exception":e}, 4):
            raise
        elif _use_sa() and getattr(cherrypy.request, "in_transaction", None):
            # We're in a transaction and using SA, let 
            # database.run_with_transaction handle and dispatch 
            # the exception
            raise
        else:
            exc_type, exc_value, exc_trace = sys.exc_info()
            remove_keys(kw, ("tg_source", "tg_errors", "tg_exceptions"))
            try:
                output = dispatch_error(self, func, None, e, *args, **kw)
            except NoApplicableMethods:
                raise exc_type, exc_value, exc_trace
            else:
                del exc_trace
                return output
コード例 #3
0
def try_call(func, self, *args, **kw):
    """Call function, catch and dispatch any resulting exception."""
    # turbogears.database import here to avoid circular imports
    from turbogears.database import restart_transaction
    try:
        return func(self, *args, **kw)
    except Exception, e:
        if isinstance(e, cherrypy.HTTPRedirect) or \
                call_on_stack("dispatch_error",
                    {"tg_source": func, "tg_exception": e}, 4):
            raise

        else:
            exc_type, exc_value, exc_trace = sys.exc_info()
            remove_keys(kw, ("tg_source", "tg_errors", "tg_exceptions"))
            if 'tg_format' in cherrypy.request.params:
                kw['tg_format'] = 'json'
            if getattr(cherrypy.request, "in_transaction", None):
                restart_transaction(1)
            try:
                output = dispatch_error(self, func, None, e, *args, **kw)
            except NoApplicableMethods:
                raise exc_type, exc_value, exc_trace
            else:
                del exc_trace
                return output
コード例 #4
0
ファイル: controllers.py プロジェクト: thraxil/gtreed
        def validate(func, *args, **kw):
            if tg_util.call_on_stack("validate", recursion_guard, 4):
                return func(*args, **kw)
            form = init_form(args and args[0] or kw["self"])
            args, kw = tg_util.to_kw(func, args, kw)

            errors = {}
            if state_factory is not None:
                state = state_factory()
            else:
                state = None

            if form:
                value = kw.copy()
                try:
                    kw.update(form.validate(value, state))
                except Invalid, e:
                    errors = e.unpack_errors()
                    cherrypy.request.validation_exception = e
                cherrypy.request.validated_form = form
コード例 #5
0
 def recurse(level, arg=None):
     if level:
         return recurse(level-1, arg)
     return util.call_on_stack('recurse', dict(arg='true'), 3)
コード例 #6
0
 def recurse(level):
     if level:
         return recurse(level-1)
     return util.call_on_stack('recurse', dict())
コード例 #7
0
ファイル: test_util.py プロジェクト: timmartin19/turbogears
 def recurse(level):
     if level:
         return recurse(level - 1)
     return util.call_on_stack('recurse', dict())
コード例 #8
0
ファイル: test_util.py プロジェクト: timmartin19/turbogears
 def recurse(level, arg=None):
     if level:
         return recurse(level - 1, arg)
     return util.call_on_stack('recurse', dict(arg='true'), 3)