dmeranda / demjson

Python module for JSON data encoding, including jsonlint. See the project Wiki here on Github. Also read the README at the bottom of this page, or the project homepage at
http://deron.meranda.us/python/demjson/
Other
302 stars 76 forks source link

Lint returning 0 for erroring geojson #15

Closed hugovk closed 8 years ago

hugovk commented 8 years ago

lint.main() isn't returning a non-zero code for a geojson file with errors.

Minimal example:

#!/usr/bin/python
import demjson

lint = demjson.jsonlint()
rc = lint.main(["a.geojson"])
print("rc:", rc)
if rc != 0:
    sys.exit(rc)

a.geojson contains only:

s

Running it (Python 2.7, Windows 7, demjson==2.2.2):

>python test.py
a.geojson:1:0: Error: Unknown identifier: u's'
   |  At line 1, column 0, offset 0 (AT-START)
('rc:', 0)

Expected result: rc should be non-zero and should exit the script.

Problem appears to be _lintcheck() is returning E instead of True or False.

A quick fix is to change the last line of _lintcheck() to:

        if success == True or success == self.SUCCESS_OK:
            return True
        else:
            return False

Which results in:

>python test.py
a.geojson:1:0: Error: Unknown identifier: u's'
   |  At line 1, column 0, offset 0 (AT-START)
('rc:', 1)
dmeranda commented 8 years ago

This was fixed in version 2.2.3 in November 2014. See the docs/CHANGES.txt file.

hugovk commented 8 years ago

Thanks.

For some reason pip install demjson is installing 2.2.2, for both Mac and Windows 7, even though I can see 2.2.3 is also there.

Please can you check and make sure PyPI has the latest 2.2.3 as the default?

I think PyPI may be missing the downloads:

$ pip install -U vanity
Collecting vanity from https://pypi.python.org/packages/source/v/vanity/vanity-2.1.0.zip#md5=ade992a97b1ba4bd1a1ff90414dde6a2
  Downloading vanity-2.1.0.zip
Installing collected packages: vanity
  Found existing installation: vanity 2.0.5
    Uninstalling vanity-2.0.5:
      Successfully uninstalled vanity-2.0.5
  Running setup.py install for vanity
    Installing vanity script to /usr/local/bin
Successfully installed vanity-2.1.0
⌁18% [hugo:/tmp/Downloads] 4s $ 
⌁18% [hugo:/tmp/Downloads] $ vanity demjson
  demjson-1.1.tar.gz    2008-01-29        2,605
  demjson-1.2.tar.gz    2008-03-13        2,581
  demjson-1.3.tar.gz    2008-03-19        3,832
  demjson-1.4.tar.gz    2008-12-17    1,626,894
  demjson-1.5.tar.gz    2010-10-10        4,314
  demjson-1.6.tar.gz    2011-04-02      198,486
  demjson-2.0.tar.gz    2014-05-21        1,718
demjson-2.0.1.tar.gz    2014-05-26        3,803
  demjson-2.2.tar.gz    2014-06-21        1,329
demjson-2.2.1.tar.gz    2014-06-24        1,241
demjson-2.2.2.tar.gz    2014-06-25      137,009
-----------------------------------------------
demjson has been downloaded 1,983,812 times!
dmeranda commented 8 years ago

@hugovk Thanks. The PyPI index has been updated to include the file download for version 2.2.3.

hugovk commented 8 years ago

Thank you, confirmed working:

[hugo:/tmp/Downloads] $ pip install -U demjson
Collecting demjson from https://pypi.python.org/packages/source/d/demjson/demjson-2.2.3.tar.gz#md5=6e0cba366f6697f51f08263516dcb4b0
  Downloading demjson-2.2.3.tar.gz (131kB)
    100% |################################| 135kB 646kB/s 
Installing collected packages: demjson
  Found existing installation: demjson 2.2.2
    Uninstalling demjson-2.2.2:
      Successfully uninstalled demjson-2.2.2
  Running setup.py install for demjson
    changing mode of build/scripts-2.7/jsonlint from 644 to 755
    changing mode of /usr/local/bin/jsonlint to 755
Successfully installed demjson-2.2.3
[hugo:/tmp/Downloads] 24s $ vanity demjson
  demjson-1.1.tar.gz    2008-01-29        2,607
  demjson-1.2.tar.gz    2008-03-13        2,583
  demjson-1.3.tar.gz    2008-03-19        3,834
  demjson-1.4.tar.gz    2008-12-17    1,627,711
  demjson-1.5.tar.gz    2010-10-10        4,316
  demjson-1.6.tar.gz    2011-04-02      198,495
  demjson-2.0.tar.gz    2014-05-21        1,720
demjson-2.0.1.tar.gz    2014-05-26        3,805
  demjson-2.2.tar.gz    2014-06-21        1,331
demjson-2.2.1.tar.gz    2014-06-24        1,243
demjson-2.2.2.tar.gz    2014-06-25      137,203
demjson-2.2.3.tar.gz    2015-09-03           45
-----------------------------------------------
demjson has been downloaded 1,984,893 times!