1
1
import copy
2
2
import time
3
- import warnings
4
3
5
4
import django
6
5
from django .conf import settings
7
6
from django .core .exceptions import ImproperlyConfigured , ValidationError
8
7
from django .db .backends .utils import logger
9
- from django .utils .deprecation import RemovedInDjango60Warning
10
8
from django .utils .functional import SimpleLazyObject
11
9
from django .utils .text import format_lazy
12
10
from django .utils .version import get_version_tuple
13
- from pymongo .uri_parser import parse_uri as pymongo_parse_uri
14
11
15
12
16
13
def check_django_compatability ():
@@ -30,50 +27,6 @@ def check_django_compatability():
30
27
)
31
28
32
29
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
-
77
30
def prefix_validation_error (error , prefix , code , params ):
78
31
"""
79
32
Prefix a validation error message while maintaining the existing
0 commit comments