Skip to content

Commit 0fbdf85

Browse files
author
Luke Lovett
committed
PYTHON-1113 - Index collation documentation into API docs.
1 parent 8fdb581 commit 0fbdf85

File tree

7 files changed

+34
-16
lines changed

7 files changed

+34
-16
lines changed

doc/api/pymongo/collation.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
:mod:`collation` -- Tools for working with collations.
2+
======================================================
3+
4+
.. automodule:: pymongo.collation
5+
:synopsis: Tools for working with collations.
6+
7+
.. autoclass:: pymongo.collation.Collation
8+
.. autoclass:: pymongo.collation.CollationStrength
9+
:members:
10+
:member-order: bysource
11+
.. autoclass:: pymongo.collation.CollationAlternate
12+
:members:
13+
:member-order: bysource
14+
.. autoclass:: pymongo.collation.CollationCaseFirst
15+
:members:
16+
:member-order: bysource

doc/api/pymongo/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Sub-modules:
3232
:maxdepth: 2
3333

3434
database
35+
collation
3536
collection
3637
command_cursor
3738
cursor

pymongo/bulk.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,11 @@ def execute(self, write_concern):
483483
with client._socket_for_writes() as sock_info:
484484
if sock_info.max_wire_version < 5 and self.uses_collation:
485485
raise ConfigurationError(
486-
'Specifying a collation is unsupported with a max wire '
487-
'version of %d.' % (sock_info.max_wire_version,))
486+
'Must be connected to MongoDB 3.4+ to use a collation.')
488487
if not write_concern.acknowledged:
488+
if self.uses_collation:
489+
raise ConfigurationError(
490+
'Collation is unsupported for unacknowledged writes.')
489491
self.execute_no_results(sock_info, generator)
490492
elif sock_info.max_wire_version > 1:
491493
return self.execute_command(sock_info, generator, write_concern)

pymongo/collation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Tools for working with `collations`_.
1616
17-
.. collations: http://userguide.icu-project.org/collation/concepts
17+
.. _collations: http://userguide.icu-project.org/collation/concepts
1818
"""
1919

2020
from pymongo import common
@@ -95,11 +95,9 @@ class Collation(object):
9595
9696
:Parameters:
9797
- `locale`: (string) The locale of the collation. This should be a string
98-
that identifies an `ICU locale ID`_ exactly. For example, ``en_US``
99-
is valid, but ``en_us`` and ``en-US`` are not.
100-
101-
The following parameters are all optional:
102-
98+
that identifies an `ICU locale ID` exactly. For example, ``en_US`` is
99+
valid, but ``en_us`` and ``en-US`` are not. Consult the MongoDB
100+
documentation for a list of supported locales.
103101
- `caseLevel`: (optional) If ``True``, turn on case sensitivity if
104102
`strength` is 1 or 2 (case sensitivity is implied if `strength` is
105103
greater than 2). Defaults to ``False``.

pymongo/collection.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,7 @@ def _update(self, sock_info, criteria, document, upsert=False,
729729
if collation is not None:
730730
if sock_info.max_wire_version < 5:
731731
raise ConfigurationError(
732-
'Specifying a collation is unsupported with a max wire '
733-
'version of %d.' % (sock_info.max_wire_version,))
732+
'Must be connected to MongoDB 3.4+ to use collations.')
734733
elif not acknowledged:
735734
raise ConfigurationError(
736735
'Collation is unsupported for unacknowledged writes.')
@@ -976,8 +975,7 @@ def _delete(
976975
if collation is not None:
977976
if sock_info.max_wire_version < 5:
978977
raise ConfigurationError(
979-
'Specifying a collation is unsupported with a max wire '
980-
'version of %d.' % (sock_info.max_wire_version,))
978+
'Must be connected to MongoDB 3.4+ to use collations.')
981979
elif not acknowledged:
982980
raise ConfigurationError(
983981
'Collation is unsupported for unacknowledged writes.')
@@ -1420,8 +1418,7 @@ def __create_index(self, keys, index_options):
14201418
if collation is not None:
14211419
if sock_info.max_wire_version < 5:
14221420
raise ConfigurationError(
1423-
'Specifying a collation is unsupported with a max wire '
1424-
'version of %d.' % (sock_info.max_wire_version,))
1421+
'Must be connected to MongoDB 3.4+ to use collations.')
14251422
else:
14261423
index['collation'] = collation
14271424
cmd = SON([('createIndexes', self.name), ('indexes', [index])])

pymongo/pool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ def command(self, dbname, spec, slave_ok=False,
382382
spec['writeConcern'] = write_concern.document
383383
elif self.max_wire_version < 5 and collation is not None:
384384
raise ConfigurationError(
385-
'Specifying a collation is unsupported with a max wire '
386-
'version of %d.' % (self.max_wire_version,))
385+
'Must be connected to MongoDB 3.4+ to use a collation.')
387386
try:
388387
return command(self.sock, dbname, spec, slave_ok,
389388
self.is_mongos, read_preference, codec_options,

test/test_collation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ def test_unacknowledged_write(self):
334334
collection.update_one(
335335
{'hello': 'world'}, {'$set': {'hello': 'moon'}},
336336
collation=self.collation)
337+
bulk = collection.initialize_ordered_bulk_op()
338+
bulk.find({'hello': 'world'}, collation=self.collation).update_one(
339+
{'$set': {'hello': 'moon'}})
340+
with self.assertRaises(ConfigurationError):
341+
bulk.execute()
337342

338343
@raisesConfigurationErrorForOldMongoDB
339344
def test_cursor_collation(self):

0 commit comments

Comments
 (0)