Holds the result of a usage request. The character, document and team_document properties provide details about each corresponding usage type. These properties allow each usage type to be checked individually. The any_limit_reached property checks if for any usage type the amount us
| 125 | |
| 126 | |
| 127 | class Usage: |
| 128 | """Holds the result of a usage request. |
| 129 | |
| 130 | The character, document and team_document properties provide details about |
| 131 | each corresponding usage type. These properties allow each usage type to be |
| 132 | checked individually. |
| 133 | The any_limit_reached property checks if for any usage type the amount used |
| 134 | has reached the allowed amount. |
| 135 | """ |
| 136 | |
| 137 | class Detail: |
| 138 | def __init__(self, json: Optional[dict], prefix: str): |
| 139 | self._count = get_int_safe(json, f"{prefix}_count") |
| 140 | self._limit = get_int_safe(json, f"{prefix}_limit") |
| 141 | |
| 142 | @property |
| 143 | def count(self) -> Optional[int]: |
| 144 | """Returns the amount used for this usage type, may be None.""" |
| 145 | return self._count |
| 146 | |
| 147 | @property |
| 148 | def limit(self) -> Optional[int]: |
| 149 | """Returns the maximum amount for this usage type, may be None.""" |
| 150 | return self._limit |
| 151 | |
| 152 | @property |
| 153 | def valid(self) -> bool: |
| 154 | """True iff both the count and limit are set for this usage |
| 155 | type.""" |
| 156 | return self._count is not None and self._limit is not None |
| 157 | |
| 158 | @property |
| 159 | def limit_reached(self) -> bool: |
| 160 | """True if this limit is valid and the amount used is greater than |
| 161 | or equal to the amount allowed, otherwise False.""" |
| 162 | return self.valid and self.count >= self.limit # type: ignore[operator] # noqa: E501 |
| 163 | |
| 164 | @property |
| 165 | def limit_exceeded(self) -> bool: |
| 166 | """Deprecated, use limit_reached instead.""" |
| 167 | import warnings |
| 168 | |
| 169 | warnings.warn( |
| 170 | "limit_reached is deprecated", DeprecationWarning, stacklevel=2 |
| 171 | ) |
| 172 | return self.limit_reached |
| 173 | |
| 174 | def __str__(self) -> str: |
| 175 | return f"{self.count} of {self.limit}" if self.valid else "Unknown" |
| 176 | |
| 177 | def __init__(self, json: Optional[dict]): |
| 178 | self._character = self.Detail(json, "character") |
| 179 | self._document = self.Detail(json, "document") |
| 180 | self._team_document = self.Detail(json, "team_document") |
| 181 | |
| 182 | @property |
| 183 | def any_limit_reached(self) -> bool: |
| 184 | """True if for any API usage type, the amount used is greater than or |