class EasyDB:
  def _ur(s,x):
    return x.encode('utf-8')
  
  def __init__(s):
    s._base = {}
    s._reg_classes = []
    import cerealizer
    s._c = cerealizer 
    del cerealizer 
    

  def Save(s):
    try:
      s._register()
      buf = s._c.dumps(s._base)
      f = open(s._path,"w+")
      f.write(buf)
      f.close()
      return True
    except: return False
    
  def Load(s, path, autocommit = True, create = False):
    s._path = path
    try: s._path = s._ur(path)
    except: pass
    s._commit = autocommit
    if create: return True
    try:
      f = open(s._path,"r")
      buf = f.read()
      f.close()
      s._base = s._c.loads(buf)
      return True
    except: return False

  def _register(s):
    reload(s._c)
    for r in s._reg_classes:
      try:
        s._c.register(r)
      except: pass

  def Register(s, classr):
    if not classr in s._reg_classes:
      s._reg_classes.append(classr)
    s._register()

  def Get(s, key):
    if s._base.has_key(key):
      return s._base[key]
    else: return None
    
  def Add(s, key, value):
    s._base.update({key:value})
    if s._commit: s.Save()
  
  def Del(s, key):
    if s._base.has_key(key):
      del s._base[key]
      if s._commit: s.Save()
  
  def GetKeys(s):
    return s._base.keys()
  
  def GetValues(s):
    return s._base.values()