Returns a list of dictionary representations of the contained objects. An attempt is made to flatten out the returned list when there is only one item in the collection. This is to support backwards compatibility with previous versions of python-stix. * If t
(self)
| 340 | return l |
| 341 | |
| 342 | def to_list(self): |
| 343 | """Returns a list of dictionary representations of the contained |
| 344 | objects. |
| 345 | |
| 346 | An attempt is made to flatten out the returned list when there is only |
| 347 | one item in the collection. This is to support backwards |
| 348 | compatibility with previous versions of python-stix. |
| 349 | |
| 350 | * If the list repr has more than one item, return the list. |
| 351 | * If there is only one item, inspect it. |
| 352 | |
| 353 | * If the item is not a dictionary, return it. |
| 354 | * If its ``ordinality`` key has a corresponding value of ``1``, remove |
| 355 | it from the dictionary since it's assumed if there is only one item. |
| 356 | * After removing ``ordinality``, if the only key left is ``value``, |
| 357 | just return the value of ``value`` (a string). |
| 358 | |
| 359 | """ |
| 360 | if not self: |
| 361 | return [] |
| 362 | |
| 363 | if len(self) > 1: |
| 364 | return super(StructuredTextList, self).to_list() |
| 365 | |
| 366 | # One item. Temporarily unset the ordinality if its the default value. |
| 367 | text = self._inner[0] |
| 368 | |
| 369 | # Temporarily unset the ordinality to create our dictionary |
| 370 | with _unset_default(text): |
| 371 | d = text.to_dict() |
| 372 | |
| 373 | return d |
| 374 | |
| 375 | to_dict = to_list |
| 376 |
no test coverage detected