[prev in list] [next in list] [prev in thread] [next in thread]
List: pyamf-commits
Subject: [pyamf-commits] r70 - in branches/amf3-5/pyamf: . tests
From: pyamf-commits () collab ! com (pyamf-commits () collab ! com)
Date: 2007-10-23 23:51:11
Message-ID: 20071023215104.439E87BC027 () mail ! collab ! com
[Download RAW message or body]
Author: nick
Date: 2007-10-23 23:51:04 +0200 (Tue, 23 Oct 2007)
New Revision: 70
Modified:
branches/amf3-5/pyamf/amf3.py
branches/amf3-5/pyamf/tests/amf3.py
Log:
Added support & tests for python lists
Modified: branches/amf3-5/pyamf/amf3.py
===================================================================
--- branches/amf3-5/pyamf/amf3.py 2007-10-23 21:29:13 UTC (rev 69)
+++ branches/amf3-5/pyamf/amf3.py 2007-10-23 21:51:04 UTC (rev 70)
@@ -245,15 +245,15 @@
size = self.readInteger()
if size & REFERENCE_BIT == 0:
return self.obj_refs[size >> 1]
+
size >>= 1
key = self.readString()
+
if key == "":
# integer indexes only -> python list
- result = []
+ result = [self.readElement() for i in xrange(size)]
+
self.obj_refs.append(result)
- for i in xrange(size):
- el = self.readElement()
- result.append(el)
else:
# key,value pairs -> python dict
result = {}
@@ -469,6 +469,28 @@
ms = time.mktime(n.timetuple())
self.output.write_double(ms * 100.0)
+ def writeArray(self, n):
+ """
+ Writes a list to the stream.
+ """
+ self.writeType(ASTypes.ARRAY)
+ try:
+ ref = self.obj_refs.index(n)
+ use_ref = 1
+ except ValueError:
+ # add an object reference
+ self.obj_refs.append(n)
+ use_ref = 0
+
+ if use_ref == 1:
+ self._writeInteger(ref << 1)
+ else:
+ self._writeInteger(len(n) << 1 | REFERENCE_BIT)
+
+ self.output.write_uchar(0x01)
+ for x in n:
+ self.writeElement(x)
+
class AMF3Class:
def __init__(self, name=None, encoding=None, attrs=None):
Modified: branches/amf3-5/pyamf/tests/amf3.py
===================================================================
--- branches/amf3-5/pyamf/tests/amf3.py 2007-10-23 21:29:13 UTC (rev 69)
+++ branches/amf3-5/pyamf/tests/amf3.py 2007-10-23 21:51:04 UTC (rev 70)
@@ -112,6 +112,20 @@
(x, '\x08\x00'),
(x, '\x08\x00')])
+ def test_list(self):
+ self._run([
+ ([0, 1, 2, 3], '\x09\x09\x01\x04\x00\x04\x01\x04\x02\x04\x03')])
+
+ def test_list_references(self):
+ self.e.obj_refs = []
+
+ y = [0, 1, 2, 3]
+
+ self._run([
+ (y, '\x09\x09\x01\x04\x00\x04\x01\x04\x02\x04\x03'),
+ (y, '\x09\x00'),
+ (y, '\x09\x00')])
+
class ParserTestCase(unittest.TestCase):
def setUp(self):
self.buf = util.BufferedByteStream()
@@ -178,12 +192,24 @@
('<a><b>hello world</b></a>', '\x06\x33<a><b>hello world</b></a>')
])
+ def test_list(self):
+ self._run([
+ ([0, 1, 2, 3], '\x09\x09\x01\x04\x00\x04\x01\x04\x02\x04\x03')])
+
+ def test_list_references(self):
+ y = [0, 1, 2, 3]
+
+ self.obj_refs = [y]
+
+ self._run([
+ (y, '\x09\x00')])
+
class ModifiedUTF8TestCase(unittest.TestCase):
def test_encode(self):
data = [
('hello', '\x00\x05\x68\x65\x6c\x6c\x6f'),
(u'??????????????????', '\x00\x09\xe1\x9a\xa0\xe1\x9b\x87\xe1\x9a\xbb')]
-
+
for x in data:
self.assertEqual(amf3.encode_utf8_modified(x[0]), x[1])
@@ -197,7 +223,7 @@
def suite():
suite = unittest.TestSuite()
-
+
suite.addTest(unittest.makeSuite(TypesTestCase, 'test'))
suite.addTest(unittest.makeSuite(ModifiedUTF8TestCase, 'test'))
suite.addTest(unittest.makeSuite(EncoderTestCase, 'test'))
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic