<commit_before>import os
from StringIO import StringIO
import pickle
import sqlite3
from python_zipcodes.exceptions import ImproperlyConfiguredError
from python_zipcodes.django_app.zipcodes.models import ZipCode

class DummyStorage(object):
    def __init__(self, *args, **kwargs):
        try:
            self.importer = kwargs['importer']
            self.fill_cache()
        except KeyError:
            raise ImproperlyConfiguredError

    def fill_cache(self):
        self.cached_data = self.read()

    def drop(self):
        """Delete all the data"""
        self.cached_data = {}

    def update(self):
        self.drop()
        self.cached_data = self.importer.parse(self.importer.download())
        self.save()

    def read(self):
        """Reads data from the storage format"""
        return self.compile()

    def save(self, zip_codes):
        pass
    
    def compile(self):
        """Opens the source file and converst it to a dict"""
        try:
            content = open(os.path.join(self.importer.cache_dir,self.importer.txt), 'rb')
            content.close()
        except IOError:
            content = self.importer.download()
        content.seek(0)
        zip_codes = self.importer.parse(content)
        self.save(zip_codes)
        return zip_codes


class PickleStorage(DummyStorage):
    pickled = 'zipcodes.pickled'

    def drop(self):
        os.remove(os.path.join(self.importer.cache_dir, self.pickled))
        super(PickleStorage, self).drop()

    def read(self):
        try:<commit_msg>fixing saving upon update<commit_after>import os
from StringIO import StringIO
import pickle
import sqlite3
from python_zipcodes.exceptions import ImproperlyConfiguredError
from python_zipcodes.django_app.zipcodes.models import ZipCode

class DummyStorage(object):
    def __init__(self, *args, **kwargs):
        try:
            self.importer = kwargs['importer']
            self.fill_cache()
        except KeyError:
            raise ImproperlyConfiguredError

    def fill_cache(self):
        self.cached_data = self.read()

    def drop(self):
        """Delete all the data"""
        self.cached_data = {}

    def update(self):
        self.drop()
        self.cached_data = self.importer.parse(self.importer.download())
        self.save(self.cached_data)

    def read(self):
        """Reads data from the storage format"""
        return self.compile()

    def save(self, zip_codes):
        pass
    
    def compile(self):
        """Opens the source file and converst it to a dict"""
        try:
            content = open(os.path.join(self.importer.cache_dir,self.importer.txt), 'rb')
            content.close()
        except IOError:
            content = self.importer.download()
        content.seek(0)
        zip_codes = self.importer.parse(content)
        self.save(zip_codes)
        return zip_codes


class PickleStorage(DummyStorage):
    pickled = 'zipcodes.pickled'

    def drop(self):
        os.remove(os.path.join(self.importer.cache_dir, self.pickled))
        super(PickleStorage, self).drop()

    def read(self):
        try:
{'fraction_non_alphanumeric': 0.10385852090032155, 'fraction_numerical': 0.0012861736334405145, 'mean_word_length': 2.4837625979843225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5295694', 'n_tokens_mistral': 927, 'n_tokens_neox': 906, 'n_words': 208}