| 522 | |
| 523 | |
| 524 | def make_read_preference( |
| 525 | mode: int, tag_sets: Optional[_TagSets], max_staleness: int = -1 |
| 526 | ) -> _ServerMode: |
| 527 | if mode == _PRIMARY: |
| 528 | if tag_sets not in (None, [{}]): |
| 529 | raise ConfigurationError("Read preference primary cannot be combined with tags") |
| 530 | if max_staleness != -1: |
| 531 | raise ConfigurationError( |
| 532 | "Read preference primary cannot be combined with maxStalenessSeconds" |
| 533 | ) |
| 534 | return Primary() |
| 535 | return _ALL_READ_PREFERENCES[mode](tag_sets, max_staleness) # type: ignore |
| 536 | |
| 537 | |
| 538 | _MODES = ( |