11import copy
22import time
3- import warnings
43
54import django
65from django .conf import settings
76from django .core .exceptions import ImproperlyConfigured , ValidationError
87from django .db .backends .utils import logger
9- from django .utils .deprecation import RemovedInDjango60Warning
108from django .utils .functional import SimpleLazyObject
119from django .utils .text import format_lazy
1210from django .utils .version import get_version_tuple
13- from pymongo .uri_parser import parse_uri as pymongo_parse_uri
1411
1512
1613def check_django_compatability ():
@@ -30,50 +27,6 @@ def check_django_compatability():
3027 )
3128
3229
33- def parse_uri (uri , * , db_name = None , options = None , test = None ):
34- """
35- Convert the given uri into a dictionary suitable for Django's DATABASES
36- setting.
37- """
38- warnings .warn (
39- 'parse_uri() is deprecated. Put the connection string in DATABASES["HOST"] instead.' ,
40- RemovedInDjango60Warning ,
41- stacklevel = 2 ,
42- )
43- uri = pymongo_parse_uri (uri )
44- host = None
45- port = None
46- if uri ["fqdn" ]:
47- # This is a SRV URI and the host is the fqdn.
48- host = f"mongodb+srv://{ uri ['fqdn' ]} "
49- else :
50- nodelist = uri .get ("nodelist" )
51- if len (nodelist ) == 1 :
52- host , port = nodelist [0 ]
53- elif len (nodelist ) > 1 :
54- host = "," .join ([f"{ host } :{ port } " for host , port in nodelist ])
55- db_name = db_name or uri ["database" ]
56- if not db_name :
57- raise ImproperlyConfigured ("You must provide the db_name parameter." )
58- opts = uri .get ("options" )
59- if options :
60- opts .update (options )
61- settings_dict = {
62- "ENGINE" : "django_mongodb_backend" ,
63- "NAME" : db_name ,
64- "HOST" : host ,
65- "PORT" : port ,
66- "USER" : uri .get ("username" ),
67- "PASSWORD" : uri .get ("password" ),
68- "OPTIONS" : opts ,
69- }
70- if "authSource" not in settings_dict ["OPTIONS" ] and uri ["database" ]:
71- settings_dict ["OPTIONS" ]["authSource" ] = uri ["database" ]
72- if test :
73- settings_dict ["TEST" ] = test
74- return settings_dict
75-
76-
7730def prefix_validation_error (error , prefix , code , params ):
7831 """
7932 Prefix a validation error message while maintaining the existing
0 commit comments