Commits

Oliver Tonnhofer committed 829d183

refactored tile_buffer to function

  • Participants
  • Parent commits 2205633

Comments (0)

Files changed (3)

File mapproxy/cache/base.py

 
 from mapproxy.util.lock import FileLock, cleanup_lockdir
 
+@contextmanager
+def tile_buffer(tile):
+    data = tile.source.as_buffer(seekable=True)
+    data.seek(0)
+    yield data
+    tile.size = data.tell()
+    tile.timestamp = time.time()
+    data.seek(0)
+    tile.stored = True
+
 class TileCacheBase(object):
     """
     Base implementation of a tile cache.
         """
         raise NotImplementedError()
     
-    @contextmanager
-    def tile_buffer(self, tile):
-        data = tile.source.as_buffer(seekable=True)
-        data.seek(0)
-        yield data
-        tile.size = data.tell()
-        tile.timestamp = time.time()
-        data.seek(0)
-        tile.stored = True
 
 class FileBasedLocking(object):
     """

File mapproxy/cache/file.py

 
 from mapproxy.util import ensure_directory
 from mapproxy.image import ImageSource, is_single_color_image
-from mapproxy.cache.base import TileCacheBase, FileBasedLocking
+from mapproxy.cache.base import TileCacheBase, FileBasedLocking, tile_buffer
 
 import logging
 log = logging.getLogger('mapproxy.cache.file')
         if os.path.islink(location):
             os.unlink(location)
             
-        with self.tile_buffer(tile) as buf:
+        with tile_buffer(tile) as buf:
             with open(location, 'wb') as f:
                 log.debug('writing %r to %s' % (tile.coord, location))
                 f.write(buf.read())

File mapproxy/cache/mbtiles.py

 from cStringIO import StringIO
 
 from mapproxy.image import ImageSource
-from mapproxy.cache.base import TileCacheBase, FileBasedLocking
+from mapproxy.cache.base import TileCacheBase, FileBasedLocking, tile_buffer
 from mapproxy.util.times import parse_httpdate
 from mapproxy.util.lock import FileLock
 
             return False
     
     def store_tile(self, tile):
-        with self.tile_buffer(tile) as buf:
+        with tile_buffer(tile) as buf:
             content = buffer(buf.read())
             x, y, level = tile.coord
             cursor = self.db.cursor()