File: read_preferences.py

package info (click to toggle)
python-mongomock 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,028 kB
  • sloc: python: 16,412; makefile: 24
file content (40 lines) | stat: -rw-r--r-- 848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class _Primary:

    @property
    def mongos_mode(self):
        return 'primary'

    @property
    def mode(self):
        return 0

    @property
    def name(self):
        return 'Primary'

    @property
    def document(self):
        return {'mode': 'primary'}

    @property
    def tag_sets(self):
        return [{}]

    @property
    def max_staleness(self):
        return -1

    @property
    def min_wire_version(self):
        return 0


def ensure_read_preference_type(key, value):
    """Raise a TypeError if the value is not a type compatible for ReadPreference."""
    for attr in ('document', 'mode', 'mongos_mode', 'max_staleness'):
        if not hasattr(value, attr):
            raise TypeError('{} must be an instance of {}'.format(
                key, 'pymongo.read_preference.ReadPreference'))


PRIMARY = _Primary()