-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow local constraints files (#1105)
- Loading branch information
1 parent
f343411
commit 59ccd8b
Showing
9 changed files
with
191 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{"class": ["d1"], "dataset": ["extremes-dt"], "expver": ["0001"], "type": ["fc"], "date": ["20240404", "20240405", "20240406", "20240407", "20240408", "20240409", "20240410", "20240411", "20240412"], "time": ["0000"], "stream": ["oper"], "levtype": ["hl"], "levelist": ["100"], "step": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96"], "param": ["228246", "228247"]}, | ||
{"class": ["d1"], "dataset": ["extremes-dt"], "expver": ["0001"], "type": ["fc"], "date": ["20240404", "20240405", "20240406", "20240407", "20240408", "20240409", "20240410", "20240411", "20240412"], "time": ["0000"], "stream": ["oper"], "levtype": ["pl"], "levelist": ["1000", "925", "850", "700", "600", "500", "400", "300", "250", "200", "150", "100", "70", "50", "30", "20", "10", "5", "1"], "step": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96"], "param": ["129", "130", "131", "132", "133", "157"]}, | ||
{"class": ["d1"], "dataset": ["extremes-dt"], "expver": ["0001"], "type": ["fc"], "date": ["20240404", "20240405", "20240406", "20240407", "20240408", "20240409", "20240410", "20240411", "20240412"], "time": ["0000"], "stream": ["oper"], "levtype": ["sfc"], "step": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96"], "param": ["31", "34", "78", "134", "136", "137", "151", "165", "166", "167", "168", "3020", "228029", "228050", "228218", "228219", "228221", "228235", "260015"]}, | ||
{"class": ["d1"], "dataset": ["extremes-dt"], "expver": ["0001"], "type": ["fc"], "date": ["20240404", "20240405", "20240406", "20240407", "20240408", "20240409", "20240410", "20240411", "20240412"], "time": ["0000"], "stream": ["oper"], "levtype": ["sfc"], "step": ["0-1", "1-2", "2-3", "3-4", "4-5", "5-6", "6-7", "7-8", "8-9", "9-10", "10-11", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "18-19", "19-20", "20-21", "21-22", "22-23", "23-24", "24-25", "25-26", "26-27", "27-28", "28-29", "29-30", "30-31", "31-32", "32-33", "33-34", "34-35", "35-36", "36-37", "37-38", "38-39", "39-40", "40-41", "41-42", "42-43", "43-44", "44-45", "45-46", "46-47", "47-48", "48-49", "49-50", "50-51", "51-52", "52-53", "53-54", "54-55", "55-56", "56-57", "57-58", "58-59", "59-60", "60-61", "61-62", "62-63", "63-64", "64-65", "65-66", "66-67", "67-68", "68-69", "69-70", "70-71", "71-72", "72-73", "73-74", "74-75", "75-76", "76-77", "77-78", "78-79", "79-80", "80-81", "81-82", "82-83", "83-84", "84-85", "85-86", "86-87", "87-88", "88-89", "89-90", "90-91", "91-92", "92-93", "93-94", "94-95", "95-96"], "param": ["142", "144", "169", "175", "176", "177", "178", "179", "180", "181", "205", "228", "228216"]}, | ||
{"class": ["d1"], "dataset": ["extremes-dt"], "expver": ["0001"], "type": ["fc"], "date": ["20240404", "20240405", "20240406", "20240407", "20240408", "20240409", "20240410", "20240411", "20240412"], "time": ["0000"], "stream": ["oper"], "levtype": ["sfc"], "step": ["0-6", "6-12", "12-18", "18-24", "24-30", "30-36", "36-42", "42-48", "48-54", "54-60", "60-66", "66-72", "72-78", "78-84", "84-90", "90-96"], "param": ["228058"]}, | ||
{"class": ["d1"], "dataset": ["extremes-dt"], "expver": ["0001"], "type": ["fc"], "date": ["20240404", "20240405", "20240406", "20240407", "20240408", "20240409", "20240410", "20240411", "20240412"], "time": ["0000"], "stream": ["wave"], "levtype": ["sfc"], "step": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96"], "param": ["140221", "140229", "140230", "140231", "140232"]} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018, CS GROUP - France, https://www.csgroup.eu/ | ||
# | ||
# This file is part of EODAG project | ||
# https://www.github.com/CS-SI/EODAG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from __future__ import annotations | ||
|
||
import os | ||
from typing import Any, Tuple | ||
|
||
import requests | ||
|
||
from eodag.utils import uri_to_path | ||
from eodag.utils.exceptions import RequestError | ||
|
||
|
||
class LocalFileAdapter(requests.adapters.BaseAdapter): | ||
"""Protocol Adapter to allow Requests to GET file:// URLs inspired | ||
by https://stackoverflow.com/questions/10123929/fetch-a-file-from-a-local-url-with-python-requests/27786580 | ||
`LocalFileAdapter` class available for the moment (on the 2024-04-22) | ||
""" | ||
|
||
@staticmethod | ||
def _chkpath(method: str, path: str) -> Tuple[int, str]: | ||
"""Return an HTTP status for the given filesystem path. | ||
:param method: method of the request | ||
:type method: str | ||
:param path: path of the given file | ||
:type path: str | ||
:returns: HTTP status and its associated message | ||
:rtype: Tuple[int, str] | ||
""" | ||
if method.lower() in ("put", "delete"): | ||
return 501, "Not Implemented" # TODO | ||
elif method.lower() not in ("get", "head"): | ||
return 405, "Method Not Allowed" | ||
elif os.path.isdir(path): | ||
return 400, "Path Not A File" | ||
elif not os.path.isfile(path): | ||
return 404, "File Not Found" | ||
elif not os.access(path, os.R_OK): | ||
return 403, "Access Denied" | ||
else: | ||
return 200, "OK" | ||
|
||
def send(self, req: requests.PreparedRequest, **kwargs: Any) -> requests.Response: | ||
"""Wraps a file, described in request, in a Response object. | ||
:param req: The PreparedRequest being "sent". | ||
:type req: :class:`~requests.PreparedRequest` | ||
:param kwargs: (not used) additionnal arguments of the request | ||
:type kwargs: Any | ||
:returns: a Response object containing the file | ||
:rtype: :class:`~requests.Response` | ||
""" | ||
response = requests.Response() | ||
|
||
path_url = uri_to_path(req.url) | ||
|
||
if req.method is None or req.url is None: | ||
raise RequestError("Method or url of the request is missing") | ||
response.status_code, response.reason = self._chkpath(req.method, path_url) | ||
if response.status_code == 200 and req.method.lower() != "head": | ||
try: | ||
response.raw = open(path_url, "rb") | ||
except (OSError, IOError) as err: | ||
response.status_code = 500 | ||
response.reason = str(err) | ||
response.url = req.url | ||
response.request = req | ||
|
||
return response | ||
|
||
def close(self): | ||
"""Closes without cleaning up adapter specific items.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters