def test_load_unknown_class(self): def class_loader(x): return None pyamf.register_class_loader(class_loader) with self.assertRaises(pyamf.UnknownClassAlias): pyamf.load_class('spam.eggs')
def test_load_class_by_alias(self): def class_loader(x): self.assertEquals(x, "spam.eggs") return pyamf.ClassAlias(Spam, "spam.eggs") pyamf.register_class_loader(class_loader) self.assertTrue("spam.eggs" not in pyamf.CLASS_CACHE.keys()) pyamf.load_class("spam.eggs") self.assertTrue("spam.eggs" in pyamf.CLASS_CACHE.keys())
def test_load_class_by_alias(self): def class_loader(x): self.assertEqual(x, 'spam.eggs') return pyamf.ClassAlias(Spam, 'spam.eggs') pyamf.register_class_loader(class_loader) self.assertTrue('spam.eggs' not in pyamf.CLASS_CACHE.keys()) pyamf.load_class('spam.eggs') self.assertTrue('spam.eggs' in pyamf.CLASS_CACHE.keys())
def test_load_class(self): def class_loader(x): self.assertEqual(x, 'spam.eggs') return Spam pyamf.register_class_loader(class_loader) self.assertTrue('spam.eggs' not in list(pyamf.CLASS_CACHE.keys())) pyamf.load_class('spam.eggs') self.assertTrue('spam.eggs' in list(pyamf.CLASS_CACHE.keys()))
def loadTable_amf(login, classAlias, filterStr, orderStr): table = npi.loadTable(login, classAlias.replace("models.",""), filterStr, orderStr) tl = [] for row in table: trow = pyamf.load_class(classAlias).createInstance() trow.__dict__ = row tl.append(trow) return ArrayCollection(tl)
def loadTable_amf(login, classAlias, filterStr, orderStr): table = npi.loadTable(login, classAlias.replace("models.", ""), filterStr, orderStr) tl = [] for row in table: trow = pyamf.load_class(classAlias).createInstance() trow.__dict__ = row tl.append(trow) return ArrayCollection(tl)
def readTypedObject(self): """ Reads an ActionScript object from the stream and attempts to 'cast' it. @see: L{load_class<pyamf.load_class>} """ classname = self.readString() alias = pyamf.load_class(classname) ret = alias() self.context.addObject(ret) self._readObject(ret, alias) return ret
def readTypedObject(self): """ Reads an ActionScript object from the stream and attempts to 'cast' it. @see: L{load_class<pyamf.load_class>} """ classname = self.readString() alias = None try: alias = pyamf.load_class(classname) ret = alias.createInstance() except pyamf.UnknownClassAlias: if self.strict: raise ret = pyamf.TypedObject(classname) self.context.addObject(ret) self._readObject(ret, alias) return ret
def readTypedObject(self): """ Reads an ActionScript object from the stream and attempts to 'cast' it. @see: L{load_class<pyamf.load_class>} """ classname = self.readString() alias = None try: alias = pyamf.load_class(classname) ret = alias.createInstance(codec=self) except pyamf.UnknownClassAlias: if self.strict: raise ret = pyamf.TypedObject(classname) self.context.addObject(ret) self._readObject(ret, alias) return ret
def load(self, class_alias, key): klass = pyamf.load_class(class_alias).klass session = Schema().session return session.query(klass).get(key)
def test_load_class_by_module(self): pyamf.load_class('__builtin__.tuple')
def remove(self, class_alias, key): klass = pyamf.load_class(class_alias).klass session = Schema().session obj = session.query(klass).get(key) session.delete(obj) session.commit()
def test_load_class_by_module_bad(self): with self.assertRaises(pyamf.UnknownClassAlias): pyamf.load_class('__builtin__.tuple.')
def loadAll(self, class_alias): klass = pyamf.load_class(class_alias).klass session = Schema().session return session.query(klass).all()