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

Fix tc-copy cannot import name 'imap' #669

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions tc-copy
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main(argv):
else:
tilestream = input_tilestore.list()
if options.i is not None and options.n is not None:
tilestream = imap(EveryNth(options.n, options.i), tilestream)
tilestream = map(EveryNth(options.n, options.i), tilestream)
if options.randomize:
tilestream = list(tilestream)
random.shuffle(tilestream)
Expand All @@ -90,7 +90,7 @@ def main(argv):
tilestream = map(benchmark.sample(), tilestream)
tilestream = input_tilestore.get(tilestream)
if benchmark:
tilestream = imap(benchmark.sample("get"), tilestream)
tilestream = map(benchmark.sample("get"), tilestream)
for i, g in enumerate(generate):
tilestream = g.get(tilestream)
if options.benchmark:
Expand Down
11 changes: 7 additions & 4 deletions tilecloud/store/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ def get_one(self, tile):
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
else:
tile.error = response.text
if tile.content_type:
if tile.content_type.startswith("image/"):
tile.data = response.content
else:
tile.error = response.text
elif response.status_code != 200:
tile.error = "Unable to read content type {0}".format(title.content_type)
Comment on lines +38 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you do this change? Shouldn't just be:

Suggested change
if tile.content_type:
if tile.content_type.startswith("image/"):
tile.data = response.content
else:
tile.error = response.text
elif response.status_code != 200:
tile.error = "Unable to read content type {0}".format(title.content_type)
if tile.content_type and tile.content_type.startswith("image/"):
tile.data = response.content
else:
tile.error = response.text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes the response has content but not content type header set so it continues failing, i tested it using openstreetmap

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you an example of URL that didn't returns a content-type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just merge the first part, and for this I do an alternative as #673, does it look good?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't i it be better coding three commands, Ill make it up

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