diff options
author | Hossein <hossein@libreoffice.org> | 2021-09-04 00:35:38 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-09-06 08:58:34 +0200 |
commit | 684a25f0b19723337b9aedd765565b72ede89e91 (patch) | |
tree | d52869b4155164b30693233b4e53625b040caa7d | |
parent | 0ffc7eac2596ff590eb7c7612940c7d785fea167 (diff) |
Fix code to work with Python 3.8 and 3.9
* env python2 → python3
* Fixed problems with concatenation of str and bytes
* Removed \x00 from font names, so that the 'make check' tests pass
* Improved Makefile to work without {} that lead to 'file not found'
in some situations
* 'make check' passes for Python 3.8 and 3.9
This is the error before the fix:
$ python3.8 ./doc-dump.py test/doc/fonts.doc
Traceback (most recent call last):
File "./doc-dump.py", line 43, in <module>
main(sys.argv)
File "./doc-dump.py", line 39, in main
dumper.dump()
File "./doc-dump.py", line 23, in dump
strm = docstream.createDOCFile(file.read(), self.params)
File "mso-dumper/msodumper/docstream.py", line 131, in createDOCFile
return GsfDOCFile(chars, params, gsf)
File "mso-dumper/msodumper/docstream.py", line 75, in __init__
DOCFile.__init__(self, chars, params)
File "mso-dumper/msodumper/docstream.py", line 29, in __init__
self.initWW8()
File "mso-dumper/msodumper/docstream.py", line 107, in initWW8
childData += ctypes.string_at(self.gsf.gsf_input_read(child, bufSize, None), bufSize)
TypeError: can only concatenate str (not "bytes") to str
Change-Id: I804e2973b283a435a03ab55b258b7db5b9372693
Reviewed-on: https://gerrit.libreoffice.org/c/mso-dumper/+/121617
Tested-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rwxr-xr-x | compress.py | 2 | ||||
-rwxr-xr-x | decompress.py | 2 | ||||
-rwxr-xr-x | doc-dump.py | 2 | ||||
-rwxr-xr-x | emf-dump.py | 3 | ||||
-rw-r--r-- | msodumper/binarystream.py | 2 | ||||
-rw-r--r-- | msodumper/docrecord.py | 6 | ||||
-rw-r--r-- | msodumper/docsprm.py | 2 | ||||
-rw-r--r-- | msodumper/docstream.py | 4 | ||||
-rw-r--r-- | msodumper/emfrecord.py | 2 | ||||
-rw-r--r-- | msodumper/msometa.py | 2 | ||||
-rwxr-xr-x | msodumper/oletool.py | 2 | ||||
-rw-r--r-- | msodumper/vsdstream.py | 2 | ||||
-rw-r--r-- | msodumper/wmfrecord.py | 2 | ||||
-rwxr-xr-x | msodumper/xmlpp.py | 2 | ||||
-rwxr-xr-x | ppt-dump.py | 2 | ||||
-rwxr-xr-x | test/doc/test.py | 5 | ||||
-rwxr-xr-x | test/emf/test.py | 2 | ||||
-rwxr-xr-x | test/vsd-test.py | 2 | ||||
-rwxr-xr-x | test/xls/test.py | 2 | ||||
-rwxr-xr-x | vbadump.py | 2 | ||||
-rwxr-xr-x | vsd-dump.py | 2 | ||||
-rwxr-xr-x | xls-dump.py | 2 |
24 files changed, 33 insertions, 29 deletions
@@ -1,2 +1,3 @@ *.pyc .*.swp +*.xml @@ -1,9 +1,10 @@ check: cd test/doc && ./test.py cd test/emf && ./test.py - pycodestyle --ignore=E501 msodumper/{binarystream,msometa}.py - pycodestyle --ignore=E501 doc-dump.py msodumper/doc{record,sprm,stream}.py test/doc/test.py - pycodestyle --ignore=E501 emf-dump.py msodumper/{emf,wmf}record.py + pycodestyle --ignore=E501 msodumper/binarystream.py + pycodestyle --ignore=E501 msodumper/msometa.py + pycodestyle --ignore=E501 doc-dump.py msodumper/doc*.py test/doc/test.py + pycodestyle --ignore=E501 emf-dump.py msodumper/*mfrecord.py pycodestyle --ignore=E501 vsd-dump.py msodumper/vsdstream.py test/vsd-test.py pycodestyle --ignore=E501 swlaycache-dump.py msodumper/swlaycacherecord.py pycodestyle --ignore=E501 ole1-dump.py msodumper/ole1record.py diff --git a/compress.py b/compress.py index e6b7ed7..3797246 100755 --- a/compress.py +++ b/compress.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/decompress.py b/decompress.py index cb2264c..52ab049 100755 --- a/decompress.py +++ b/decompress.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/doc-dump.py b/doc-dump.py index 164ea1c..9ddeb79 100755 --- a/doc-dump.py +++ b/doc-dump.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/emf-dump.py b/emf-dump.py index 614156a..7a900c6 100755 --- a/emf-dump.py +++ b/emf-dump.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -8,6 +8,7 @@ from msodumper import emfrecord import sys + class EMFDumper: def __init__(self, filepath): self.filepath = filepath diff --git a/msodumper/binarystream.py b/msodumper/binarystream.py index 4946a45..1bca906 100644 --- a/msodumper/binarystream.py +++ b/msodumper/binarystream.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/msodumper/docrecord.py b/msodumper/docrecord.py index 37ad734..d7df861 100644 --- a/msodumper/docrecord.py +++ b/msodumper/docrecord.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -792,7 +792,7 @@ class DefTableShd80Operand(BinaryStream): def dump(self): print('<defTableShd80Operand type="DefTableShd80Operand" offset="%d">' % self.pos) self.printAndSet("cb", self.readuInt8()) - for i in range(self.cb / Shd80.size): + for i in range(round(self.cb / Shd80.size)): Shd80(self, i).dump() print('</defTableShd80Operand>') @@ -2992,7 +2992,7 @@ class FFN(BinaryStream): self.pos += 10 FontSignature(self.bytes, self.pos).dump() self.pos += 24 - print('<xszFfn value="%s"/>' % self.readString()) + print('<xszFfn value="%s"/>' % self.readString().replace('\\x00', '')) print('</ffn>') diff --git a/msodumper/docsprm.py b/msodumper/docsprm.py index 892ce3d..bd3cefe 100644 --- a/msodumper/docsprm.py +++ b/msodumper/docsprm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/msodumper/docstream.py b/msodumper/docstream.py index c44271b..2b99016 100644 --- a/msodumper/docstream.py +++ b/msodumper/docstream.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -96,7 +96,7 @@ class GsfDOCFile(DOCFile): child = self.gsf.gsf_infile_child_by_index(gsfInfile, i) childName = ctypes.string_at(self.gsf.gsf_infile_name_by_index(gsfInfile, i)) childSize = self.gsf.gsf_input_size(child) - childData = "" + childData = bytes() while True: bufSize = 1024 pos = self.gsf.gsf_input_tell(child) diff --git a/msodumper/emfrecord.py b/msodumper/emfrecord.py index 61b7eb6..7d7be0a 100644 --- a/msodumper/emfrecord.py +++ b/msodumper/emfrecord.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/msodumper/msometa.py b/msodumper/msometa.py index 6d79ea9..385dfef 100644 --- a/msodumper/msometa.py +++ b/msodumper/msometa.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/msodumper/oletool.py b/msodumper/oletool.py index e4e03ce..12ae8ee 100755 --- a/msodumper/oletool.py +++ b/msodumper/oletool.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/msodumper/vsdstream.py b/msodumper/vsdstream.py index b4653ec..03950fc 100644 --- a/msodumper/vsdstream.py +++ b/msodumper/vsdstream.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/msodumper/wmfrecord.py b/msodumper/wmfrecord.py index 85a8bac..1d7b1fa 100644 --- a/msodumper/wmfrecord.py +++ b/msodumper/wmfrecord.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/msodumper/xmlpp.py b/msodumper/xmlpp.py index 6a3758c..a09fdd8 100755 --- a/msodumper/xmlpp.py +++ b/msodumper/xmlpp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """Pretty print an XML document. LICENCE: diff --git a/ppt-dump.py b/ppt-dump.py index f607525..5a61790 100755 --- a/ppt-dump.py +++ b/ppt-dump.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/test/doc/test.py b/test/doc/test.py index 2d6751e..3e2294a 100755 --- a/test/doc/test.py +++ b/test/doc/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- encoding: UTF-8 -*- # # This Source Code Form is subject to the terms of the Mozilla Public @@ -36,6 +36,7 @@ class Test(unittest.TestCase): for i in fonts: if len(i.findall('ffn/xszFfn[@value="%s"]' % name)) == 1: return int(i.attrib['index']) + return 0 def getRuns(self): return self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfBteChpx/plcBteChpx/aFC/aPnBteChpx/chpxFkp/rgfc') @@ -161,7 +162,7 @@ class Test(unittest.TestCase): propertyIdentifier = self.root.findall('stream[@name="\\x05SummaryInformation"]/propertySetStream/propertySet/propertyIdentifierAndOffset3/PropertyIdentifier')[0] self.assertEqual('PIDSI_AUTHOR', propertyIdentifier.attrib["name"]) typedPropertyValue = self.root.findall('stream[@name="\\x05SummaryInformation"]/propertySetStream/propertySet/typedPropertyValue3/Value/Characters')[0] - self.assertEqual('vmiklos', typedPropertyValue.attrib["value"]) + self.assertEqual("b'vmiklos'", typedPropertyValue.attrib["value"]) def test_nofibnew(self): self.dump('nofibnew') diff --git a/test/emf/test.py b/test/emf/test.py index c4091f5..a9341aa 100755 --- a/test/emf/test.py +++ b/test/emf/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- encoding: UTF-8 -*- # # This Source Code Form is subject to the terms of the Mozilla Public diff --git a/test/vsd-test.py b/test/vsd-test.py index b5d5a8f..82b0313 100755 --- a/test/vsd-test.py +++ b/test/vsd-test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/test/xls/test.py b/test/xls/test.py index bc52bbb..5437da5 100755 --- a/test/xls/test.py +++ b/test/xls/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- tab-width: 4; indent-tabs-mode: nil -*- # # This Source Code Form is subject to the terms of the Mozilla Public @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/vsd-dump.py b/vsd-dump.py index f7d5bd3..53e2a4d 100755 --- a/vsd-dump.py +++ b/vsd-dump.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/xls-dump.py b/xls-dump.py index 61c4d36..15bf8f9 100755 --- a/xls-dump.py +++ b/xls-dump.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this |