本文整理汇总了Python中mapproxy.cache.file.FileCache类的典型用法代码示例。如果您正苦于以下问题:Python FileCache类的具体用法?Python FileCache怎么用?Python FileCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileCache类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestQuadkeyFileTileCache
class TestQuadkeyFileTileCache(TileCacheTestBase):
def setup(self):
TileCacheTestBase.setup(self)
self.cache = FileCache(self.cache_dir, 'png', directory_layout='quadkey')
def test_store_tile(self):
tile = self.create_tile((3, 4, 2))
self.cache.store_tile(tile)
tile_location = os.path.join(self.cache_dir, '11.png' )
assert os.path.exists(tile_location), tile_location
示例2: load_tile
def load_tile(self, tile, with_metadata=False):
self.loaded_tiles.add(tile.coord)
return FileCache.load_tile(self, tile, with_metadata)
示例3: store_tile
def store_tile(self, tile):
assert tile.coord not in self.stored_tiles
self.stored_tiles.add(tile.coord)
if self.cache_dir != '/dev/null':
FileCache.store_tile(self, tile)
示例4: setup
def setup(self):
TileCacheTestBase.setup(self)
self.cache = FileCache(self.cache_dir, 'png', directory_layout='quadkey')
示例5: TestFileTileCache
class TestFileTileCache(TileCacheTestBase):
def setup(self):
TileCacheTestBase.setup(self)
self.cache = FileCache(self.cache_dir, 'png')
def test_store_tile(self):
tile = self.create_tile((5, 12, 4))
self.cache.store_tile(tile)
tile_location = os.path.join(self.cache_dir,
'04', '000', '000', '005', '000', '000', '012.png' )
assert os.path.exists(tile_location), tile_location
def test_single_color_tile_store(self):
img = Image.new('RGB', (256, 256), color='#ff0105')
tile = Tile((0, 0, 4), ImageSource(img, image_opts=ImageOptions(format='image/png')))
self.cache.link_single_color_images = True
self.cache.store_tile(tile)
assert self.cache.is_cached(tile)
loc = self.cache.tile_location(tile)
assert os.path.islink(loc)
assert os.path.realpath(loc).endswith('ff0105.png')
assert is_png(open(loc, 'rb'))
tile2 = Tile((0, 0, 1), ImageSource(img))
self.cache.store_tile(tile2)
assert self.cache.is_cached(tile2)
loc2 = self.cache.tile_location(tile2)
assert os.path.islink(loc2)
assert os.path.realpath(loc2).endswith('ff0105.png')
assert is_png(open(loc2, 'rb'))
assert loc != loc2
assert os.path.samefile(loc, loc2)
def test_single_color_tile_store_w_alpha(self):
img = Image.new('RGBA', (256, 256), color='#ff0105')
tile = Tile((0, 0, 4), ImageSource(img, image_opts=ImageOptions(format='image/png')))
self.cache.link_single_color_images = True
self.cache.store_tile(tile)
assert self.cache.is_cached(tile)
loc = self.cache.tile_location(tile)
assert os.path.islink(loc)
assert os.path.realpath(loc).endswith('ff0105ff.png')
assert is_png(open(loc, 'rb'))
def test_load_metadata_missing_tile(self):
tile = Tile((0, 0, 0))
self.cache.load_tile_metadata(tile)
assert tile.timestamp == 0
assert tile.size == 0
def create_cached_tile(self, tile):
loc = self.cache.tile_location(tile, create_dir=True)
with open(loc, 'wb') as f:
f.write(b'foo')
示例6: check_level_location
def check_level_location(self, layout, level, path):
cache = FileCache('/tmp/foo', 'png', directory_layout=layout)
eq_(cache.level_location(level), path)
示例7: check_tile_location
def check_tile_location(self, layout, tile_coord, path):
cache = FileCache('/tmp/foo', 'png', directory_layout=layout)
eq_(cache.tile_location(Tile(tile_coord)), path)
示例8: TestFileTileCache
class TestFileTileCache(TileCacheTestBase):
def setup(self):
TileCacheTestBase.setup(self)
self.cache = FileCache(self.cache_dir, 'png')
def test_store_tile(self):
tile = self.create_tile((5, 12, 4))
self.cache.store_tile(tile)
tile_location = os.path.join(self.cache_dir,
'04', '000', '000', '005', '000', '000', '012.png' )
assert os.path.exists(tile_location), tile_location
def test_single_color_tile_store(self):
img = Image.new('RGB', (256, 256), color='#ff0105')
tile = Tile((0, 0, 4), ImageSource(img, image_opts=ImageOptions(format='image/png')))
self.cache.link_single_color_images = True
self.cache.store_tile(tile)
assert self.cache.is_cached(tile)
loc = self.cache.tile_location(tile)
assert os.path.islink(loc)
assert os.path.realpath(loc).endswith('ff0105.png')
assert is_png(open(loc, 'rb'))
tile2 = Tile((0, 0, 1), ImageSource(img))
self.cache.store_tile(tile2)
assert self.cache.is_cached(tile2)
loc2 = self.cache.tile_location(tile2)
assert os.path.islink(loc2)
assert os.path.realpath(loc2).endswith('ff0105.png')
assert is_png(open(loc2, 'rb'))
assert loc != loc2
assert os.path.samefile(loc, loc2)
def test_single_color_tile_store_w_alpha(self):
img = Image.new('RGBA', (256, 256), color='#ff0105')
tile = Tile((0, 0, 4), ImageSource(img, image_opts=ImageOptions(format='image/png')))
self.cache.link_single_color_images = True
self.cache.store_tile(tile)
assert self.cache.is_cached(tile)
loc = self.cache.tile_location(tile)
assert os.path.islink(loc)
assert os.path.realpath(loc).endswith('ff0105ff.png')
assert is_png(open(loc, 'rb'))
def test_load_metadata_missing_tile(self):
tile = Tile((0, 0, 0))
self.cache.load_tile_metadata(tile)
assert tile.timestamp == 0
assert tile.size == 0
def create_cached_tile(self, tile):
loc = self.cache.tile_location(tile, create_dir=True)
with open(loc, 'wb') as f:
f.write(b'foo')
def check_tile_location(self, layout, tile_coord, path):
cache = FileCache('/tmp/foo', 'png', directory_layout=layout)
eq_(cache.tile_location(Tile(tile_coord)), path)
def test_tile_locations(self):
yield self.check_tile_location, 'mp', (12345, 67890, 2), '/tmp/foo/02/0001/2345/0006/7890.png'
yield self.check_tile_location, 'mp', (12345, 67890, 12), '/tmp/foo/12/0001/2345/0006/7890.png'
yield self.check_tile_location, 'tc', (12345, 67890, 2), '/tmp/foo/02/000/012/345/000/067/890.png'
yield self.check_tile_location, 'tc', (12345, 67890, 12), '/tmp/foo/12/000/012/345/000/067/890.png'
yield self.check_tile_location, 'tms', (12345, 67890, 2), '/tmp/foo/2/12345/67890.png'
yield self.check_tile_location, 'tms', (12345, 67890, 12), '/tmp/foo/12/12345/67890.png'
yield self.check_tile_location, 'quadkey', (0, 0, 0), '/tmp/foo/.png'
yield self.check_tile_location, 'quadkey', (0, 0, 1), '/tmp/foo/0.png'
yield self.check_tile_location, 'quadkey', (1, 1, 1), '/tmp/foo/3.png'
yield self.check_tile_location, 'quadkey', (12345, 67890, 12), '/tmp/foo/200200331021.png'
yield self.check_tile_location, 'arcgis', (1, 2, 3), '/tmp/foo/L03/R00000002/C00000001.png'
yield self.check_tile_location, 'arcgis', (9, 2, 3), '/tmp/foo/L03/R00000002/C00000009.png'
yield self.check_tile_location, 'arcgis', (10, 2, 3), '/tmp/foo/L03/R00000002/C0000000a.png'
yield self.check_tile_location, 'arcgis', (12345, 67890, 12), '/tmp/foo/L12/R00010932/C00003039.png'
def check_level_location(self, layout, level, path):
cache = FileCache('/tmp/foo', 'png', directory_layout=layout)
eq_(cache.level_location(level), path)
def test_level_locations(self):
yield self.check_level_location, 'mp', 2, '/tmp/foo/02'
yield self.check_level_location, 'mp', 12, '/tmp/foo/12'
yield self.check_level_location, 'tc', 2, '/tmp/foo/02'
yield self.check_level_location, 'tc', 12, '/tmp/foo/12'
yield self.check_level_location, 'tms', '2', '/tmp/foo/2'
yield self.check_level_location, 'tms', 12, '/tmp/foo/12'
yield self.check_level_location, 'arcgis', 3, '/tmp/foo/L03'
yield self.check_level_location, 'arcgis', 3, '/tmp/foo/L03'
yield self.check_level_location, 'arcgis', 3, '/tmp/foo/L03'
yield self.check_level_location, 'arcgis', 12, '/tmp/foo/L12'
#.........这里部分代码省略.........