python-bcb 0.3.6__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bcb/currency.py +368 -210
- bcb/http.py +101 -15
- bcb/odata/api.py +116 -31
- bcb/odata/framework.py +304 -68
- bcb/sgs/__init__.py +197 -73
- bcb/sgs/regional_economy.py +68 -44
- {python_bcb-0.3.6.dist-info → python_bcb-0.4.0.dist-info}/METADATA +45 -11
- python_bcb-0.4.0.dist-info/RECORD +14 -0
- {python_bcb-0.3.6.dist-info → python_bcb-0.4.0.dist-info}/WHEEL +1 -1
- python_bcb-0.3.6.dist-info/RECORD +0 -14
- {python_bcb-0.3.6.dist-info → python_bcb-0.4.0.dist-info}/licenses/LICENSE +0 -0
bcb/odata/framework.py
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
import logging
|
|
5
|
+
import math
|
|
4
6
|
import threading
|
|
5
7
|
from io import BytesIO
|
|
6
8
|
from typing import Any, Optional, Union
|
|
9
|
+
from urllib.parse import quote
|
|
7
10
|
|
|
11
|
+
import httpx
|
|
8
12
|
from lxml import etree
|
|
9
|
-
import json
|
|
10
|
-
from urllib.parse import quote
|
|
11
13
|
from typing_extensions import Self
|
|
12
14
|
|
|
13
|
-
from bcb.http import
|
|
15
|
+
from bcb.http import (
|
|
16
|
+
RequestTimeout,
|
|
17
|
+
get_async_client,
|
|
18
|
+
get_client,
|
|
19
|
+
raise_for_request_error,
|
|
20
|
+
raise_for_status,
|
|
21
|
+
timeout_kwargs,
|
|
22
|
+
)
|
|
14
23
|
from bcb.exceptions import ODataError
|
|
15
24
|
|
|
16
25
|
logger = logging.getLogger(__name__)
|
|
@@ -20,6 +29,77 @@ logger = logging.getLogger(__name__)
|
|
|
20
29
|
_METADATA_CACHE: dict[str, "ODataMetadata"] = {}
|
|
21
30
|
_METADATA_CACHE_LOCK = threading.RLock()
|
|
22
31
|
|
|
32
|
+
|
|
33
|
+
def _load_json_object(text: str, *, context: str) -> dict[str, Any]:
|
|
34
|
+
try:
|
|
35
|
+
data = json.loads(text)
|
|
36
|
+
except json.JSONDecodeError as ex:
|
|
37
|
+
raise ODataError(f"{context} returned invalid JSON: {ex}") from ex
|
|
38
|
+
if not isinstance(data, dict):
|
|
39
|
+
raise ODataError(f"{context} returned invalid JSON payload: expected object")
|
|
40
|
+
return data
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _required_field(data: dict[str, Any], field: str, *, context: str) -> Any:
|
|
44
|
+
try:
|
|
45
|
+
return data[field]
|
|
46
|
+
except KeyError as ex:
|
|
47
|
+
raise ODataError(f"{context} response missing required field {field!r}") from ex
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _load_xml_document(content: bytes, *, context: str) -> Any:
|
|
51
|
+
try:
|
|
52
|
+
return etree.parse(BytesIO(content))
|
|
53
|
+
except etree.XMLSyntaxError as ex:
|
|
54
|
+
raise ODataError(f"{context} returned invalid XML: {ex}") from ex
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _format_odata_string_literal(value: Any) -> str:
|
|
58
|
+
if value is None:
|
|
59
|
+
raise ODataError("Edm.String filter values cannot be None")
|
|
60
|
+
escaped = str(value).replace("'", "''")
|
|
61
|
+
return f"'{escaped}'"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _format_odata_literal(edm_type: Optional[str], value: Any) -> str:
|
|
65
|
+
if value is None:
|
|
66
|
+
raise ODataError(f"{edm_type or 'Unknown'} filter values cannot be None")
|
|
67
|
+
|
|
68
|
+
if edm_type == "Edm.Decimal":
|
|
69
|
+
try:
|
|
70
|
+
decimal_value = float(value)
|
|
71
|
+
except (TypeError, ValueError) as ex:
|
|
72
|
+
raise ODataError(f"Invalid Edm.Decimal filter value: {value!r}") from ex
|
|
73
|
+
if not math.isfinite(decimal_value):
|
|
74
|
+
raise ODataError(f"Invalid Edm.Decimal filter value: {value!r}")
|
|
75
|
+
return f"{decimal_value}"
|
|
76
|
+
|
|
77
|
+
if edm_type in ("Edm.Int16", "Edm.Int32", "Edm.Int64"):
|
|
78
|
+
try:
|
|
79
|
+
return f"{int(value)}"
|
|
80
|
+
except (TypeError, ValueError) as ex:
|
|
81
|
+
raise ODataError(f"Invalid {edm_type} filter value: {value!r}") from ex
|
|
82
|
+
|
|
83
|
+
if edm_type == "Edm.String":
|
|
84
|
+
return _format_odata_string_literal(value)
|
|
85
|
+
|
|
86
|
+
if edm_type == "Edm.Date":
|
|
87
|
+
try:
|
|
88
|
+
formatted = value.strftime("%Y-%m-%d")
|
|
89
|
+
except AttributeError as ex:
|
|
90
|
+
raise ODataError(f"Invalid Edm.Date filter value: {value!r}") from ex
|
|
91
|
+
if not isinstance(formatted, str):
|
|
92
|
+
raise ODataError(f"Invalid Edm.Date filter value: {value!r}")
|
|
93
|
+
return formatted
|
|
94
|
+
|
|
95
|
+
if edm_type == "Edm.Boolean":
|
|
96
|
+
if not isinstance(value, bool):
|
|
97
|
+
raise ODataError(f"Invalid Edm.Boolean filter value: {value!r}")
|
|
98
|
+
return str(value).lower()
|
|
99
|
+
|
|
100
|
+
raise ODataError(f"Unsupported OData filter literal type: {edm_type or 'Unknown'}")
|
|
101
|
+
|
|
102
|
+
|
|
23
103
|
# Edm.Boolean
|
|
24
104
|
# Edm.Byte
|
|
25
105
|
# Edm.Date
|
|
@@ -174,23 +254,25 @@ class ODataPropertyOrderBy:
|
|
|
174
254
|
return f"<{str(self)}>"
|
|
175
255
|
|
|
176
256
|
|
|
177
|
-
class
|
|
178
|
-
def __init__(self, obj: "ODataProperty", oth: Any, operator: str) -> None:
|
|
179
|
-
self.obj = obj
|
|
180
|
-
self.other = oth
|
|
181
|
-
self.operator = operator
|
|
182
|
-
|
|
257
|
+
class ODataFilterExpression:
|
|
183
258
|
def statement(self) -> str:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return
|
|
259
|
+
raise NotImplementedError
|
|
260
|
+
|
|
261
|
+
def __and__(self, other: object) -> Any:
|
|
262
|
+
if not isinstance(other, ODataFilterExpression):
|
|
263
|
+
return NotImplemented
|
|
264
|
+
return ODataCombinedFilter(self, other, "and")
|
|
265
|
+
|
|
266
|
+
def __or__(self, other: object) -> Any:
|
|
267
|
+
if not isinstance(other, ODataFilterExpression):
|
|
268
|
+
return NotImplemented
|
|
269
|
+
return ODataCombinedFilter(self, other, "or")
|
|
270
|
+
|
|
271
|
+
def __bool__(self) -> bool:
|
|
272
|
+
raise TypeError(
|
|
273
|
+
"OData filters cannot be evaluated as booleans. "
|
|
274
|
+
"Use & for AND and | for OR, with parentheses around comparisons."
|
|
275
|
+
)
|
|
194
276
|
|
|
195
277
|
def __str__(self) -> str:
|
|
196
278
|
return self.statement()
|
|
@@ -199,6 +281,32 @@ class ODataPropertyFilter:
|
|
|
199
281
|
return f"<filter: {str(self)}>"
|
|
200
282
|
|
|
201
283
|
|
|
284
|
+
class ODataCombinedFilter(ODataFilterExpression):
|
|
285
|
+
def __init__(
|
|
286
|
+
self,
|
|
287
|
+
left: ODataFilterExpression,
|
|
288
|
+
right: ODataFilterExpression,
|
|
289
|
+
operator: str,
|
|
290
|
+
) -> None:
|
|
291
|
+
self.left = left
|
|
292
|
+
self.right = right
|
|
293
|
+
self.operator = operator
|
|
294
|
+
|
|
295
|
+
def statement(self) -> str:
|
|
296
|
+
return f"({self.left.statement()} {self.operator} {self.right.statement()})"
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class ODataPropertyFilter(ODataFilterExpression):
|
|
300
|
+
def __init__(self, obj: "ODataProperty", oth: Any, operator: str) -> None:
|
|
301
|
+
self.obj = obj
|
|
302
|
+
self.other = oth
|
|
303
|
+
self.operator = operator
|
|
304
|
+
|
|
305
|
+
def statement(self) -> str:
|
|
306
|
+
literal = _format_odata_literal(self.obj.type, self.other)
|
|
307
|
+
return f"{self.obj.name} {self.operator} {literal}"
|
|
308
|
+
|
|
309
|
+
|
|
202
310
|
class ODataProperty:
|
|
203
311
|
def __init__(self, **kwargs: Any) -> None:
|
|
204
312
|
self.data: dict[str, Any] = kwargs
|
|
@@ -269,25 +377,49 @@ class ODataMetadata:
|
|
|
269
377
|
"edmx": "http://docs.oasis-open.org/odata/ns/edmx",
|
|
270
378
|
}
|
|
271
379
|
|
|
272
|
-
def __init__(self, url: str) -> None:
|
|
380
|
+
def __init__(self, url: str, *, timeout: RequestTimeout = None) -> None:
|
|
273
381
|
self.url = url
|
|
274
|
-
self.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
382
|
+
self._timeout = timeout
|
|
383
|
+
self._load_document(timeout=timeout)
|
|
384
|
+
try:
|
|
385
|
+
_xpath = "edmx:DataServices/edm:Schema"
|
|
386
|
+
schemas = self.doc.xpath(_xpath, namespaces=self.namespaces)
|
|
387
|
+
if not schemas:
|
|
388
|
+
raise ODataError(f"OData metadata {self.url} missing schema")
|
|
389
|
+
schema = schemas[0]
|
|
390
|
+
self.namespace = schema.attrib["Namespace"]
|
|
391
|
+
self._used_elements: list[str] = []
|
|
392
|
+
self._parse_entities(schema)
|
|
393
|
+
self._parse_entity_sets(schema)
|
|
394
|
+
self._parse_functions(schema)
|
|
395
|
+
self._parse_function_imports(schema)
|
|
396
|
+
except ODataError:
|
|
397
|
+
raise
|
|
398
|
+
except (KeyError, IndexError, TypeError) as ex:
|
|
399
|
+
raise ODataError(
|
|
400
|
+
f"OData metadata {self.url} has invalid structure: {ex}"
|
|
401
|
+
) from ex
|
|
402
|
+
|
|
403
|
+
def _load_document(self, *, timeout: RequestTimeout = None) -> None:
|
|
285
404
|
logger.debug(f"Fetching OData metadata from {self.url}")
|
|
286
|
-
|
|
405
|
+
try:
|
|
406
|
+
res = get_client().get(self.url, **timeout_kwargs(timeout))
|
|
407
|
+
except httpx.HTTPError as ex:
|
|
408
|
+
raise_for_request_error(
|
|
409
|
+
ex, context=f"OData metadata {self.url}", error_cls=ODataError
|
|
410
|
+
)
|
|
287
411
|
logger.debug(
|
|
288
412
|
f"OData metadata response: status={res.status_code}, length={len(res.content)}"
|
|
289
413
|
)
|
|
290
|
-
|
|
414
|
+
raise_for_status(
|
|
415
|
+
res,
|
|
416
|
+
context=f"OData metadata {self.url}",
|
|
417
|
+
error_cls=ODataError,
|
|
418
|
+
not_found_cls=ODataError,
|
|
419
|
+
rate_limit_cls=ODataError,
|
|
420
|
+
server_error_cls=ODataError,
|
|
421
|
+
)
|
|
422
|
+
self.doc = _load_xml_document(res.content, context=f"OData metadata {self.url}")
|
|
291
423
|
|
|
292
424
|
def _parse_entity(self, entity_element: Any, namespace: str) -> ODataEntity:
|
|
293
425
|
name = entity_element.attrib["Name"]
|
|
@@ -376,21 +508,51 @@ class ODataService:
|
|
|
376
508
|
OData service root URL
|
|
377
509
|
"""
|
|
378
510
|
|
|
379
|
-
def __init__(self, url: str) -> None:
|
|
511
|
+
def __init__(self, url: str, *, timeout: RequestTimeout = None) -> None:
|
|
380
512
|
self.url = url
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
513
|
+
self._timeout = timeout
|
|
514
|
+
try:
|
|
515
|
+
res = get_client().get(self.url, **timeout_kwargs(timeout))
|
|
516
|
+
except httpx.HTTPError as ex:
|
|
517
|
+
raise_for_request_error(
|
|
518
|
+
ex, context=f"OData service {self.url}", error_cls=ODataError
|
|
519
|
+
)
|
|
520
|
+
raise_for_status(
|
|
521
|
+
res,
|
|
522
|
+
context=f"OData service {self.url}",
|
|
523
|
+
error_cls=ODataError,
|
|
524
|
+
not_found_cls=ODataError,
|
|
525
|
+
rate_limit_cls=ODataError,
|
|
526
|
+
server_error_cls=ODataError,
|
|
527
|
+
)
|
|
528
|
+
context = f"OData service {self.url}"
|
|
529
|
+
self.api_data = _load_json_object(res.text, context=context)
|
|
530
|
+
value = _required_field(self.api_data, "value", context=context)
|
|
531
|
+
if not isinstance(value, list):
|
|
532
|
+
raise ODataError("OData service response field 'value' must be a list")
|
|
533
|
+
endpoints = []
|
|
534
|
+
for endpoint in value:
|
|
535
|
+
if not isinstance(endpoint, dict):
|
|
536
|
+
raise ODataError(
|
|
537
|
+
"OData service response field 'value' must contain objects"
|
|
538
|
+
)
|
|
539
|
+
endpoints.append(ODataEndPoint(**endpoint))
|
|
540
|
+
self.endpoints = endpoints
|
|
541
|
+
odata_context = _required_field(
|
|
542
|
+
self.api_data, "@odata.context", context=context
|
|
543
|
+
)
|
|
544
|
+
if not isinstance(odata_context, str):
|
|
545
|
+
raise ODataError(
|
|
546
|
+
"OData service response field '@odata.context' must be a string"
|
|
547
|
+
)
|
|
548
|
+
self._odata_context_url = odata_context
|
|
387
549
|
|
|
388
550
|
# Use cached metadata if available, otherwise create and cache new one
|
|
389
551
|
with _METADATA_CACHE_LOCK:
|
|
390
552
|
if self._odata_context_url in _METADATA_CACHE:
|
|
391
553
|
self.metadata = _METADATA_CACHE[self._odata_context_url]
|
|
392
554
|
else:
|
|
393
|
-
self.metadata = ODataMetadata(self._odata_context_url)
|
|
555
|
+
self.metadata = ODataMetadata(self._odata_context_url, timeout=timeout)
|
|
394
556
|
_METADATA_CACHE[self._odata_context_url] = self.metadata
|
|
395
557
|
|
|
396
558
|
def __getitem__(self, item: str) -> Union[ODataEntitySet, ODataFunctionImport]:
|
|
@@ -416,36 +578,57 @@ class ODataService:
|
|
|
416
578
|
def entity_sets(self) -> dict[str, ODataEntitySet]:
|
|
417
579
|
return self.metadata.entity_sets
|
|
418
580
|
|
|
419
|
-
def
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if
|
|
424
|
-
|
|
425
|
-
|
|
581
|
+
def _standalone_entity_sets(self) -> list[ODataEntitySet]:
|
|
582
|
+
return [
|
|
583
|
+
entity_set
|
|
584
|
+
for name, entity_set in self.entity_sets.items()
|
|
585
|
+
if f"{self.metadata.namespace}.{name}" not in self.metadata._used_elements
|
|
586
|
+
]
|
|
587
|
+
|
|
588
|
+
def describe(self, *, full: bool = False) -> None:
|
|
589
|
+
entity_sets = self._standalone_entity_sets()
|
|
590
|
+
function_imports = list(self.function_imports.values())
|
|
591
|
+
|
|
592
|
+
if full:
|
|
593
|
+
if entity_sets:
|
|
594
|
+
print("EntitySets:")
|
|
595
|
+
for entity_set in entity_sets:
|
|
596
|
+
entity_set.describe()
|
|
597
|
+
if function_imports:
|
|
598
|
+
print("FunctionImports:")
|
|
599
|
+
for function_import in function_imports:
|
|
600
|
+
function_import.describe()
|
|
601
|
+
return
|
|
602
|
+
|
|
603
|
+
if entity_sets:
|
|
426
604
|
print("EntitySets:")
|
|
427
|
-
for
|
|
428
|
-
print(" ",
|
|
429
|
-
if
|
|
605
|
+
for entity_set in entity_sets:
|
|
606
|
+
print(" ", entity_set.name)
|
|
607
|
+
if function_imports:
|
|
430
608
|
print("FunctionImports:")
|
|
431
|
-
for
|
|
432
|
-
print(" ",
|
|
609
|
+
for function_import in function_imports:
|
|
610
|
+
print(" ", function_import.name)
|
|
433
611
|
|
|
434
612
|
def query(
|
|
435
613
|
self, entity_set: Union[ODataEntitySet, ODataFunctionImport]
|
|
436
614
|
) -> "ODataQuery":
|
|
437
|
-
return ODataQuery(entity_set, self.url)
|
|
615
|
+
return ODataQuery(entity_set, self.url, timeout=self._timeout)
|
|
438
616
|
|
|
439
617
|
|
|
440
618
|
class ODataQuery:
|
|
441
619
|
def __init__(
|
|
442
|
-
self,
|
|
620
|
+
self,
|
|
621
|
+
entity: Union[ODataEntitySet, ODataFunctionImport],
|
|
622
|
+
url: str,
|
|
623
|
+
*,
|
|
624
|
+
timeout: RequestTimeout = None,
|
|
443
625
|
) -> None:
|
|
444
626
|
self.entity = entity
|
|
445
627
|
self.base_url = url
|
|
628
|
+
self._timeout = timeout
|
|
446
629
|
self._params: dict[str, Any] = {}
|
|
447
630
|
self.function_parameters: dict[str, Any] = {}
|
|
448
|
-
self._filter: list[
|
|
631
|
+
self._filter: list[ODataFilterExpression] = []
|
|
449
632
|
self._select: list[ODataProperty] = []
|
|
450
633
|
self._orderby: list[ODataPropertyOrderBy] = []
|
|
451
634
|
self._raw = False
|
|
@@ -477,7 +660,10 @@ class ODataQuery:
|
|
|
477
660
|
raise ODataError(f"Unknown parameter: {arg}")
|
|
478
661
|
return self
|
|
479
662
|
|
|
480
|
-
def
|
|
663
|
+
def _format_parameter(self, parameter: ODataParameter, value: Any) -> str:
|
|
664
|
+
return parameter.format(value)
|
|
665
|
+
|
|
666
|
+
def filter(self, *args: ODataFilterExpression) -> Self:
|
|
481
667
|
if len(args):
|
|
482
668
|
self._filter.extend(args)
|
|
483
669
|
return self
|
|
@@ -527,43 +713,93 @@ class ODataQuery:
|
|
|
527
713
|
self._orderby = []
|
|
528
714
|
self._params = {}
|
|
529
715
|
|
|
530
|
-
def
|
|
531
|
-
|
|
716
|
+
def _resolve_timeout(self, timeout: RequestTimeout) -> RequestTimeout:
|
|
717
|
+
if timeout is None:
|
|
718
|
+
return self._timeout
|
|
719
|
+
return timeout
|
|
532
720
|
|
|
533
|
-
|
|
534
|
-
|
|
721
|
+
def collect(self, *, timeout: RequestTimeout = None) -> Any:
|
|
722
|
+
url = self.odata_url()
|
|
723
|
+
data = _load_json_object(
|
|
724
|
+
self.text(timeout=timeout), context=f"OData query {url}"
|
|
725
|
+
)
|
|
726
|
+
_required_field(data, "value", context=f"OData query {url}")
|
|
727
|
+
return data
|
|
728
|
+
|
|
729
|
+
async def async_text(self, *, timeout: RequestTimeout = None) -> str:
|
|
730
|
+
"""Async version of text(). Fetches OData response using shared client."""
|
|
535
731
|
params = self._build_parameters()
|
|
536
732
|
if self.is_function and len(self.function_parameters):
|
|
537
733
|
for p in self.entity.function.parameters: # type: ignore[union-attr]
|
|
538
734
|
val = self.function_parameters[p.name or ""]
|
|
539
735
|
if p.required and val is None:
|
|
540
736
|
raise ODataError("Parameter not set: " + (p.name or ""))
|
|
541
|
-
params["@" + (p.name or "")] =
|
|
737
|
+
params["@" + (p.name or "")] = self._format_parameter(p, val)
|
|
542
738
|
qs = "&".join([f"{quote(k)}={quote(str(v))}" for k, v in params.items()])
|
|
543
739
|
headers = {"OData-Version": "4.0", "OData-MaxVersion": "4.0"}
|
|
544
|
-
|
|
740
|
+
url = self.odata_url()
|
|
741
|
+
try:
|
|
742
|
+
res = await get_async_client().get(
|
|
743
|
+
url + "?" + qs,
|
|
744
|
+
headers=headers,
|
|
745
|
+
**timeout_kwargs(self._resolve_timeout(timeout)),
|
|
746
|
+
)
|
|
747
|
+
except httpx.HTTPError as ex:
|
|
748
|
+
raise_for_request_error(
|
|
749
|
+
ex, context=f"OData query {url}", error_cls=ODataError
|
|
750
|
+
)
|
|
751
|
+
raise_for_status(
|
|
752
|
+
res,
|
|
753
|
+
context=f"OData query {url}",
|
|
754
|
+
error_cls=ODataError,
|
|
755
|
+
not_found_cls=ODataError,
|
|
756
|
+
rate_limit_cls=ODataError,
|
|
757
|
+
server_error_cls=ODataError,
|
|
758
|
+
)
|
|
545
759
|
return res.text
|
|
546
760
|
|
|
547
|
-
async def async_collect(self) -> Any:
|
|
761
|
+
async def async_collect(self, *, timeout: RequestTimeout = None) -> Any:
|
|
548
762
|
"""Async version of collect(). Awaits async_text() and parses JSON."""
|
|
549
|
-
|
|
763
|
+
url = self.odata_url()
|
|
764
|
+
data = _load_json_object(
|
|
765
|
+
await self.async_text(timeout=timeout), context=f"OData query {url}"
|
|
766
|
+
)
|
|
767
|
+
_required_field(data, "value", context=f"OData query {url}")
|
|
768
|
+
return data
|
|
550
769
|
|
|
551
|
-
def text(self) -> str:
|
|
770
|
+
def text(self, *, timeout: RequestTimeout = None) -> str:
|
|
552
771
|
params = self._build_parameters()
|
|
553
772
|
if self.is_function and len(self.function_parameters):
|
|
554
773
|
for p in self.entity.function.parameters: # type: ignore[union-attr]
|
|
555
774
|
val = self.function_parameters[p.name or ""]
|
|
556
775
|
if p.required and val is None:
|
|
557
776
|
raise ODataError("Parameter not set: " + (p.name or ""))
|
|
558
|
-
params["@" + (p.name or "")] =
|
|
777
|
+
params["@" + (p.name or "")] = self._format_parameter(p, val)
|
|
559
778
|
qs = "&".join([f"{quote(k)}={quote(str(v))}" for k, v in params.items()])
|
|
560
779
|
headers = {"OData-Version": "4.0", "OData-MaxVersion": "4.0"}
|
|
561
780
|
url = self.odata_url()
|
|
562
781
|
logger.debug(f"Fetching OData query from {url}")
|
|
563
|
-
|
|
782
|
+
try:
|
|
783
|
+
res = get_client().get(
|
|
784
|
+
url + "?" + qs,
|
|
785
|
+
headers=headers,
|
|
786
|
+
**timeout_kwargs(self._resolve_timeout(timeout)),
|
|
787
|
+
)
|
|
788
|
+
except httpx.HTTPError as ex:
|
|
789
|
+
raise_for_request_error(
|
|
790
|
+
ex, context=f"OData query {url}", error_cls=ODataError
|
|
791
|
+
)
|
|
564
792
|
logger.debug(
|
|
565
793
|
f"OData query response: status={res.status_code}, length={len(res.text)}"
|
|
566
794
|
)
|
|
795
|
+
raise_for_status(
|
|
796
|
+
res,
|
|
797
|
+
context=f"OData query {url}",
|
|
798
|
+
error_cls=ODataError,
|
|
799
|
+
not_found_cls=ODataError,
|
|
800
|
+
rate_limit_cls=ODataError,
|
|
801
|
+
server_error_cls=ODataError,
|
|
802
|
+
)
|
|
567
803
|
return res.text
|
|
568
804
|
|
|
569
805
|
def show(self) -> None:
|