Skip to content

Commit 8d66b56

Browse files
committed
Correct python module import for auth examples
1 parent 30882a5 commit 8d66b56

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

doc/examples/authentication.rst

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ credentials can be specified through the MongoDB URI or passed to the
1313
:meth:`~pymongo.database.Database.authenticate` method::
1414

1515
>>> from pymongo import MongoClient
16-
>>> client = pymongo.MongoClient('example.com')
16+
>>> client = MongoClient('example.com')
1717
>>> client.the_database.authenticate('user', 'password')
1818
True
1919
>>>
2020
>>> uri = "mongodb://user:password@example.com/the_database"
21-
>>> client = pymongo.MongoClient(uri)
21+
>>> client = MongoClient(uri)
2222
>>>
2323

2424
When using MongoDB's delegated authentication features, a separate
2525
authentication source can be specified (using PyMongo 2.5 or newer)::
2626

2727
>>> from pymongo import MongoClient
28-
>>> client = pymongo.MongoClient('example.com')
28+
>>> client = MongoClient('example.com')
2929
>>> client.the_database.authenticate('user',
3030
... 'password',
3131
... source='source_database')
3232
True
3333
>>>
3434
>>> uri = "mongodb://user:password@example.com/?authSource=source_database"
35-
>>> client = pymongo.MongoClient(uri)
35+
>>> client = MongoClient(uri)
3636
>>>
3737

3838
MONGODB-X509
@@ -47,11 +47,11 @@ and newer::
4747

4848
>>> import ssl
4949
>>> from pymongo import MongoClient
50-
>>> client = pymongo.MongoClient('example.com',
51-
... ssl=True,
52-
... ssl_certfile='/path/to/client.pem',
53-
... ssl_cert_reqs=ssl.CERT_REQUIRED,
54-
... ssl_ca_certs='/path/to/ca.pem')
50+
>>> client = MongoClient('example.com',
51+
... ssl=True,
52+
... ssl_certfile='/path/to/client.pem',
53+
... ssl_cert_reqs=ssl.CERT_REQUIRED,
54+
... ssl_ca_certs='/path/to/ca.pem')
5555
>>> client.the_database.authenticate("<X.509 derived username>",
5656
... mechanism='MONGODB-X509')
5757
True
@@ -61,11 +61,11 @@ MONGODB-X509 authenticates against the $external virtual database, so you
6161
do not have to specify a database in the URI::
6262

6363
>>> uri = "mongodb://<X.509 derived username>@example.com/?authMechanism=MONGODB-X509"
64-
>>> client = pymongo.MongoClient(uri,
65-
... ssl=True,
66-
... ssl_certfile='/path/to/client.pem',
67-
... ssl_cert_reqs=ssl.CERT_REQUIRED,
68-
... ssl_ca_certs='/path/to/ca.pem')
64+
>>> client = MongoClient(uri,
65+
... ssl=True,
66+
... ssl_certfile='/path/to/client.pem',
67+
... ssl_cert_reqs=ssl.CERT_REQUIRED,
68+
... ssl_ca_certs='/path/to/ca.pem')
6969
>>>
7070

7171
.. note::
@@ -99,27 +99,27 @@ $external virtual database so you do not have to specify a database in the
9999
URI::
100100

101101
>>> # Note: the kerberos principal must be url encoded.
102-
>>> import pymongo
102+
>>> from pymongo import MongoClient
103103
>>> uri = "mongodb://mongodbuser%40EXAMPLE.COM@example.com/?authMechanism=GSSAPI"
104-
>>> client = pymongo.MongoClient(uri)
104+
>>> client = MongoClient(uri)
105105
>>>
106106

107107
or using :meth:`~pymongo.database.Database.authenticate`::
108108

109-
>>> import pymongo
110-
>>> client = pymongo.MongoClient('example.com')
109+
>>> from pymongo import MongoClient
110+
>>> client = MongoClient('example.com')
111111
>>> db = client.test
112112
>>> db.authenticate('mongodbuser@EXAMPLE.COM', mechanism='GSSAPI')
113113
True
114114

115115
The default service name used by MongoDB and PyMongo is `mongodb`. You can
116116
specify a custom service name with the ``gssapiServiceName`` option::
117117

118-
>>> import pymongo
118+
>>> from pymongo import MongoClient
119119
>>> uri = "mongodb://mongodbuser%40EXAMPLE.COM@example.com/?authMechanism=GSSAPI&gssapiServiceName=myservicename"
120-
>>> client = pymongo.MongoClient(uri)
120+
>>> client = MongoClient(uri)
121121
>>>
122-
>>> client = pymongo.MongoClient('example.com')
122+
>>> client = MongoClient('example.com')
123123
>>> db = client.test
124124
>>> db.authenticate('mongodbuser@EXAMPLE.COM', mechanism='GSSAPI', gssapiServiceName='myservicename')
125125
True
@@ -141,15 +141,15 @@ to an LDAP server. Using the PLAIN mechanism is very similar to MONGODB-CR.
141141
These examples use the $external virtual database for LDAP support::
142142

143143
>>> from pymongo import MongoClient
144-
>>> client = pymongo.MongoClient('example.com')
144+
>>> client = MongoClient('example.com')
145145
>>> client.the_database.authenticate('user',
146146
... 'password',
147147
... source='$external',
148148
... mechanism='PLAIN')
149149
True
150150
>>>
151151
>>> uri = "mongodb://user:password@example.com/?authMechanism=PLAIN&authSource=$external"
152-
>>> client = pymongo.MongoClient(uri)
152+
>>> client = MongoClient(uri)
153153
>>>
154154

155155
SASL PLAIN is a clear-text authentication mechanism. We **strongly** recommend
@@ -158,22 +158,22 @@ the SASL PLAIN mechanism::
158158

159159
>>> import ssl
160160
>>> from pymongo import MongoClient
161-
>>> client = pymongo.MongoClient('example.com',
162-
... ssl=True,
163-
... ssl_certfile='/path/to/client.pem',
164-
... ssl_cert_reqs=ssl.CERT_REQUIRED,
165-
... ssl_ca_certs='/path/to/ca.pem')
161+
>>> client = MongoClient('example.com',
162+
... ssl=True,
163+
... ssl_certfile='/path/to/client.pem',
164+
... ssl_cert_reqs=ssl.CERT_REQUIRED,
165+
... ssl_ca_certs='/path/to/ca.pem')
166166
>>> client.the_database.authenticate('user',
167167
... 'password',
168168
... source='$external',
169169
... mechanism='PLAIN')
170170
True
171171
>>>
172172
>>> uri = "mongodb://user:password@example.com/?authMechanism=PLAIN&authSource=$external"
173-
>>> client = pymongo.MongoClient(uri,
174-
... ssl=True,
175-
... ssl_certfile='/path/to/client.pem',
176-
... ssl_cert_reqs=ssl.CERT_REQUIRED,
177-
... ssl_ca_certs='/path/to/ca.pem')
173+
>>> client = MongoClient(uri,
174+
... ssl=True,
175+
... ssl_certfile='/path/to/client.pem',
176+
... ssl_cert_reqs=ssl.CERT_REQUIRED,
177+
... ssl_ca_certs='/path/to/ca.pem')
178178
>>>
179179

0 commit comments

Comments
 (0)