[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pyamf-commits
Subject:    [pyamf-commits] r90 - branches/remoting-2/pyamf
From:       pyamf-commits () collab ! com (pyamf-commits () collab ! com)
Date:       2007-10-29 17:14:50
Message-ID: 20071029161443.382217BC069 () mail ! collab ! com
[Download RAW message or body]

Author: nick
Date: 2007-10-29 17:14:43 +0100 (Mon, 29 Oct 2007)
New Revision: 90

Modified:
   branches/remoting-2/pyamf/__init__.py
   branches/remoting-2/pyamf/amf0.py
   branches/remoting-2/pyamf/amf3.py
   branches/remoting-2/pyamf/messaging.py
Log:
API improvements

Modified: branches/remoting-2/pyamf/__init__.py
===================================================================
--- branches/remoting-2/pyamf/__init__.py	2007-10-29 15:53:53 UTC (rev 89)
+++ branches/remoting-2/pyamf/__init__.py	2007-10-29 16:14:43 UTC (rev 90)
@@ -36,6 +36,12 @@
 CLASS_CACHE = {}
 CLASS_LOADERS = []
 
+# Encoding types
+AMF0 = 0
+AMF3 = 3
+
+ENCODING_TYPES = (AMF0, AMF3)
+
 class GeneralTypes:
     """
     PyAMF global constants
@@ -313,3 +319,44 @@
 # Register some basic classes
 register_class(Bag, 'flex.messaging.io.ArrayCollection')
 register_class(Bag, 'flex.messaging.io.ObjectProxy')
+
+def decode(stream, encoding=AMF0, context=None):
+    """
+    A helper function to decode a datastream. 
+    """
+    if encoding not in ENCODING_TYPES:
+        raise ValueError("Unknown encoding")
+
+    if encoding == AMF0:
+        decoder = amf0.Parser(stream, context)
+    elif encoding == AMF3:
+        from pyamf import amf3
+
+        decoder = amf3.Parser(stream, context)
+
+    decoder = Parser(stream, context)
+
+    for el in decoder.readElement():
+        yield el
+
+def encode(element, encoding=AMF0, context=None):
+    """
+    A helper function to encode an element
+    
+    Returns a StringIO object
+    """
+    if encoding not in ENCODING_TYPES:
+        raise ValueError("Unknown encoding")
+
+    if encoding == AMF0:
+        encoder = amf0.Encoder(stream, context)
+    elif encoding == AMF3:
+        from pyamf import amf3
+
+        encoder = amf3.Encoder(stream, context)
+
+    buf = util.BufferedByteStream()
+
+    encoder.writeElement(element)
+
+    return buf

Modified: branches/remoting-2/pyamf/amf0.py
===================================================================
--- branches/remoting-2/pyamf/amf0.py	2007-10-29 15:53:53 UTC (rev 89)
+++ branches/remoting-2/pyamf/amf0.py	2007-10-29 16:14:43 UTC (rev 90)
@@ -423,3 +423,25 @@
         self.writeType(ASTypes.XML)
         self.output.write_ulong(len(data))
         self.output.write(data)
+
+def decode(stream, context=None):
+    """
+    A helper function to decode an AMF0 datastream. 
+    """
+    decoder = Parser(stream, context)
+    
+    for el in decoder.readElement():
+        yield el
+
+def encode(element, context=None):
+    """
+    A helper function to encode an element into AMF0 format.
+    
+    Returns a StringIO object
+    """
+    buf = util.BufferedByteStream()
+    encoder = Encoder(buf, context)
+
+    encoder.writeElement(element)
+
+    return buf

Modified: branches/remoting-2/pyamf/amf3.py
===================================================================
--- branches/remoting-2/pyamf/amf3.py	2007-10-29 15:53:53 UTC (rev 89)
+++ branches/remoting-2/pyamf/amf3.py	2007-10-29 16:14:43 UTC (rev 90)
@@ -804,3 +804,25 @@
     utf16 = "".join([chr((c >> 8) & 0xff) + chr(c & 0xff) for c in utf16])
 
     return unicode(utf16, "utf_16_be")
+
+def decode(stream, context=None):
+    """
+    A helper function to decode an AMF3 datastream. 
+    """
+    decoder = Parser(stream, context)
+    
+    for el in decoder.readElement():
+        yield el
+
+def encode(element, context=None):
+    """
+    A helper function to encode an element into AMF3 format.
+
+    Returns a StringIO object
+    """
+    buf = util.BufferedByteStream()
+    encoder = Encoder(buf, context)
+
+    encoder.writeElement(element)
+
+    return buf

Modified: branches/remoting-2/pyamf/messaging.py
===================================================================
--- branches/remoting-2/pyamf/messaging.py	2007-10-29 15:53:53 UTC (rev 89)
+++ branches/remoting-2/pyamf/messaging.py	2007-10-29 16:14:43 UTC (rev 90)
@@ -30,9 +30,6 @@
 import pyamf
 from pyamf import util
 
-AMF0 = 0
-AMF3 = 3
-
 class ClientTypes:
     # Specifies a Flash Player 6.0 - 8.0 client.
     Flash    = 0

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic