Esempio n. 1
0
    def getMappedByReference(self, ref):
        if not isinstance(ref, (int, long)):
            raise TypeError("Bad reference type.")

        try:
            return self.mapped[ref]
        except IndexError:
            raise pyamf.ReferenceError("Reference %r not found" % ref)
Esempio n. 2
0
 def getReferenceTo(self, obj):
     """
     @raise pyamf.ReferenceError: Value not found.
     """
     try:
         return self.dict[self.func(obj)]
     except KeyError:
         raise pyamf.ReferenceError("Value %r not found" % (obj, ))
Esempio n. 3
0
    def readObject(self):
        """
        Reads an object from the stream.

        @raise ReferenceError: Unknown reference found.
        @raise DecodeError: Unknown object encoding detected.
        """
        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)

            return obj

        ref >>= 1

        class_def = self._getClassDefinition(ref)
        alias = class_def.alias

        obj = alias.createInstance(codec=self)
        obj_attrs = dict()

        self.context.addObject(obj)

        if class_def.encoding in (
                ObjectEncoding.EXTERNAL,
                ObjectEncoding.PROXY):
            obj.__readamf__(DataInput(self))

            if self.use_proxies is True:
                obj = self.readProxy(obj)

            return obj
        elif class_def.encoding == ObjectEncoding.DYNAMIC:
            self._readStatic(class_def, obj_attrs)
            self._readDynamic(class_def, obj_attrs)
        elif class_def.encoding == ObjectEncoding.STATIC:
            self._readStatic(class_def, obj_attrs)
        else:
            raise pyamf.DecodeError("Unknown object encoding")

        alias.applyAttributes(obj, obj_attrs, codec=self)

        if self.use_proxies is True:
            obj = self.readProxy(obj)

        return obj
Esempio n. 4
0
    def remove(self, obj):
        h = self.func(obj)

        try:
            idx = self.dict[h]
        except KeyError:
            raise pyamf.ReferenceError("%r is not a valid reference" % (obj, ))

        del self.list[idx]
        del self.dict[h]

        return idx
Esempio n. 5
0
    def getByReference(self, ref):
        """
        @raise TypeError: Bad reference type.
        @raise pyamf.ReferenceError: Reference not found.
        """
        if not isinstance(ref, (int, long)):
            raise TypeError("Bad reference type")

        try:
            return self.list[ref]
        except IndexError:
            raise pyamf.ReferenceError("Reference %r not found" % (ref, ))
Esempio n. 6
0
    def readReference(self):
        """
        Reads a reference from the data stream.

        @raise pyamf.ReferenceError: Unknown reference.
        """
        idx = self.stream.read_ushort()
        o = self.context.getObject(idx)

        if o is None:
            raise pyamf.ReferenceError('Unknown reference %d' % (idx,))

        return o
Esempio n. 7
0
    def getReferenceTo(self, obj):
        """
        Returns a reference to C{obj} if it is contained within this index.

        @raise pyamf.ReferenceError: Value not found.
        """
        try:
            return self.dict[self.func(obj)]
        except KeyError:
            if self.exceptions is False:
                return None

            raise pyamf.ReferenceError("Value %r not found" % (obj, ))
Esempio n. 8
0
    def hasAMF3ObjectReference(self, obj):
        """
        Gets a reference for an object.

        @raise ReferenceError: Unknown AMF3 object reference.
        """
        return obj in self.amf3_objs
        o = self.amf3_objs.getReferenceTo(obj)

        if o is None and self.exceptions:
            raise pyamf.ReferenceError('Unknown AMF3 reference for (%r)' %
                                       (obj, ))

        return o
Esempio n. 9
0
    def getByReference(self, ref):
        """
        Returns an object based on the reference.

        @raise TypeError: Bad reference type.
        @raise pyamf.ReferenceError: Reference not found.
        """
        if not isinstance(ref, (int, long)):
            raise TypeError("Bad reference type")

        try:
            return self.list[ref]
        except IndexError:
            if self.exceptions is False:
                return None

            raise pyamf.ReferenceError("Reference %r not found" % (ref, ))
Esempio n. 10
0
    def getMappedByReference(self, ref):
        """
        Returns the mapped object by reference.

        @raise TypeError: Bad reference type.
        @raise pyamf.ReferenceError: Reference not found.
        """
        if not isinstance(ref, (int, long)):
            raise TypeError("Bad reference type.")

        try:
            return self.mapped[ref]
        except IndexError:
            if self.exceptions is False:
                return None

            raise pyamf.ReferenceError("Reference %r not found" % ref)