Skip to content

Commit eecaa13

Browse files
API docs update.
1 parent bced612 commit eecaa13

File tree

8 files changed

+120
-55
lines changed

8 files changed

+120
-55
lines changed

pyamf/__init__.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737
#: L{ClassAlias} object.
3838
#: @see: L{register_class}, L{unregister_class}, and L{register_package}
3939
CLASS_CACHE = {}
40+
4041
#: Class loaders. An iterable of callables that are handed a string alias and
4142
#: return a class object or C{None} it not handled.
4243
#: @see: L{register_class_loader} and L{unregister_class_loader}
4344
CLASS_LOADERS = set()
45+
4446
#: Custom type map.
4547
#: @see: L{get_type}, L{add_type}, and L{remove_type}
4648
TYPE_MAP = {}
49+
4750
#: Maps error classes to string codes.
4851
#: @see: L{add_error_class} and L{remove_error_class}
4952
ERROR_CLASS_MAP = {
@@ -61,9 +64,11 @@
6164
#: Specifies that objects are serialized using AMF for ActionScript 1.0
6265
#: and 2.0 that were introduced in the Adobe Flash Player 6.
6366
AMF0 = 0
67+
6468
#: Specifies that objects are serialized using AMF for ActionScript 3.0
6569
#: that was introduced in the Adobe Flash Player 9.
6670
AMF3 = 3
71+
6772
#: Supported AMF encoding types.
6873
#: @see: L{AMF0}, L{AMF3}, and L{DEFAULT_ENCODING}
6974
ENCODING_TYPES = (AMF0, AMF3)
@@ -159,11 +164,14 @@ class TypedObject(dict):
159164
registered class to apply it to.
160165
161166
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.
163169
164170
@ivar alias: The alias of the typed object.
165171
@type alias: C{string}
166172
@since: 0.4
173+
@raise DecodeError: Unable to decode an externalised stream.
174+
@raise EncodeError: Unable to encode an externalised stream.
167175
"""
168176

169177
def __init__(self, alias):
@@ -229,10 +237,13 @@ def getEncodableAttributes(self, obj, **kwargs):
229237
def register_class(klass, alias=None):
230238
"""
231239
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.
233242
234243
@return: The registered L{ClassAlias} instance.
235244
@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>}
236247
"""
237248
meta = util.get_class_meta(klass)
238249

@@ -409,8 +420,9 @@ def decode(stream, *args, **kwargs):
409420
A generator function to decode a datastream.
410421
411422
@param stream: AMF data to be decoded.
412-
@type stream: byte data.
423+
@type stream: byte data
413424
@kwarg encoding: AMF encoding type. One of L{ENCODING_TYPES}.
425+
@type encoding: C{int}
414426
@return: A generator that will decode each element in the stream.
415427
"""
416428
encoding = kwargs.pop('encoding', DEFAULT_ENCODING)
@@ -423,8 +435,9 @@ def encode(*args, **kwargs):
423435
"""
424436
A helper function to encode an element.
425437
426-
@param args: The python data to be encoded.
438+
@param args: The Python data to be encoded.
427439
@kwarg encoding: AMF encoding type. One of L{ENCODING_TYPES}.
440+
@type encoding: C{int}
428441
@return: A L{util.BufferedByteStream} object that contains the data.
429442
"""
430443
encoding = kwargs.pop('encoding', DEFAULT_ENCODING)
@@ -442,6 +455,8 @@ def get_decoder(encoding, *args, **kwargs):
442455
"""
443456
Returns a L{codec.Decoder} capable of decoding AMF[C{encoding}] streams.
444457
458+
@param encoding: AMF encoding type. One of L{ENCODING_TYPES}.
459+
@type encoding: C{int}
445460
@raise ValueError: Unknown C{encoding}.
446461
"""
447462
def _get_decoder_class():
@@ -469,7 +484,9 @@ def get_encoder(encoding, *args, **kwargs):
469484
"""
470485
Returns a L{codec.Encoder} capable of encoding AMF[C{encoding}] streams.
471486
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.
473490
"""
474491
def _get_encoder_class():
475492
if encoding == AMF0:
@@ -497,7 +514,10 @@ def blaze_loader(alias):
497514
Loader for BlazeDS framework compatibility classes, specifically
498515
implementing C{ISmallMessage}.
499516
517+
@type alias: C{string}
500518
@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>}
501521
@since: 0.5
502522
"""
503523
if alias not in ['DSC', 'DSK']:
@@ -512,6 +532,7 @@ def flex_loader(alias):
512532
"""
513533
Loader for L{Flex<pyamf.flex>} framework compatibility classes.
514534
535+
@type alias: C{string}
515536
@raise UnknownClassAlias: Trying to load an unknown Flex compatibility class.
516537
"""
517538
if not alias.startswith('flex.'):
@@ -535,7 +556,8 @@ def add_type(type_, func=None):
535556
Adds a custom type to L{TYPE_MAP}. A custom type allows fine grain control
536557
of what to encode to an AMF data stream.
537558
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).
539561
@raise KeyError: Type already exists.
540562
@see: L{get_type} and L{remove_type}
541563
"""
@@ -612,6 +634,9 @@ def add_error_class(klass, code):
612634
@param code: Exception code
613635
@type code: C{str}
614636
@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.
615640
"""
616641
if not isinstance(code, python.str_types):
617642
code = code.decode('utf-8')
@@ -643,7 +668,10 @@ def remove_error_class(klass):
643668
>>> pyamf.add_error_class(AuthenticationError, 'Auth.Failed')
644669
>>> pyamf.remove_error_class(AuthenticationError)
645670
671+
@type klass: C{str} or class
646672
@see: L{add_error_class}
673+
@raise ValueError: Cannot find registered class.
674+
@raise TypeError: C{klass} is invalid type.
647675
"""
648676
if isinstance(klass, python.str_types):
649677
if klass not in ERROR_CLASS_MAP:
@@ -751,16 +779,18 @@ def register_package(module=None, package=None, separator='.', ignore=[],
751779
@type package: C{string} or C{None}
752780
@param separator: The separator used to append to C{package} to form the
753781
complete alias.
782+
@type separator: C{string}
754783
@param ignore: To give fine grain control over what gets aliased and what
755784
doesn't, supply a list of classes that you B{do not} want to be aliased.
756785
@type ignore: C{iterable}
757786
@param strict: Whether only classes that originate from C{module} will be
758787
registered.
788+
@type strict: C{boolean}
759789
760790
@return: A dict of all the classes that were registered and their respective
761791
L{ClassAlias} counterparts.
762792
@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}.
764794
"""
765795
if isinstance(module, python.str_types):
766796
if module == '':
@@ -843,7 +873,7 @@ def set_default_etree(etree):
843873
return xml.set_default_interface(etree)
844874

845875

846-
#: setup some some standard class registrations and class loaders.
876+
# setup some some standard class registrations and class loaders.
847877
register_class(ASObject)
848878
register_class_loader(flex_loader)
849879
register_class_loader(blaze_loader)

pyamf/amf3.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#: @see: U{OSFlash documentation (external)
8787
#: <http://osflash.org/documentation/amf3#x07_-_xml_legacy_flashxmlxmldocument_class>}
8888
TYPE_XML = '\x07'
89-
#: In AMF 3 an ActionScript Date is serialized simply as the number of
89+
#: In AMF 3 an ActionScript Date is serialized as the number of
9090
#: milliseconds elapsed since the epoch of midnight, 1st Jan 1970 in the
9191
#: UTC time zone. Local time zone information is not sent.
9292
TYPE_DATE = '\x08'
@@ -112,7 +112,9 @@
112112
#: Reference bit.
113113
REFERENCE_BIT = 0x01
114114

115-
#: The maximum that can be represented by a signed 29 bit integer.
115+
#: The maximum value for an int that will avoid promotion to an
116+
#: ActionScript Number when sent via AMF 3 is represented by a
117+
#: signed 29 bit integer: 2^28 - 1.
116118
MAX_29B_INT = 0x0FFFFFFF
117119

118120
#: The minimum that can be represented by a signed 29 bit integer.
@@ -151,8 +153,6 @@ class ObjectEncoding:
151153
class DataOutput(object):
152154
"""
153155
I am a C{StringIO} type object containing byte data from the AMF stream.
154-
ActionScript 3.0 introduced the C{flash.utils.ByteArray} class to support
155-
the manipulation of raw data in the form of an Array of bytes.
156156
I provide a set of methods for writing binary data with ActionScript 3.0.
157157
158158
This class is the I/O counterpart to the L{DataInput} class, which reads
@@ -327,8 +327,8 @@ class DataInput(object):
327327
"""
328328
I provide a set of methods for reading binary data with ActionScript 3.0.
329329
330-
This class is the I/O counterpart to the L{DataOutput} class,
331-
which writes binary data.
330+
This class is the I/O counterpart to the L{DataOutput} class, which writes
331+
binary data.
332332
333333
@see: U{IDataInput on Livedocs (external)
334334
<http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/IDataInput.html>}
@@ -670,7 +670,7 @@ def getClassByReference(self, ref):
670670

671671
def getClass(self, klass):
672672
"""
673-
Return class reference.
673+
Returns a class reference.
674674
675675
@return: Class reference.
676676
"""
@@ -681,6 +681,7 @@ def addClass(self, alias, klass):
681681
Creates a reference to C{class_def}.
682682
683683
@param alias: C{ClassDefinition} instance.
684+
@type alias: C{ClassDefinition}
684685
"""
685686
ref = self.class_idx
686687

@@ -999,6 +1000,9 @@ def _readDynamic(self, class_def, obj):
9991000
def readObject(self):
10001001
"""
10011002
Reads an object from the stream.
1003+
1004+
@raise ReferenceError: Unknown reference found.
1005+
@raise DecodeError: Unknown object encoding detected.
10021006
"""
10031007
ref = self.readInteger(False)
10041008

@@ -1242,8 +1246,13 @@ def writeDate(self, n):
12421246
"""
12431247
Writes a C{datetime} instance to the stream.
12441248
1249+
Does not support C{datetime.time} instances because AMF3 has
1250+
no way to encode time objects, so please use C{datetime.datetime}
1251+
instead.
1252+
12451253
@type n: L{datetime}
12461254
@param n: The C{Date} data to be encoded to the AMF3 data stream.
1255+
@raise EncodeError: A datetime.time instance was found
12471256
"""
12481257
if isinstance(n, datetime.time):
12491258
raise pyamf.EncodeError('A datetime.time instance was found but '
@@ -1521,7 +1530,7 @@ def encode_int(n):
15211530
@param n: The integer to be encoded
15221531
@return: The encoded string
15231532
@rtype: C{str}
1524-
@raise OverflowError: Out of range.
1533+
@raise OverflowError: C{c} is out of range.
15251534
"""
15261535
global ENCODED_INT_CACHE
15271536

pyamf/flex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ArrayCollection(list):
2121
2222
The C{ArrayCollection} class is a wrapper class that exposes an Array
2323
as a collection that can be accessed and manipulated using the
24-
methods and properties of the `ICollectionView` or `IList`
24+
methods and properties of the C{ICollectionView} or C{IList}
2525
interfaces in the Flex framework.
2626
2727
@see: U{ArrayCollection on Livedocs <http://

pyamf/flex/messaging.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AbstractMessage(object):
5151
@type clientId: C{str}
5252
@ivar destination: Message destination.
5353
@type destination: C{str}
54-
@ivar headers: Message headers. Core header names start with DS.
54+
@ivar headers: Message headers. Core header names start with C{DS}.
5555
@type headers: C{dict}
5656
@ivar messageId: Unique Message ID.
5757
@type messageId: C{str}
@@ -202,10 +202,12 @@ def __writeamf__(self, output):
202202

203203
def getSmallMessage(self):
204204
"""
205-
Return a ISmallMessage representation of this object. If one is not
206-
available, L{NotImplementedError} will be raised.
205+
Return a C{ISmallMessage} representation of this object. If one is not
206+
available, C{NotImplementedError} will be raised.
207207
208208
@since: 0.5
209+
@see: U{ISmallMessage on Adobe Help (external)<http://
210+
help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/messaging/messages/ISmallMessage.html>}
209211
"""
210212
raise NotImplementedError
211213

@@ -214,7 +216,7 @@ class AsyncMessage(AbstractMessage):
214216
"""
215217
I am the base class for all asynchronous Flex messages.
216218
217-
@see: U{AsyncMessage on Livedocs<http://
219+
@see: U{AsyncMessage on Adobe Help<http://
218220
help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/messaging/messages/AsyncMessage.html>}
219221
220222
@ivar correlationId: Correlation id of the message.
@@ -263,7 +265,7 @@ def __writeamf__(self, output):
263265

264266
def getSmallMessage(self):
265267
"""
266-
Return a ISmallMessage representation of this async message.
268+
Return a C{ISmallMessage} representation of this async message.
267269
268270
@since: 0.5
269271
"""
@@ -277,7 +279,7 @@ class AcknowledgeMessage(AsyncMessage):
277279
Every message sent within the messaging system must receive an
278280
acknowledgement.
279281
280-
@see: U{AcknowledgeMessage on Livedocs<http://
282+
@see: U{AcknowledgeMessage on Adobe Help (external)<http://
281283
help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/messaging/messages/AcknowledgeMessage.html>}
282284
"""
283285

@@ -302,7 +304,7 @@ def __writeamf__(self, output):
302304

303305
def getSmallMessage(self):
304306
"""
305-
Return a ISmallMessage representation of this acknowledge message.
307+
Return a C{ISmallMessage} representation of this acknowledge message.
306308
307309
@since: 0.5
308310
"""
@@ -314,7 +316,7 @@ class CommandMessage(AsyncMessage):
314316
Provides a mechanism for sending commands related to publish/subscribe
315317
messaging, ping, and cluster operations.
316318
317-
@see: U{CommandMessage on Livedocs<http://
319+
@see: U{CommandMessage on Adobe Help (external)<http://
318320
help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/messaging/messages/CommandMessage.html>}
319321
320322
@ivar operation: The command
@@ -396,7 +398,7 @@ def __writeamf__(self, output):
396398

397399
def getSmallMessage(self):
398400
"""
399-
Return a ISmallMessage representation of this command message.
401+
Return a C{ISmallMessage} representation of this command message.
400402
401403
@since: 0.5
402404
"""
@@ -409,7 +411,7 @@ class ErrorMessage(AcknowledgeMessage):
409411
410412
This class is used to report errors within the messaging system.
411413
412-
@see: U{ErrorMessage on Livedocs<http://
414+
@see: U{ErrorMessage on Adobe Help (external)<http://
413415
help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/messaging/messages/ErrorMessage.html>}
414416
"""
415417

@@ -443,7 +445,7 @@ def __init__(self, *args, **kwargs):
443445

444446
def getSmallMessage(self):
445447
"""
446-
Return a ISmallMessage representation of this error message.
448+
Return a C{ISmallMessage} representation of this error message.
447449
448450
@since: 0.5
449451
"""
@@ -454,7 +456,7 @@ class RemotingMessage(AbstractMessage):
454456
"""
455457
I am used to send RPC requests to a remote endpoint.
456458
457-
@see: U{RemotingMessage on Livedocs<http://
459+
@see: U{RemotingMessage on Adobe Help (external)<http://
458460
help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/messaging/messages/RemotingMessage.html>}
459461
"""
460462

0 commit comments

Comments
 (0)