Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom json encoding in jsonrpc handler. #165

Closed

Conversation

dpnova
Copy link
Collaborator

@dpnova dpnova commented Feb 1, 2015

This also includes some basic tests for the jsonrpc handler.

Note #133 for previous discussion.

This also includes some basic tests for the jsonrpc handler.
@dpnova
Copy link
Collaborator Author

dpnova commented Feb 1, 2015

Broken test depends on acceptance of: #164

EDIT: woops clicked wrong button.

@dpnova dpnova closed this Feb 1, 2015
@dpnova dpnova reopened this Feb 1, 2015
@posita
Copy link

posita commented Feb 24, 2015

Not that you need my approval, but 👍 for the approach. This looks like this addresses my original beef in #133.

@vltr
Copy link

vltr commented Sep 16, 2015

quick, dirty question: why only in the rpc?

$ grep -n "json_" *.py
auth.py:544:        callback(escape.json_decode(response.body))
auth.py:668:        callback(escape.json_decode(response.body))
auth.py:852:        session = escape.json_decode(self.get_argument("session"))
auth.py:929:            json = escape.json_decode(response.body)
auth.py:1090:        callback(escape.json_decode(response.body))
escape.py:44:    _json_decode = json.loads
...
[truncated for obvious reasons]
...
escape.py:94:    return _json_decode(to_basestring(value))
httpclient.py:226:        q = escape.json_encode({"method": method, "params": args,
httpclient.py:241:                data = escape.json_decode(response.body)
jsonrpc.py:57:            req = cyclone.escape.json_decode(self.request.body)
jsonrpc.py:85:        self.finish(cyclone.escape.json_encode(data))
sse.py:58:            message = escape.json_encode(message)
template.py:79:We provide the functions escape(), url_escape(), json_encode(), and squeeze()
template.py:259:            "json_encode": escape.json_encode,
web.py:523:            chunk = escape.json_encode(chunk)
websocket.py:111:            message = cyclone.escape.json_encode(message)

afaik, this does not solve the monkey patching problem from #133 if you think cyclone wise.

@fiorix
Copy link
Owner

fiorix commented Sep 16, 2015

True. We'll need more patches. Unfortunately I cannot do that atm but will be happy to review, merge, and release.

@dpnova
Copy link
Collaborator Author

dpnova commented Sep 17, 2015

Just to clarify here, we're proposing being able to set the json encoder and decoder at a class level for the regular request handler? How does this make sense? Perhaps for the websocket and sse handlers?

@vltr
Copy link

vltr commented Sep 17, 2015

in #133, it's discussed monkey patching on cyclone.escape.json_*, right? i know it's for using in the jsonrpc handler, but that would not bring any normalization cyclone wise talking, since json encoding and decoding are used not only in the json rpc. just my two cents ...

@posita
Copy link

posita commented Sep 18, 2015

@vltr, I think it's probably better to separate them, and allow overriding at the RPC layer. There may be cases where one wants different behaviors in different contexts (rather than a global one, which is probably the wrong thing to do, but the easiest option I had at the time).

The problem with the RPC code is that you don't have direct control over the JSON parser that is used. There may be other contexts that are similar, but I would suggest filing separate issues for each of them (as @dpnova mentioned, possibly the websocket and sse handlers). If one is doing one's own JSON parsing, one can do whatever one likes (obviously).

That's just my $1.05 (NSFW). ⚠️

@vltr
Copy link

vltr commented Sep 18, 2015

@posita, your $1.05 worth a laugh hahaha! well, I see no problem by this implementation being only about the json-rpc. in my handlers, I already have my own json encoder / decoder by using self.json_encode and self.json_decode. i'm not being a pita, i was just thinking about the overall. perhaps a factory or a default encoder / decoder setting would be a better idea for the rest of the api. cheers! :)

@vltr
Copy link

vltr commented Oct 15, 2015

ok, a new version of cyclone on pypi depends on this? if so, i'll propose a PR.

cheers,
richard.

ps: will cyclone use semantic versioning instead of git-$(date +%Y%m%d)0X (as it is now in "setup.py:80") ? :)

@fiorix
Copy link
Owner

fiorix commented Oct 15, 2015

It does make sense, we can drop the date there.

@vltr
Copy link

vltr commented Oct 15, 2015

thanks @fiorix! i'll make a PR for this json "dilemma" ;)

vltr pushed a commit to vltr/cyclone that referenced this pull request Oct 16, 2015
@dpnova
Copy link
Collaborator Author

dpnova commented Jan 7, 2016

Green here too @fiorix cheers!

@dpnova
Copy link
Collaborator Author

dpnova commented Feb 17, 2017

I'm going to accept this PR in two days. (ie Monday next week - if anyone has an issue let me know by then!)

@vltr
Copy link

vltr commented Feb 17, 2017

wow, i didn't even remember of this PR ...

@posita
Copy link

posita commented Feb 17, 2017

🎉

@fiorix
Copy link
Owner

fiorix commented Jul 13, 2019

Stuck for too long, conflicting.

@fiorix fiorix closed this Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants