These are chat archives for cherrypy/cherrypy

26th
Apr 2018
Sviatoslav Sydorenko
@webknjaz
Apr 26 2018 07:20 UTC
@dddh have you enabled @cherrypy.tools.gzip too?
@webknjaz https://tld.jp/~dddh/_cherrypy-2018042600.py.txt 'tools.gzip.on': True
Sviatoslav Sydorenko
@webknjaz
Apr 26 2018 10:09 UTC
Please don't let us follow suspiciously looking links. Could you please post code with python highlighting for readability.
Sviatoslav Sydorenko
@webknjaz
Apr 26 2018 12:11 UTC
btw gitter allows doing it right here:
def hi():
    return 'Hello'
Sviatoslav Sydorenko
@webknjaz
Apr 26 2018 12:21 UTC
i believe with json_in and gzip tools both enabled you should get it working via:
class YourController:
    @cherrypy.expose
    @cherrypy.tools.gzip()
    @cherrypy.tools.json_in()
    @cherrypy.tools.json_out()
    def index(self):
        your_payload = cherrypy.request.json
        return {'some': 'dict'}
Jason R. Coombs
@jaraco
Apr 26 2018 12:58 UTC
@webknjaz I’d be surpised if that just worked. I’m pretty sure the gzip tool is for compressing the response, not for decompressing the request body, which is what dddh is seeking.
Moreover, the gzip tool doesn’t compress json content by default; you have to specify the content type for the tool to compress it.
Sviatoslav Sydorenko
@webknjaz
Apr 26 2018 13:00 UTC
oh
Jason R. Coombs
@jaraco
Apr 26 2018 13:01 UTC
You’d also have to make sure the priorities were set on those tools so they run in the appropriate order as well.
Sviatoslav Sydorenko
@webknjaz
Apr 26 2018 13:05 UTC
So it requires smth like:
...
cherrypy.tools.gunzip = Tool('before_request_body', cherrypy.lib.encoding.decompress, priority=20)
...
    @cherrypy.tools.gunzip()
    ...
    def index(self):
        ...
Sviatoslav Sydorenko
@webknjaz
Apr 26 2018 13:21 UTC
@jaraco I'm thinking of adding this to modules in order to make them behave as Python 3 under Python 2. What do you think?
from __future__ import absolute_import, division, print_function
__metaclass__ = type
Jason R. Coombs
@jaraco
Apr 26 2018 13:22 UTC
The first line is fine (and preferred). Maybe also add unicode_literals.
I’m not sure I understand the purpose of __metaclass__ = type
I’ve only seen metaclass used in classes, so I’ll have to learn more about what a module-level __metaclass__ attribute means.
I wish I’d known of that years ago.
Yes, an enthusiastic +1