fv ddlmZddlZ ddlmZdZ ddlZddl m Z m Z dZ ddZd dZy#e$r ddlZdZn#e$r ZeZYdZ[ndZ[wwxYwY;wxYw#e$rZddl m Z m Z eZ YdZ[DdZ[wwxYw) ) MongoClientN)mock) parse_uri split_hostsct|trt|d|dSd|vrt|ddSt ||S)Nrrz://T)warnnodelist) default_port) isinstancetuple_parse_any_hostrr)hostr s X/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/mongomock/patch.pyrrsG$tAwQ00 }D)*55 t, 77c6trttrdntjit t |t tfr|n|gD]}jt|fdGfdd}tjd|S)aPatch pymongo.MongoClient. This will patch the class MongoClient and use mongomock to mock MongoDB servers. It keeps a consistant state of servers across multiple clients so you can do: ``` client = pymongo.MongoClient(host='localhost', port=27017) client.db.coll.insert_one({'name': 'Pascal'}) other_client = pymongo.MongoClient('mongodb://localhost:27017') client.db.coll.find_one() ``` The data is persisted as long as the patch lives. Args: on_new: Behavior when accessing a new server (not in servers): 'create': mock a new empty server, accept any client connection. 'error': raise a ValueError immediately when trying to access. 'timeout': behave as pymongo when a server does not exist, raise an error after a timeout. 'pymongo': use an actual pymongo client. servers: a list of server that are avaiable. Nctrtt|i|} |j}|j|_|S#t$rYnwxYw|jvsdk(r||j<|Sdk(rQt j |jddtjjd|jzdk(r|i|Std|jzdzz) NcreatetimeoutserverSelectionTimeoutMSi0uz%%s:%d: [Errno 111] Connection refusedpymongoz%MongoDB server %s:%d does not exist. z%s) _IMPORT_PYMONGO_ERRORraddress_storeKeyErrortimesleepgetrerrorsServerSelectionTimeoutError ValueError)argskwargsclientpersisted_client PyMongoClienton_newparsed_serverspersisted_clientss r_create_persistent_clientz(patch.._create_persistent_clientGs ' 'd-f- 0@ ,33FMM    >>^ +v/A06 fnn -M Y  JJvzz"._PersistentClientc|i|S)N)clsr"r#r*s r__new__z(patch.._PersistentClient.__new__es,d=f= =rN)__name__ __module__ __qualname__r0)r*sr_PersistentClientr,ds >rr4zpymongo.MongoClient) _IMPORT_MOCK_ERRORrrrsetr listr updaterrpatch)serversr'serverr4r&r*r(r)s ` @@@@rr9r9s6   ++ UN'$?'gYNof56O_:>> ::+-> ??r)ii) localhosterror) mongo_clientrrunittestrr5 ImportErrorr=rpymongo.uri_parserrrrhelpersrr9r.rrrCs% #"9  8I@1##! #"# #"/!"sK,AA9AA AAA  AAA, A''A,