Skip to content

Commit d40ba44

Browse files
author
vbuell
committed
initial import of junk
1 parent 46c9889 commit d40ba44

File tree

9 files changed

+49
-0
lines changed

9 files changed

+49
-0
lines changed

javaobj.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import StringIO
2+
import struct
3+
4+
def loads(object):
5+
f = StringIO.StringIO(object)
6+
ba = f.read(4)
7+
(magic, version) = struct.unpack(">HH", ba)
8+
print magic
9+
if magic != 0xaced:
10+
raise RuntimeError("The stream is not java serialized object. Magic number failed.")
11+
12+
print version
13+
14+
print type(object), Magic
15+

obj0.ser

8 Bytes
Binary file not shown.

obj1.ser

14 Bytes
Binary file not shown.

obj2.ser

16 Bytes
Binary file not shown.

obj3.ser

7 Bytes
Binary file not shown.

obj4.ser

7 Bytes
Binary file not shown.

obj5.ser

129 Bytes
Binary file not shown.

obj6.ser

37 Bytes
Binary file not shown.

tests.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import random
2+
import unittest
3+
import javaobj
4+
5+
class TestSequenceFunctions(unittest.TestCase):
6+
7+
def setUp(self):
8+
self.seq = range(10)
9+
10+
def read_file(self, filename):
11+
file = open(filename, 'rb')
12+
return file.read()
13+
14+
def test_0(self):
15+
jobj = self.read_file("obj0.ser")
16+
pobj = javaobj.loads(jobj)
17+
18+
print pobj
19+
20+
# make sure the shuffled sequence does not lose any elements
21+
random.shuffle(self.seq)
22+
self.seq.sort()
23+
self.assertEqual(self.seq, range(10))
24+
25+
# should raise an exception for an immutable sequence
26+
self.assertRaises(TypeError, random.shuffle, (1,2,3))
27+
28+
def test_choice(self):
29+
element = random.choice(self.seq)
30+
self.assertTrue(element in self.seq)
31+
32+
33+
if __name__ == '__main__':
34+
unittest.main()

0 commit comments

Comments
 (0)