# infoauth.py - graba y lee data ligeramente scrambleada # Copyright (C) 2009 - Facundo Batista # # 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 . from __future__ import with_statement import cPickle as pickle import os def load(filename): '''Load slightly scrambled data from filename.''' with open(filename) as fh: s = fh.read() data = pickle.loads(s.decode("zip")) return data def dump(data, filename): '''Dumps data to filename slightly scrambled.''' s = pickle.dumps(data) with open(filename, "w") as fh: fh.write(s.encode("zip")) if __name__ == "__main__": import tempfile import random import string # simple test fname = tempfile.mkstemp()[1] try: # dump random stuff a = random.randint(-3, 200) b = "".join(random.sample(string.letters, 50)) dump([a, b], fname) # load and compare c, d = load(fname) assert c == a assert b == d finally: os.remove(fname)