41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# Copyright (C) 2014 Andrey Golovizin
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
import pickle
|
|
from os import path
|
|
|
|
|
|
class GlyphDB(object):
|
|
def __init__(self, filename):
|
|
self.filename = filename
|
|
if path.isfile(self.filename):
|
|
with open(self.filename, 'rb') as fileobj:
|
|
self.data = pickle.load(fileobj)
|
|
else:
|
|
self.data = {}
|
|
|
|
def __getitem__(self, key):
|
|
return self.data.__getitem__(key)
|
|
|
|
def __setitem__(self, key, value):
|
|
return self.data.__setitem__(key, value)
|
|
|
|
def __delitem__(self, key):
|
|
return self.data.__delitem__(key)
|
|
|
|
def save(self):
|
|
with open(self.filename, 'wb') as fileobj:
|
|
pickle.dump(self.data, fileobj)
|