@@ -2027,11 +2027,47 @@ def reused_existing(self) -> bool:
20272027 return self ._reused_existing
20282028
20292029
2030+ class TranslationMemoryJobStatus (str , Enum ):
2031+ """Status of a translation memory import or export job.
2032+
2033+ Members are strings and compare equal to the status string the API
2034+ returns, for example ``TranslationMemoryJobStatus.COMPLETED ==
2035+ "completed"``.
2036+ """
2037+
2038+ AWAITING_INPUT = "awaiting_input"
2039+ PROCESSING = "processing"
2040+ COMPLETED = "completed"
2041+ FAILED = "failed"
2042+ EXPIRED = "expired"
2043+
2044+ def __str__ (self ) -> str :
2045+ return self .value
2046+
2047+ def __format__ (self , format_spec : str ) -> str :
2048+ return format (self .value , format_spec )
2049+
2050+ # Hash like the plain status string, so members and strings are
2051+ # interchangeable as dict keys and set members.
2052+ __hash__ = str .__hash__
2053+
2054+
2055+ def _parse_translation_memory_job_status (
2056+ status : Any ,
2057+ ) -> Union [TranslationMemoryJobStatus , str ]:
2058+ try :
2059+ return TranslationMemoryJobStatus (status )
2060+ except ValueError :
2061+ # Unknown statuses are kept as given.
2062+ return status
2063+
2064+
20302065class TranslationMemoryJobResult :
20312066 """The outcome of a translation memory import or export job.
20322067
2033- :param status: Job status, one of "awaiting_input", "processing",
2034- "completed", "downloaded", "failed" or "expired".
2068+ :param status: Job status. A known status is returned as a
2069+ TranslationMemoryJobStatus member, any other value as the plain
2070+ string.
20352071 :param required_action: Human-readable action the caller must take, set
20362072 while the job is waiting on the caller.
20372073 :param download_url: Download URL of the exported TMX file, set once an
@@ -2061,7 +2097,7 @@ def __init__(
20612097 translation_memory_id : Optional [str ] = None ,
20622098 skipped_segment_count : Optional [int ] = None ,
20632099 ):
2064- self ._status = status
2100+ self ._status = _parse_translation_memory_job_status ( status )
20652101 self ._required_action = required_action
20662102 self ._download_url = download_url
20672103 self ._expires_at = expires_at
@@ -2089,8 +2125,9 @@ def from_json(json) -> "TranslationMemoryJobResult":
20892125 )
20902126
20912127 @property
2092- def status (self ) -> str :
2093- """Returns the job status."""
2128+ def status (self ) -> Union [TranslationMemoryJobStatus , str ]:
2129+ """Returns the job status: a TranslationMemoryJobStatus member, or the
2130+ plain string for a status this library does not know."""
20942131 return self ._status
20952132
20962133 @property
@@ -2238,8 +2275,9 @@ def result(self) -> Optional[TranslationMemoryJobResult]:
22382275 return self ._results [0 ] if self ._results else None
22392276
22402277 @property
2241- def status (self ) -> Optional [str ]:
2242- """Returns the status of the job result."""
2278+ def status (self ) -> Optional [Union [TranslationMemoryJobStatus , str ]]:
2279+ """Returns the status of the job result, see
2280+ TranslationMemoryJobResult.status."""
22432281 return self .result .status if self .result else None
22442282
22452283 @property
0 commit comments