Package pyamf :: Package flex
[hide private]
[frames] | no frames]

Source Code for Package pyamf.flex

  1  # Copyright (c) 2007-2008 The PyAMF Project. 
  2  # See LICENSE for details. 
  3   
  4  """ 
  5  Compatibility classes/functions for Flex. 
  6   
  7  @note: Not available in ActionScript 1.0 and 2.0. 
  8  @see: U{Flex on Wikipedia (external) 
  9  <http://en.wikipedia.org/wiki/Adobe_Flex>} 
 10   
 11  @author: U{Nick Joyce<mailto:nick@boxdesign.co.uk>} 
 12   
 13  @since: 0.1.0 
 14  """ 
 15   
 16  import pyamf 
 17   
 18  __all__ = ['ArrayCollection', 'ObjectProxy'] 
 19   
20 -class ArrayCollection(dict):
21 """ 22 I represent the ActionScript 3 based class 23 C{flex.messaging.io.ArrayCollection} used in the Flex framework. 24 25 The ArrayCollection class is a wrapper class that exposes an Array 26 as a collection that can be accessed and manipulated using the 27 methods and properties of the C{ICollectionView} or C{IList} 28 interfaces in the Flex framework. 29 30 @see: U{ArrayCollection on Livedocs (external) 31 <http://livedocs.adobe.com/flex/201/langref/mx/collections/ArrayCollection.html>} 32 """ 33
34 - def __init__(self, source=None):
35 if source is not None: 36 if isinstance(source, (list, tuple)): 37 for i in range(len(source)): 38 self[i] = source[i] 39 elif isinstance(source, (dict)): 40 for k, v in source.iteritems(): 41 self[k] = v
42
43 - def __repr__(self):
44 return "<flex.messaging.io.ArrayCollection %s>" % dict.__repr__(self)
45
46 - def __readamf__(self, input):
47 data = input.readObject() 48 49 if hasattr(data, 'iteritems'): 50 for (k, v) in data.iteritems(): 51 self[k] = v 52 else: 53 count = 0 54 for i in data: 55 self[count] = i 56 count += 1
57
58 - def __writeamf__(self, output):
59 output.writeObject(pyamf.MixedArray(self), use_references=False)
60 61 pyamf.register_class(ArrayCollection, 'flex.messaging.io.ArrayCollection', 62 metadata=['external', 'amf3']) 63
64 -class ObjectProxy(object):
65 """ 66 I represent the ActionScript 3 based class C{flex.messaging.io.ObjectProxy} 67 used in the Flex framework. Flex's ObjectProxy class allows an anonymous, 68 dynamic ActionScript Object to be bindable and report change events. 69 70 @see: U{ObjectProxy on Livedocs (external) 71 <http://livedocs.adobe.com/flex/201/langref/mx/utils/ObjectProxy.html>} 72 """ 73
74 - def __init__(self, object=None):
75 if object is None: 76 self._amf_object = pyamf.ASObject() 77 else: 78 self._amf_object = object
79
80 - def __repr__(self):
81 return "<flex.messaging.io.ObjectProxy %s>" % self._amf_object
82
83 - def __getattr__(self, name):
84 if name == '_amf_object': 85 return self.__dict__['_amf_object'] 86 87 return getattr(self.__dict__['_amf_object'], name)
88
89 - def __setattr__(self, name, value):
90 if name == '_amf_object': 91 self.__dict__['_amf_object'] = value 92 else: 93 setattr(self._amf_object, name, value)
94
95 - def __readamf__(self, input):
96 self._amf_object = input.readObject()
97
98 - def __writeamf__(self, output):
99 output.writeObject(self._amf_object)
100 101 pyamf.register_class(ObjectProxy, 'flex.messaging.io.ObjectProxy', 102 metadata=['external', 'amf3']) 103