Beispiel #1
0
    def fixed_get(self, key):
        import os
        import errno
        import warnings
        from webassets.cache import make_md5

        if not os.path.exists(self.directory):
            error_logger.warn("Cache directory {} doesn't exist, not going "
                              "to attempt to read cache file".format(
                                  self.directory))
            return None

        try:
            hash = make_md5(self.V, key)
        except IOError as e:
            if e.errno != errno.ENOENT:
                raise
            return None

        filename = os.path.join(self.directory, '%s' % hash)
        try:
            f = open(filename, 'rb')
        except IOError as e:
            if e.errno != errno.ENOENT:
                raise
            return None
        try:
            result = f.read()
        finally:
            f.close()

        unpickled = webassets.cache.safe_unpickle(result)
        if unpickled is None:
            warnings.warn('Ignoring corrupted cache file %s' % filename)
        return unpickled
Beispiel #2
0
	def fixed_get(self, key):
		import os
		import errno
		import warnings
		from webassets.cache import make_md5

		try:
			hash = make_md5(self.V, key)
		except IOError as e:
			if e.errno != errno.ENOENT:
				raise
			return None

		filename = os.path.join(self.directory, '%s' % hash)
		try:
			f = open(filename, 'rb')
		except IOError as e:
			if e.errno != errno.ENOENT:
				raise
			return None
		try:
			result = f.read()
		finally:
			f.close()

		unpickled = webassets.cache.safe_unpickle(result)
		if unpickled is None:
			warnings.warn('Ignoring corrupted cache file %s' % filename)
		return unpickled
Beispiel #3
0
	def fixed_get(self, key):
		import os
		import errno
		import warnings
		from webassets.cache import make_md5

		try:
			hash = make_md5(self.V, key)
		except IOError as e:
			if e.errno != errno.ENOENT:
				raise
			return None

		filename = os.path.join(self.directory, '%s' % hash)
		try:
			f = open(filename, 'rb')
		except IOError as e:
			if e.errno != errno.ENOENT:
				raise
			return None
		try:
			result = f.read()
		finally:
			f.close()

		unpickled = webassets.cache.safe_unpickle(result)
		if unpickled is None:
			warnings.warn('Ignoring corrupted cache file %s' % filename)
		return unpickled
Beispiel #4
0
	def fixed_get(self, key):
		import os
		import errno
		import warnings
		from webassets.cache import make_md5

		if not os.path.exists(self.directory):
			error_logger.warn("Cache directory {} doesn't exist, not going "
			                  "to attempt to read cache file".format(self.directory))
			return None

		try:
			hash = make_md5(self.V, key)
		except IOError as e:
			if e.errno != errno.ENOENT:
				raise
			return None

		filename = os.path.join(self.directory, '%s' % hash)
		try:
			f = open(filename, 'rb')
		except IOError as e:
			if e.errno != errno.ENOENT:
				raise
			return None
		try:
			result = f.read()
		finally:
			f.close()

		unpickled = webassets.cache.safe_unpickle(result)
		if unpickled is None:
			warnings.warn('Ignoring corrupted cache file %s' % filename)
		return unpickled
Beispiel #5
0
    def get(self, key):
        now = time.time()
        md5 = '%s' % make_md5(self.V, key)
        unpickled, cached_time = self.cache.get(md5, (None, 0))

        if now > cached_time:
            unpickled = None

        if unpickled is None:
            directory = self.directory
            filename = os.path.join(directory, '%s' % md5)
            try:
                f = open(filename, 'rb')
            except IOError as e:
                if e.errno != errno.ENOENT:
                    raise
                return None
            try:
                result = f.read()
            finally:
                f.close()

            unpickled = safe_unpickle(result)
            if unpickled is None:
                warnings.warn('Ignoring corrupted cache file %s' % filename)

            self.cache[md5] = (unpickled, now)
        return unpickled
Beispiel #6
0
	def fixed_set(self, key, data):
		md5 = '%s' % cache.make_md5(self.V, key)
		filename = os.path.join(self.directory, md5)
		fd, temp_filename = tempfile.mkstemp(prefix='.' + md5,
		                                     dir=self.directory)
		try:
			with os.fdopen(fd, 'wb') as f:
				pickle.dump(data, f)
				f.flush()
			shutil.move(temp_filename, filename)
		except:
			os.remove(temp_filename)
			raise
Beispiel #7
0
	def fixed_set(self, key, data):
		md5 = '%s' % cache.make_md5(self.V, key)
		filename = os.path.join(self.directory, md5)
		fd, temp_filename = tempfile.mkstemp(prefix='.' + md5,
		                                     dir=self.directory)
		try:
			with os.fdopen(fd, 'wb') as f:
				pickle.dump(data, f)
				f.flush()
			shutil.move(temp_filename, filename)
		except:
			os.remove(temp_filename)
			raise
Beispiel #8
0
	def fixed_set(self, key, data):
		import os
		import tempfile
		import pickle
		import shutil

		if not os.path.exists(self.directory):
			error_logger.warn("Cache directory {} doesn't exist, not going "
			                  "to attempt to write cache file".format(self.directory))

		md5 = '%s' % cache.make_md5(self.V, key)
		filename = os.path.join(self.directory, md5)
		fd, temp_filename = tempfile.mkstemp(prefix='.' + md5,
		                                     dir=self.directory)
		try:
			with os.fdopen(fd, 'wb') as f:
				pickle.dump(data, f)
				f.flush()
			shutil.move(temp_filename, filename)
		except:
			os.remove(temp_filename)
			raise
Beispiel #9
0
	def fixed_set(self, key, data):
		import os
		import tempfile
		import pickle
		import shutil

		if not os.path.exists(self.directory):
			error_logger.warn("Cache directory {} doesn't exist, not going "
			                  "to attempt to write cache file".format(self.directory))

		md5 = '%s' % cache.make_md5(self.V, key)
		filename = os.path.join(self.directory, md5)
		fd, temp_filename = tempfile.mkstemp(prefix='.' + md5,
		                                     dir=self.directory)
		try:
			with os.fdopen(fd, 'wb') as f:
				pickle.dump(data, f)
				f.flush()
			shutil.move(temp_filename, filename)
		except:
			os.remove(temp_filename)
			raise
Beispiel #10
0
    def set(self, key, data):
        now = time.time()
        md5 = '%s' % make_md5(self.V, key)
        self.cache[md5] = (data, now + 600)

        directory = self.directory
        filename = os.path.join(directory, md5)
        try:
            fd, temp_filename = tempfile.mkstemp(prefix='.' + md5, dir=directory)
        except OSError:
            if not os.path.exists(directory):
                os.makedirs(directory)
                fd, temp_filename = tempfile.mkstemp(prefix='.' + md5, dir=directory)

        try:
            with os.fdopen(fd, 'wb') as f:
                pickle.dump(data, f)
                f.flush()
            os.rename(temp_filename, filename)
        except:
            os.unlink(temp_filename)
            raise