Skip to content

Commit 18ed903

Browse files
committed
PYTHON-2046 Cleanup docs
1 parent e953f24 commit 18ed903

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

bson/json_util.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
This module provides two helper methods `dumps` and `loads` that wrap the
1818
native :mod:`json` methods and provide explicit BSON conversion to and from
1919
JSON. :class:`~bson.json_util.JSONOptions` provides a way to control how JSON
20-
is emitted and parsed, with the default being the legacy PyMongo format.
21-
:mod:`~bson.json_util` can also generate Canonical or Relaxed `Extended JSON`_
22-
when :const:`CANONICAL_JSON_OPTIONS` or :const:`RELAXED_JSON_OPTIONS` is
20+
is emitted and parsed, with the default being the Relaxed Extended JSON format.
21+
:mod:`~bson.json_util` can also generate Canonical or legacy `Extended JSON`_
22+
when :const:`CANONICAL_JSON_OPTIONS` or :const:`LEGACY_JSON_OPTIONS` is
2323
provided, respectively.
2424
2525
.. _Extended JSON: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst
@@ -32,17 +32,17 @@
3232
>>> loads('[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$scope": {}, "$code": "function x() { return 1; }"}}, {"bin": {"$type": "80", "$binary": "AQIDBA=="}}]')
3333
[{'foo': [1, 2]}, {'bar': {'hello': 'world'}}, {'code': Code('function x() { return 1; }', {})}, {'bin': Binary(b'...', 128)}]
3434
35-
Example usage (serialization):
35+
Example usage with :const:`RELAXED_JSON_OPTIONS` (the default):
3636
3737
.. doctest::
3838
3939
>>> from bson import Binary, Code
4040
>>> from bson.json_util import dumps
4141
>>> dumps([{'foo': [1, 2]},
4242
... {'bar': {'hello': 'world'}},
43-
... {'code': Code("function x() { return 1; }", {})},
43+
... {'code': Code("function x() { return 1; }")},
4444
... {'bin': Binary(b"\x01\x02\x03\x04")}])
45-
'[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }", "$scope": {}}}, {"bin": {"$binary": "AQIDBA==", "$type": "00"}}]'
45+
'[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }"}}, {"bin": {"$binary": {"base64": "AQIDBA==", "subType": "00"}}}]'
4646
4747
Example usage (with :const:`CANONICAL_JSON_OPTIONS`):
4848
@@ -57,18 +57,18 @@
5757
... json_options=CANONICAL_JSON_OPTIONS)
5858
'[{"foo": [{"$numberInt": "1"}, {"$numberInt": "2"}]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }"}}, {"bin": {"$binary": {"base64": "AQIDBA==", "subType": "00"}}}]'
5959
60-
Example usage (with :const:`RELAXED_JSON_OPTIONS`):
60+
Example usage (with :const:`LEGACY_JSON_OPTIONS`):
6161
6262
.. doctest::
6363
6464
>>> from bson import Binary, Code
65-
>>> from bson.json_util import dumps, RELAXED_JSON_OPTIONS
65+
>>> from bson.json_util import dumps, LEGACY_JSON_OPTIONS
6666
>>> dumps([{'foo': [1, 2]},
6767
... {'bar': {'hello': 'world'}},
68-
... {'code': Code("function x() { return 1; }")},
68+
... {'code': Code("function x() { return 1; }", {})},
6969
... {'bin': Binary(b"\x01\x02\x03\x04")}],
70-
... json_options=RELAXED_JSON_OPTIONS)
71-
'[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }"}}, {"bin": {"$binary": {"base64": "AQIDBA==", "subType": "00"}}}]'
70+
... json_options=LEGACY_JSON_OPTIONS)
71+
'[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }", "$scope": {}}}, {"bin": {"$binary": "AQIDBA==", "$type": "00"}}]'
7272
7373
Alternatively, you can manually pass the `default` to :func:`json.dumps`.
7474
It won't handle :class:`~bson.binary.Binary` and :class:`~bson.code.Code`

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ Breaking Changes in 4.0
101101
- Removed :const:`bson.json_util.STRICT_JSON_OPTIONS`. Use
102102
:const:`~bson.json_util.RELAXED_JSON_OPTIONS` or
103103
:const:`~bson.json_util.CANONICAL_JSON_OPTIONS` instead.
104+
- Changed the default JSON encoding representation from legacy to relaxed.
105+
The json_mode parameter for :const:`bson.json_util.dumps` now defaults to
106+
:const:`~bson.json_util.RELAXED_JSON_OPTIONS`.
104107
- The "tls" install extra is no longer necessary or supported and will be
105108
ignored by pip.
106109

doc/migrate-to-pymongo3.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ modifier. Code like this::
124124
# Set a 5 second select() timeout.
125125
>>> cursor = collection.find({"a": 1}, network_timeout=5)
126126

127-
can be changed to this with PyMongo 2.9 or later:
128-
129-
.. doctest::
127+
can be changed to this with PyMongo 2.9 or later::
130128

131129
# Set a 5 second (5000 millisecond) server side query timeout.
132130
>>> cursor = collection.find({"a": 1}, modifiers={"$maxTimeMS": 5000})

doc/migrate-to-pymongo4.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,13 @@ can be changed to this::
662662
uu = uuid.uuid4()
663663
uuid_legacy = Binary.from_uuid(uu, PYTHON_LEGACY)
664664

665+
Default JSONMode changed from LEGACY to RELAXED
666+
-----------------------------------------------
667+
668+
Changed the default JSON encoding representation from legacy to relaxed.
669+
The json_mode parameter for :const:`bson.json_util.dumps` now defaults to
670+
:const:`~bson.json_util.RELAXED_JSON_OPTIONS`.
671+
665672
Removed features with no migration path
666673
---------------------------------------
667674

gridfs/grid_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def seekable(self):
658658
def __iter__(self):
659659
"""Return an iterator over all of this file's data.
660660
661-
The iterator will return lines (delimited by b'\n') of
661+
The iterator will return lines (delimited by ``b'\\n'``) of
662662
:class:`bytes`. This can be useful when serving files
663663
using a webserver that handles such an iterator efficiently.
664664

0 commit comments

Comments
 (0)