Exemple #1
0
        def wrapper(*args, **kw):  
            # honor output_handler_override
            if self.config['output_handler_override']:
                self.handler = self.config['output_handler_override']

            log.debug("decorating '%s' with '%s:%s'" % \
                (func.__name__, self.handler, self.template))  
            
            res = self.func(*args, **kw)
            
            out = SAVED_STDOUT
            tmpl_content = None
            
            if not res:
                res = dict()
            if type(res) != dict:
                raise CementRuntimeError, \
                    "Controller functions must return type dict()."
            
            if self.handler:
                h = get_handler('output', self.handler)(res, self.template)
                namespaces['root'].config['output_handler'] = self.handler
                out_txt = h.render()
            
                if not out_txt:
                    out_txt = ''
                
                if res.has_key('output_file') and res['output_file']:
                    f = open(res['output_file'], 'w+')
                    f.write(out_txt)
                    f.close()
                elif out:
                    out.write(out_txt)
                    
                # return res and out_txt, because we want it to be 
                # readable when called directly from 
                # run_controller_command()
                return (res, out_txt)
Exemple #2
0
        def wrapper(*args, **kw):
            # honor output_handler_override
            if self.config['output_handler_override']:
                self.handler = self.config['output_handler_override']

            log.debug("decorating '%s' with '%s:%s'" % \
                (func.__name__, self.handler, self.template))

            res = self.func(*args, **kw)

            out = SAVED_STDOUT
            tmpl_content = None

            if not res:
                res = dict()
            if type(res) != dict:
                raise CementRuntimeError, \
                    "Controller functions must return type dict()."

            if self.handler:
                h = get_handler('output', self.handler)(res, self.template)
                namespaces['root'].config['output_handler'] = self.handler
                out_txt = h.render()

                if not out_txt:
                    out_txt = ''

                if res.has_key('output_file') and res['output_file']:
                    f = open(res['output_file'], 'w+')
                    f.write(out_txt)
                    f.close()
                elif out:
                    out.write(out_txt)

                # return res and out_txt, because we want it to be
                # readable when called directly from
                # run_controller_command()
                return (res, out_txt)
Exemple #3
0
def test_get_handler_bad():
    get_handler('output', 'bogus handler name')
Exemple #4
0
def test_get_handler():
    get_handler('output', 'json')
Exemple #5
0
def test_get_handler_bad():  
    get_handler('output', 'bogus handler name')
Exemple #6
0
def test_get_handler():  
    get_handler('output', 'json')