desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Return a ISmallMessage representation of this object. If one is not
available, L{NotImplementedError} will be raised.
@since: 0.5'
| def getSmallMessage(self):
| raise NotImplementedError
|
'Return a ISmallMessage representation of this async message.
@since: 0.5'
| def getSmallMessage(self):
| return AsyncMessageExt(**self.__dict__)
|
'Return a ISmallMessage representation of this acknowledge message.
@since: 0.5'
| def getSmallMessage(self):
| return AcknowledgeMessageExt(**self.__dict__)
|
'Return a ISmallMessage representation of this command message.
@since: 0.5'
| def getSmallMessage(self):
| return CommandMessageExt(**self.__dict__)
|
'Return a ISmallMessage representation of this error message.
@since: 0.5'
| def getSmallMessage(self):
| raise NotImplementedError
|
'Adds the specified item to the end of the list.
@param item: The object to add to the collection.
@since: 0.4'
| def addItem(self, item):
| self.append(item)
|
'Adds the item at the specified index.
@param item: The object to add to the collection.
@param index: The index at which to place the item.
@raise IndexError: If index is less than 0 or greater than the length
of the list.
@since: 0.4'
| def addItemAt(self, item, index):
| if ((index < 0) or (index > len(self))):
raise IndexError
self.insert(index, item)
|
'Gets the item at the specified index.
@param index: The index in the list from which to retrieve the item.
@type index: C{int}
@param prefetch: This param is ignored and is only here as part of the
interface.
@raise IndexError: if `index < 0` or `index >= length`
@since: 0.4'
| def getItemAt(self, index, prefetch=0):
| if (index < 0):
raise IndexError
if (index > len(self)):
raise IndexError
return self.__getitem__(index)
|
'Returns the index of the item if it is in the list such that
C{getItemAt(index) == item}.
@return: The index of the item or C{-1} if the item is not in the list.
@since: 0.4'
| def getItemIndex(self, item):
| try:
return self.index(item)
except ValueError:
return (-1)
|
'Removes all items from the list.
@since: 0.4'
| def removeAll(self):
| while (len(self) > 0):
self.pop()
|
'Removes the item at the specified index and returns it. Any items that
were after this index are now one index earlier.
@param index: The index from which to remove the item.
@return: The item that was removed.
@raise IndexError: If index is less than 0 or greater than length.
@since: 0.4'
| def removeItemAt(self, index):
| if ((index < 0) or (index > len(self))):
raise IndexError
x = self[index]
del self[index]
return x
|
'Places the item at the specified index. If an item was already at that
index the new item will replace it and it will be returned.
@return: The item that was replaced, or C{None}.
@raise IndexError: If index is less than 0 or greater than length.
@since: 0.4'
| def setItemAt(self, item, index):
| if ((index < 0) or (index > len(self))):
raise IndexError
tmp = self.__getitem__(index)
self.__setitem__(index, item)
return tmp
|
'Returns an Array that is populated in the same order as the C{IList}
implementation.
@return: The array.
@rtype: C{list}'
| def toArray(self):
| return self
|
'Clears the collection.'
| def clear(self):
| self.list = []
self.dict = {}
|
'Returns an object based on the supplied reference. The C{ref} should
be an C{int}.
If the reference is not found, C{None} will be returned.'
| def getByReference(self, ref):
| try:
return self.list[ref]
except IndexError:
return None
|
'Returns a reference to C{obj} if it is contained within this index.
If the object is not contained within the collection, C{-1} will be
returned.
@param obj: The object to find the reference to.
@return: An C{int} representing the reference or C{-1} is the object
is not contained within the collection.'
| def getReferenceTo(self, obj):
| return self.dict.get(self.func(obj), (-1))
|
'Appends C{obj} to this index.
@note: Uniqueness is not checked
@return: The reference to C{obj} in this index.'
| def append(self, obj):
| h = self.func(obj)
self.list.append(obj)
idx = (len(self.list) - 1)
self.dict[h] = idx
return idx
|
'Clears the context.'
| def clear(self):
| self._objects.clear()
self._class_aliases = {}
self._unicodes = {}
self.extra = {}
|
'Gets an object based on a reference.
@type ref: C{int}
@return: The referenced object or C{None} if not found.'
| def getObject(self, ref):
| return self._objects.getByReference(ref)
|
'Gets a reference for an already referenced object.
@return: The reference to the object or C{-1} if the object is not in
the context.'
| def getObjectReference(self, obj):
| return self._objects.getReferenceTo(obj)
|
'Adds a reference to C{obj}.
@return: Reference to C{obj}.
@rtype: C{int}'
| def addObject(self, obj):
| return self._objects.append(obj)
|
'Gets a class alias based on the supplied C{klass}. If one is not found
in the global context, one is created locally.
If you supply a string alias and the class is not registered,
L{pyamf.UnknownClassAlias} will be raised.
@param klass: A class object or string alias.
@return: The L{pyamf.ClassAlias} instance that des... | def getClassAlias(self, klass):
| try:
return self._class_aliases[klass]
except KeyError:
pass
try:
alias = self._class_aliases[klass] = pyamf.get_class_alias(klass)
except pyamf.UnknownClassAlias:
if isinstance(klass, python.str_types):
raise
alias = (util.get_class_alias(klass) or py... |
'Returns the corresponding string for the supplied utf-8 encoded bytes.
If there is no string object, one is created.
@since: 0.6'
| def getStringForBytes(self, s):
| h = hash(s)
u = self._unicodes.get(h, None)
if (u is not None):
return u
u = self._unicodes[h] = s.decode('utf-8')
return u
|
'Returns the corresponding utf-8 encoded string for a given unicode
object. If there is no string, one is encoded.
@since: 0.6'
| def getBytesForString(self, u):
| h = hash(u)
s = self._unicodes.get(h, None)
if (s is not None):
return s
s = self._unicodes[h] = u.encode('utf-8')
return s
|
'A context factory.'
| def buildContext(self):
| raise NotImplementedError
|
'Returns a callable based on C{data}. If no such callable can be found,
the default must be to return C{None}.'
| def getTypeFunc(self, data):
| raise NotImplementedError
|
'Add data for the decoder to work on.'
| def send(self, data):
| self.stream.append(data)
|
'Part of the iterator protocol.'
| def next(self):
| try:
return self.readElement()
except pyamf.EOStream:
raise StopIteration
|
'Reads an AMF3 element from the data stream.
@raise DecodeError: The ActionScript type is unsupported.
@raise EOStream: No more data left to decode.'
| def readElement(self):
| pos = self.stream.tell()
try:
t = self.stream.read(1)
except IOError:
raise pyamf.EOStream
try:
func = self._func_cache[t]
except KeyError:
func = self.getTypeFunc(t)
if (not func):
raise pyamf.DecodeError(('Unsupported ActionScript type %... |
'Subclasses should override this and all write[type] functions'
| def _write_type(self, obj, **kwargs):
| raise NotImplementedError
|
'Encodes an iterable. The default is to write If the iterable has an al'
| def writeSequence(self, iterable):
| try:
alias = self.context.getClassAlias(iterable.__class__)
except (AttributeError, pyamf.UnknownClassAlias):
self.writeList(iterable)
return
if alias.external:
self.writeObject(iterable)
return
self.writeList(iterable)
|
'Iterates over a generator object and encodes all that is returned.'
| def writeGenerator(self, gen):
| n = getattr(gen, 'next')
while True:
try:
self.writeElement(n())
except StopIteration:
break
|
'Returns a callable that will encode C{data} to C{self.stream}. If
C{data} is unencodable, then C{None} is returned.'
| def getTypeFunc(self, data):
| if (data is None):
return self.writeNull
t = type(data)
if ((t is str) or issubclass(t, str)):
return self.writeBytes
if ((t is unicode) or issubclass(t, unicode)):
return self.writeString
elif (t is bool):
return self.writeBoolean
elif (t is float):
retur... |
'Encodes C{data} to AMF. If the data is not able to be matched to an AMF
type, then L{pyamf.EncodeError} will be raised.'
| def writeElement(self, data):
| key = type(data)
func = None
try:
func = self._func_cache[key]
except KeyError:
func = self.getTypeFunc(data)
if (func is None):
raise pyamf.EncodeError(('Unable to encode %r (type %r)' % (data, key)))
self._func_cache[key] = func
func(data)... |
'@param encoder: Encoder containing the stream.
@type encoder: L{amf3.Encoder<pyamf.amf3.Encoder>}'
| def __init__(self, encoder):
| self.encoder = encoder
self.stream = encoder.stream
|
'Writes a Boolean value.
@type value: C{bool}
@param value: A C{Boolean} value determining which byte is written.
If the parameter is C{True}, C{1} is written; if C{False}, C{0} is
written.
@raise ValueError: Non-boolean value found.'
| def writeBoolean(self, value):
| if (not isinstance(value, bool)):
raise ValueError('Non-boolean value found')
if (value is True):
self.stream.write_uchar(1)
else:
self.stream.write_uchar(0)
|
'Writes a byte.
@type value: C{int}'
| def writeByte(self, value):
| self.stream.write_char(value)
|
'Writes an unsigned byte.
@type value: C{int}
@since: 0.5'
| def writeUnsignedByte(self, value):
| return self.stream.write_uchar(value)
|
'Writes an IEEE 754 double-precision (64-bit) floating
point number.
@type value: C{number}'
| def writeDouble(self, value):
| self.stream.write_double(value)
|
'Writes an IEEE 754 single-precision (32-bit) floating
point number.
@type value: C{float}'
| def writeFloat(self, value):
| self.stream.write_float(value)
|
'Writes a 32-bit signed integer.
@type value: C{int}'
| def writeInt(self, value):
| self.stream.write_long(value)
|
'Writes a multibyte string to the datastream using the
specified character set.
@type value: C{str}
@param value: The string value to be written.
@type charset: C{str}
@param charset: The string denoting the character set to use. Possible
character set strings include C{shift-jis}, C{cn-gb},
C{iso-8859-1} and others.
@... | def writeMultiByte(self, value, charset):
| if (type(value) is unicode):
value = value.encode(charset)
self.stream.write(value)
|
'Writes an object to data stream in AMF serialized format.
@param value: The object to be serialized.'
| def writeObject(self, value):
| self.encoder.writeElement(value)
|
'Writes a 16-bit integer.
@type value: C{int}
@param value: A byte value as an integer.'
| def writeShort(self, value):
| self.stream.write_short(value)
|
'Writes a 16-bit unsigned integer.
@type value: C{int}
@param value: A byte value as an integer.
@since: 0.5'
| def writeUnsignedShort(self, value):
| self.stream.write_ushort(value)
|
'Writes a 32-bit unsigned integer.
@type value: C{int}
@param value: A byte value as an unsigned integer.'
| def writeUnsignedInt(self, value):
| self.stream.write_ulong(value)
|
'Writes a UTF-8 string to the data stream.
The length of the UTF-8 string in bytes is written first,
as a 16-bit integer, followed by the bytes representing the
characters of the string.
@type value: C{str}
@param value: The string value to be written.'
| def writeUTF(self, value):
| buf = util.BufferedByteStream()
buf.write_utf8_string(value)
bytes = buf.getvalue()
self.stream.write_ushort(len(bytes))
self.stream.write(bytes)
|
'Writes a UTF-8 string. Similar to L{writeUTF}, but does
not prefix the string with a 16-bit length word.
@type value: C{str}
@param value: The string value to be written.'
| def writeUTFBytes(self, value):
| val = None
if isinstance(value, unicode):
val = value
else:
val = unicode(value, 'utf8')
self.stream.write_utf8_string(val)
|
'@param decoder: AMF3 decoder containing the stream.
@type decoder: L{amf3.Decoder<pyamf.amf3.Decoder>}'
| def __init__(self, decoder=None):
| self.decoder = decoder
self.stream = decoder.stream
|
'Read C{Boolean}.
@raise ValueError: Error reading Boolean.
@rtype: C{bool}
@return: A Boolean value, C{True} if the byte
is nonzero, C{False} otherwise.'
| def readBoolean(self):
| byte = self.stream.read(1)
if (byte == '\x00'):
return False
elif (byte == '\x01'):
return True
else:
raise ValueError('Error reading boolean')
|
'Reads a signed byte.
@rtype: C{int}
@return: The returned value is in the range -128 to 127.'
| def readByte(self):
| return self.stream.read_char()
|
'Reads an IEEE 754 double-precision floating point number from the
data stream.
@rtype: C{number}
@return: An IEEE 754 double-precision floating point number.'
| def readDouble(self):
| return self.stream.read_double()
|
'Reads an IEEE 754 single-precision floating point number from the
data stream.
@rtype: C{number}
@return: An IEEE 754 single-precision floating point number.'
| def readFloat(self):
| return self.stream.read_float()
|
'Reads a signed 32-bit integer from the data stream.
@rtype: C{int}
@return: The returned value is in the range -2147483648 to 2147483647.'
| def readInt(self):
| return self.stream.read_long()
|
'Reads a multibyte string of specified length from the data stream
using the specified character set.
@type length: C{int}
@param length: The number of bytes from the data stream to read.
@type charset: C{str}
@param charset: The string denoting the character set to use.
@rtype: C{str}
@return: UTF-8 encoded string.'
| def readMultiByte(self, length, charset):
| bytes = self.stream.read(length)
return unicode(bytes, charset)
|
'Reads an object from the data stream.
@return: The deserialized object.'
| def readObject(self):
| return self.decoder.readElement()
|
'Reads a signed 16-bit integer from the data stream.
@rtype: C{uint}
@return: The returned value is in the range -32768 to 32767.'
| def readShort(self):
| return self.stream.read_short()
|
'Reads an unsigned byte from the data stream.
@rtype: C{uint}
@return: The returned value is in the range 0 to 255.'
| def readUnsignedByte(self):
| return self.stream.read_uchar()
|
'Reads an unsigned 32-bit integer from the data stream.
@rtype: C{uint}
@return: The returned value is in the range 0 to 4294967295.'
| def readUnsignedInt(self):
| return self.stream.read_ulong()
|
'Reads an unsigned 16-bit integer from the data stream.
@rtype: C{uint}
@return: The returned value is in the range 0 to 65535.'
| def readUnsignedShort(self):
| return self.stream.read_ushort()
|
'Reads a UTF-8 string from the data stream.
The string is assumed to be prefixed with an unsigned
short indicating the length in bytes.
@rtype: C{str}
@return: A UTF-8 string produced by the byte
representation of characters.'
| def readUTF(self):
| length = self.stream.read_ushort()
return self.stream.read_utf8_string(length)
|
'Reads a sequence of C{length} UTF-8 bytes from the data
stream and returns a string.
@type length: C{int}
@param length: The number of bytes from the data stream to read.
@rtype: C{str}
@return: A UTF-8 string produced by the byte representation of
characters of specified C{length}.'
| def readUTFBytes(self, length):
| return self.readMultiByte(length, 'utf-8')
|
'Forces compression of the underlying stream.'
| def compress(self):
| self.compressed = True
|
'Clears the context.'
| def clear(self):
| codec.Context.clear(self)
self.strings.clear()
self.proxied_objects = {}
self.classes = {}
self.class_ref = {}
self.class_idx = 0
|
'Gets a string based on a reference C{ref}.
@param ref: The reference index.
@type ref: C{str}
@rtype: C{str} or C{None}
@return: The referenced string.'
| def getString(self, ref):
| return self.strings.getByReference(ref)
|
'Return string reference.
@type s: C{str}
@param s: The referenced string.
@return: The reference index to the string.
@rtype: C{int} or C{None}'
| def getStringReference(self, s):
| return self.strings.getReferenceTo(s)
|
'Creates a reference to C{s}. If the reference already exists, that
reference is returned.
@type s: C{str}
@param s: The string to be referenced.
@rtype: C{int}
@return: The reference index.
@raise TypeError: The parameter C{s} is not of C{basestring} type.'
| def addString(self, s):
| if (not isinstance(s, basestring)):
raise TypeError
if (len(s) == 0):
return (-1)
return self.strings.append(s)
|
'Return class reference.
@return: Class reference.'
| def getClassByReference(self, ref):
| return self.class_ref.get(ref)
|
'Return class reference.
@return: Class reference.'
| def getClass(self, klass):
| return self.classes.get(klass)
|
'Creates a reference to C{class_def}.
@param alias: C{ClassDefinition} instance.'
| def addClass(self, alias, klass):
| ref = self.class_idx
self.class_ref[ref] = alias
cd = self.classes[klass] = alias
cd.reference = ref
self.class_idx += 1
return ref
|
'Returns the unproxied version of C{proxy} as stored in the context, or
unproxies the proxy and returns that \'raw\' object.
@see: L{pyamf.flex.unproxy_object}
@since: 0.6'
| def getObjectForProxy(self, proxy):
| obj = self.proxied_objects.get(id(proxy))
if (obj is None):
from pyamf import flex
obj = flex.unproxy_object(proxy)
self.addProxyObject(obj, proxy)
return obj
|
'Stores a reference to the unproxied and proxied versions of C{obj} for
later retrieval.
@since: 0.6'
| def addProxyObject(self, obj, proxied):
| self.proxied_objects[id(obj)] = proxied
self.proxied_objects[id(proxied)] = obj
|
'Returns the proxied version of C{obj} as stored in the context, or
creates a new proxied object and returns that.
@see: L{pyamf.flex.proxy_object}
@since: 0.6'
| def getProxyForObject(self, obj):
| proxied = self.proxied_objects.get(id(obj))
if (proxied is None):
from pyamf import flex
proxied = flex.proxy_object(obj)
self.addProxyObject(obj, proxied)
return proxied
|
'Decodes a proxied object from the stream.
@since: 0.6'
| def readProxy(self, obj):
| return self.context.getObjectForProxy(obj)
|
'Read undefined.'
| def readUndefined(self):
| return pyamf.Undefined
|
'Read null.
@return: C{None}
@rtype: C{None}'
| def readNull(self):
| return None
|
'Returns C{False}.
@return: C{False}
@rtype: C{bool}'
| def readBoolFalse(self):
| return False
|
'Returns C{True}.
@return: C{True}
@rtype: C{bool}'
| def readBoolTrue(self):
| return True
|
'Read number.'
| def readNumber(self):
| return self.stream.read_double()
|
'Reads and returns an integer from the stream.
@type signed: C{bool}
@see: U{Parsing integers on OSFlash
<http://osflash.org/amf3/parsing_integers>} for the AMF3 integer data
format.'
| def readInteger(self, signed=True):
| return decode_int(self.stream, signed)
|
'Reads and returns a utf-8 encoded byte array.'
| def readBytes(self):
| (length, is_reference) = self._readLength()
if is_reference:
return self.context.getString(length)
if (length == 0):
return ''
result = self.stream.read(length)
self.context.addString(result)
return result
|
'Reads and returns a string from the stream.'
| def readString(self):
| (length, is_reference) = self._readLength()
if is_reference:
result = self.context.getString(length)
return self.context.getStringForBytes(result)
if (length == 0):
return ''
result = self.stream.read(length)
self.context.addString(result)
return self.context.getStringFor... |
'Read date from the stream.
The timezone is ignored as the date is always in UTC.'
| def readDate(self):
| ref = self.readInteger(False)
if ((ref & REFERENCE_BIT) == 0):
return self.context.getObject((ref >> 1))
ms = self.stream.read_double()
result = util.get_datetime((ms / 1000.0))
if (self.timezone_offset is not None):
result += self.timezone_offset
self.context.addObject(result)
... |
'Reads an array from the stream.
@warning: There is a very specific problem with AMF3 where the first
three bytes of an encoded empty C{dict} will mirror that of an encoded
C{{\'\': 1, \'2\': 2}}'
| def readArray(self):
| size = self.readInteger(False)
if ((size & REFERENCE_BIT) == 0):
return self.context.getObject((size >> 1))
size >>= 1
key = self.readBytes()
if (key == ''):
result = []
self.context.addObject(result)
for i in xrange(size):
result.append(self.readElement()... |
'Reads class definition from the stream.'
| def _getClassDefinition(self, ref):
| is_ref = ((ref & REFERENCE_BIT) == 0)
ref >>= 1
if is_ref:
class_def = self.context.getClassByReference(ref)
return class_def
name = self.readBytes()
alias = None
if (name == ''):
name = pyamf.ASObject
try:
alias = pyamf.get_class_alias(name)
except pyamf.... |
'Reads an object from the stream.'
| def readObject(self):
| ref = self.readInteger(False)
if ((ref & REFERENCE_BIT) == 0):
obj = self.context.getObject((ref >> 1))
if (obj is None):
raise pyamf.ReferenceError(('Unknown reference %d' % ((ref >> 1),)))
if (self.use_proxies is True):
obj = self.readProxy(obj)
re... |
'Reads an xml object from the stream.
@return: An etree interface compatible object
@see: L{xml.set_default_interface}'
| def readXML(self):
| ref = self.readInteger(False)
if ((ref & REFERENCE_BIT) == 0):
return self.context.getObject((ref >> 1))
xmlstring = self.stream.read((ref >> 1))
x = xml.fromstring(xmlstring)
self.context.addObject(x)
return x
|
'Reads a string from the data stream and converts it into
an XML Tree.
@see: L{readXML}'
| def readXMLString(self):
| return self.readXML()
|
'Reads a string of data from the stream.
Detects if the L{ByteArray} was compressed using C{zlib}.
@see: L{ByteArray}
@note: This is not supported in ActionScript 1.0 and 2.0.'
| def readByteArray(self):
| ref = self.readInteger(False)
if ((ref & REFERENCE_BIT) == 0):
return self.context.getObject((ref >> 1))
buffer = self.stream.read((ref >> 1))
try:
buffer = zlib.decompress(buffer)
compressed = True
except zlib.error:
compressed = False
obj = ByteArray(buffer)
... |
'@see: L{codec.Encoder.getTypeFunc}'
| def getTypeFunc(self, data):
| t = type(data)
if (t in python.int_types):
return self.writeInteger
elif (t is ByteArray):
return self.writeByteArray
elif (t is pyamf.MixedArray):
return self.writeDict
return codec.Encoder.getTypeFunc(self, data)
|
'Writes an C{pyamf.Undefined} value to the stream.'
| def writeUndefined(self, n):
| self.stream.write(TYPE_UNDEFINED)
|
'Writes a C{null} value to the stream.'
| def writeNull(self, n):
| self.stream.write(TYPE_NULL)
|
'Writes a Boolean to the stream.'
| def writeBoolean(self, n):
| t = TYPE_BOOL_TRUE
if (n is False):
t = TYPE_BOOL_FALSE
self.stream.write(t)
|
'AMF3 integers are encoded.
@param n: The integer data to be encoded to the AMF3 data stream.
@type n: integer data
@see: U{Parsing Integers on OSFlash
<http://osflash.org/documentation/amf3/parsing_integers>}
for more info.'
| def _writeInteger(self, n):
| self.stream.write(encode_int(n))
|
'Writes an integer to the stream.
@type n: integer data
@param n: The integer data to be encoded to the AMF3 data stream.'
| def writeInteger(self, n):
| if ((n < MIN_29B_INT) or (n > MAX_29B_INT)):
self.writeNumber(float(n))
return
self.stream.write(TYPE_INTEGER)
self.stream.write(encode_int(n))
|
'Writes a float to the stream.
@type n: C{float}'
| def writeNumber(self, n):
| self.stream.write(TYPE_NUMBER)
self.stream.write_double(n)
|
'Writes a raw string to the stream.
@type s: C{str}
@param s: The string data to be encoded to the AMF3 data stream.'
| def serialiseString(self, s):
| if (type(s) is unicode):
s = self.context.getBytesForString(s)
self.serialiseBytes(s)
|
'Writes a raw string to the stream.'
| def writeBytes(self, b):
| self.stream.write(TYPE_STRING)
self.serialiseBytes(b)
|
'Writes a string to the stream. It will be B{UTF-8} encoded.'
| def writeString(self, s):
| s = self.context.getBytesForString(s)
self.writeBytes(s)
|
'Writes a C{datetime} instance to the stream.
@type n: L{datetime}
@param n: The C{Date} data to be encoded to the AMF3 data stream.'
| def writeDate(self, n):
| if isinstance(n, datetime.time):
raise pyamf.EncodeError(('A datetime.time instance was found but AMF3 has no way to encode time objects. Please use datetime.datetime instead (got:%r)' % (n,)))
self.stream.write(TYPE_DATE)
ref = self.context.getO... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.