From d133981a874aa741485c61ceb69a5c7f64a7f4e3 Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Fri, 13 May 2011 14:48:03 +0200 Subject: [PATCH] implement PickleContainer --- annotations/container.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/annotations/container.py b/annotations/container.py index f5b69c1..e7ddf4e 100644 --- a/annotations/container.py +++ b/annotations/container.py @@ -1,6 +1,10 @@ import os import fnmatch from core.exceptions import ImproperlyConfigured +try: + import cPickle as pickle +except: + import pickle class AnnotationContainerFactory: def __init__(self, containers): @@ -95,3 +99,18 @@ class AnnotationContainer: num += len(frame['annotations']) return num +class PickleContainer(AnnotationContainer): + """ + Simple container which just pickles the annotations to disk. + """ + + def load(self, fname): + f = open(fname, "rb") + self.annotations_ = pickle.load(f) + self.filename_ = fname + + def save(self, fname): + f = open(fname, "wb") + pickle.dump(self.annotations(), f) + self.filename_ = fname +