Skip to content

Commit

Permalink
Merge branch 'feature/http_api' into http_api/remove_nonfunctional_no…
Browse files Browse the repository at this point in the history
…t_implemented_check
  • Loading branch information
Frosty2500 authored Jun 20, 2024
2 parents 8e66b2c + f57a640 commit 00e87b6
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 178 deletions.
21 changes: 10 additions & 11 deletions basyx/aas/adapter/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#
# SPDX-License-Identifier: MIT

# TODO: remove this once the werkzeug type annotations have been fixed
# https://github.com/pallets/werkzeug/issues/2836
# mypy: disable-error-code="arg-type"

import abc
import base64
import binascii
Expand All @@ -18,7 +14,7 @@
import json
import itertools

from lxml import etree # type: ignore
from lxml import etree
import werkzeug.exceptions
import werkzeug.routing
import werkzeug.urls
Expand Down Expand Up @@ -156,15 +152,15 @@ def serialize(self, obj: ResponseData, cursor: Optional[int], stripped: bool) ->
root_elem.append(child)
etree.cleanup_namespaces(root_elem)
xml_str = etree.tostring(root_elem, xml_declaration=True, encoding="utf-8")
return xml_str
return xml_str # type: ignore[return-value]


class XmlResponseAlt(XmlResponse):
def __init__(self, *args, content_type="text/xml", **kwargs):
super().__init__(*args, **kwargs, content_type=content_type)


def result_to_xml(result: Result, **kwargs) -> etree.Element:
def result_to_xml(result: Result, **kwargs) -> etree._Element:
result_elem = etree.Element("result", **kwargs)
success_elem = etree.Element("success")
success_elem.text = xml_serialization.boolean_to_xml(result.success)
Expand All @@ -177,7 +173,7 @@ def result_to_xml(result: Result, **kwargs) -> etree.Element:
return result_elem


def message_to_xml(message: Message) -> etree.Element:
def message_to_xml(message: Message) -> etree._Element:
message_elem = etree.Element("message")
message_type_elem = etree.Element("messageType")
message_type_elem.text = str(message.message_type)
Expand Down Expand Up @@ -629,7 +625,7 @@ def _get_submodel_reference(cls, aas: model.AssetAdministrationShell, submodel_i
raise NotFound(f"The AAS {aas!r} doesn't have a submodel reference to {submodel_id!r}!")

@classmethod
def _get_slice(cls, request: Request, iterator: Iterator[T]) -> Tuple[Iterator[T], int]:
def _get_slice(cls, request: Request, iterator: Iterable[T]) -> Tuple[Iterator[T], int]:
limit_str = request.args.get('limit', default="10")
cursor_str = request.args.get('cursor', default="0")
try:
Expand Down Expand Up @@ -702,6 +698,7 @@ def handle_request(self, request: Request):
# TODO: remove this 'type: ignore' comment once the werkzeug type annotations have been fixed
# https://github.com/pallets/werkzeug/issues/2836
return endpoint(request, values, map_adapter=map_adapter) # type: ignore[operator]

# any raised error that leaves this function will cause a 500 internal server error
# so catch raised http exceptions and return them
except werkzeug.exceptions.NotAcceptable as e:
Expand Down Expand Up @@ -949,7 +946,8 @@ def post_submodel_submodel_elements_id_short_path(self, request: Request, url_ar
raise BadRequest(f"{parent!r} is not a namespace, can't add child submodel element!")
# TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T]
# see https://github.com/python/mypy/issues/5374
new_submodel_element = HTTPApiDecoder.request_body(request, model.SubmodelElement, # type: ignore
new_submodel_element = HTTPApiDecoder.request_body(request,
model.SubmodelElement, # type: ignore[type-abstract]
is_stripped_request(request))
try:
parent.add_referable(new_submodel_element)
Expand All @@ -969,7 +967,8 @@ def put_submodel_submodel_elements_id_short_path(self, request: Request, url_arg
submodel_element = self._get_submodel_submodel_elements_id_short_path(url_args)
# TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T]
# see https://github.com/python/mypy/issues/5374
new_submodel_element = HTTPApiDecoder.request_body(request, model.SubmodelElement, # type: ignore
new_submodel_element = HTTPApiDecoder.request_body(request,
model.SubmodelElement, # type: ignore[type-abstract]
is_stripped_request(request))
submodel_element.update_from(new_submodel_element)
submodel_element.commit()
Expand Down
143 changes: 73 additions & 70 deletions basyx/aas/adapter/xml/xml_deserialization.py

Large diffs are not rendered by default.

172 changes: 87 additions & 85 deletions basyx/aas/adapter/xml/xml_serialization.py

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import os
import sys
import datetime
from sphinx.ext import intersphinx


sys.path.insert(0, os.path.abspath('../..'))
Expand Down Expand Up @@ -71,14 +70,10 @@

def on_missing_reference(app, env, node, contnode):
path = node["reftarget"].split(".")
# pyecma376_2 doesn't have a documentation we can link to, so suppress missing reference warnings.
# TODO: pyecma376_2 doesn't have a documentation we can link to, so suppress missing reference warnings.
# see: https://github.com/rwth-iat/PyECMA376-2/issues/3
if path[0] == "pyecma376_2":
return contnode
# lxml uses _Element instead of Element and _ElementTree instead of ElementTree in its documentation,
# causing missing references if untreated.
if len(path) > 2 and path[0:2] == ["lxml", "etree"] and path[2] in {"Element", "ElementTree"}:
node["reftarget"] = ".".join(path[0:2] + ["_" + path[2]] + path[3:])
return intersphinx.resolve_reference_in_inventory(env, "lxml", node, contnode)
return None


Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python-dateutil>=2.8,<3.0
types-python-dateutil
pyecma376-2>=0.2.4
urllib3>=1.26,<2.0
Werkzeug~=3.0
Werkzeug>=3.0.3,<4
schemathesis~=3.7
hypothesis~=6.13
lxml-stubs~=0.5.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
'lxml>=4.2,<5',
'urllib3>=1.26,<2.0',
'pyecma376-2>=0.2.4',
'Werkzeug~=3.0'
'Werkzeug>=3.0.3,<4'
]
)
4 changes: 2 additions & 2 deletions test/adapter/xml/test_xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from basyx.aas.adapter.xml import StrictAASFromXmlDecoder, XMLConstructables, read_aas_xml_file, \
read_aas_xml_file_into, read_aas_xml_element
from basyx.aas.adapter._generic import XML_NS_MAP
from lxml import etree # type: ignore
from lxml import etree
from typing import Iterable, Type, Union


Expand Down Expand Up @@ -434,7 +434,7 @@ def __init__(self, *args, **kwargs):

class EnhancedAASDecoder(StrictAASFromXmlDecoder):
@classmethod
def construct_submodel(cls, element: etree.Element, object_class=EnhancedSubmodel, **kwargs) \
def construct_submodel(cls, element: etree._Element, object_class=EnhancedSubmodel, **kwargs) \
-> model.Submodel:
return super().construct_submodel(element, object_class=object_class, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion test/adapter/xml/test_xml_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import unittest

from lxml import etree # type: ignore
from lxml import etree

from basyx.aas import model
from basyx.aas.adapter.xml import write_aas_xml_file, xml_serialization
Expand Down

0 comments on commit 00e87b6

Please sign in to comment.