@@ -101,18 +101,40 @@ def __init__(
101
101
database or auth information are passed, the last database,
102
102
username, and password present will be used. For username and
103
103
passwords reserved characters like ':', '/', '+' and '@' must be
104
- escaped following RFC 2396.
104
+ percent encoded following RFC 2396::
105
+
106
+ try:
107
+ # Python 3.x
108
+ from urllib.parse import quote_plus
109
+ except ImportError:
110
+ # Python 2.x
111
+ from urllib import quote_plus
112
+
113
+ uri = "mongodb://%s:%s@%s" % (
114
+ quote_plus(user), quote_plus(password), host)
115
+ client = MongoClient(uri)
116
+
117
+ Unix domain sockets are also supported. The socket path must be percent
118
+ encoded in the URI::
119
+
120
+ uri = "mongodb://%s:%s@%s" % (
121
+ quote_plus(user), quote_plus(password), quote_plus(socket_path))
122
+ client = MongoClient(uri)
123
+
124
+ But not when passed as a simple hostname::
125
+
126
+ client = MongoClient('/tmp/mongodb-27017.sock')
105
127
106
128
.. warning:: When using PyMongo in a multiprocessing context, please
107
129
read :ref:`multiprocessing` first.
108
130
109
131
:Parameters:
110
- - `host` (optional): hostname or IP address of a single mongod or
111
- mongos instance to connect to, or a mongodb URI, or a list of
112
- hostnames / mongodb URIs. If `host` is an IPv6 literal
113
- it must be enclosed in '[' and ']' characters following
114
- the RFC2732 URL syntax (e.g. '[::1]' for localhost). Multihomed
115
- and round robin DNS addresses are **not** supported.
132
+ - `host` (optional): hostname or IP address or Unix domain socket
133
+ path of a single mongod or mongos instance to connect to, or a
134
+ mongodb URI, or a list of hostnames / mongodb URIs. If `host` is
135
+ an IPv6 literal it must be enclosed in '[' and ']' characters
136
+ following the RFC2732 URL syntax (e.g. '[::1]' for localhost).
137
+ Multihomed and round robin DNS addresses are **not** supported.
116
138
- `port` (optional): port number on which to connect
117
139
- `document_class` (optional): default class to use for
118
140
documents returned from queries on this client
0 commit comments