MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / Hello

Class Hello

pymongo/hello.py:65–224  ·  view source on GitHub ↗

Parse a hello response from the server. .. versionadded:: 3.12

Source from the content-addressed store, hash-verified

63
64
65class Hello(Generic[_DocumentType]):
66 """Parse a hello response from the server.
67
68 .. versionadded:: 3.12
69 """
70
71 __slots__ = ("_doc", "_server_type", "_is_writable", "_is_readable", "_awaitable")
72
73 def __init__(self, doc: _DocumentType, awaitable: bool = False) -> None:
74 self._server_type = _get_server_type(doc)
75 self._doc: _DocumentType = doc
76 self._is_writable = self._server_type in (
77 SERVER_TYPE.RSPrimary,
78 SERVER_TYPE.Standalone,
79 SERVER_TYPE.Mongos,
80 SERVER_TYPE.LoadBalancer,
81 )
82
83 self._is_readable = self.server_type == SERVER_TYPE.RSSecondary or self._is_writable
84 self._awaitable = awaitable
85
86 @property
87 def document(self) -> _DocumentType:
88 """The complete hello command response document.
89
90 .. versionadded:: 3.4
91 """
92 return copy.copy(self._doc)
93
94 @property
95 def server_type(self) -> int:
96 return self._server_type
97
98 @property
99 def all_hosts(self) -> set[tuple[str, int]]:
100 """List of hosts, passives, and arbiters known to this server."""
101 return set(
102 map(
103 common.clean_node,
104 itertools.chain(
105 self._doc.get("hosts", []),
106 self._doc.get("passives", []),
107 self._doc.get("arbiters", []),
108 ),
109 )
110 )
111
112 @property
113 def tags(self) -> Mapping[str, Any]:
114 """Replica set member tags or empty dict."""
115 return self._doc.get("tags", {})
116
117 @property
118 def primary(self) -> Optional[tuple[str, int]]:
119 """This server's opinion about who the primary is, or None."""
120 if self._doc.get("primary"):
121 return common.partition_node(self._doc["primary"])
122 else:

Callers 15

make_server_descriptionFunction · 0.90
_check_with_socketMethod · 0.90
_run_scenarioFunction · 0.90
got_helloFunction · 0.90
got_helloFunction · 0.90
_check_with_socketMethod · 0.90
_check_with_socketMethod · 0.90
test_reprMethod · 0.90
_check_onceMethod · 0.90
parse_hello_responseFunction · 0.90
_check_with_socketMethod · 0.90
_run_scenarioFunction · 0.90

Calls

no outgoing calls

Tested by 12

make_server_descriptionFunction · 0.72
_check_with_socketMethod · 0.72
_run_scenarioFunction · 0.72
got_helloFunction · 0.72
got_helloFunction · 0.72
_check_with_socketMethod · 0.72
_check_with_socketMethod · 0.72
test_reprMethod · 0.72
parse_hello_responseFunction · 0.72
_check_with_socketMethod · 0.72
_run_scenarioFunction · 0.72
got_helloFunction · 0.72