Skip to content

Commit 9be9058

Browse files
authored
Merge pull request #928 from planetlabs/landsat-asset-download-920
fix Landsat asset download
2 parents 98a76a3 + 5cc72a4 commit 9be9058

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

planet/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import random
2020
import re
2121
import string
22-
from typing import AsyncGenerator, Callable, List
22+
from typing import AsyncGenerator, Callable, List, Optional
23+
from urllib.parse import urlparse
2324

2425
import httpx
2526
from tqdm.asyncio import tqdm
@@ -174,13 +175,12 @@ def _get_filename_from_headers(headers):
174175
return match.group(1) if match else None
175176

176177

177-
def _get_filename_from_url(url):
178-
"""Get a filename from a URL.
178+
def _get_filename_from_url(url: str) -> Optional[str]:
179+
"""Get a filename from a url.
179180
180-
:returns: a filename (i.e. ``basename``)
181-
:rtype: str or None
181+
Getting a name for Landsat imagery uses this function.
182182
"""
183-
path = url.path
183+
path = urlparse(url).path
184184
name = path[path.rfind('/') + 1:]
185185
return name or None
186186

tests/unit/test_models.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from pathlib import Path
2020
import re
2121

22-
from httpx import URL
2322
import pytest
2423

2524
from planet import models
@@ -30,7 +29,7 @@
3029

3130
def test_StreamingBody_name_filename():
3231
r = MagicMock(name='response')
33-
r.url = URL('https://planet.com/path/to/example.tif?foo=f6f1')
32+
r.url = 'https://planet.com/path/to/example.tif?foo=f6f1'
3433
r.headers = {
3534
'date': 'Thu, 14 Feb 2019 16:13:26 GMT',
3635
'last-modified': 'Wed, 22 Nov 2017 17:22:31 GMT',
@@ -45,7 +44,7 @@ def test_StreamingBody_name_filename():
4544

4645
def test_StreamingBody_name_url():
4746
r = MagicMock(name='response')
48-
r.url = URL('https://planet.com/path/to/example.tif?foo=f6f1')
47+
r.url = 'https://planet.com/path/to/example.tif?foo=f6f1'
4948
r.headers = {
5049
'date': 'Thu, 14 Feb 2019 16:13:26 GMT',
5150
'last-modified': 'Wed, 22 Nov 2017 17:22:31 GMT',
@@ -60,7 +59,7 @@ def test_StreamingBody_name_url():
6059

6160
def test_StreamingBody_name_content():
6261
r = MagicMock(name='response')
63-
r.url = URL('https://planet.com/path/to/noname/')
62+
r.url = 'https://planet.com/path/to/noname/'
6463
r.headers = {
6564
'date': 'Thu, 14 Feb 2019 16:13:26 GMT',
6665
'last-modified': 'Wed, 22 Nov 2017 17:22:31 GMT',
@@ -102,12 +101,12 @@ def test__get_filename_from_headers(headers, expected):
102101
@pytest.mark.parametrize(
103102
'url,expected',
104103
[
105-
(URL('https://planet.com/'), None),
106-
(URL('https://planet.com/path/to/'), None),
107-
(URL('https://planet.com/path/to/example.tif'), 'example.tif'),
108-
(URL('https://planet.com/path/to/example.tif?foo=f6f1&bar=baz'),
104+
('https://planet.com/', None),
105+
('https://planet.com/path/to/', None),
106+
('https://planet.com/path/to/example.tif', 'example.tif'),
107+
('https://planet.com/path/to/example.tif?foo=f6f1&bar=baz',
109108
'example.tif'),
110-
(URL('https://planet.com/path/to/example.tif?foo=f6f1#quux'),
109+
('https://planet.com/path/to/example.tif?foo=f6f1#quux',
111110
'example.tif'),
112111
])
113112
def test__get_filename_from_url(url, expected):

0 commit comments

Comments
 (0)