+\hDpdZddlmZddlmZddlmZddlmZerddl m Z dZ dZ dd Z dd Zdd Zdd Zy )aCriteria to select ServerDescriptions based on maxStalenessSeconds. The Max Staleness Spec says: When there is a known primary P, a secondary S's staleness is estimated with this formula: (S.lastUpdateTime - S.lastWriteDate) - (P.lastUpdateTime - P.lastWriteDate) + heartbeatFrequencyMS When there is no known primary, a secondary S's staleness is estimated with: SMax.lastWriteDate - S.lastWriteDate + heartbeatFrequencyMS where "SMax" is the secondary with the greatest lastWriteDate. ) annotations) TYPE_CHECKING)ConfigurationError) SERVER_TYPE) Selection Zc||tzkrtdt||dzfz|tkrtdt|fzy)NzmaxStalenessSeconds must be at least heartbeatFrequencyMS + %d seconds. maxStalenessSeconds is set to %d, heartbeatFrequencyMS is set to %d.izJmaxStalenessSeconds must be at least %d. maxStalenessSeconds is set to %d.)IDLE_WRITE_PERIODrSMALLEST_MAX_STALENESS) max_stalenessheartbeat_frequencys b/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/max_staleness_selectors.py_validate_max_stalenessr.sk*->>>  2!-1Dt1KL M  --  03I=2Y Z  .c|j}|sJg}|jD]}|jtjk(rr|j r |j sJ|j |j z |j |j z z |jz}||ks|j||j||j|S)zEApply max_staleness, in seconds, to a Selection with a known primary.) primaryserver_descriptions server_typer RSSecondarylast_write_datelast_update_timerappendwith_server_descriptions)r selectionrsdss stalenesss r _with_primaryr?sG N7 C  * *  ==K33 3$$)@)@ @@##a&7&77++g.E.EEG//0  M) 1 JJqM   - -c 22rc|j}|s|jgSg}|jD]}|jtj k(rX|j r |j sJ|j |j z |jz}||ksf|j|x|j||j|S)zFApply max_staleness, in seconds, to a Selection with no known primary.) "secondary_with_max_last_write_daterrrrrrrr)r rsmaxrrrs r _no_primaryr#Ws  7 7 9D 11"55 C  * *  ==K33 3''A,=,= ==,,q/@/@@9C`C``IM) 1 JJqM   - -c 22rc|dk(r|St||j|jr t||St ||S)z0Apply max_staleness, in seconds, to a Selection.)rrrrr#)r rs rselectr&osE M9+H+HI]I66=)44rN)r intrr'returnNone)r r'rrr(r)__doc__ __future__rtypingrpymongo.errorsrpymongo.server_typerpymongo.server_selectorsrr r rrr#r&rrr1s@ # -+2  "3030 5r