Example #1
0
    class Root:
        def index(self):
            return "Howdy earth!"

        index.exposed = True

        def euro(self):
            hooks = list(cherrypy.request.hooks['before_finalize'])
            hooks.sort()
            assert [x.callback.__name__ for x in hooks] == ['encode', 'gzip']
            assert [x.priority for x in hooks] == [70, 80]
            yield u"Hello,"
            yield u"world"
            yield europoundUnicode

        euro.exposed = True

        # Bare hooks
        def pipe(self):
            return cherrypy.request.body

        pipe.exposed = True
        pipe._cp_config = {'hooks.before_request_body': pipe_body}

        # Multiple decorators; include kwargs just for fun.
        # Note that encode must run before gzip.
        def decorated_euro(self, *vpath):
            yield u"Hello,"
            yield u"world"
            yield europoundUnicode

        decorated_euro.exposed = True
        decorated_euro = tools.gzip(compress_level=6)(decorated_euro)
        decorated_euro = tools.encode(errors='ignore')(decorated_euro)
Example #2
0
        class Root:
            @cherrypy.expose
            def index(self):
                return 'Howdy earth!'

            @cherrypy.expose
            @cherrypy.config(**{
                'tools.streamer.on': True,
                'tools.streamer.arg': 'arg value'
            })
            def tarfile(self):
                assert cherrypy.request.config.get(
                    'tools.streamer.arg') == 'arg value'
                cherrypy.response.output.write(ntob('I am '))
                cherrypy.response.output.write(ntob('a tarfile'))

            @cherrypy.expose
            def euro(self):
                hooks = list(cherrypy.request.hooks['before_finalize'])
                hooks.sort()
                cbnames = [x.callback.__name__ for x in hooks]
                assert cbnames == ['gzip'], cbnames
                priorities = [x.priority for x in hooks]
                assert priorities == [80], priorities
                yield ntou('Hello,')
                yield ntou('world')
                yield europoundUnicode

            # Bare hooks
            @cherrypy.expose
            @cherrypy.config(**{'hooks.before_request_body': pipe_body})
            def pipe(self):
                return cherrypy.request.body

            # Multiple decorators; include kwargs just for fun.
            # Note that rotator must run before gzip.
            @cherrypy.expose
            def decorated_euro(self, *vpath):
                yield ntou('Hello,')
                yield ntou('world')
                yield europoundUnicode

            decorated_euro = tools.gzip(compress_level=6)(decorated_euro)
            decorated_euro = tools.rotator(scale=3)(decorated_euro)
Example #3
0
        class Root:
            def index(self):
                return "Howdy earth!"

            index.exposed = True

            def tarfile(self):
                cherrypy.response.output.write(ntob('I am '))
                cherrypy.response.output.write(ntob('a tarfile'))

            tarfile.exposed = True
            tarfile._cp_config = {'tools.streamer.on': True}

            def euro(self):
                hooks = list(cherrypy.request.hooks['before_finalize'])
                hooks.sort()
                cbnames = [x.callback.__name__ for x in hooks]
                assert cbnames == ['gzip'], cbnames
                priorities = [x.priority for x in hooks]
                assert priorities == [80], priorities
                yield ntou("Hello,")
                yield ntou("world")
                yield europoundUnicode

            euro.exposed = True

            # Bare hooks
            def pipe(self):
                return cherrypy.request.body

            pipe.exposed = True
            pipe._cp_config = {'hooks.before_request_body': pipe_body}

            # Multiple decorators; include kwargs just for fun.
            # Note that rotator must run before gzip.
            def decorated_euro(self, *vpath):
                yield ntou("Hello,")
                yield ntou("world")
                yield europoundUnicode

            decorated_euro.exposed = True
            decorated_euro = tools.gzip(compress_level=6)(decorated_euro)
            decorated_euro = tools.rotator(scale=3)(decorated_euro)
Example #4
0
        class Root:
            def index(self):
                return 'Howdy earth!'

            index.exposed = True

            def tarfile(self):
                cherrypy.response.output.write(ntob('I am '))
                cherrypy.response.output.write(ntob('a tarfile'))

            tarfile.exposed = True
            tarfile._cp_config = {'tools.streamer.on': True}

            def euro(self):
                hooks = list(cherrypy.request.hooks['before_finalize'])
                hooks.sort()
                cbnames = [x.callback.__name__ for x in hooks]
                priorities = [x.priority for x in hooks]
                yield ntou('Hello,')
                yield ntou('world')
                yield europoundUnicode

            euro.exposed = True

            def pipe(self):
                return cherrypy.request.body

            pipe.exposed = True
            pipe._cp_config = {'hooks.before_request_body': pipe_body}

            def decorated_euro(self, *vpath):
                yield ntou('Hello,')
                yield ntou('world')
                yield europoundUnicode

            decorated_euro.exposed = True
            decorated_euro = tools.gzip(compress_level=6)(decorated_euro)
            decorated_euro = tools.rotator(scale=3)(decorated_euro)