Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows to have no content type #673

Merged
merged 2 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ pylint:
options:
max-line-length: 110
disable:
- abstract-method
- too-many-instance-attributes
- too-many-ancestors
- too-many-return-statements
- too-many-branches
- too-many-arguments
- too-many-locals
- too-few-public-methods
- wrong-import-order
- no-else-return
- abstract-method
- invalid-name
- redefined-builtin
- broad-except
- too-many-locals
- no-else-return
- wrong-import-order
- too-many-instance-attributes
- too-many-ancestors
- too-few-public-methods
- too-many-return-statements
- cyclic-import # see: https://github.com/PyCQA/pylint/issues/850

pep8:
Expand Down
2 changes: 1 addition & 1 deletion tc-copy
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main(argv):
try:
output_tilestore = TileStore.load(args[-1])
for arg in args[:-1]:
input_tilestore = TileStore.load(arg)
input_tilestore = TileStore.load(arg, allows_no_contenttype=options.add_content_type)
if bounding_pyramid:
tilestream = BoundingPyramidTileStore(bounding_pyramid).list()
else:
Expand Down
4 changes: 2 additions & 2 deletions tilecloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def put_one(tile):
raise NotImplementedError

@staticmethod
def load(name): # pragma: no cover
def load(name, allows_no_contenttype=False): # pragma: no cover
"""
Construct a :class:`TileStore` from a name.

Expand Down Expand Up @@ -745,7 +745,7 @@ def load(name): # pragma: no cover
from tilecloud.layout.template import TemplateTileLayout
from tilecloud.store.url import URLTileStore

return URLTileStore((TemplateTileLayout(name),))
return URLTileStore((TemplateTileLayout(name),), allows_no_contenttype=allows_no_contenttype)
if name.startswith("memcached://"):
from tilecloud.layout.template import TemplateTileLayout
from tilecloud.lib.memcached import MemcachedClient
Expand Down
23 changes: 17 additions & 6 deletions tilecloud/store/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@


class URLTileStore(TileStore):
def __init__(self, tilelayouts, headers=None, **kwargs):
def __init__(self, tilelayouts, headers=None, allows_no_contenttype=False, **kwargs):
TileStore.__init__(self, **kwargs)
self.allows_no_contenttype = allows_no_contenttype
self.tilelayouts = tuple(tilelayouts)
self.session = requests.session()
if headers is not None:
Expand All @@ -29,16 +30,26 @@ def get_one(self, tile):
logger.info("GET %s", url)
try:
response = self.session.get(url)
if response.status_code == 404:
if response.status_code == 404 or response.status_code == 204:
return None
tile.content_encoding = response.headers.get("Content-Encoding")
tile.content_type = response.headers.get("Content-Type")
if response.status_code < 300:
tile.data = response.content
if tile.content_type.startswith("image/"):
tile.data = response.content
if response.status_code != 200:
tile.error = "Unsupportetd status code {}: {}".format(
response.status_code, response.reason
)
if tile.content_type:
if tile.content_type.startswith("image/"):
tile.data = response.content
else:
tile.error = response.text
else:
tile.error = response.text
if self.allows_no_contenttype:
tile.data = response.content
else:
tile.error = "The Content-Type header is missing"

else:
tile.error = response.reason
except requests.exceptions.RequestException as e:
Expand Down