openpreserve / jpylyzer

JP2 (JPEG 2000 Part 1) validator and properties extractor. Jpylyzer was specifically created to check that a JP2 file really conforms to the format's specifications. Additionally jpylyzer is able to extract technical characteristics.
http://jpylyzer.openpreservation.org/
Other
69 stars 28 forks source link

Jython compatibility #96

Closed anjackson closed 6 years ago

anjackson commented 7 years ago

For reference, following on from issue #95, this is how I've got it working under Jython. The main thing is to allow a fail-over to using a byte array when mmap doesn't work.

However, I also found I had to change a bit of unicode escape logic and I don't really know why. If I use the original code, this happens:

$ java -jar ~/Downloads/jython-standalone-2.7.0.jar ./jpylyzer/jpylyzer.py vdc_100022551931.0x000001 
<?xml version='1.0' encoding='UTF-8'?>
Traceback (most recent call last):
  File "./jpylyzer/jpylyzer.py", line 732, in <module>
    main()
  File "./jpylyzer/jpylyzer.py", line 728, in main
    checkFiles(args.inputRecursiveFlag, args.inputWrapperFlag, jp2In)
  File "./jpylyzer/jpylyzer.py", line 654, in checkFiles
    xmlElement = checkOneFile(path)
  File "./jpylyzer/jpylyzer.py", line 315, in checkOneFile
    fileNameCleaned = stripSurrogatePairs(fileName)
  File "./jpylyzer/jpylyzer.py", line 435, in stripSurrogatePairs
    lone = re.compile(
  File "/Users/andy/Documents/workspace/jpylyzer/jpylyzer/six.py", line 647, in u
    return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 115-121: illegal Unicode character

unicode(s.replace(r'\\', r'\\\\'), "utf-8") rather than unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") it works fine. AFAICT.

One remaining oddity if that the pretty-printing under the Jython minidom library behaves slightly differently (as described in this post which indicates this may be old Python behaviour that Jython still observes even through CPython does not). But this is not a problem and the output is identical if pretty-printing is disabled.

bitsgalore commented 6 years ago

Closing request as @anjackson doesn't need Jython support anymore.