def getDecodableAttributes(self, obj, attrs, codec=None):
        key = attrs.setdefault(self.KEY_ATTR, None)
        attrs = pyamf.ClassAlias.getDecodableAttributes(self, obj, attrs, codec=codec)

        del attrs[self.KEY_ATTR]
        new_obj = None

        # attempt to load the object from the datastore if KEY_ATTR exists.
        if key and codec:
            new_obj = loadInstanceFromDatastore(self.klass, key, codec)

        # clean up the stub
        if isinstance(obj, ModelStub) and hasattr(obj, 'klass'):
            del obj.klass

        if new_obj:
            obj.__dict__ = new_obj.__dict__.copy()

        obj.__class__ = self.klass
        apply_init = True

        if self.properties:
            for k in [k for k in attrs.keys() if k in self.properties.keys()]:
                prop = self.properties[k]
                v = attrs[k]

                if isinstance(prop, db.FloatProperty) and isinstance(v, (int, long)):
                    attrs[k] = float(v)
                elif isinstance(prop, db.IntegerProperty) and isinstance(v, float):
                    x = long(v)

                    # only convert the type if there is no mantissa - otherwise
                    # let the chips fall where they may
                    if x == v:
                        attrs[k] = x
                elif isinstance(prop, db.ListProperty) and v is None:
                    attrs[k] = []
                elif isinstance(v, datetime.datetime):
                    # Date/Time Property fields expect specific types of data
                    # whereas PyAMF only decodes into datetime.datetime objects.
                    if isinstance(prop, db.DateProperty):
                        attrs[k] = v.date()
                    elif isinstance(prop, db.TimeProperty):
                        attrs[k] = v.time()

                if new_obj is None and isinstance(v, ModelStub) and prop.required and k in self.reference_properties:
                    apply_init = False
                    del attrs[k]

        # If the object does not exist in the datastore, we must fire the
        # class constructor. This sets internal attributes that pyamf has
        # no business messing with ..
        if new_obj is None and apply_init is True:
            obj.__init__(**attrs)

        return attrs
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/PyAMF-0.6.1/pyamf/adapters/_google_appengine_ext_db.py/DataStoreClassAlias.getDecodableAttributes/original