예제 #1
0
파일: ncards.py 프로젝트: qznc/ik
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
예제 #2
0
파일: ncards.py 프로젝트: qznc/ik
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
예제 #3
0
파일: ncards.py 프로젝트: qznc/ik
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
예제 #4
0
파일: ncards.py 프로젝트: qznc/ik
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