[prev in list] [next in list] [prev in thread] [next in thread]
List: pyamf-commits
Subject: [pyamf-commits] r1803 -
From: commits () pyamf ! org (commits () pyamf ! org)
Date: 2008-11-24 18:03:19
Message-ID: 20081124170302.697337BC063 () mail ! collab ! com
[Download RAW message or body]
Author: nick
Date: 2008-11-24 18:03:01 +0100 (Mon, 24 Nov 2008)
New Revision: 1803
Modified:
pyamf/branches/arraycollection-list-349/pyamf/flex/__init__.py
Log:
Changed the supertype of ArrayCollection from dict to list, implemented the IList interface
Modified: pyamf/branches/arraycollection-list-349/pyamf/flex/__init__.py
===================================================================
--- pyamf/branches/arraycollection-list-349/pyamf/flex/__init__.py 2008-11-24 15:45:21 UTC (rev 1802)
+++ pyamf/branches/arraycollection-list-349/pyamf/flex/__init__.py 2008-11-24 17:03:01 UTC (rev 1803)
@@ -15,7 +15,7 @@
__all__ = ['ArrayCollection', 'ObjectProxy']
-class ArrayCollection(dict):
+class ArrayCollection(list):
"""
I represent the ActionScript 3 based class
C{flex.messaging.io.ArrayCollection} used in the Flex framework.
@@ -27,19 +27,24 @@
@see: U{ArrayCollection on Livedocs (external)
<http://livedocs.adobe.com/flex/201/langref/mx/collections/ArrayCollection.html>}
+
+ @note: This class does not implement the remote object part of the
+ documentation.
+
+ @ivar length: [read-only] The number of items in this collection.
+ Introduced in 0.4.
+ @type length: C{int}
"""
def __init__(self, source=None):
- if source is not None:
- if hasattr(source, 'iteritems'):
- for k, v in source.iteritems():
- self[k] = v
- else:
- for i in range(len(source)):
- self[i] = source[i]
+ if source is not None and hasattr(source, 'iter'):
+ c = 0
+ for i in iter(source):
+ self[c] = c
+
def __repr__(self):
- return "<flex.messaging.io.ArrayCollection %s>" % dict.__repr__(self)
+ return "<flex.messaging.io.ArrayCollection %s>" % list.__repr__(self)
def __readamf__(self, input):
data = input.readObject()
@@ -56,6 +61,122 @@
def __writeamf__(self, output):
output.writeObject(pyamf.MixedArray(self), use_references=False)
+ def _get_length(self):
+ return len(self)
+
+ def _set_length(self, length):
+ raise RuntimeError("Property length is read-only")
+
+ length = property(_get_length, _set_length)
+
+ def addItem(self, item):
+ """
+ Adds the specified item to the end of the list.
+
+ @param item: The object to add to the collection.
+ @type item: C{mixed}.
+ @since: 0.4
+ """
+ self.append(item)
+
+ def addItemAt(self, item, index):
+ """
+ Adds the item at the specified index.
+
+ @param item: The object to add to the collection.
+ @type item: C{mixed}.
+ @param index: The index at which to place the item.
+ @raise IndexError: If index is less than 0 or greater than the length
+ of the list.
+ @since: 0.4
+ """
+ if 0 > index < len(self):
+ raise IndexError
+
+ self.insert(index, item)
+
+ def getItemAt(self, index, prefetch=0):
+ """
+ Gets the item at the specified index.
+
+ @param index: The index in the list from which to retrieve the item.
+ @type index: C{int}
+ @param prefetch: This param is ignored and is only here as part of the
+ interface.
+ @raise IndexError: if index < 0 or index >= length
+ @return: The item at index C{index}.
+ @rtype: C{mixed}.
+ @since: 0.4
+ """
+ return self.__getitem__(index)
+
+ def getItemIndex(self, item):
+ """
+ Returns the index of the item if it is in the list such that
+ getItemAt(index) == item.
+
+ @param item: The item to find.
+ @type item: C{mixed}.
+ @return: The index of the item or -1 if the item is not in the list.
+ @rtype: C{int}
+ @since: 0.4
+ """
+ try:
+ return self.index(item)
+ except ValueError:
+ return -1
+
+ def removeAll(self):
+ """
+ Removes all items from the list.
+
+ @since: 0.4
+ """
+ for i in range(len(self)):
+ del self[i]
+
+ def removeItemAt(self, index):
+ """
+ Removes the item at the specified index and returns it. Any items that
+ were after this index are now one index earlier.
+
+ @param index: The index from which to remove the item.
+ @return: The item that was removed.
+ @rtype: C{mixed}.
+ @raise IndexError: is index is less than 0 or greater than length.
+ @since: 0.4
+ """
+ x = self[index]
+
+ del self[index]
+
+ return x
+
+ def setItemAt(self, item, index):
+ """
+ Places the item at the specified index. If an item was already at that
+ index the new item will replace it and it will be returned.
+
+ @param item: The new item to be placed at the specified index.
+ @type item: C{mixed}.
+ @param index: The index at which to place the item.
+ @type index: C{int}
+ @return: The item that was replaced, or C{None}.
+ @rtype: C{mixed} or C{None}.
+ @raise IndexError: is index is less than 0 or greater than length.
+ @since: 0.4
+ """
+
+ def toArray(self):
+ """
+ Returns an Array that is populated in the same order as the IList
+ implementation.
+
+ @return: The array.
+ @rtype: C{list}
+ """
+ return self
+
pyamf.register_class(ArrayCollection, 'flex.messaging.io.ArrayCollection',
metadata=['external', 'amf3'])
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic