[prev in list] [next in list] [prev in thread] [next in thread]
List: pyamf-commits
Subject: [pyamf-commits] r1790 - in pyamf/branches/strict-encoding-376: .
From: commits () pyamf ! org (commits () pyamf ! org)
Date: 2008-11-23 20:49:53
Message-ID: 20081123194936.093C57BC026 () mail ! collab ! com
[Download RAW message or body]
Author: nick
Date: 2008-11-23 20:49:35 +0100 (Sun, 23 Nov 2008)
New Revision: 1790
Modified:
pyamf/branches/strict-encoding-376/
pyamf/branches/strict-encoding-376/CHANGES.txt
pyamf/branches/strict-encoding-376/INSTALL.txt
pyamf/branches/strict-encoding-376/LICENSE.txt
pyamf/branches/strict-encoding-376/MAINTAINERS.txt
pyamf/branches/strict-encoding-376/cpyamf/
pyamf/branches/strict-encoding-376/cpyamf/__init__.py
pyamf/branches/strict-encoding-376/cpyamf/util.c
pyamf/branches/strict-encoding-376/cpyamf/util.h
pyamf/branches/strict-encoding-376/ez_setup.py
pyamf/branches/strict-encoding-376/pyamf/__init__.py
pyamf/branches/strict-encoding-376/pyamf/adapters/__init__.py
pyamf/branches/strict-encoding-376/pyamf/adapters/_django_db_models_fields.py
pyamf/branches/strict-encoding-376/pyamf/adapters/_django_db_models_query.py
pyamf/branches/strict-encoding-376/pyamf/adapters/_google_appengine_ext_db.py
pyamf/branches/strict-encoding-376/pyamf/adapters/_sets.py
pyamf/branches/strict-encoding-376/pyamf/amf0.py
pyamf/branches/strict-encoding-376/pyamf/amf3.py
pyamf/branches/strict-encoding-376/pyamf/flex/__init__.py
pyamf/branches/strict-encoding-376/pyamf/flex/data.py
pyamf/branches/strict-encoding-376/pyamf/flex/messaging.py
pyamf/branches/strict-encoding-376/pyamf/logging.py
pyamf/branches/strict-encoding-376/pyamf/remoting/__init__.py
pyamf/branches/strict-encoding-376/pyamf/remoting/amf0.py
pyamf/branches/strict-encoding-376/pyamf/remoting/amf3.py
pyamf/branches/strict-encoding-376/pyamf/remoting/client/__init__.py
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/__init__.py
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/django.py
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/google.py
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/twisted.py
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/wsgi.py
pyamf/branches/strict-encoding-376/pyamf/sol.py
pyamf/branches/strict-encoding-376/pyamf/tests/__init__.py
pyamf/branches/strict-encoding-376/pyamf/tests/adapters/__init__.py
pyamf/branches/strict-encoding-376/pyamf/tests/adapters/test_django.py
pyamf/branches/strict-encoding-376/pyamf/tests/adapters/test_google.py
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/__init__.py
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_django.py
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_google.py
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_twisted.py
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_wsgi.py
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/__init__.py
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/bar/__init__.py
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/bar/baz.py
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/bar/gak.py
pyamf/branches/strict-encoding-376/pyamf/tests/imports/spam.py
pyamf/branches/strict-encoding-376/pyamf/tests/modules/
pyamf/branches/strict-encoding-376/pyamf/tests/remoting/__init__.py
pyamf/branches/strict-encoding-376/pyamf/tests/remoting/test_client.py
pyamf/branches/strict-encoding-376/pyamf/tests/remoting/test_remoteobject.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_adapters.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_amf0.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_amf3.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_basic.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_flex.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_flex_messaging.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_gateway.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_imports.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_modules.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_remoting.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_sol.py
pyamf/branches/strict-encoding-376/pyamf/tests/test_util.py
pyamf/branches/strict-encoding-376/pyamf/tests/util.py
pyamf/branches/strict-encoding-376/pyamf/util/__init__.py
pyamf/branches/strict-encoding-376/pyamf/util/imports.py
pyamf/branches/strict-encoding-376/setup.cfg
pyamf/branches/strict-encoding-376/setup.py
Log:
Merged forward
Property changes on: pyamf/branches/strict-encoding-376
___________________________________________________________________
Modified: svn:mergeinfo
- /pyamf/branches/adapter-helper-350:1638-1668
/pyamf/branches/bytearray-amf0-379:1752-1765
/pyamf/branches/class-def-ref-341:1594-1597
/pyamf/branches/class-init-args-322:1527-1528,1530-1532
/pyamf/branches/client-http-headers-api-337:1604-1609
/pyamf/branches/error-stacktrace-331:1624-1644
/pyamf/branches/gae-key-307:1603-1760
/pyamf/branches/gerard-celementtree-364:1687-1697
/pyamf/branches/gerard-cpyamf-225:1611-1661
/pyamf/branches/immutable-set-280:1746-1764
/pyamf/branches/nan-failures-345:1624-1640
/pyamf/branches/raise-python3.0-351:1642-1647
/pyamf/branches/register_class-args-check-334:1542-1592
/pyamf/branches/remoting-request-context-309-2:1595-1607
/pyamf/branches/tempfile-338:1588-1596
/pyamf/branches/win-sol-test-failures-344:1624-1645
/pyamf/trunk:361-1524,1527-1540,1542-1582,1588-1602,1624-1641,1673-1686,1699-1751
/trunk:2-360
+ /pyamf/branches/adapter-helper-350:1638-1668
/pyamf/branches/bytearray-amf0-379:1752-1765
/pyamf/branches/class-def-ref-341:1594-1597
/pyamf/branches/class-init-args-322:1527-1528,1530-1532
/pyamf/branches/client-http-headers-api-337:1604-1609
/pyamf/branches/error-stacktrace-331:1624-1644
/pyamf/branches/gae-key-307:1603-1760
/pyamf/branches/gerard-celementtree-364:1687-1697
/pyamf/branches/gerard-cpyamf-225:1611-1661
/pyamf/branches/immutable-set-280:1746-1764
/pyamf/branches/nan-failures-345:1624-1640
/pyamf/branches/raise-python3.0-351:1642-1647
/pyamf/branches/register_class-args-check-334:1542-1592
/pyamf/branches/remoting-request-context-309-2:1595-1607
/pyamf/branches/slots-347:1675-1781
/pyamf/branches/strict-decoding-378:1743-1788
/pyamf/branches/tempfile-338:1588-1596
/pyamf/branches/win-sol-test-failures-344:1624-1645
/pyamf/trunk:1774-1789
Modified: pyamf/branches/strict-encoding-376/CHANGES.txt
===================================================================
--- pyamf/branches/strict-encoding-376/CHANGES.txt 2008-11-23 19:43:44 UTC (rev 1789)
+++ pyamf/branches/strict-encoding-376/CHANGES.txt 2008-11-23 19:49:35 UTC (rev 1790)
@@ -9,6 +9,7 @@
- Encoders how have a 'strict' mode. Not generally useful for the time being
but will help with developments in the future. Type mapped functions now
require a second 'encoder' attribute. (Ticket:376)
+ - Added support for __slots__. (Ticket:347)
- ByteArray now does not throw an error when used in the Remoting framework
(Ticket:379)
- A new adapter that converts sets.ImmutableSet and sets.Set to tuples before
Property changes on: pyamf/branches/strict-encoding-376/CHANGES.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/INSTALL.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/LICENSE.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/MAINTAINERS.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/cpyamf
___________________________________________________________________
Modified: svn:mergeinfo
- /pyamf/branches/adapter-helper-350/cpyamf:1638-1668
/pyamf/branches/bytearray-amf0-379/cpyamf:1752-1765
/pyamf/branches/class-def-ref-341/cpyamf:1594-1597
/pyamf/branches/class-init-args-322/cpyamf:1527-1528,1530-1532
/pyamf/branches/client-http-headers-api-337/cpyamf:1604-1609
/pyamf/branches/error-stacktrace-331/cpyamf:1624-1644
/pyamf/branches/gerard-celementtree-364/cpyamf:1687-1697
/pyamf/branches/gerard-cpyamf-225/cpyamf:1611-1661
/pyamf/branches/immutable-set-280/cpyamf:1746-1764
/pyamf/branches/nan-failures-345/cpyamf:1624-1640
/pyamf/branches/raise-python3.0-351/cpyamf:1642-1647
/pyamf/branches/register_class-args-check-334/cpyamf:1542-1592
/pyamf/branches/remoting-request-context-309-2/cpyamf:1595-1607
/pyamf/branches/tempfile-338/cpyamf:1588-1596
/pyamf/branches/win-sol-test-failures-344/cpyamf:1624-1645
/pyamf/trunk/cpyamf:1525-1526,1541,1583-1587,1594,1624-1641,1673-1686,1699-1751
+ /pyamf/branches/adapter-helper-350/cpyamf:1638-1668
/pyamf/branches/bytearray-amf0-379/cpyamf:1752-1765
/pyamf/branches/class-def-ref-341/cpyamf:1594-1597
/pyamf/branches/class-init-args-322/cpyamf:1527-1528,1530-1532
/pyamf/branches/client-http-headers-api-337/cpyamf:1604-1609
/pyamf/branches/error-stacktrace-331/cpyamf:1624-1644
/pyamf/branches/gerard-celementtree-364/cpyamf:1687-1697
/pyamf/branches/gerard-cpyamf-225/cpyamf:1611-1661
/pyamf/branches/immutable-set-280/cpyamf:1746-1764
/pyamf/branches/nan-failures-345/cpyamf:1624-1640
/pyamf/branches/raise-python3.0-351/cpyamf:1642-1647
/pyamf/branches/register_class-args-check-334/cpyamf:1542-1592
/pyamf/branches/remoting-request-context-309-2/cpyamf:1595-1607
/pyamf/branches/slots-347/cpyamf:1675-1781
/pyamf/branches/strict-decoding-378/cpyamf:1743-1788
/pyamf/branches/tempfile-338/cpyamf:1588-1596
/pyamf/branches/win-sol-test-failures-344/cpyamf:1624-1645
/pyamf/trunk/cpyamf:1525-1526,1541,1583-1587,1594,1624-1641,1774-1789
Property changes on: pyamf/branches/strict-encoding-376/cpyamf/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/cpyamf/util.c
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/cpyamf/util.h
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/ez_setup.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/__init__.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/__init__.py 2008-11-23 19:43:44 UTC (rev \
1789)
+++ pyamf/branches/strict-encoding-376/pyamf/__init__.py 2008-11-23 19:49:35 UTC (rev \
1790) @@ -469,6 +469,43 @@
"""
return self.klass(*args, **kwargs)
+class TypedObject(dict):
+ """
+ This class is used when a strongly typed object is decoded but there is no
+ registered class to apply it to.
+
+ This object can only be used for 'simple' streams - i.e. not externalized
+ data. If encountered, a L{DecodeError} will be thrown.
+
+ @ivar alias: The alias of the typed object.
+ @ivar alias: C{unicode}
+ """
+
+ def __init__(self, alias):
+ dict.__init__(self)
+
+ self.alias = alias
+
+ def __readamf__(self, o):
+ raise DecodeError('Unable to decode an externalised stream.\n\nThe '
+ 'class alias \'%s\' was found and because strict mode is False an'
+ ' attempt was made to decode the object automatically. To decode '
+ 'this stream, a registered class with the alias and a '
+ 'corresponding __readamf__ method will be required.' % (
+ self.alias,))
+
+ def __writeamf__(self, o):
+ raise EncodeError('Unable to encode an externalised stream.\n\nThe '
+ 'class alias \'%s\' was found and because strict mode is False an'
+ 'attempt was made to encode the object automatically. To encode '
+ 'this stream, a registered class with the alias and a '
+ 'corresponding __readamf__ method will be required.' % (
+ self.alias,))
+
+class TypedObjectClassAlias(ClassAlias):
+ def createInstance(self):
+ return TypedObject(self.alias)
+
class BaseDecoder(object):
"""
Base AMF decoder.
@@ -479,11 +516,15 @@
@type type_map: C{list}
@ivar stream: The underlying data stream.
@type stream: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
+ @ivar strict: Defines how strict the decoding should be. For the time
+ being this relates to typed objects in the stream that do not have a
+ registered alias. Introduced in 0.4.
+ @type strict: C{bool}
"""
context_class = BaseContext
type_map = {}
- def __init__(self, data=None, context=None):
+ def __init__(self, data=None, context=None, strict=False):
"""
@type data: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param data: Data stream.
@@ -506,6 +547,8 @@
raise TypeError("context must be of type %s.%s" % (
self.context_class.__module__, self.context_class.__name__))
+ self.strict = strict
+
def readType(self):
"""
Override in a subclass.
@@ -908,7 +951,7 @@
except UnknownClassAlias:
return False
-def decode(stream, encoding=AMF0, context=None):
+def decode(stream, encoding=AMF0, context=None, strict=False):
"""
A generator function to decode a datastream.
@@ -921,7 +964,7 @@
@param context: Context.
@return: Each element in the stream.
"""
- decoder = _get_decoder_class(encoding)(stream, context)
+ decoder = _get_decoder_class(encoding)(stream, context, strict)
while 1:
try:
@@ -958,8 +1001,8 @@
return stream
-def get_decoder(encoding, data=None, context=None):
- return _get_decoder_class(encoding)(data=data, context=context)
+def get_decoder(encoding, data=None, context=None, strict=False):
+ return _get_decoder_class(encoding)(data=data, context=context, strict=strict)
def _get_decoder_class(encoding):
"""
@@ -1209,3 +1252,5 @@
register_class_loader(flex_loader)
register_adapters()
+
+register_alias_type(TypedObjectClassAlias, TypedObject)
\ No newline at end of file
Property changes on: pyamf/branches/strict-encoding-376/pyamf/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/adapters/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/adapters/_django_db_models_fields.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/adapters/_django_db_models_query.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/adapters/_google_appengine_ext_db.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/adapters/_sets.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/amf0.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/amf0.py 2008-11-23 19:43:44 UTC (rev \
1789)
+++ pyamf/branches/strict-encoding-376/pyamf/amf0.py 2008-11-23 19:49:35 UTC (rev \
1790) @@ -301,9 +301,18 @@
@see: L{load_class<pyamf.load_class>}
"""
classname = self.readString()
- alias = pyamf.load_class(classname)
+ alias = None
- ret = alias.createInstance()
+ try:
+ alias = pyamf.load_class(classname)
+
+ ret = alias.createInstance()
+ except pyamf.UnknownClassAlias:
+ if self.strict:
+ raise
+
+ ret = pyamf.TypedObject(classname)
+
self.context.addObject(ret)
self._readObject(ret, alias)
@@ -321,7 +330,7 @@
self.context.amf3_context = amf3.Context()
- decoder = pyamf._get_decoder_class(pyamf.AMF3)(self.stream, \
self.context.amf3_context) + decoder = \
pyamf._get_decoder_class(pyamf.AMF3)(self.stream, self.context.amf3_context, \
strict=self.strict)
element = decoder.readElement()
self.context.addAMF3Object(element)
@@ -774,7 +783,7 @@
self.writeType(ASTypes.AMF3)
encoder.writeElement(data)
-def decode(stream, context=None):
+def decode(stream, context=None, strict=False):
"""
A helper function to decode an AMF0 datastream.
@@ -783,7 +792,7 @@
@type context: L{Context<pyamf.amf0.Context>}
@param context: AMF0 Context.
"""
- decoder = Decoder(stream, context)
+ decoder = Decoder(stream, context, strict=strict)
while 1:
try:
Property changes on: pyamf/branches/strict-encoding-376/pyamf/amf0.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/amf3.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/amf3.py 2008-11-23 19:43:44 UTC (rev \
1789)
+++ pyamf/branches/strict-encoding-376/pyamf/amf3.py 2008-11-23 19:49:35 UTC (rev \
1790) @@ -631,6 +631,14 @@
else:
dynamic_attrs = attrs
+ if hasattr(obj, '__slots__'):
+ if static_attrs is None:
+ static_attrs = {}
+
+ for k in obj.__slots__:
+ static_attrs[k] = getattr(obj, k)
+ del dynamic_attrs[k]
+
return (static_attrs, dynamic_attrs)
def createInstance(self):
@@ -1089,7 +1097,20 @@
if class_ref:
class_def = self.context.getClassDefinition(ref)
else:
- class_def = ClassDefinition(self.readString(), encoding=ref & 0x03)
+ class_name = self.readString()
+
+ if class_name == '':
+ class_name = None
+ else:
+ try:
+ class_name = pyamf.get_class_alias(class_name)
+ except pyamf.UnknownClassAlias:
+ if self.strict:
+ raise
+
+ class_name = pyamf.TypedObjectClassAlias(pyamf.TypedObject, \
class_name) +
+ class_def = ClassDefinition(class_name, encoding=ref & 0x03)
self.context.addClassDefinition(class_def)
return class_ref, class_def, ref >> 2
@@ -1709,7 +1730,7 @@
self._writeString(util.ET.tostring(n, 'utf-8'), False)
-def decode(stream, context=None):
+def decode(stream, context=None, strict=False):
"""
A helper function to decode an AMF3 datastream.
@@ -1718,7 +1739,7 @@
@type context: L{Context}
@param context: Context.
"""
- decoder = Decoder(stream, context)
+ decoder = Decoder(stream, context, strict)
while 1:
try:
Property changes on: pyamf/branches/strict-encoding-376/pyamf/amf3.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/flex/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/flex/data.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/flex/messaging.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/logging.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/remoting/__init__.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/remoting/__init__.py 2008-11-23 19:43:44 \
UTC (rev 1789)
+++ pyamf/branches/strict-encoding-376/pyamf/remoting/__init__.py 2008-11-23 19:49:35 \
UTC (rev 1790) @@ -632,7 +632,7 @@
@type strict: C{bool}
@param strict: Determines whether encoding should be strict. Specifically
header/body lengths will be written correctly, instead of the default 0.
- Default is C{False}.
+ Default is C{False}. Introduced in 0.4.
@rtype: C{StringIO}
@return: File object.
"""
Property changes on: pyamf/branches/strict-encoding-376/pyamf/remoting/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/remoting/amf0.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/remoting/amf3.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/remoting/client/__init__.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/remoting/client/__init__.py 2008-11-23 \
19:43:44 UTC (rev 1789)
+++ pyamf/branches/strict-encoding-376/pyamf/remoting/client/__init__.py 2008-11-23 \
19:49:35 UTC (rev 1790) @@ -212,6 +212,7 @@
self.client_type = client_type
self.headers = remoting.HeaderCollection()
self.http_headers = {}
+ self.strict = strict
self._setUrl(url)
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/remoting/client/__init__.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/__init__.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/django.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/google.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/twisted.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/remoting/gateway/wsgi.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/sol.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/adapters/__init__.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/adapters/test_django.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/adapters/test_google.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/__init__.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_django.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_google.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_twisted.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/gateway/test_wsgi.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/__init__.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/bar/__init__.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/bar/baz.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/imports/foo/bar/gak.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/imports/spam.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/modules
___________________________________________________________________
Added: svn:mergeinfo
+ /pyamf/branches/adapter-helper-350/pyamf/tests/modules:1638-1668
/pyamf/branches/bytearray-amf0-379/pyamf/tests/modules:1752-1765
/pyamf/branches/class-def-ref-341/pyamf/tests/modules:1594-1597
/pyamf/branches/class-init-args-322/pyamf/tests/modules:1527-1528,1530-1532
/pyamf/branches/client-http-headers-api-337/pyamf/tests/modules:1604-1609
/pyamf/branches/error-stacktrace-331/pyamf/tests/modules:1624-1644
/pyamf/branches/gae-key-307/pyamf/tests/modules:1603-1760
/pyamf/branches/gerard-celementtree-364/pyamf/tests/modules:1687-1697
/pyamf/branches/gerard-cpyamf-225/pyamf/tests/modules:1611-1661
/pyamf/branches/nan-failures-345/pyamf/tests/modules:1624-1640
/pyamf/branches/raise-python3.0-351/pyamf/tests/modules:1642-1647
/pyamf/branches/register_class-args-check-334/pyamf/tests/modules:1542-1592
/pyamf/branches/remoting-request-context-309-2/pyamf/tests/modules:1595-1607
/pyamf/branches/tempfile-338/pyamf/tests/modules:1588-1596
/pyamf/branches/win-sol-test-failures-344/pyamf/tests/modules:1624-1645
/pyamf/trunk/pyamf/tests/modules:361-1524,1527-1540,1542-1582,1588-1602,1624-1641,1673-1686,1699-1751
/trunk/pyamf/tests/modules:2-360
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/remoting/__init__.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/remoting/test_client.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/remoting/test_remoteobject.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_adapters.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/tests/test_amf0.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/tests/test_amf0.py 2008-11-23 19:43:44 \
UTC (rev 1789)
+++ pyamf/branches/strict-encoding-376/pyamf/tests/test_amf0.py 2008-11-23 19:49:35 \
UTC (rev 1790) @@ -397,6 +397,34 @@
'\x00\x0bfamily_name\x02\x00\x03Doe\x00\ngiven_name\x02\x00\x04'
'Jane\x00\x00\t')
+ def test_slots(self):
+ class Person(object):
+ __slots__ = ('family_name', 'given_name')
+
+ u = Person()
+ u.family_name = 'Doe'
+ u.given_name = 'Jane'
+
+ self.encoder.writeElement(u)
+
+ self.assertEquals(self.buf.getvalue(), '\x03\x00\x0bfamily_name\x02'
+ '\x00\x03Doe\x00\ngiven_name\x02\x00\x04Jane\x00\x00\t')
+
+ def test_slots_registered(self):
+ class Person(object):
+ __slots__ = ('family_name', 'given_name')
+
+ u = Person()
+ u.family_name = 'Doe'
+ u.given_name = 'Jane'
+
+ pyamf.register_class(Person, 'spam.eggs.Person')
+ self.encoder.writeElement(u)
+
+ self.assertEquals(self.buf.getvalue(), '\x10\x00\x10spam.eggs.Person'
+ '\x00\x0bfamily_name\x02\x00\x03Doe\x00\ngiven_name\x02\x00\x04'
+ 'Jane\x00\x00\t')
+
def test_elementtree_tag(self):
class NotAnElement(object):
items = lambda self: []
@@ -412,7 +440,8 @@
self.encoder.writeElement(foo)
self.assertEquals(self.buf.getvalue(),
- '\x03\x00\x04text\x02\x00\x03bar\x00\x04tail\x05\x00\x03tag\x02\x00\x03foo\x00\x00\t')
+ '\x03\x00\x04text\x02\x00\x03bar\x00\x04tail\x05\x00\x03tag\x02'
+ '\x00\x03foo\x00\x00\t')
def test_funcs(self):
def x():
@@ -662,6 +691,63 @@
self.assertEquals(foo.foo, 'bar')
+ def test_not_strict(self):
+ self.assertFalse(self.decoder.strict)
+
+ # write a typed object to the stream
+ self.buf.write('\x10\x00\tspam.eggs\x00\x03foo\x02\x00\x03bar\x00\x00\t')
+ self.buf.seek(0)
+
+ self.assertFalse('spam.eggs' in pyamf.CLASS_CACHE)
+
+ obj = self.decoder.readElement()
+
+ self.assertTrue(isinstance(obj, pyamf.TypedObject))
+ self.assertEquals(obj.alias, 'spam.eggs')
+ self.assertEquals(obj, {'foo': 'bar'})
+
+ def test_strict(self):
+ self.decoder.strict = True
+
+ self.assertTrue(self.decoder.strict)
+
+ # write a typed object to the stream
+ self.buf.write('\x10\x00\tspam.eggs\x00\x03foo\x02\x00\x03bar\x00\x00\t')
+ self.buf.seek(0)
+
+ self.assertFalse('spam.eggs' in pyamf.CLASS_CACHE)
+
+ self.assertRaises(pyamf.UnknownClassAlias, self.decoder.readElement)
+
+ def test_slots(self):
+ class Person(object):
+ __slots__ = ('family_name', 'given_name')
+
+ self.buf.write('\x03\x00\x0bfamily_name\x02\x00\x03Doe\x00\n'
+ 'given_name\x02\x00\x04Jane\x00\x00\t')
+ self.buf.seek(0)
+
+ foo = self.decoder.readElement()
+
+ self.assertEquals(foo.family_name, 'Doe')
+ self.assertEquals(foo.given_name, 'Jane')
+
+ def test_slots_registered(self):
+ class Person(object):
+ __slots__ = ('family_name', 'given_name')
+
+ pyamf.register_class(Person, 'spam.eggs.Person')
+
+ self.buf.write('\x10\x00\x10spam.eggs.Person\x00\x0bfamily_name\x02'
+ '\x00\x03Doe\x00\ngiven_name\x02\x00\x04Jane\x00\x00\t')
+ self.buf.seek(0)
+
+ foo = self.decoder.readElement()
+
+ self.assertTrue(isinstance(foo, Person))
+ self.assertEquals(foo.family_name, 'Doe')
+ self.assertEquals(foo.given_name, 'Jane')
+
class HelperTestCase(unittest.TestCase):
def test_encode(self):
buf = amf0.encode(1)
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_amf0.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/tests/test_amf3.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/tests/test_amf3.py 2008-11-23 19:43:44 \
UTC (rev 1789)
+++ pyamf/branches/strict-encoding-376/pyamf/tests/test_amf3.py 2008-11-23 19:49:35 \
UTC (rev 1790) @@ -473,8 +473,6 @@
self.assertEqual(self.buf.getvalue(), '\n\x0b\x1dorg.pyamf.spam\x07baz'
'\x06\x0bhello\x01')
- pyamf.unregister_class(Spam)
-
def test_byte_array(self):
self._run([(amf3.ByteArray('hello'), '\x0c\x0bhello')])
@@ -579,8 +577,34 @@
self.assertEquals(self.buf.getvalue(), '\n\x0b!spam.eggs.Person\x17'
'family_name\x06\x07Doe\x15given_name\x06\tJane\x01')
- pyamf.unregister_class(Person)
+ def test_slots(self):
+ class Person(object):
+ __slots__ = ('family_name', 'given_name')
+ u = Person()
+ u.family_name = 'Doe'
+ u.given_name = 'Jane'
+
+ self.encoder.writeElement(u)
+
+ self.assertEquals(self.buf.getvalue(), '\n\x0b\x01\x17family_name\x15'
+ 'given_name\x06\x07Doe\x06\tJane\x01')
+
+ def test_slots_registered(self):
+ class Person(object):
+ __slots__ = ('family_name', 'given_name')
+
+ pyamf.register_class(Person, 'spam.eggs.Person')
+
+ u = Person()
+ u.family_name = 'Doe'
+ u.given_name = 'Jane'
+
+ self.encoder.writeElement(u)
+
+ self.assertEquals(self.buf.getvalue(), '\n\x0b!spam.eggs.Person\x17'
+ 'family_name\x15given_name\x06\x07Doe\x06\tJane\x01')
+
def test_elementtree_tag(self):
class NotAnElement(object):
items = lambda self: []
@@ -890,6 +914,51 @@
self.assertTrue(class_def in self.context.class_defs)
self.context.class_defs.remove(class_def)
+ def test_not_strict(self):
+ self.assertFalse(self.decoder.strict)
+
+ # write a typed object to the stream
+ self.buf.write('\n\x0b\x13spam.eggs\x07foo\x06\x07bar\x01')
+ self.buf.seek(0)
+
+ self.assertFalse('spam.eggs' in pyamf.CLASS_CACHE)
+
+ obj = self.decoder.readElement()
+
+ self.assertTrue(isinstance(obj, pyamf.TypedObject))
+ self.assertEquals(obj.alias, 'spam.eggs')
+ self.assertEquals(obj, {'foo': 'bar'})
+
+ def test_strict(self):
+ self.decoder.strict = True
+
+ self.assertTrue(self.decoder.strict)
+
+ # write a typed object to the stream
+ self.buf.write('\n\x0b\x13spam.eggs\x07foo\x06\x07bar\x01')
+ self.buf.seek(0)
+
+ self.assertFalse('spam.eggs' in pyamf.CLASS_CACHE)
+
+ self.assertRaises(pyamf.UnknownClassAlias, self.decoder.readElement)
+
+ def test_slots(self):
+ class Person(object):
+ __slots__ = ('family_name', 'given_name')
+
+ pyamf.register_class(Person, 'spam.eggs.Person')
+
+ self.buf.write('\n+!spam.eggs.Person\x17family_name\x15given_name\x06'
+ '\x07Doe\x06\tJane\x02\x06\x06\x04\x06\x08\x01')
+ self.buf.seek(0)
+
+ foo = self.decoder.readElement()
+
+ self.assertTrue(isinstance(foo, Person))
+ self.assertEquals(foo.family_name, 'Doe')
+ self.assertEquals(foo.given_name, 'Jane')
+ self.assertEquals(self.buf.remaining(), 0)
+
class ObjectEncodingTestCase(_util.ClassCacheClearingTestCase):
def setUp(self):
_util.ClassCacheClearingTestCase.setUp(self)
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_amf3.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/tests/test_basic.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/tests/test_basic.py 2008-11-23 19:43:44 \
UTC (rev 1789)
+++ pyamf/branches/strict-encoding-376/pyamf/tests/test_basic.py 2008-11-23 19:49:35 \
UTC (rev 1790) @@ -328,14 +328,16 @@
self.assertRaises(ValueError, pyamf.get_decoder, 'spam')
context = amf0.Context()
- decoder = pyamf.get_decoder(pyamf.AMF0, data='123', context=context)
+ decoder = pyamf.get_decoder(pyamf.AMF0, data='123', context=context, \
strict=True) self.assertEquals(decoder.stream.getvalue(), '123')
self.assertEquals(decoder.context, context)
+ self.assertTrue(decoder.strict)
context = amf3.Context()
- decoder = pyamf.get_decoder(pyamf.AMF3, data='456', context=context)
+ decoder = pyamf.get_decoder(pyamf.AMF3, data='456', context=context, \
strict=True) self.assertEquals(decoder.stream.getvalue(), '456')
self.assertEquals(decoder.context, context)
+ self.assertTrue(decoder.strict)
def test_get_encoder(self):
from pyamf import amf0, amf3
@@ -778,6 +780,13 @@
self.assertEquals(alias.__class__, DummyAlias)
self.assertEquals(alias.klass, B)
+class TypedObjectTestCase(unittest.TestCase):
+ def test_externalised(self):
+ o = pyamf.TypedObject(None)
+
+ self.assertRaises(pyamf.DecodeError, o.__readamf__, None)
+ self.assertRaises(pyamf.EncodeError, o.__writeamf__, None)
+
def suite():
suite = unittest.TestSuite()
@@ -792,6 +801,7 @@
suite.addTest(unittest.makeSuite(ErrorClassMapTestCase))
suite.addTest(unittest.makeSuite(RegisterAliasTypeTestCase))
suite.addTest(unittest.makeSuite(BaseContextTestCase))
+ suite.addTest(unittest.makeSuite(TypedObjectTestCase))
return suite
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_basic.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_flex.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: \
pyamf/branches/strict-encoding-376/pyamf/tests/test_flex_messaging.py \
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_gateway.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_imports.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_modules.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_remoting.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_sol.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/test_util.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/tests/util.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: pyamf/branches/strict-encoding-376/pyamf/util/__init__.py
===================================================================
--- pyamf/branches/strict-encoding-376/pyamf/util/__init__.py 2008-11-23 19:43:44 UTC \
(rev 1789)
+++ pyamf/branches/strict-encoding-376/pyamf/util/__init__.py 2008-11-23 19:49:35 UTC \
(rev 1790) @@ -550,7 +550,14 @@
return attrs
elif hasattr(obj, '__dict__'):
return obj.__dict__
+ elif hasattr(obj, '__slots__'):
+ attrs = {}
+ for k in obj.__slots__:
+ attrs[k] = getattr(obj, k)
+
+ return attrs
+
return None
def get_instance_attrs(obj, alias):
Property changes on: pyamf/branches/strict-encoding-376/pyamf/util/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/pyamf/util/imports.py
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/setup.cfg
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: pyamf/branches/strict-encoding-376/setup.py
___________________________________________________________________
Added: svn:eol-style
+ native
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic