Skip to content

Commit 00c85f9

Browse files
committed
Corrected _create_hexdump
Now works with str.format()
1 parent 8db56c9 commit 00c85f9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

javaobj.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
# -- Content-Encoding: UTF-8 --
13
"""
24
Provides functions for reading and writing (writing is WIP currently) Java
35
objects serialized or will be deserialized by ObjectOutputStream. This form of
@@ -706,13 +708,14 @@ def _create_hexdump(self, src, length=16):
706708
"""
707709
FILTER = ''.join((len(repr(chr(x))) == 3) and chr(x) or '.'
708710
for x in range(256))
711+
pattern = "{{0:04X}} {{1:<{0}}} {{2}}\n".format(length * 3)
712+
709713
result = []
710714
for i in range(0, len(src), length):
711715
s = src[i:i + length]
712716
hexa = ' '.join("{0:02X}".format(ord(x)) for x in s)
713717
printable = s.translate(FILTER)
714-
result.append("{0:04X} {1:-*s} {2}\n".format(i, length * 3, hexa,
715-
printable))
718+
result.append(pattern.format(i, hexa, printable))
716719

717720
return ''.join(result)
718721

0 commit comments

Comments
 (0)