elements
trestle.core.models.elements
¤
Element wrapper of an OSCAL model element.
Attributes¤
logger = logging.getLogger(__name__)
module-attribute
¤
Classes¤
Element
¤
Element wrapper of an OSCAL model.
Source code in trestle/core/models/elements.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
Attributes¤
IGNORE_WRAPPER_ALIAS = '__'
class-attribute
instance-attribute
¤
Functions¤
__eq__(other)
¤
Check that two elements are equal.
Source code in trestle/core/models/elements.py
608 609 610 611 612 613 |
|
__init__(elem, wrapper_alias='')
¤
Initialize an element wrapper.
wrapper_alias is the OSCAL alias for the given elem object and used for seriazation in to_json() method.
For example, - List[Catalog.Group] element should have wrapper alias 'groups' - Catalog element should have wrapper alias 'catalog'
wrapper_alias is deduced for collection type object
if wrapper_alias = IGNORE_WRAPPER_ALIAS, then it is ignored and assumed to be json-serializable during to_json()
Source code in trestle/core/models/elements.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
__str__()
¤
Return string representation of element.
Source code in trestle/core/models/elements.py
604 605 606 |
|
get()
¤
Return the model object.
Source code in trestle/core/models/elements.py
415 416 417 |
|
get_allowed_sub_element_types()
classmethod
¤
Get the list of allowed sub element types.
Source code in trestle/core/models/elements.py
589 590 591 592 |
|
get_at(element_path=None, check_parent=True)
¤
Get the element at the specified element path.
it will return the sub-model object at the path. Sub-model object can be of type OscalBaseModel or List
Source code in trestle/core/models/elements.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
get_preceding_element(element_path)
¤
Get the preceding element in the path.
Source code in trestle/core/models/elements.py
476 477 478 479 480 |
|
get_sub_element_class(parent_elm, sub_element_name)
classmethod
¤
Get the class of the sub-element.
Source code in trestle/core/models/elements.py
583 584 585 586 587 |
|
is_allowed_sub_element_type(elm)
classmethod
¤
Check if is of allowed sub element type.
Source code in trestle/core/models/elements.py
594 595 596 597 598 599 600 601 602 |
|
set_at(element_path, sub_element)
¤
Set a sub_element at the path in the current element.
Sub element can be Element, OscalBaseModel, list or None type
It returns the element itself so that chaining operation can be done such as
element.set_at(path, sub-element).get()
.
Source code in trestle/core/models/elements.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
|
to_json(pretty=True)
¤
Convert into JSON string.
Source code in trestle/core/models/elements.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
|
to_yaml()
¤
Convert into YAML string.
Source code in trestle/core/models/elements.py
552 553 554 555 556 557 558 559 560 561 562 |
|
ElementPath
¤
Element path wrapper of an element.
This only allows a single wildcard '*' at the end to denote elements of an array or dict
Source code in trestle/core/models/elements.py
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
Attributes¤
PATH_SEPARATOR: str = const.ALIAS_PATH_SEPARATOR
class-attribute
instance-attribute
¤
WILDCARD: str = '*'
class-attribute
instance-attribute
¤
Functions¤
__eq__(other)
¤
Override equality method.
Source code in trestle/core/models/elements.py
359 360 361 362 363 364 |
|
__init__(element_path, parent_path=None)
¤
Initialize an element wrapper.
It assumes the element path contains oscal field alias with hyphens only
Source code in trestle/core/models/elements.py
46 47 48 49 50 51 52 53 54 55 56 57 |
|
__str__()
¤
Return string representation of element path.
Source code in trestle/core/models/elements.py
355 356 357 |
|
find_last_file_in_path(content_type, model_dir)
¤
Find the last (nearest) existing file in the element path leading to this element.
Source code in trestle/core/models/elements.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
get()
¤
Return the path parts as a list.
Source code in trestle/core/models/elements.py
74 75 76 |
|
get_element_name()
¤
Return the element alias name from the path.
Essentailly this the last part of the element path
Source code in trestle/core/models/elements.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
get_first()
¤
Return the first part of the path.
Source code in trestle/core/models/elements.py
218 219 220 |
|
get_full()
¤
Return the full path including parent path parts as a dot separated str.
Source code in trestle/core/models/elements.py
226 227 228 229 |
|
get_full_path_parts()
¤
Get full path parts to the element including parent path parts as a list.
Source code in trestle/core/models/elements.py
246 247 248 249 250 251 252 253 254 255 256 |
|
get_last()
¤
Return the last part of the path.
Source code in trestle/core/models/elements.py
222 223 224 |
|
get_obm_wrapped_type(root_model=None, use_parent=False)
¤
Get the type of the element. Wraps the collection type in an OscalBaseModel as a root element.
This should principally be used for validating content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_model
|
Optional[Type[Any]]
|
An OscalBaseModel Type from which to base the approach on. |
None
|
use_parent
|
bool
|
Whether or not to normalise the full path across parent ElementPaths, default to not. |
False
|
Returns:
Type | Description |
---|---|
Type[OscalBaseModel]
|
The type of the model whether wrapped or not as an OscalBaseModel. |
Source code in trestle/core/models/elements.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
get_parent()
¤
Return the parent path.
It can be None or a valid ElementPath
Source code in trestle/core/models/elements.py
211 212 213 214 215 216 |
|
get_preceding_path()
¤
Return the element path to the preceding element in the path.
Source code in trestle/core/models/elements.py
258 259 260 261 262 263 264 265 266 267 268 |
|
get_type(root_model=None, use_parent=False)
¤
Get the type of an element.
If possible the model type will be derived from one of the top level models, otherwise a 'root model' can be passed for situations where this is not possible.
This type path should NOT have wild cards in it. It may have* indices. Valid Examples: catalog.metadata catalog.groups catalog.groups.group catalog catalog.groups.0
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_model
|
Optional[Type[Any]]
|
An OscalBaseModel Type from which to base the approach on. |
None
|
use_parent
|
bool
|
Whether or not to normalise the full path across parent ElementPaths, default to not. |
False
|
Returns:
Type | Description |
---|---|
Type[Any]
|
The type of the model whether or not it is an OscalBaseModel or not. |
Source code in trestle/core/models/elements.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
is_multipart()
¤
Assert whether or not an element path is multiple parts.
Originally element paths had to have multiple paths. This provides a check for higher level code that still has that requirement.
Single part
catalog control assessment-results
Multipart
catalog.metadata catalog.controls.control
Source code in trestle/core/models/elements.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
make_absolute(model_dir, reference_dir)
¤
Make the parts absolute from the top model dir.
Source code in trestle/core/models/elements.py
286 287 288 289 290 291 292 293 294 295 296 297 |
|
make_relative(model_relative_path)
¤
Make the parts relative to the model path.
Source code in trestle/core/models/elements.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
to_file_path(content_type=None, root_dir='')
¤
Convert to a file or directory path for the element path.
if content_type is not passed, it will return a path for directory
Source code in trestle/core/models/elements.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
to_root_path(content_type=None)
¤
Convert to a file path for the element root.
Source code in trestle/core/models/elements.py
345 346 347 348 349 350 351 352 353 |
|
to_string()
¤
Return the path parts as a dot-separated string.
Source code in trestle/core/models/elements.py
207 208 209 |
|
Functions¤
handler: python