Skip to content

Conversation

@mrmetrix4
Copy link
Contributor

demjson does not support python3.

@taooceros
Copy link
Member

I think demjson does support python3. Though it is good to keep the package up to date. Any reason we want to use demjson3 over the standard json library of python?

@mrmetrix4
Copy link
Contributor Author

I think demjson does support python3. Though it is good to keep the package up to date. Any reason we want to use demjson3 over the standard json library of python?

Talking about demjson, the "og" demjson uses "DICT.has_key" which doesn't exist in python3 (python plugins that I have ported from Wox didn't work for me so I had to manually patch the flowlauncher package and install demjson3 myself).
Considering the demjson vs json, I don't know the original reason for using demjson, but if I were to guess, it has something to do with unicode and multilingual support.

@taooceros taooceros requested a review from Zeroto521 April 16, 2022 22:03
@Zeroto521
Copy link
Member

Zeroto521 commented Apr 18, 2022

@mrmetrix4 I will check this new changing at today night. Lately, I'm kind of busy.

@jjw24 jjw24 added the bug Something isn't working label Apr 18, 2022
@Zeroto521
Copy link
Member

Talking about demjson, the "og" demjson uses "DICT.has_key" which doesn't exist in python3 ( python plugins that I have ported from Wox didn't work for me so I had to manually patch the flowlauncher package and install demjson3 myself).

Is there a specific plugin?

Considering the demjson vs json, I don't know the original reason for using demjson, but if I were to guess, it has something to do with unicode and multilingual support.

The standard json lib can't handle empty inputting.

if len(sys.argv) > 1: # from input to get jsonrpc
self.rpc_request = demjson.decode(sys.argv[1])

In [1]: import json

In [2]: json.loads("")
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 json.loads("")

File C:\Software\miniforge3\lib\json\__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    341     s = s.decode(detect_encoding(s), 'surrogatepass')
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:
    348     cls = JSONDecoder

File C:\Software\miniforge3\lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w)
    332 def decode(self, s, _w=WHITESPACE.match):
    333     """Return the Python representation of ``s`` (a ``str`` instance
    334     containing a JSON document).
    335
    336     """
--> 337     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338     end = _w(s, end).end()
    339     if end != len(s):

File C:\Software\miniforge3\lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    353     obj, end = self.scan_once(s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@Zeroto521
Copy link
Member

Zeroto521 commented Apr 18, 2022

demjson does not support python3.

Well, as so far demjson is working fine with python3.x.

I don't mind replace demjson with demjson3.
I want to know demjson3 has any advantage compare to demjson such as running speed, importing speed.

@mrmetrix4
Copy link
Contributor Author

mrmetrix4 commented Apr 18, 2022

Talking about demjson, the "og" demjson uses "DICT.has_key" which doesn't exist in python3 ( python plugins that I have ported from Wox didn't work for me so I had to manually patch the flowlauncher package and install demjson3 myself).

Is there a specific plugin?

No, just some that I have coded for QoL in my work.

Well, as so far demjson is working fine with python3.x.

demjson does not support python3.

Well, as so far demjson is working fine with python3.x.

I wanted to install the package in order to show you but with Py3.10 I cant even get it:

C:\Users\mrmet>pip install flowlauncher --no-cache-dir
Defaulting to user installation because normal site-packages is not writeable
Collecting flowlauncher
  Downloading flowlauncher-0.1.1-py3-none-any.whl (4.6 kB)
Collecting demjson
  Downloading demjson-2.2.4.tar.gz (131 kB)
     ---------------------------------------- 131.5/131.5 KB 969.7 kB/s eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      error in demjson setup command: use_2to3 is invalid.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

@mrmetrix4
Copy link
Contributor Author

demjson does not support python3.

Well, as so far demjson is working fine with python3.x.

I don't mind replace demjson with demjson3. I want to know demjson3 has any advantage compare to demjson such as running speed, importing speed.

Iv'e done some testings, the latest version that works with demjson is 3.8.10.

@mrmetrix4
Copy link
Contributor Author

The standard json lib can't handle empty inputting.

if len(sys.argv) > 1: # from input to get jsonrpc
self.rpc_request = demjson.decode(sys.argv[1])

demjson can't either (3 or the original) ->

# With original
import demjson
demjson.decode("")
# Error
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    demjson.decode("")
  File "C:\Users\mrmet\AppData\Roaming\FlowLauncher\Plugins\Hello World Python-1.0.0\lib\demjson.py", line 5696, in decode
    result = j.decode( txt,
  File "C:\Users\mrmet\AppData\Roaming\FlowLauncher\Plugins\Hello World Python-1.0.0\lib\demjson.py", line 4915, in decode
    raise errors[0]
demjson.JSONDecodeError: No value to decode
# With 3
import demjson3
demjson3.decode("")
# Error
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    demjson3.decode("")
  File "C:\Users\mrmet\AppData\Roaming\Python\Python310\site-packages\demjson3.py", line 6423, in decode
    result = j.decode(
  File "C:\Users\mrmet\AppData\Roaming\Python\Python310\site-packages\demjson3.py", line 5607, in decode
    raise errors[0]
demjson3.JSONDecodeError: No value to decode

@Zeroto521
Copy link
Member

The core problem is setuptools already removes lib2to3 from version 58.0.0.

@mrmetrix4
Copy link
Contributor Author

The core problem is setuptools already removes lib2to3 from version 58.0.0.

Cool, so I see two possibilities:

  1. Move the demjson3.
  2. Understand why we use demjson at all and maybe try to use the native json lib.

Do you want me to write a poc using the native json lib?

@mrmetrix4
Copy link
Contributor Author

Do you want me to write a poc using the native json lib?

I've done it anyway, works well for me:
Native Json PR

@Zeroto521
Copy link
Member

Well, it took a little time to find out the reason why use demjson. The details see commit aa145ff.

use demjson replace json to solve json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) problem. json can't recognize '

@Zeroto521
Copy link
Member

The empty string is the answer to handle this line problem from original source wox.py.

https://github.com/Wox-launcher/Wox/blob/121a9103beaa2fe3cd0d64b18928b0a9247801c8/JsonRPC/wox.py#L13

To avoid empty inputting.

if len(sys.argv) > 1: # from input to get jsonrpc

@mrmetrix4
Copy link
Contributor Author

mrmetrix4 commented Apr 21, 2022

Well, it took a little time to find out the reason why use demjson. The details see commit aa145ff.

use demjson replace json to solve json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) problem. json can't recognize '

That's not a problem, that's by design. JSON should not contain single quotes.
I wouldn't want something that claims it's JSON to be formatted with single quotes.

The empty string is the answer to handle this line problem from original source wox.py.

https://github.com/Wox-launcher/Wox/blob/121a9103beaa2fe3cd0d64b18928b0a9247801c8/JsonRPC/wox.py#L13

To avoid empty inputting.

if len(sys.argv) > 1: # from input to get jsonrpc

So this if statement fixes it without being a problem, isn't it?

@taooceros
Copy link
Member

We use standard json lib to create the json input, so it shouldn't contain ' anymore.

@mrmetrix4
Copy link
Contributor Author

We use standard json lib to create the json input, so it shouldn't contain ' anymore.

Therefore, please consider merging #15 in.

@Zeroto521
Copy link
Member

JSON should not contain single quotes. It's right as a protocol. But it's also hard to constrict the inputting from the user.

Another solution is to drop sys.argv and demjson.
I'm thinking we don't need to parser sys.argv actually.
Why do we define a python package called flowlauncher?
To define the port which let the user could use query and context_menu RPC methods, not others.
Based on my writing plugin experiences, sys.argv line only works in running tests like python test.py {blah blah blah}.

rpc_request = demjson.decode(sys.argv[1])

if request_method_name in ["query", "context_menu"]:
print(demjson.encode({"result": results}))

@taooceros
Copy link
Member

Because that's how flow currently pass in the query information (by sys.argv).

@mrmetrix4
Copy link
Contributor Author

Because that's how flow currently pass in the query information (by sys.argv).

Agree,
Until there's a better solution, native json is better since it's supported on both sided (Flow & Python).

@Zeroto521 Zeroto521 changed the title Changed demjson to demjson3 BUG: Changed demjson to demjson3 to solve demjons installing problem Apr 26, 2022
@Zeroto521
Copy link
Member

It could use json replace dejson. #15
Because sys.argv is a port to receive JSON-RPC from Flow Launcher not the user or developer.
The inputting string is a standard JSON. But source code should add some comments to remind the developer about this.

@mrmetrix4 mrmetrix4 closed this Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants