47
47
import base64
48
48
import enum
49
49
50
- from typing import Any , Callable , Dict , IO , Iterable , Optional , Set , Tuple , Type , TypeVar
50
+ from typing import Any , Callable , Dict , Iterable , Optional , Set , Tuple , Type , TypeVar
51
51
from .._generic import XML_NS_MAP , XML_NS_AAS , MODELLING_KIND_INVERSE , ASSET_KIND_INVERSE , KEY_TYPES_INVERSE , \
52
52
ENTITY_TYPES_INVERSE , IEC61360_DATA_TYPES_INVERSE , IEC61360_LEVEL_TYPES_INVERSE , KEY_TYPES_CLASSES_INVERSE , \
53
- REFERENCE_TYPES_INVERSE , DIRECTION_INVERSE , STATE_OF_EVENT_INVERSE , QUALIFIER_KIND_INVERSE
53
+ REFERENCE_TYPES_INVERSE , DIRECTION_INVERSE , STATE_OF_EVENT_INVERSE , QUALIFIER_KIND_INVERSE , PathOrIO
54
54
55
55
NS_AAS = XML_NS_AAS
56
56
REQUIRED_NAMESPACES : Set [str ] = {XML_NS_MAP ["aas" ]}
@@ -315,8 +315,8 @@ def _failsafe_construct_mandatory(element: etree.Element, constructor: Callable[
315
315
"""
316
316
constructed = _failsafe_construct (element , constructor , False , ** kwargs )
317
317
if constructed is None :
318
- raise TypeError ("The result of a non-failsafe _failsafe_construct() call was None! "
319
- "This is a bug in the Eclipse BaSyx Python SDK XML deserialization, please report it!" )
318
+ raise AssertionError ("The result of a non-failsafe _failsafe_construct() call was None! "
319
+ "This is a bug in the Eclipse BaSyx Python SDK XML deserialization, please report it!" )
320
320
return constructed
321
321
322
322
@@ -1186,14 +1186,16 @@ class StrictStrippedAASFromXmlDecoder(StrictAASFromXmlDecoder, StrippedAASFromXm
1186
1186
pass
1187
1187
1188
1188
1189
- def _parse_xml_document (file : IO , failsafe : bool = True , ** parser_kwargs : Any ) -> Optional [etree .Element ]:
1189
+ def _parse_xml_document (file : PathOrIO , failsafe : bool = True , ** parser_kwargs : Any ) -> Optional [etree .Element ]:
1190
1190
"""
1191
1191
Parse an XML document into an element tree
1192
1192
1193
1193
:param file: A filename or file-like object to read the XML-serialized data from
1194
1194
:param failsafe: If True, the file is parsed in a failsafe way: Instead of raising an Exception if the document
1195
1195
is malformed, parsing is aborted, an error is logged and None is returned
1196
1196
:param parser_kwargs: Keyword arguments passed to the XMLParser constructor
1197
+ :raises ~lxml.etree.XMLSyntaxError: **Non-failsafe**: If the given file(-handle) has invalid XML
1198
+ :raises KeyError: **Non-failsafe**: If a required namespace has not been declared on the XML document
1197
1199
:return: The root element of the element tree
1198
1200
"""
1199
1201
@@ -1249,7 +1251,7 @@ class XMLConstructables(enum.Enum):
1249
1251
KEY = enum .auto ()
1250
1252
REFERENCE = enum .auto ()
1251
1253
MODEL_REFERENCE = enum .auto ()
1252
- GLOBAL_REFERENCE = enum .auto ()
1254
+ EXTERNAL_REFERENCE = enum .auto ()
1253
1255
ADMINISTRATIVE_INFORMATION = enum .auto ()
1254
1256
QUALIFIER = enum .auto ()
1255
1257
SECURITY = enum .auto ()
@@ -1289,11 +1291,11 @@ class XMLConstructables(enum.Enum):
1289
1291
DATA_SPECIFICATION_IEC61360 = enum .auto ()
1290
1292
1291
1293
1292
- def read_aas_xml_element (file : IO , construct : XMLConstructables , failsafe : bool = True , stripped : bool = False ,
1294
+ def read_aas_xml_element (file : PathOrIO , construct : XMLConstructables , failsafe : bool = True , stripped : bool = False ,
1293
1295
decoder : Optional [Type [AASFromXmlDecoder ]] = None , ** constructor_kwargs ) -> Optional [object ]:
1294
1296
"""
1295
1297
Construct a single object from an XML string. The namespaces have to be declared on the object itself, since there
1296
- is no surrounding aasenv element.
1298
+ is no surrounding environment element.
1297
1299
1298
1300
:param file: A filename or file-like object to read the XML-serialized data from
1299
1301
:param construct: A member of the enum :class:`~.XMLConstructables`, specifying which type to construct.
@@ -1305,6 +1307,10 @@ def read_aas_xml_element(file: IO, construct: XMLConstructables, failsafe: bool
1305
1307
This parameter is ignored if a decoder class is specified.
1306
1308
:param decoder: The decoder class used to decode the XML elements
1307
1309
:param constructor_kwargs: Keyword arguments passed to the constructor function
1310
+ :raises ~lxml.etree.XMLSyntaxError: **Non-failsafe**: If the given file(-handle) has invalid XML
1311
+ :raises KeyError: **Non-failsafe**: If a required namespace has not been declared on the XML document
1312
+ :raises (~basyx.aas.model.base.AASConstraintViolation, KeyError, ValueError): **Non-failsafe**: Errors during
1313
+ construction of the objects
1308
1314
:return: The constructed object or None, if an error occurred in failsafe mode.
1309
1315
"""
1310
1316
decoder_ = _select_decoder (failsafe , stripped , decoder )
@@ -1316,7 +1322,7 @@ def read_aas_xml_element(file: IO, construct: XMLConstructables, failsafe: bool
1316
1322
constructor = decoder_ .construct_reference
1317
1323
elif construct == XMLConstructables .MODEL_REFERENCE :
1318
1324
constructor = decoder_ .construct_model_reference
1319
- elif construct == XMLConstructables .GLOBAL_REFERENCE :
1325
+ elif construct == XMLConstructables .EXTERNAL_REFERENCE :
1320
1326
constructor = decoder_ .construct_external_reference
1321
1327
elif construct == XMLConstructables .ADMINISTRATIVE_INFORMATION :
1322
1328
constructor = decoder_ .construct_administrative_information
@@ -1397,7 +1403,7 @@ def read_aas_xml_element(file: IO, construct: XMLConstructables, failsafe: bool
1397
1403
return _failsafe_construct (element , constructor , decoder_ .failsafe , ** constructor_kwargs )
1398
1404
1399
1405
1400
- def read_aas_xml_file_into (object_store : model .AbstractObjectStore [model .Identifiable ], file : IO ,
1406
+ def read_aas_xml_file_into (object_store : model .AbstractObjectStore [model .Identifiable ], file : PathOrIO ,
1401
1407
replace_existing : bool = False , ignore_existing : bool = False , failsafe : bool = True ,
1402
1408
stripped : bool = False , decoder : Optional [Type [AASFromXmlDecoder ]] = None ,
1403
1409
** parser_kwargs : Any ) -> Set [model .Identifier ]:
@@ -1419,6 +1425,14 @@ def read_aas_xml_file_into(object_store: model.AbstractObjectStore[model.Identif
1419
1425
This parameter is ignored if a decoder class is specified.
1420
1426
:param decoder: The decoder class used to decode the XML elements
1421
1427
:param parser_kwargs: Keyword arguments passed to the XMLParser constructor
1428
+ :raises ~lxml.etree.XMLSyntaxError: **Non-failsafe**: If the given file(-handle) has invalid XML
1429
+ :raises KeyError: **Non-failsafe**: If a required namespace has not been declared on the XML document
1430
+ :raises KeyError: **Non-failsafe**: Encountered a duplicate identifier
1431
+ :raises KeyError: Encountered an identifier that already exists in the given ``object_store`` with both
1432
+ ``replace_existing`` and ``ignore_existing`` set to ``False``
1433
+ :raises (~basyx.aas.model.base.AASConstraintViolation, KeyError, ValueError): **Non-failsafe**: Errors during
1434
+ construction of the objects
1435
+ :raises TypeError: **Non-failsafe**: Encountered an undefined top-level list (e.g. ``<aas:submodels1>``)
1422
1436
:return: A set of :class:`Identifiers <basyx.aas.model.base.Identifier>` that were added to object_store
1423
1437
"""
1424
1438
ret : Set [model .Identifier ] = set ()
@@ -1470,14 +1484,20 @@ def read_aas_xml_file_into(object_store: model.AbstractObjectStore[model.Identif
1470
1484
return ret
1471
1485
1472
1486
1473
- def read_aas_xml_file (file : IO , ** kwargs : Any ) -> model .DictObjectStore [model .Identifiable ]:
1487
+ def read_aas_xml_file (file : PathOrIO , ** kwargs : Any ) -> model .DictObjectStore [model .Identifiable ]:
1474
1488
"""
1475
1489
A wrapper of :meth:`~basyx.aas.adapter.xml.xml_deserialization.read_aas_xml_file_into`, that reads all objects in an
1476
1490
empty :class:`~basyx.aas.model.provider.DictObjectStore`. This function supports
1477
1491
the same keyword arguments as :meth:`~basyx.aas.adapter.xml.xml_deserialization.read_aas_xml_file_into`.
1478
1492
1479
1493
:param file: A filename or file-like object to read the XML-serialized data from
1480
1494
:param kwargs: Keyword arguments passed to :meth:`~basyx.aas.adapter.xml.xml_deserialization.read_aas_xml_file_into`
1495
+ :raises ~lxml.etree.XMLSyntaxError: **Non-failsafe**: If the given file(-handle) has invalid XML
1496
+ :raises KeyError: **Non-failsafe**: If a required namespace has not been declared on the XML document
1497
+ :raises KeyError: **Non-failsafe**: Encountered a duplicate identifier
1498
+ :raises (~basyx.aas.model.base.AASConstraintViolation, KeyError, ValueError): **Non-failsafe**: Errors during
1499
+ construction of the objects
1500
+ :raises TypeError: **Non-failsafe**: Encountered an undefined top-level list (e.g. ``<aas:submodels1>``)
1481
1501
:return: A :class:`~basyx.aas.model.provider.DictObjectStore` containing all AAS objects from the XML file
1482
1502
"""
1483
1503
object_store : model .DictObjectStore [model .Identifiable ] = model .DictObjectStore ()
0 commit comments