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

Refactored for Python3 compatibility #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

candale
Copy link

@candale candale commented Jun 18, 2017

Refactored the code so that is Python3 compatible. It mostly had trouble when dealing with bytes and returning keys from dictionaries.

I also added object in the inheritance for JsonResource and Webservice because their base classes did not do, which required the call to the unbound __init__ method of the parent.

This should solve, at least partially, issue #12 .

@@ -58,10 +58,11 @@ def jsonrpc_server_call(target, jsonrpc_request, json_decoder=None):
json_decoder = ScrapyJSONDecoder()

try:
req = json_decoder.decode(jsonrpc_request)
req = json_decoder.decode(jsonrpc_request.decode())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.decode() is almost always wrong - it decodes using sys.getdefaultencoding(), which can vary across machines, and which is often ascii. I think it is better to decode from UTF-8 because this is what JSON standard requires.

@candale
Copy link
Author

candale commented Jun 19, 2017

I've also overridden the log method in WebService because it encoded the log line even if it was on Python3, which turned it into bytes.

@candale
Copy link
Author

candale commented Jun 26, 2017

@kmike Any other observations on this PR?

@dariuschira
Copy link

This works well for me with python3, no issues encountered

@dariuschira
Copy link

Can we merge it?

@sibiryakov
Copy link
Contributor

Hi @ChiraMircea can you guys write a test for this? It's extremely hard to reason on your code without tests.

@dariuschira
Copy link

Hey @sibiryakov I added a few basic tests and py37 to tox, hope it's enough, please let me know if you think more tests are required.

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.

4 participants