37
37
#: L{ClassAlias} object.
38
38
#: @see: L{register_class}, L{unregister_class}, and L{register_package}
39
39
CLASS_CACHE = {}
40
+
40
41
#: Class loaders. An iterable of callables that are handed a string alias and
41
42
#: return a class object or C{None} it not handled.
42
43
#: @see: L{register_class_loader} and L{unregister_class_loader}
43
44
CLASS_LOADERS = set ()
45
+
44
46
#: Custom type map.
45
47
#: @see: L{get_type}, L{add_type}, and L{remove_type}
46
48
TYPE_MAP = {}
49
+
47
50
#: Maps error classes to string codes.
48
51
#: @see: L{add_error_class} and L{remove_error_class}
49
52
ERROR_CLASS_MAP = {
61
64
#: Specifies that objects are serialized using AMF for ActionScript 1.0
62
65
#: and 2.0 that were introduced in the Adobe Flash Player 6.
63
66
AMF0 = 0
67
+
64
68
#: Specifies that objects are serialized using AMF for ActionScript 3.0
65
69
#: that was introduced in the Adobe Flash Player 9.
66
70
AMF3 = 3
71
+
67
72
#: Supported AMF encoding types.
68
73
#: @see: L{AMF0}, L{AMF3}, and L{DEFAULT_ENCODING}
69
74
ENCODING_TYPES = (AMF0 , AMF3 )
@@ -159,11 +164,14 @@ class TypedObject(dict):
159
164
registered class to apply it to.
160
165
161
166
This object can only be used for standard streams - i.e. not externalized
162
- data. If encountered, a L{DecodeError} will be raised.
167
+ data. If encountered, and C{strict} mode is C{False}, a L{DecodeError}
168
+ or L{EncodeError} will be raised.
163
169
164
170
@ivar alias: The alias of the typed object.
165
171
@type alias: C{string}
166
172
@since: 0.4
173
+ @raise DecodeError: Unable to decode an externalised stream.
174
+ @raise EncodeError: Unable to encode an externalised stream.
167
175
"""
168
176
169
177
def __init__ (self , alias ):
@@ -229,10 +237,13 @@ def getEncodableAttributes(self, obj, **kwargs):
229
237
def register_class (klass , alias = None ):
230
238
"""
231
239
Registers a class to be used in the data streaming. This is the equivalent
232
- to the C{[RemoteClass(alias="foobar")]} AS3 metatag.
240
+ of the C{[RemoteClass(alias="foobar")]} metatag in Adobe Flex, and the
241
+ C{flash.net.registerClassAlias} method in Actionscript 3.0.
233
242
234
243
@return: The registered L{ClassAlias} instance.
235
244
@see: L{unregister_class}
245
+ @see: U{flash.net.registerClassAlias on Adobe Help (external)
246
+ <http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#registerClassAlias%28%29>}
236
247
"""
237
248
meta = util .get_class_meta (klass )
238
249
@@ -409,8 +420,9 @@ def decode(stream, *args, **kwargs):
409
420
A generator function to decode a datastream.
410
421
411
422
@param stream: AMF data to be decoded.
412
- @type stream: byte data.
423
+ @type stream: byte data
413
424
@kwarg encoding: AMF encoding type. One of L{ENCODING_TYPES}.
425
+ @type encoding: C{int}
414
426
@return: A generator that will decode each element in the stream.
415
427
"""
416
428
encoding = kwargs .pop ('encoding' , DEFAULT_ENCODING )
@@ -423,8 +435,9 @@ def encode(*args, **kwargs):
423
435
"""
424
436
A helper function to encode an element.
425
437
426
- @param args: The python data to be encoded.
438
+ @param args: The Python data to be encoded.
427
439
@kwarg encoding: AMF encoding type. One of L{ENCODING_TYPES}.
440
+ @type encoding: C{int}
428
441
@return: A L{util.BufferedByteStream} object that contains the data.
429
442
"""
430
443
encoding = kwargs .pop ('encoding' , DEFAULT_ENCODING )
@@ -442,6 +455,8 @@ def get_decoder(encoding, *args, **kwargs):
442
455
"""
443
456
Returns a L{codec.Decoder} capable of decoding AMF[C{encoding}] streams.
444
457
458
+ @param encoding: AMF encoding type. One of L{ENCODING_TYPES}.
459
+ @type encoding: C{int}
445
460
@raise ValueError: Unknown C{encoding}.
446
461
"""
447
462
def _get_decoder_class ():
@@ -469,7 +484,9 @@ def get_encoder(encoding, *args, **kwargs):
469
484
"""
470
485
Returns a L{codec.Encoder} capable of encoding AMF[C{encoding}] streams.
471
486
472
- @raise ValueError: Unknown C{encoding}.
487
+ @kwarg encoding: AMF encoding type. One of L{ENCODING_TYPES}.
488
+ @type encoding: C{int}
489
+ @raise ValueError: Unknown C{encoding} type.
473
490
"""
474
491
def _get_encoder_class ():
475
492
if encoding == AMF0 :
@@ -497,7 +514,10 @@ def blaze_loader(alias):
497
514
Loader for BlazeDS framework compatibility classes, specifically
498
515
implementing C{ISmallMessage}.
499
516
517
+ @type alias: C{string}
500
518
@see: U{BlazeDS<http://opensource.adobe.com/wiki/display/blazeds/BlazeDS>}
519
+ @see: U{ISmallMessage on Adobe Help (external)
520
+ <http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/messaging/messages/ISmallMessage.html>}
501
521
@since: 0.5
502
522
"""
503
523
if alias not in ['DSC' , 'DSK' ]:
@@ -512,6 +532,7 @@ def flex_loader(alias):
512
532
"""
513
533
Loader for L{Flex<pyamf.flex>} framework compatibility classes.
514
534
535
+ @type alias: C{string}
515
536
@raise UnknownClassAlias: Trying to load an unknown Flex compatibility class.
516
537
"""
517
538
if not alias .startswith ('flex.' ):
@@ -535,7 +556,8 @@ def add_type(type_, func=None):
535
556
Adds a custom type to L{TYPE_MAP}. A custom type allows fine grain control
536
557
of what to encode to an AMF data stream.
537
558
538
- @raise TypeError: Unable to add as a custom type (expected a class or callable).
559
+ @raise TypeError: Unable to add C{_type} as a custom type (expected a class
560
+ or callable).
539
561
@raise KeyError: Type already exists.
540
562
@see: L{get_type} and L{remove_type}
541
563
"""
@@ -612,6 +634,9 @@ def add_error_class(klass, code):
612
634
@param code: Exception code
613
635
@type code: C{str}
614
636
@see: L{remove_error_class}
637
+ @raise TypeError: C{klass} must be of class type.
638
+ @raise TypeError: Error classes must subclass the C{__builtin__.Exception} class.
639
+ @raise ValueError: C{code} is already registered to an error class.
615
640
"""
616
641
if not isinstance (code , python .str_types ):
617
642
code = code .decode ('utf-8' )
@@ -643,7 +668,10 @@ def remove_error_class(klass):
643
668
>>> pyamf.add_error_class(AuthenticationError, 'Auth.Failed')
644
669
>>> pyamf.remove_error_class(AuthenticationError)
645
670
671
+ @type klass: C{str} or class
646
672
@see: L{add_error_class}
673
+ @raise ValueError: Cannot find registered class.
674
+ @raise TypeError: C{klass} is invalid type.
647
675
"""
648
676
if isinstance (klass , python .str_types ):
649
677
if klass not in ERROR_CLASS_MAP :
@@ -751,16 +779,18 @@ def register_package(module=None, package=None, separator='.', ignore=[],
751
779
@type package: C{string} or C{None}
752
780
@param separator: The separator used to append to C{package} to form the
753
781
complete alias.
782
+ @type separator: C{string}
754
783
@param ignore: To give fine grain control over what gets aliased and what
755
784
doesn't, supply a list of classes that you B{do not} want to be aliased.
756
785
@type ignore: C{iterable}
757
786
@param strict: Whether only classes that originate from C{module} will be
758
787
registered.
788
+ @type strict: C{boolean}
759
789
760
790
@return: A dict of all the classes that were registered and their respective
761
791
L{ClassAlias} counterparts.
762
792
@since: 0.5
763
- @raise TypeError: Cannot get a list of classes from C{module}
793
+ @raise TypeError: Cannot get a list of classes from C{module}.
764
794
"""
765
795
if isinstance (module , python .str_types ):
766
796
if module == '' :
@@ -843,7 +873,7 @@ def set_default_etree(etree):
843
873
return xml .set_default_interface (etree )
844
874
845
875
846
- #: setup some some standard class registrations and class loaders.
876
+ # setup some some standard class registrations and class loaders.
847
877
register_class (ASObject )
848
878
register_class_loader (flex_loader )
849
879
register_class_loader (blaze_loader )
0 commit comments