Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
queue.load()
except botocore.exceptions.EndpointConnectionError:
logger.warning("Error fetching SQS attributes", exc_info=True)
return True
attributes = queue.attributes
if int(attributes["ApproximateNumberOfMessages"]) == 0:
if int(attributes["ApproximateNumberOfMessagesNotVisible"]) == 0:
return True
else:
time.sleep(int(attributes["VisibilityTimeout"]) / 4.0)
return False
class SQSTileStore(TileStore):
def __init__(self, queue, on_empty=maybe_stop, **kwargs):
TileStore.__init__(self, **kwargs)
self.queue = queue
self.on_empty = on_empty
def __contains__(self, tile):
return False
@staticmethod
def get_one(tile):
return tile
def list(self):
while True:
try:
sqs_messages = self.queue.receive_messages(MaxNumberOfMessages=BATCH_SIZE)
from collections import deque
from tilecloud import Tile, TileStore
from tilecloud.grid.quad import QuadTileGrid
class RenderingTheWorldTileStore(TileStore):
"""http://mapbox.com/blog/rendering-the-world/"""
def __init__(self, subdivide, tilegrid=None, queue=None, seeds=()):
super(RenderingTheWorldTileStore, self).__init__()
self.subdivide = subdivide
self.tilegrid = tilegrid
if self.tilegrid is None:
self.tilegrid = QuadTileGrid()
self.queue = queue
if self.queue is None:
self.queue = deque()
for seed in seeds:
self.queue.append(seed)
def list(self):
try:
from c2cwsgiutils import stats
from tilecloud import TileStore
class TimedTileStoreWrapper(TileStore):
"""
A wrapper around a TileStore that adds timer metrics.
"""
def __init__(self, tile_store, stats_name):
super().__init__()
self._tile_store = tile_store
self._stats_name = stats_name
def _get_stats_name(self, func_name, tile=None):
if tile and 'layer' in tile.metadata:
return [self._stats_name, tile.metadata['layer'], func_name]
else:
return [self._stats_name, func_name]
def _time_iteration(self, generator, func_name):
while True:
from itertools import chain, groupby, starmap
from tilecloud import TileStore
class MultiTileStore(TileStore):
def __init__(self, stores):
TileStore.__init__(self)
self._stores = stores
def _get_store(self, layer):
assert layer is not None
result = self._stores.get(layer) if layer is not None else self._default_store
return result
def __contains__(self, tile):
"""
Return true if this store contains ``tile``.
:param tile: Tile
:type tile: :class:`Tile`
import os.path
import re
import zipfile
from collections import defaultdict
from datetime import datetime
from tilecloud import Tile, TileStore
from tilecloud.layout.osm import OSMTileLayout
from tilecloud.layout.wrapped import WrappedTileLayout
class ZipTileStore(TileStore):
def __init__(self, zipfile, layout=None, **kwargs): # pylint: disable=redefined-outer-name
TileStore.__init__(self, **kwargs)
self.zipfile = zipfile
self.layout = layout
if self.layout is None:
extension_count = defaultdict(int)
for name in self.zipfile.namelist():
extension_count[os.path.splitext(name)[1]] += 1
for extension, _ in sorted(
extension_count.items(), key=lambda p: tuple(reversed(p)), reverse=True
):
if re.match(r"\.(jpe?g|png)\Z", extension, re.I):
self.layout = WrappedTileLayout(OSMTileLayout(), suffix=extension)
break
if self.layout is None:
self.layout = OSMTileLayout()
def __init__(self, zipfile, layout=None, **kwargs): # pylint: disable=redefined-outer-name
TileStore.__init__(self, **kwargs)
self.zipfile = zipfile
self.layout = layout
if self.layout is None:
extension_count = defaultdict(int)
for name in self.zipfile.namelist():
extension_count[os.path.splitext(name)[1]] += 1
for extension, _ in sorted(
extension_count.items(), key=lambda p: tuple(reversed(p)), reverse=True
):
if re.match(r"\.(jpe?g|png)\Z", extension, re.I):
self.layout = WrappedTileLayout(OSMTileLayout(), suffix=extension)
break
if self.layout is None:
self.layout = OSMTileLayout()
from tilecloud import TileStore
class MemcachedTileStore(TileStore):
def __init__(self, client, tilelayout, flags=0, exptime=0, **kwargs):
TileStore.__init__(self, **kwargs)
self.client = client
self.tilelayout = tilelayout
self.flags = flags
self.exptime = exptime
def __contains__(self, tile):
flags, _, _ = self.client.get(self.tilelayout.filename(tile.tilecoord, tile.metadata))
return flags is not None
def get_one(self, tile):
flags, value, cas = self.client.get(self.tilelayout.filename(tile.tilecoord, tile.metadata))
tile.memcached_flags = flags
tile.data = value
tile.memcached_cas = cas
"""All tiles in a bounding box"""
def __init__(self, bounding_pyramid=None):
self.bounding_pyramid = bounding_pyramid or BoundingPyramid()
def list(self):
for tilecoord in self.bounding_pyramid:
yield Tile(tilecoord)
def put_one(self, tile):
self.bounding_pyramid.add(tile.tilecoord)
return tile
class FilesystemTileStore(TileStore):
"""Tiles stored in a filesystem"""
def __init__(self, tile_layout):
self.tile_layout = tile_layout
def delete_one(self, tile):
filename = self.tile_layout.filename(tile.tilecoord)
if os.path.exists(filename):
os.remove(filename)
return tile
def get_all(self):
for tile in self.list():
with open(tile.path) as file:
tile.data = file.read()
yield tile
def get_one(self, tile):
tile.data = None
return tile
def list(self):
# FIXME warn that this consumes lines
filename_re = re.compile(self.tile_layout.pattern)
for line in self.lines:
match = filename_re.search(line)
if match:
yield Tile(self.tile_layout.tilecoord(match.group()), line=line)
class MaskTileStore(TileStore):
"""A black and white image representing present and absent tiles"""
def __init__(self, z, slices, file=None):
self.z = z
self.xbounds, self.ybounds = slices
self.width = self.xbounds.stop - self.xbounds.start
self.height = self.ybounds.stop - self.ybounds.start
if file:
self.image = PIL.Image.open(file)
assert self.image.mode == '1'
assert self.image.size == (self.width, self.height)
else:
self.image = PIL.Image.new('1', (self.width, self.height))
self.pixels = self.image.load()
def delete_one(self, tile):