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

Method _clone

pymongo/synchronous/cursor.py:261–301  ·  view source on GitHub ↗

Internal clone helper.

(self, deepcopy: bool = True, base: Optional[Cursor] = None)

Source from the content-addressed store, hash-verified

259 return self._clone(True)
260
261 def _clone(self, deepcopy: bool = True, base: Optional[Cursor] = None) -> Cursor: # type: ignore[type-arg]
262 """Internal clone helper."""
263 if not base:
264 if self._session and not self._session._implicit:
265 base = self._clone_base(self._session)
266 else:
267 base = self._clone_base(None)
268
269 values_to_clone = (
270 "spec",
271 "projection",
272 "skip",
273 "limit",
274 "max_time_ms",
275 "max_await_time_ms",
276 "comment",
277 "max",
278 "min",
279 "ordering",
280 "explain",
281 "hint",
282 "batch_size",
283 "max_scan",
284 "query_flags",
285 "collation",
286 "empty",
287 "show_record_id",
288 "return_key",
289 "allow_disk_use",
290 "snapshot",
291 "exhaust",
292 "has_filter",
293 "cursor_type",
294 )
295 data = {
296 k: v for k, v in self.__dict__.items() if k.startswith("_") and k[1:] in values_to_clone
297 }
298 if deepcopy:
299 data = self._deepcopy(data)
300 base.__dict__.update(data)
301 return base
302
303 def _clone_base(self, session: Optional[ClientSession]) -> Cursor: # type: ignore[type-arg]
304 """Creates an empty Cursor object for information to be copied into."""

Callers 4

cloneMethod · 0.95
__copy__Method · 0.95
__deepcopy__Method · 0.95
explainMethod · 0.45

Calls 4

_clone_baseMethod · 0.95
_deepcopyMethod · 0.95
itemsMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected