Skip to content

fix Landsat asset download #928

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

Merged
merged 1 commit into from
Apr 14, 2023
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
12 changes: 6 additions & 6 deletions planet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import random
import re
import string
from typing import AsyncGenerator, Callable, List
from typing import AsyncGenerator, Callable, List, Optional
from urllib.parse import urlparse

import httpx
from tqdm.asyncio import tqdm
Expand Down Expand Up @@ -174,13 +175,12 @@ def _get_filename_from_headers(headers):
return match.group(1) if match else None


def _get_filename_from_url(url):
"""Get a filename from a URL.
def _get_filename_from_url(url: str) -> Optional[str]:
"""Get a filename from a url.

:returns: a filename (i.e. ``basename``)
:rtype: str or None
Getting a name for Landsat imagery uses this function.
"""
path = url.path
path = urlparse(url).path
name = path[path.rfind('/') + 1:]
return name or None

Expand Down
17 changes: 8 additions & 9 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from pathlib import Path
import re

from httpx import URL
import pytest

from planet import models
Expand All @@ -30,7 +29,7 @@

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

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

def test_StreamingBody_name_content():
r = MagicMock(name='response')
r.url = URL('https://planet.com/path/to/noname/')
r.url = 'https://planet.com/path/to/noname/'
r.headers = {
'date': 'Thu, 14 Feb 2019 16:13:26 GMT',
'last-modified': 'Wed, 22 Nov 2017 17:22:31 GMT',
Expand Down Expand Up @@ -102,12 +101,12 @@ def test__get_filename_from_headers(headers, expected):
@pytest.mark.parametrize(
'url,expected',
[
(URL('https://planet.com/'), None),
(URL('https://planet.com/path/to/'), None),
(URL('https://planet.com/path/to/example.tif'), 'example.tif'),
(URL('https://planet.com/path/to/example.tif?foo=f6f1&bar=baz'),
('https://planet.com/', None),
('https://planet.com/path/to/', None),
('https://planet.com/path/to/example.tif', 'example.tif'),
('https://planet.com/path/to/example.tif?foo=f6f1&bar=baz',
'example.tif'),
(URL('https://planet.com/path/to/example.tif?foo=f6f1#quux'),
('https://planet.com/path/to/example.tif?foo=f6f1#quux',
'example.tif'),
])
def test__get_filename_from_url(url, expected):
Expand Down