def testMarmaladeable(self): m = Marmaladeable(1, B(), "testing", [1, 2, 3]) s = marmalade.jellyToXML(m) u = marmalade.unjellyFromXML(s) assert u.sequence == [u.instance, u.instance] u.sequence.append(u.instance) u.jellyDOMVersion = 2 s2 = marmalade.jellyToXML(u) u2 = marmalade.unjellyFromXML(s2) self.assertEquals( u2.sequence, [u2.instance, u2.instance, u2.instance])
def testMethodSelfIdentity(self): a = A() b = B() a.bmethod = b.bmethod b.a = a im_ = marmalade.unjellyFromXML(marmalade.jellyToXML(b)).a.bmethod self.assertEquals(im_.im_class, im_.im_self.__class__)
def decode(self): from twisted.persisted.marmalade import unjellyFromXML sys.modules['__main__'] = EverythingEphemeral() application = unjellyFromXML(StringIO.StringIO(self.data)) sys.modules['__main__'] = mainMod styles.doUpgrade() return application
def decode(filename, data): from twisted.persisted.marmalade import unjellyFromXML log.msg('<Loading file="%s" />' % (filename,)) sys.modules['__main__'] = EverythingEphemeral() application = unjellyFromXML(StringIO.StringIO(data)) application.persistStyle = 'xml' sys.modules['__main__'] = mainMod styles.doUpgrade() return application
def _rowLoader(self, tableName, parentRow, data, whereClause, forceChildren): d = self.tableDirs[ tableName] tableInfo = self.schema[tableName] filenames = os.listdir(d) results = [] newRows = [] for filename in filenames: if (filename.find(self.extension) != len(filename) - len(self.extension)): continue f = open(d + "/" + filename, "r") proxy = marmalade.unjellyFromXML(f) f.close() # match object with whereClause... NOTE: this is insanely slow.. # every object in the directory is loaded and checked! stop = 0 if whereClause: for item in whereClause: (columnName, cond, value) = item #TODO: just do EQUAL for now if proxy.kw[columnName] != value: stop = 1 if stop: continue # find the row in the cache or add it resultObject = self.findInCache(tableInfo.rowClass, proxy.kw) if not resultObject: resultObject = tableInfo.rowFactoryMethod[0]( tableInfo.rowClass, data, proxy.kw) self.addToCache(resultObject) newRows.append(resultObject) results.append(resultObject) # add these rows to the parentRow if required if parentRow: self.addToParent(parentRow, newRows, tableName) # load children or each of these rows if required for relationship in tableInfo.relationships: if not forceChildren and not relationship.autoLoad: continue for row in results: # build where clause childWhereClause = self.buildWhereClause(relationship, row) # load the children immediately, but do nothing with them self._rowLoader(relationship.childRowClass.rowTableName, row, data, childWhereClause, forceChildren) return results
def testBasicIdentity(self): dj = marmalade.DOMJellier().jellyToNode d = {'hello': 'world', "method": dj} l = [1, 2, 3, "he\tllo\n\n\"x world!", u"goodbye \n\t\u1010 world!", 1, 1.0, 100 ** 100l, unittest, marmalade.DOMJellier, d, funktion, True, False, (2, 4, [2]), ] t = tuple(l) l.append(l) l.append(t) l.append(t) uj = marmalade.unjellyFromXML(marmalade.jellyToXML([l, l])) assert uj[0] is uj[1] assert uj[1][0:5] == l[0:5]
def testBasicIdentity(self): # Anyone wanting to make this datastructure more complex, and thus this # test more comprehensive, is welcome to do so. dj = marmalade.DOMJellier().jellyToNode d = {'hello': 'world', "method": dj} l = [1, 2, 3, "he\tllo\n\n\"x world!", u"goodbye \n\t\u1010 world!", 1, 1.0, 100 ** 100l, unittest, marmalade.DOMJellier, d, funktion ] t = tuple(l) l.append(l) l.append(t) l.append(t) uj = marmalade.unjellyFromXML(marmalade.jellyToXML([l, l])) assert uj[0] is uj[1] assert uj[1][0:5] == l[0:5]
def testBasicIdentity(self): # Anyone wanting to make this datastructure more complex, and thus this # test more comprehensive, is welcome to do so. dj = marmalade.DOMJellier().jellyToNode d = {'hello': 'world', "method": dj} l = [1, 2, 3, "he\tllo\n\n\"x world!", u"goodbye \n\t\u1010 world!", 1, 1.0, 100 ** 100l, unittest, marmalade.DOMJellier, d, funktion, True, False, (2, 4, [2]), ] t = tuple(l) l.append(l) l.append(t) l.append(t) uj = marmalade.unjellyFromXML(marmalade.jellyToXML([l, l])) assert uj[0] is uj[1] assert uj[1][0:5] == l[0:5]
def testCopyReg(self): s = "foo_bar" sio = StringIO.StringIO() sio.write(s) assert marmalade.unjellyFromXML(marmalade.jellyToXML({1:sio}))[1].getvalue() == s