def test(self): tilestore = NullTileStore() tile = Tile(TileCoord(0, 0, 0)) self.assertFalse(tile in tilestore) self.assertEqual(list(tilestore.delete([tile])), [tile]) self.assertEqual(list(tilestore.list()), []) self.assertEqual(list(tilestore.get([tile])), [tile]) self.assertEqual(list(tilestore.put([tile])), [tile])
def load(cls, name): # pragma: no cover """ Construct a :class:`TileStore` from a name. :param name: Name :type name: string :rtype: :class:`TileStore` The following shortcuts are available: bounds://<bounding-pyramid> file://<template> http://<template> and https://<template> memcached://<server>:<port>/<template> s3://<bucket>/<template> sqs://<region>/<queue> <filename>.bsddb <filename>.mbtiles <filename>.zip <module> """ if name == 'null://': from tilecloud.store.null import NullTileStore return NullTileStore() if name.startswith('bounds://'): from tilecloud.store.boundingpyramid import BoundingPyramidTileStore return BoundingPyramidTileStore( BoundingPyramid.from_string(name[9:])) if name.startswith('file://'): from tilecloud.layout.template import TemplateTileLayout from tilecloud.store.filesystem import FilesystemTileStore return FilesystemTileStore(TemplateTileLayout(name[7:]), ) if name.startswith('http://') or name.startswith('https://'): from tilecloud.layout.template import TemplateTileLayout from tilecloud.store.url import URLTileStore return URLTileStore((TemplateTileLayout(name), )) if name.startswith('memcached://'): from tilecloud.layout.template import TemplateTileLayout from tilecloud.store.memcached import MemcachedTileStore from tilecloud.lib.memcached import MemcachedClient server, template = name[12:].split('/', 1) host, port = server.split(':', 1) client = MemcachedClient(host, int(port)) return MemcachedTileStore(client, TemplateTileLayout(template)) if name.startswith('s3://'): from tilecloud.layout.template import TemplateTileLayout from tilecloud.store.s3 import S3TileStore bucket, template = name[5:].split('/', 1) return S3TileStore(bucket, TemplateTileLayout(template)) if name.startswith('sqs://'): from tilecloud.store.sqs import SQSTileStore import boto.sqs from boto.sqs.jsonmessage import JSONMessage region_name, queue_name = name[6:].split('/', 1) connection = boto.sqs.connect_to_region(region_name) queue = connection.create_queue(queue_name) queue.set_message_class(JSONMessage) return SQSTileStore(queue) root, ext = os.path.splitext(name) if ext == '.bsddb': import bsddb from tilecloud.store.bsddb import BSDDBTileStore return BSDDBTileStore(bsddb.hashopen(name)) if ext == '.mbtiles': import sqlite3 from tilecloud.store.mbtiles import MBTilesTileStore return MBTilesTileStore(sqlite3.connect(name)) if ext == '.zip': import zipfile from tilecloud.store.zip import ZipTileStore return ZipTileStore(zipfile.ZipFile(name, 'a')) module = __import__(name) components = name.split('.') module = reduce(lambda module, attr: getattr(module, attr), components[1:], module) return getattr(module, 'tilestore')
def load(name): # pragma: no cover """ Construct a :class:`TileStore` from a name. :param name: Name :type name: string :rtype: :class:`TileStore` The following shortcuts are available: bounds://<bounding-pyramid> file://<template> http://<template> and https://<template> memcached://<server>:<port>/<template> s3://<bucket>/<template> sqs://<region>/<queue> <filename>.bsddb <filename>.mbtiles <filename>.zip <module> """ if name == "null://": from tilecloud.store.null import NullTileStore return NullTileStore() if name.startswith("bounds://"): from tilecloud.store.boundingpyramid import BoundingPyramidTileStore return BoundingPyramidTileStore( BoundingPyramid.from_string(name[9:])) if name.startswith("file://"): from tilecloud.layout.template import TemplateTileLayout from tilecloud.store.filesystem import FilesystemTileStore return FilesystemTileStore(TemplateTileLayout(name[7:]), ) if name.startswith("http://") or name.startswith("https://"): from tilecloud.layout.template import TemplateTileLayout from tilecloud.store.url import URLTileStore return URLTileStore((TemplateTileLayout(name), )) if name.startswith("memcached://"): from tilecloud.layout.template import TemplateTileLayout from tilecloud.lib.memcached import MemcachedClient from tilecloud.store.memcached import MemcachedTileStore server, template = name[12:].split("/", 1) host, port = server.split(":", 1) client = MemcachedClient(host, int(port)) return MemcachedTileStore(client, TemplateTileLayout(template)) if name.startswith("s3://"): from tilecloud.layout.template import TemplateTileLayout from tilecloud.store.s3 import S3TileStore bucket, template = name[5:].split("/", 1) return S3TileStore(bucket, TemplateTileLayout(template)) if name.startswith("sqs://"): import boto.sqs # pylint: disable=import-error from boto.sqs.jsonmessage import JSONMessage # pylint: disable=import-error from tilecloud.store.sqs import SQSTileStore region_name, queue_name = name[6:].split("/", 1) connection = boto.sqs.connect_to_region(region_name) queue = connection.create_queue(queue_name) queue.set_message_class(JSONMessage) return SQSTileStore(queue) if name.startswith("redis://"): from tilecloud.store.redis import RedisTileStore return RedisTileStore(name) _, ext = os.path.splitext(name) if ext == ".bsddb": import bsddb # pylint: disable=import-error from tilecloud.store.bsddb import BSDDBTileStore return BSDDBTileStore(bsddb.hashopen(name)) if ext == ".mbtiles": import sqlite3 from tilecloud.store.mbtiles import MBTilesTileStore return MBTilesTileStore(sqlite3.connect(name)) if ext == ".zip": import zipfile from tilecloud.store.zip import ZipTileStore return ZipTileStore(zipfile.ZipFile(name, "a")) module = __import__(name) components = name.split(".") module = reduce(getattr, components[1:], module) return getattr(module, "tilestore")