| 303 | super().__init__() |
| 304 | |
| 305 | def __new__( |
| 306 | cls: Type[JSONOptions], |
| 307 | strict_number_long: Optional[bool] = None, |
| 308 | datetime_representation: Optional[int] = None, |
| 309 | strict_uuid: Optional[bool] = None, |
| 310 | json_mode: int = JSONMode.RELAXED, |
| 311 | *args: Any, |
| 312 | **kwargs: Any, |
| 313 | ) -> JSONOptions: |
| 314 | kwargs["tz_aware"] = kwargs.get("tz_aware", False) |
| 315 | if kwargs["tz_aware"]: |
| 316 | kwargs["tzinfo"] = kwargs.get("tzinfo", utc) |
| 317 | if datetime_representation not in ( |
| 318 | DatetimeRepresentation.LEGACY, |
| 319 | DatetimeRepresentation.NUMBERLONG, |
| 320 | DatetimeRepresentation.ISO8601, |
| 321 | None, |
| 322 | ): |
| 323 | raise ValueError( |
| 324 | "JSONOptions.datetime_representation must be one of LEGACY, " |
| 325 | "NUMBERLONG, or ISO8601 from DatetimeRepresentation." |
| 326 | ) |
| 327 | self = cast(JSONOptions, super().__new__(cls, *args, **kwargs)) |
| 328 | if json_mode not in (JSONMode.LEGACY, JSONMode.RELAXED, JSONMode.CANONICAL): |
| 329 | raise ValueError( |
| 330 | "JSONOptions.json_mode must be one of LEGACY, RELAXED, " |
| 331 | "or CANONICAL from JSONMode." |
| 332 | ) |
| 333 | self.json_mode = json_mode |
| 334 | if self.json_mode == JSONMode.RELAXED: |
| 335 | if strict_number_long: |
| 336 | raise ValueError("Cannot specify strict_number_long=True with JSONMode.RELAXED") |
| 337 | if datetime_representation not in (None, DatetimeRepresentation.ISO8601): |
| 338 | raise ValueError( |
| 339 | "datetime_representation must be DatetimeRepresentation." |
| 340 | "ISO8601 or omitted with JSONMode.RELAXED" |
| 341 | ) |
| 342 | if strict_uuid not in (None, True): |
| 343 | raise ValueError("Cannot specify strict_uuid=False with JSONMode.RELAXED") |
| 344 | self.strict_number_long = False |
| 345 | self.datetime_representation = DatetimeRepresentation.ISO8601 |
| 346 | self.strict_uuid = True |
| 347 | elif self.json_mode == JSONMode.CANONICAL: |
| 348 | if strict_number_long not in (None, True): |
| 349 | raise ValueError("Cannot specify strict_number_long=False with JSONMode.RELAXED") |
| 350 | if datetime_representation not in (None, DatetimeRepresentation.NUMBERLONG): |
| 351 | raise ValueError( |
| 352 | "datetime_representation must be DatetimeRepresentation." |
| 353 | "NUMBERLONG or omitted with JSONMode.RELAXED" |
| 354 | ) |
| 355 | if strict_uuid not in (None, True): |
| 356 | raise ValueError("Cannot specify strict_uuid=False with JSONMode.RELAXED") |
| 357 | self.strict_number_long = True |
| 358 | self.datetime_representation = DatetimeRepresentation.NUMBERLONG |
| 359 | self.strict_uuid = True |
| 360 | else: # JSONMode.LEGACY |
| 361 | self.strict_number_long = False |
| 362 | self.datetime_representation = DatetimeRepresentation.LEGACY |