Enumeration member corresponding to XML attribute value `xml_value`. Raises `ValueError` if `xml_value` is the empty string ("") or is not an XML attribute value registered on the enumeration. Note that enum members that do not correspond to one of the defined values for an
(cls, xml_value: str)
| 52 | |
| 53 | @classmethod |
| 54 | def from_xml(cls, xml_value: str) -> Self: |
| 55 | """Enumeration member corresponding to XML attribute value `xml_value`. |
| 56 | |
| 57 | Raises `ValueError` if `xml_value` is the empty string ("") or is not an XML attribute |
| 58 | value registered on the enumeration. Note that enum members that do not correspond to one |
| 59 | of the defined values for an XML attribute have `xml_value == ""`. These |
| 60 | "return-value only" members cannot be automatically mapped from an XML attribute value and |
| 61 | must be selected explicitly by code, based on the appropriate conditions. |
| 62 | |
| 63 | Example:: |
| 64 | |
| 65 | >>> WD_PARAGRAPH_ALIGNMENT.from_xml("center") |
| 66 | WD_PARAGRAPH_ALIGNMENT.CENTER |
| 67 | |
| 68 | """ |
| 69 | # -- the empty string never maps to a member -- |
| 70 | member = ( |
| 71 | next((member for member in cls if member.xml_value == xml_value), None) |
| 72 | if xml_value |
| 73 | else None |
| 74 | ) |
| 75 | |
| 76 | if member is None: |
| 77 | raise ValueError(f"{cls.__name__} has no XML mapping for {repr(xml_value)}") |
| 78 | |
| 79 | return member |
| 80 | |
| 81 | @classmethod |
| 82 | def to_xml(cls: Type[_T], value: int | _T) -> str: |
no outgoing calls