def merge(cards): """Merge a list of cards into one card""" new = NCard() for c in cards: for k, v in c: new.add(k, v) return new
def merge(cards): """Merge a list of cards into one card""" new = NCard() for c in cards: for k,v in c: new.add(k,v) return new
def read(fh): """Yields all cards read from a file""" chunks = dict() for name, data in read_iff(fh): chunks[name] = data fh.close() keys = chunks["KEYS"].split("\0") data = chunks["MCRD"] length = len(data) pos = 0 count = 0 cc = NCard() while pos < length: key = keys[ord(data[pos])] pos += 1 if key == keys[0]: cc.id = count yield cc count += 1 cc = NCard() else: end = data.index("\0", pos) cc.add(key, data[pos:end].decode("utf8")) pos = end + 1
def read(fh): """Yields all cards read from a file""" chunks = dict() for name,data in read_iff(fh): chunks[name] = data fh.close() keys = chunks["KEYS"].split("\0") data = chunks["MCRD"] length = len(data) pos = 0 count = 0 cc = NCard() while pos < length: key = keys[ord(data[pos])] pos += 1 if key == keys[0]: cc.id = count yield cc count += 1 cc = NCard() else: end = data.index("\0", pos) cc.add(key, data[pos:end].decode("utf8")) pos = end+1