文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 9062d943 by 李景熙

添加虚拟环境中的扩展包

parent b94623d7
from flask import Flask
from flask_cors import CORS
from dao import Image
# from views.uploadDownload import uploadDownload
# from views.textAnnotation import textAnnotation
from views.user import user
from views.task import task
from views.slice import slice
from views.imageAnnotation import image
# from views.imageAnnotation import image
from config.config import DevelopmentConfig
......@@ -16,14 +14,14 @@ app = Flask(__name__)
CORS(app)
app.config.from_object(DevelopmentConfig)
Image.db.init_app(app)
# Image.db.init_app(app)
# app.register_blueprint(textAnnotation)
# app.register_blueprint(uploadDownload)
app.register_blueprint(user)
app.register_blueprint(task)
app.register_blueprint(slice)
app.register_blueprint(image)
# app.register_blueprint(image)
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=9100)
alabaster==0.7.11
anaconda-client==1.7.2
anaconda-navigator==1.9.2
anaconda-project==0.8.2
appdirs==1.4.3
asn1crypto==0.24.0
astroid==2.0.4
astropy==3.0.4
atomicwrites==1.2.1
attrs==18.2.0
Automat==0.7.0
Babel==2.6.0
backcall==0.1.0
backports.shutil-get-terminal-size==1.0.0
beautifulsoup4==4.6.3
bitarray==0.8.3
bkcharts==0.2
blaze==0.11.3
bleach==2.1.4
bokeh==0.13.0
boto==2.49.0
Bottleneck==1.2.1
certifi==2018.8.24
cffi==1.11.5
chardet==3.0.4
click==6.7
cloudpickle==0.5.5
clyent==1.2.2
colorama==0.3.9
comtypes==1.1.7
conda==4.5.11
conda-build==3.15.1
constantly==15.1.0
contextlib2==0.5.5
cryptography==2.3.1
cycler==0.10.0
Cython==0.28.5
cytoolz==0.9.0.1
dask==0.19.1
datashape==0.5.4
decorator==4.3.0
defusedxml==0.5.0
distributed==1.23.1
docutils==0.14
entrypoints==0.2.3
et-xmlfile==1.0.1
fastcache==1.0.2
filelock==3.0.8
Werkzeug==0.14.1
pymongo==3.9.0
Flask_Cors==3.0.8
Flask==1.0.2
Flask-Cors==3.0.8
flask-mongoengine==0.9.5
Flask-WTF==0.14.3
gevent==1.3.6
glob2==0.6
greenlet==0.4.15
h5py==2.8.0
heapdict==1.0.0
html5lib==1.0.1
hyperlink==18.0.0
idna==2.7
imageio==2.4.1
imagesize==1.1.0
importlib-metadata==0.23
incremental==17.5.0
ipykernel==4.10.0
ipython==6.5.0
ipython-genutils==0.2.0
ipywidgets==7.4.1
isort==4.3.4
itsdangerous==0.24
jdcal==1.4
jedi==0.12.1
Jinja2==2.10
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-core==4.4.0
jupyterlab==0.34.9
jupyterlab-launcher==0.13.1
Keras==2.2.4
Keras-Applications==1.0.7
Keras-Preprocessing==1.0.9
keyring==13.2.1
kiwisolver==1.0.1
lazy-object-proxy==1.3.1
llvmlite==0.24.0
locket==0.2.0
lxml==4.2.5
MarkupSafe==1.0
matplotlib==2.2.3
mccabe==0.6.1
menuinst==1.4.14
mistune==0.8.3
mkl-fft==1.0.4
mkl-random==1.0.1
mongoengine==0.20.0
more-itertools==4.3.0
mpmath==1.0.0
msgpack==0.5.6
multipledispatch==0.6.0
mysql==0.0.2
mysqlclient==1.4.6
navigator-updater==0.2.1
nbconvert==5.4.0
nbformat==4.4.0
networkx==2.1
nltk==3.3
nose==1.3.7
notebook==5.6.0
numba==0.39.0
numexpr==2.6.8
numpy==1.15.1
numpydoc==0.8.0
odo==0.5.1
olefile==0.46
opencv-contrib-python==4.1.0.25
opencv-python==4.1.0.25
openpyxl==2.5.6
packaging==17.1
pandas==0.23.4
pandocfilters==1.4.2
parso==0.3.1
partd==0.3.8
path.py==11.1.0
pathlib2==2.3.2
patsy==0.5.0
peewee==3.13.3
pep8==1.7.1
pickleshare==0.7.4
Pillow==5.2.0
pkginfo==1.4.2
pluggy==0.13.0
ply==3.11
prometheus-client==0.3.1
prompt-toolkit==1.0.15
psutil==5.4.7
py==1.6.0
pyasn1==0.4.4
pyasn1-modules==0.2.2
pycodestyle==2.4.0
pycosat==0.6.3
pycparser==2.18
pycrypto==2.6.1
pycurl==7.43.0.2
pyflakes==2.0.0
Pygments==2.2.0
pylint==2.1.1
pymongo==3.10.1
PyMySQL==0.9.3
pyodbc==4.0.24
pyOpenSSL==18.0.0
pyparsing==2.2.0
PySocks==1.6.8
pytest==5.2.2
pytest-arraydiff==0.2
pytest-astropy==0.4.0
pytest-doctestplus==0.1.3
pytest-openfiles==0.3.0
pytest-remotedata==0.3.0
python-dateutil==2.7.3
pytz==2018.5
PyWavelets==1.0.0
pywin32==223
pywinpty==0.5.4
PyYAML==3.13
pyzmq==17.1.2
QtAwesome==0.4.4
qtconsole==4.4.1
QtPy==1.5.0
requests==2.19.1
rope==0.11.0
ruamel-yaml==0.15.46
scikit-image==0.14.0
scikit-learn==0.19.2
scipy==1.1.0
seaborn==0.9.0
Send2Trash==1.5.0
service-identity==17.0.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.11.0
sklearn==0.0
snowballstemmer==1.2.1
sortedcollections==1.0.1
sortedcontainers==2.0.5
Sphinx==1.7.9
sphinxcontrib-websupport==1.1.0
spyder==3.3.1
spyder-kernels==0.2.6
SQLAlchemy==1.2.11
statsmodels==0.9.0
sympy==1.1.1
tables==3.4.4
tblib==1.3.2
terminado==0.8.1
testpath==0.3.1
toolz==0.9.0
tornado==5.1
tqdm==4.26.0
traitlets==4.3.2
Twisted==18.7.0
unicodecsv==0.14.1
urllib3==1.23
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.14.1
widgetsnbextension==3.4.1
win-inet-pton==1.0.1
win-unicode-console==0.5
wincertstore==0.2
wrapt==1.10.11
WTForms==2.3.1
xlrd==1.1.0
XlsxWriter==1.1.0
xlwings==0.11.8
xlwt==1.3.0
zict==0.1.3
zipp==0.6.0
zope.interface==4.5.0
dao==0.1.3
flask_mongoengine==0.9.5
......@@ -1166,7 +1166,7 @@ def decode_file_iter(file_obj, codec_options=DEFAULT_CODEC_OPTIONS):
elif len(size_data) != 4:
raise InvalidBSON("cut off in middle of objsize")
obj_size = _UNPACK_INT_FROM(size_data, 0)[0] - 4
elements = size_data + file_obj.read(max(0, obj_size))
elements = size_data + file_obj.read(obj_size)
yield _bson_to_dict(elements, codec_options)
......
......@@ -699,7 +699,7 @@ def _parse_canonical_decimal128(doc):
def _parse_canonical_minkey(doc):
"""Decode a JSON MinKey to bson.min_key.MinKey."""
if type(doc['$minKey']) is not int or doc['$minKey'] != 1:
if doc['$minKey'] is not 1:
raise TypeError('$minKey value must be 1: %s' % (doc,))
if len(doc) != 1:
raise TypeError('Bad $minKey, extra field(s): %s' % (doc,))
......@@ -708,7 +708,7 @@ def _parse_canonical_minkey(doc):
def _parse_canonical_maxkey(doc):
"""Decode a JSON MaxKey to bson.max_key.MaxKey."""
if type(doc['$maxKey']) is not int or doc['$maxKey'] != 1:
if doc['$maxKey'] is not 1:
raise TypeError('$maxKey value must be 1: %s', (doc,))
if len(doc) != 1:
raise TypeError('Bad $minKey, extra field(s): %s' % (doc,))
......
......@@ -45,8 +45,7 @@ class RawBSONDocument(abc.Mapping):
class from the standard library so it can be used like a read-only
``dict``::
>>> from bson import encode
>>> raw_doc = RawBSONDocument(encode({'_id': 'my_doc'}))
>>> raw_doc = RawBSONDocument(BSON.encode({'_id': 'my_doc'}))
>>> raw_doc.raw
b'...'
>>> raw_doc['_id']
......
Metadata-Version: 2.1
Name: pymongo
Version: 3.10.1
Summary: Python driver for MongoDB <http://www.mongodb.org>
Home-page: http://github.com/mongodb/mongo-python-driver
Author: Mike Dirolf
Author-email: mongodb-user@googlegroups.com
Maintainer: Bernie Hackett
Maintainer-email: bernie@mongodb.com
License: Apache License, Version 2.0
Keywords: mongo,mongodb,pymongo,gridfs,bson
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Database
Requires-Python: >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*
Provides-Extra: encryption
Requires-Dist: pymongocrypt (<2.0.0) ; extra == 'encryption'
Provides-Extra: gssapi
Requires-Dist: winkerberos (>=0.5.0) ; extra == 'gssapi'
Provides-Extra: snappy
Requires-Dist: python-snappy ; extra == 'snappy'
Provides-Extra: srv
Requires-Dist: dnspython (<2.0.0,>=1.16.0) ; extra == 'srv'
Provides-Extra: tls
Provides-Extra: zstd
Requires-Dist: zstandard ; extra == 'zstd'
=======
PyMongo
=======
:Info: See `the mongo site <http://www.mongodb.org>`_ for more information. See `GitHub <http://github.com/mongodb/mongo-python-driver>`_ for the latest source.
:Author: Mike Dirolf
:Maintainer: Bernie Hackett <bernie@mongodb.com>
About
=====
The PyMongo distribution contains tools for interacting with MongoDB
database from Python. The ``bson`` package is an implementation of
the `BSON format <http://bsonspec.org>`_ for Python. The ``pymongo``
package is a native Python driver for MongoDB. The ``gridfs`` package
is a `gridfs
<http://www.mongodb.org/display/DOCS/GridFS+Specification>`_
implementation on top of ``pymongo``.
PyMongo supports MongoDB 2.6, 3.0, 3.2, 3.4, 3.6, 4.0 and 4.2.
Support / Feedback
==================
For issues with, questions about, or feedback for PyMongo, please look into
our `support channels <http://www.mongodb.org/about/support>`_. Please
do not email any of the PyMongo developers directly with issues or
questions - you're more likely to get an answer on the `mongodb-user
<http://groups.google.com/group/mongodb-user>`_ list on Google Groups.
Bugs / Feature Requests
=======================
Think you’ve found a bug? Want to see a new feature in PyMongo? Please open a
case in our issue management tool, JIRA:
- `Create an account and login <https://jira.mongodb.org>`_.
- Navigate to `the PYTHON project <https://jira.mongodb.org/browse/PYTHON>`_.
- Click **Create Issue** - Please provide as much information as possible about the issue type and how to reproduce it.
Bug reports in JIRA for all driver projects (i.e. PYTHON, CSHARP, JAVA) and the
Core Server (i.e. SERVER) project are **public**.
How To Ask For Help
-------------------
Please include all of the following information when opening an issue:
- Detailed steps to reproduce the problem, including full traceback, if possible.
- The exact python version used, with patch level::
$ python -c "import sys; print(sys.version)"
- The exact version of PyMongo used, with patch level::
$ python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
- The operating system and version (e.g. Windows 7, OSX 10.8, ...)
- Web framework or asynchronous network library used, if any, with version (e.g.
Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, ...)
Security Vulnerabilities
------------------------
If you’ve identified a security vulnerability in a driver or any other
MongoDB project, please report it according to the `instructions here
<http://docs.mongodb.org/manual/tutorial/create-a-vulnerability-report>`_.
Installation
============
PyMongo can be installed with `pip <http://pypi.python.org/pypi/pip>`_::
$ python -m pip install pymongo
Or ``easy_install`` from
`setuptools <http://pypi.python.org/pypi/setuptools>`_::
$ python -m easy_install pymongo
You can also download the project source and do::
$ python setup.py install
Do **not** install the "bson" package from pypi. PyMongo comes with its own
bson package; doing "easy_install bson" installs a third-party package that
is incompatible with PyMongo.
Dependencies
============
PyMongo supports CPython 2.7, 3.4+, PyPy, and PyPy3.5+.
Optional dependencies:
GSSAPI authentication requires `pykerberos
<https://pypi.python.org/pypi/pykerberos>`_ on Unix or `WinKerberos
<https://pypi.python.org/pypi/winkerberos>`_ on Windows. The correct
dependency can be installed automatically along with PyMongo::
$ python -m pip install pymongo[gssapi]
Support for mongodb+srv:// URIs requires `dnspython
<https://pypi.python.org/pypi/dnspython>`_::
$ python -m pip install pymongo[srv]
TLS / SSL support may require `ipaddress
<https://pypi.python.org/pypi/ipaddress>`_ and `certifi
<https://pypi.python.org/pypi/certifi>`_ or `wincertstore
<https://pypi.python.org/pypi/wincertstore>`_ depending on the Python
version in use. The necessary dependencies can be installed along with
PyMongo::
$ python -m pip install pymongo[tls]
Wire protocol compression with snappy requires `python-snappy
<https://pypi.org/project/python-snappy>`_::
$ python -m pip install pymongo[snappy]
Wire protocol compression with zstandard requires `zstandard
<https://pypi.org/project/zstandard>`_::
$ python -m pip install pymongo[zstd]
You can install all dependencies automatically with the following
command::
$ python -m pip install pymongo[snappy,gssapi,srv,tls,zstd]
Other optional packages:
- `backports.pbkdf2 <https://pypi.python.org/pypi/backports.pbkdf2/>`_,
improves authentication performance with SCRAM-SHA-1 and SCRAM-SHA-256.
It especially improves performance on Python versions older than 2.7.8.
- `monotonic <https://pypi.python.org/pypi/monotonic>`_ adds support for
a monotonic clock, which improves reliability in environments
where clock adjustments are frequent. Not needed in Python 3.
Additional dependencies are:
- (to generate documentation) sphinx_
Examples
========
Here's a basic example (for more see the *examples* section of the docs):
.. code-block:: python
>>> import pymongo
>>> client = pymongo.MongoClient("localhost", 27017)
>>> db = client.test
>>> db.name
u'test'
>>> db.my_collection
Collection(Database(MongoClient('localhost', 27017), u'test'), u'my_collection')
>>> db.my_collection.insert_one({"x": 10}).inserted_id
ObjectId('4aba15ebe23f6b53b0000000')
>>> db.my_collection.insert_one({"x": 8}).inserted_id
ObjectId('4aba160ee23f6b543e000000')
>>> db.my_collection.insert_one({"x": 11}).inserted_id
ObjectId('4aba160ee23f6b543e000002')
>>> db.my_collection.find_one()
{u'x': 10, u'_id': ObjectId('4aba15ebe23f6b53b0000000')}
>>> for item in db.my_collection.find():
... print(item["x"])
...
10
8
11
>>> db.my_collection.create_index("x")
u'x_1'
>>> for item in db.my_collection.find().sort("x", pymongo.ASCENDING):
... print(item["x"])
...
8
10
11
>>> [item["x"] for item in db.my_collection.find().limit(2).skip(1)]
[8, 11]
Documentation
=============
You will need sphinx_ installed to generate the
documentation. Documentation can be generated by running **python
setup.py doc**. Generated documentation can be found in the
*doc/build/html/* directory.
Testing
=======
The easiest way to run the tests is to run **python setup.py test** in
the root of the distribution.
To verify that PyMongo works with Gevent's monkey-patching::
$ python green_framework_test.py gevent
Or with Eventlet's::
$ python green_framework_test.py eventlet
.. _sphinx: http://sphinx.pocoo.org/
bson/__init__.py,sha256=5xqacbKZHNfKAiySoQsFj4Mo9AKTZO6GAANvBeAIu34,47285
bson/__pycache__/__init__.cpython-37.pyc,,
bson/__pycache__/binary.cpython-37.pyc,,
bson/__pycache__/code.cpython-37.pyc,,
bson/__pycache__/codec_options.cpython-37.pyc,,
bson/__pycache__/dbref.cpython-37.pyc,,
bson/__pycache__/decimal128.cpython-37.pyc,,
bson/__pycache__/errors.cpython-37.pyc,,
bson/__pycache__/int64.cpython-37.pyc,,
bson/__pycache__/json_util.cpython-37.pyc,,
bson/__pycache__/max_key.cpython-37.pyc,,
bson/__pycache__/min_key.cpython-37.pyc,,
bson/__pycache__/objectid.cpython-37.pyc,,
bson/__pycache__/py3compat.cpython-37.pyc,,
bson/__pycache__/raw_bson.cpython-37.pyc,,
bson/__pycache__/regex.cpython-37.pyc,,
bson/__pycache__/son.cpython-37.pyc,,
bson/__pycache__/timestamp.cpython-37.pyc,,
bson/__pycache__/tz_util.cpython-37.pyc,,
bson/_cbson.cp37-win_amd64.pyd,sha256=Yp96Gcndc0cgTHiYbRiUeMe5rRn02uR9anbxOMjlYoE,48640
bson/binary.py,sha256=tC2DzxoelhAAG8dHrAdx8MpLJ1wlL7KUZ4xY_724e-I,7622
bson/code.py,sha256=r6OQiapnnDvJ4HZpsZvTjmMy0IqlJ7m-W8g3VQYDPnI,3459
bson/codec_options.py,sha256=uzVAwWRjqNOZz_0SnBi5IlkfMpeqF2QvJZwBcWe_NRI,14086
bson/dbref.py,sha256=4BEbZtHn2p4_sGtK8U4pT7_17O8sk_UsjXQCT1Jw9m8,4868
bson/decimal128.py,sha256=RcaGAuRIaWpETCEuYiWqyUxC1R1eCdWnZu0GfcDQ73g,10760
bson/errors.py,sha256=3Pp69tFW2bXYi9eqYNQQKtNeRgUEtpW11CLeqSOYcHQ,1199
bson/int64.py,sha256=x-NwoJQ36q_ZyPkyMhMoO1T5m1dRPwFl4DKRH5bwAbY,1090
bson/json_util.py,sha256=9j_EqVsYmpyL39Fgfh5A1zndMCyXv_vk8vw7ICauA-4,32624
bson/max_key.py,sha256=UPWMD4jdkXlLQoRl3qDkrNGQbxnYXEt3v4f6Zgru5bI,1365
bson/min_key.py,sha256=ysRVvPVwMbXtvySt9UyhRs_4dZyUjnDD_hnDjhdOm-Q,1365
bson/objectid.py,sha256=AeWq30bD5ewdBiPjjbuuaMealmrDA2lAud-nbdbyWZU,9676
bson/py3compat.py,sha256=MsjRWGVjmguupgigUHUvYemqRupv7rcLAawCK0RJSss,2922
bson/raw_bson.py,sha256=XZZJoP0ELOvkp2WtTCKXsrZZ_qugiu9GjTceEk6hTrw,5213
bson/regex.py,sha256=b4E8DZSEnQkGyIHbkBrm7KJgpkbkBSrnKkyr04IWlrs,4419
bson/son.py,sha256=hiwu5C5jEGnr9DxUoe0W2l2ydZApp3H0k9fe4lxJlCw,5988
bson/timestamp.py,sha256=PtAJ6v7twqsaXrg0rKTm8QKW6V7WgaYt_PpKhV6PA2w,4052
bson/tz_util.py,sha256=2ifof8DjW0JMSvh8l6eu4HLQjryOeWRyE1cSQsa1S3Q,1570
gridfs/__init__.py,sha256=jSyl3NKQeeR4ioNXr2evn4r5KeNUzZ-rK6Nh0TMeC6w,37250
gridfs/__pycache__/__init__.cpython-37.pyc,,
gridfs/__pycache__/errors.cpython-37.pyc,,
gridfs/__pycache__/grid_file.cpython-37.pyc,,
gridfs/errors.py,sha256=bBZgvRigvMACEZ7t-3rTLJHRkn4BArdxoTQJspTF-es,1089
gridfs/grid_file.py,sha256=WM3bKzcw-pVVBKL7B5LAo9gVh1DZxg7vSR_entvHtsQ,31323
pymongo-3.10.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
pymongo-3.10.1.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
pymongo-3.10.1.dist-info/METADATA,sha256=_esVlkZ8c2z-KS3IcZHf3ASBA8kMOTAKQnwq5XodFsw,8315
pymongo-3.10.1.dist-info/RECORD,,
pymongo-3.10.1.dist-info/WHEEL,sha256=uaZe_9gV-4T_d4AskuIQkCgcY8wMc0UXsVFnf0_mBGs,106
pymongo-3.10.1.dist-info/top_level.txt,sha256=OinVojDdOfo1Dsp-NRfrZdp6gcJJ4bPRq61vSg5vyAs,20
pymongo/__init__.py,sha256=ouHRDewvY_IWhvnoDnbOh9jQE1JdQW4GllzhmMJ7kAI,2921
pymongo/__pycache__/__init__.cpython-37.pyc,,
pymongo/__pycache__/aggregation.cpython-37.pyc,,
pymongo/__pycache__/auth.cpython-37.pyc,,
pymongo/__pycache__/bulk.cpython-37.pyc,,
pymongo/__pycache__/change_stream.cpython-37.pyc,,
pymongo/__pycache__/client_options.cpython-37.pyc,,
pymongo/__pycache__/client_session.cpython-37.pyc,,
pymongo/__pycache__/collation.cpython-37.pyc,,
pymongo/__pycache__/collection.cpython-37.pyc,,
pymongo/__pycache__/command_cursor.cpython-37.pyc,,
pymongo/__pycache__/common.cpython-37.pyc,,
pymongo/__pycache__/compression_support.cpython-37.pyc,,
pymongo/__pycache__/cursor.cpython-37.pyc,,
pymongo/__pycache__/cursor_manager.cpython-37.pyc,,
pymongo/__pycache__/daemon.cpython-37.pyc,,
pymongo/__pycache__/database.cpython-37.pyc,,
pymongo/__pycache__/driver_info.cpython-37.pyc,,
pymongo/__pycache__/encryption.cpython-37.pyc,,
pymongo/__pycache__/encryption_options.cpython-37.pyc,,
pymongo/__pycache__/errors.cpython-37.pyc,,
pymongo/__pycache__/helpers.cpython-37.pyc,,
pymongo/__pycache__/ismaster.cpython-37.pyc,,
pymongo/__pycache__/max_staleness_selectors.cpython-37.pyc,,
pymongo/__pycache__/message.cpython-37.pyc,,
pymongo/__pycache__/mongo_client.cpython-37.pyc,,
pymongo/__pycache__/mongo_replica_set_client.cpython-37.pyc,,
pymongo/__pycache__/monitor.cpython-37.pyc,,
pymongo/__pycache__/monitoring.cpython-37.pyc,,
pymongo/__pycache__/monotonic.cpython-37.pyc,,
pymongo/__pycache__/network.cpython-37.pyc,,
pymongo/__pycache__/operations.cpython-37.pyc,,
pymongo/__pycache__/periodic_executor.cpython-37.pyc,,
pymongo/__pycache__/pool.cpython-37.pyc,,
pymongo/__pycache__/read_concern.cpython-37.pyc,,
pymongo/__pycache__/read_preferences.cpython-37.pyc,,
pymongo/__pycache__/response.cpython-37.pyc,,
pymongo/__pycache__/results.cpython-37.pyc,,
pymongo/__pycache__/saslprep.cpython-37.pyc,,
pymongo/__pycache__/server.cpython-37.pyc,,
pymongo/__pycache__/server_description.cpython-37.pyc,,
pymongo/__pycache__/server_selectors.cpython-37.pyc,,
pymongo/__pycache__/server_type.cpython-37.pyc,,
pymongo/__pycache__/settings.cpython-37.pyc,,
pymongo/__pycache__/son_manipulator.cpython-37.pyc,,
pymongo/__pycache__/srv_resolver.cpython-37.pyc,,
pymongo/__pycache__/ssl_context.cpython-37.pyc,,
pymongo/__pycache__/ssl_match_hostname.cpython-37.pyc,,
pymongo/__pycache__/ssl_support.cpython-37.pyc,,
pymongo/__pycache__/thread_util.cpython-37.pyc,,
pymongo/__pycache__/topology.cpython-37.pyc,,
pymongo/__pycache__/topology_description.cpython-37.pyc,,
pymongo/__pycache__/uri_parser.cpython-37.pyc,,
pymongo/__pycache__/write_concern.cpython-37.pyc,,
pymongo/_cmessage.cp37-win_amd64.pyd,sha256=UrF3MZsUTMqWcbQKumhLsJgRPvqPw6iB9I4x36dI-6U,32256
pymongo/aggregation.py,sha256=jSF4mwYm4Yb8I5_FFq6xwHeB3-1DAlVAWZQ-TyEmMV8,9031
pymongo/auth.py,sha256=UBiMiwcT9hZJLPYybtNEMxJJAX_C7C7DHa7CBcE65M8,21116
pymongo/bulk.py,sha256=wSW4ZReZtf3x5DaW0kWtIxCOwOjdrBtlu_afaPopI0s,27024
pymongo/change_stream.py,sha256=84fU4jECeABG-NCtbDC4BDKwg8t6MuQOoeM4wv1Ev14,14867
pymongo/client_options.py,sha256=1f1tjDckxIx_DbEv91HTNkJfBThFzrNXc2raXuhOnfc,9476
pymongo/client_session.py,sha256=HX8MX_Qj1FSAWWzm2TSSAv5QzFd4vU3rQD2uTtrXCWw,36797
pymongo/collation.py,sha256=D95kqcQcDE5K6z3L8triKtOPrigiNnbG1Fo1mTVQGDg,8033
pymongo/collection.py,sha256=oaErkEY5Z2s72hvNvupVKsWPfoaBdb8ihrYO1ZKMLKM,147454
pymongo/command_cursor.py,sha256=NhrVlvu7WHjKsTDc23RmYnTvpJUNj1ZM1dkjORt8f4M,11293
pymongo/common.py,sha256=iNvOz3jyNj3Tlv-pKmwwZWRAK_ggVYHJJ3swEHOjr3s,32884
pymongo/compression_support.py,sha256=1MiC3XTTn5M31Wj2KOWzCiqjQrxqzdeQ4mu67AACaQ4,5327
pymongo/cursor.py,sha256=cwEjS9BS1hopU7MVENZX9-sRrA2Jc9IVNKNpemZCrFM,48197
pymongo/cursor_manager.py,sha256=85mWMZUriuiW_vTfZ4bNCBGEF8mMVLJ_kbatgqqTNok,2153
pymongo/daemon.py,sha256=aEJziwmmGdFNRTyzoMaSSC6c2qY4t-D367_iujErONM,5608
pymongo/database.py,sha256=wWXPxucjtGLYnojLyjeAPyYJ4A702kUCxp-E-Kf0HL4,67484
pymongo/driver_info.py,sha256=zP3jcwvbJvleNdYaSOn9ggN9j_xJh9Z94Zz9U7AkYC0,1742
pymongo/encryption.py,sha256=Nv-URzfp49GA-iBhC-lfF_u-C2GLoqVXeWQkeInlzVg,20498
pymongo/encryption_options.py,sha256=rTLCEzJac0aLXOfOhE0WhVNNkyEq3O0yWSKiQHnxQ-k,7005
pymongo/errors.py,sha256=0tqjXMOFo0XsaukmYXeiQ5NjWnC9II_0AgMtZBm9JFQ,8733
pymongo/helpers.py,sha256=FzFqmqnpMoPqHst7qXcOcHURI8J7sOfCJt8Wg5cW4RU,10340
pymongo/ismaster.py,sha256=hBBR9elx9iYzX4PdJyziM0wT7O5_9UeMD2quyhFg4hE,4685
pymongo/max_staleness_selectors.py,sha256=-Z3KnpxyBWCzx6qUr0SRXBuBK5FrX3UdPCeMeTxyIEc,4442
pymongo/message.py,sha256=6RAwNHbQXRx4opRu5gmqiaV1cg4sJv8lDkgpBmhgQ9E,61340
pymongo/mongo_client.py,sha256=4lyo0wLUQHfsKvzA20xCJkeMGf8syNgxejwdpZA23ng,101432
pymongo/mongo_replica_set_client.py,sha256=POeQvlzc3BfveSZZyZ-SePnucCMAhiM3IFkzvPn6qfk,2003
pymongo/monitor.py,sha256=IvB9Ymy--Uny6h56QvudS404zvTUsnL7mmohKoT47K0,9599
pymongo/monitoring.py,sha256=VOB9eAxaq6QQ4E6ilLtjAuvRnyAS_C_y-gsqRsAeRkE,52108
pymongo/monotonic.py,sha256=6zp9vYFIdaBLndPVGL-9ooj9bOEtwMavbY-ruf5FT5I,1138
pymongo/network.py,sha256=EF2Rz7askar8yVor53hyAnsY3kvRo-Y4PGRJev8qbz8,12668
pymongo/operations.py,sha256=s1Fq1FwdG7Ar6jU_MrC4-z1GFd2PCtC4a0R6n5KuV1Q,14346
pymongo/periodic_executor.py,sha256=1NH3TN7H0YG7l-OaC3fMORM0NgOrvOzNsN5D5V6twmc,5796
pymongo/pool.py,sha256=DjlreomU74hTYyLr2pgr3b1f_xjppvGDUEFXMLmQ_NU,51627
pymongo/read_concern.py,sha256=5CmBOEjt4eKiP_CgD2GUs7z5c4klZ5Fx82uPjZjk4Oc,2413
pymongo/read_preferences.py,sha256=0UQOh6Hd5m03qew_Y38MF0Q97BPgFT5pwQ15wWgdCHM,16965
pymongo/response.py,sha256=XeH3e3AMv6NlPOJxXjlLxZobvdPote-jgvvWCUdG6tc,3750
pymongo/results.py,sha256=BM2AddU2uH4eDch30j1dbRExFiw7jB6FU3qsj93E7Ng,8044
pymongo/saslprep.py,sha256=UDjbHKyhRvv1L5A1T0fYmMdHQCFwFS115pdkTZFpFKk,4383
pymongo/server.py,sha256=TOjpT-Mzm3_E3eVgirxErsmzkD-IYNi1pPoQzj8Rjt0,8352
pymongo/server_description.py,sha256=CcySxIcBf7tUV_aIYoMOVMfyvAMP-O_Yq5ZnxqyNrBs,6546
pymongo/server_selectors.py,sha256=gZbZRmc97ji2PrmMykolHVWlfAG9xwX0Ir3TDOqcTtA,5463
pymongo/server_type.py,sha256=F_g0RNrLdT6qJMl2GcPIpujtZO9xJRu2Eyuxq1xby2I,905
pymongo/settings.py,sha256=_br8f6KoYlwGXGXAvCSTUOBD2_Bn0QT3r3TdYIYdejM,4339
pymongo/son_manipulator.py,sha256=oj3oTbRIifb3UPg8MhNceEswFqEKMkHu0tDeR5n-IBw,6890
pymongo/srv_resolver.py,sha256=ie66pFAJ06YnqjFETbNXtqiFKRR2qjZ84SJ0wU-hPJU,3793
pymongo/ssl_context.py,sha256=eyt7ac-JDr6_j2zX7_3vTfeehHHHWoxN5XWR39aPwd8,3766
pymongo/ssl_match_hostname.py,sha256=3DBC1Sjqr4pL6IB8pFYGfPx8-QUrspWN48cEXWGoa8U,4812
pymongo/ssl_support.py,sha256=CTBKd9hX9Z5F3CBjrwO_gtDPTzPSOcdqiuG7o8uhlBw,8514
pymongo/thread_util.py,sha256=hzXLvVGGs_aS_jJwM9cxcY_aDG8mvU89jiFFGerKoPs,4090
pymongo/topology.py,sha256=scN0n_nfYkwZPXYI-uPb11EBdgft0JNR80-1hxZp-jI,28501
pymongo/topology_description.py,sha256=KyupeAdq_aXb-V08YCQiLWPAPG13UaCkFCDZbILeVSU,22607
pymongo/uri_parser.py,sha256=QfB4yPZiG0q_Fbci-6QtbdPh9RUcMGPeWQ69UZ7BWYU,18586
pymongo/write_concern.py,sha256=z2NZ-lqzzaNzhJ5m4UUDT7pmpCeLhJhWC0npKidSfu8,5126
Wheel-Version: 1.0
Generator: bdist_wheel (0.33.6)
Root-Is-Purelib: false
Tag: cp37-cp37m-win_amd64
......@@ -64,7 +64,7 @@ SLOW_ONLY = 1
ALL = 2
"""Profile all operations."""
version_tuple = (3, 10, 1)
version_tuple = (3, 9, 0)
def get_version_string():
if isinstance(version_tuple[-1], str):
......
......@@ -95,7 +95,6 @@ Classes
"""
import collections
import os
import sys
import uuid
......@@ -268,7 +267,7 @@ class _TransactionContext(object):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if self.__session.in_transaction:
if self.__session._in_transaction:
if exc_val is None:
self.__session.commit_transaction()
else:
......@@ -357,7 +356,7 @@ class ClientSession(object):
def _end_session(self, lock):
if self._server_session is not None:
try:
if self.in_transaction:
if self._in_transaction:
self.abort_transaction()
finally:
self._client._return_server_session(self._server_session, lock)
......@@ -506,7 +505,7 @@ class ClientSession(object):
try:
ret = callback(self)
except Exception as exc:
if self.in_transaction:
if self._in_transaction:
self.abort_transaction()
if (isinstance(exc, PyMongoError) and
exc.has_error_label("TransientTransactionError") and
......@@ -515,7 +514,8 @@ class ClientSession(object):
continue
raise
if not self.in_transaction:
if self._transaction.state in (
_TxnState.NONE, _TxnState.COMMITTED, _TxnState.ABORTED):
# Assume callback intentionally ended the transaction.
return ret
......@@ -551,7 +551,7 @@ class ClientSession(object):
"""
self._check_ended()
if self.in_transaction:
if self._in_transaction:
raise InvalidOperation("Transaction already in progress")
read_concern = self._inherit_option("read_concern", read_concern)
......@@ -589,7 +589,7 @@ class ClientSession(object):
"Cannot call commitTransaction after calling abortTransaction")
elif state is _TxnState.COMMITTED:
# We're explicitly retrying the commit, move the state back to
# "in progress" so that in_transaction returns true.
# "in progress" so that _in_transaction returns true.
self._transaction.state = _TxnState.IN_PROGRESS
retry = True
......@@ -750,7 +750,7 @@ class ClientSession(object):
"""Process a response to a command that was run with this session."""
self._advance_cluster_time(reply.get('$clusterTime'))
self._advance_operation_time(reply.get('operationTime'))
if self.in_transaction and self._transaction.sharded:
if self._in_transaction and self._transaction.sharded:
recovery_token = reply.get('recoveryToken')
if recovery_token:
self._transaction.recovery_token = recovery_token
......@@ -761,11 +761,8 @@ class ClientSession(object):
return self._server_session is None
@property
def in_transaction(self):
"""True if this session has an active multi-statement transaction.
.. versionadded:: 3.10
"""
def _in_transaction(self):
"""True if this session has an active multi-statement transaction."""
return self._transaction.active()
@property
......@@ -786,7 +783,7 @@ class ClientSession(object):
def _txn_read_preference(self):
"""Return read preference of this transaction or None."""
if self.in_transaction:
if self._in_transaction:
return self._transaction.opts.read_preference
return None
......@@ -796,14 +793,14 @@ class ClientSession(object):
self._server_session.last_use = monotonic.time()
command['lsid'] = self._server_session.session_id
if not self.in_transaction:
if not self._in_transaction:
self._transaction.reset()
if is_retryable:
command['txnNumber'] = self._server_session.transaction_id
return
if self.in_transaction:
if self._in_transaction:
if read_preference != ReadPreference.PRIMARY:
raise InvalidOperation(
'read preference in a transaction must be primary, not: '
......@@ -835,13 +832,12 @@ class ClientSession(object):
class _ServerSession(object):
def __init__(self, pool_id):
def __init__(self):
# Ensure id is type 4, regardless of CodecOptions.uuid_representation.
self.session_id = {'id': Binary(uuid.uuid4().bytes, 4)}
self.last_use = monotonic.time()
self._transaction_id = 0
self.dirty = False
self.pool_id = pool_id
def mark_dirty(self):
"""Mark this session as dirty.
......@@ -871,14 +867,6 @@ class _ServerSessionPool(collections.deque):
This class is not thread-safe, access it while holding the Topology lock.
"""
def __init__(self, *args, **kwargs):
super(_ServerSessionPool, self).__init__(*args, **kwargs)
self.pool_id = 0
def reset(self):
self.pool_id += 1
self.clear()
def pop_all(self):
ids = []
while self:
......@@ -899,7 +887,7 @@ class _ServerSessionPool(collections.deque):
if not s.timed_out(session_timeout_minutes):
return s
return _ServerSession(self.pool_id)
return _ServerSession()
def return_server_session(self, server_session, session_timeout_minutes):
self._clear_stale(session_timeout_minutes)
......@@ -907,9 +895,7 @@ class _ServerSessionPool(collections.deque):
self.return_server_session_no_lock(server_session)
def return_server_session_no_lock(self, server_session):
# Discard sessions from an old pool to avoid duplicate sessions in the
# child process after a fork.
if server_session.pool_id == self.pool_id and not server_session.dirty:
if not server_session.dirty:
self.appendleft(server_session)
def _clear_stale(self, session_timeout_minutes):
......
......@@ -824,7 +824,7 @@ class BaseObject(object):
"""Read only access to the write concern of this instance or session.
"""
# Override this operation's write concern with the transaction's.
if session and session.in_transaction:
if session and session._in_transaction:
return DEFAULT_WRITE_CONCERN
return self.write_concern
......
# Copyright 2019-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Support for spawning a daemon process.
PyMongo only attempts to spawn the mongocryptd daemon process when automatic
client-side field level encryption is enabled. See
:ref:`automatic-client-side-encryption` for more info.
"""
import os
import subprocess
import sys
import time
# The maximum amount of time to wait for the intermediate subprocess.
_WAIT_TIMEOUT = 10
_THIS_FILE = os.path.realpath(__file__)
if sys.version_info[0] < 3:
def _popen_wait(popen, timeout):
"""Implement wait timeout support for Python 2."""
from pymongo.monotonic import time as _time
deadline = _time() + timeout
# Initial delay of 1ms
delay = .0005
while True:
returncode = popen.poll()
if returncode is not None:
return returncode
remaining = deadline - _time()
if remaining <= 0:
# Just return None instead of raising an error.
return None
delay = min(delay * 2, remaining, .5)
time.sleep(delay)
else:
def _popen_wait(popen, timeout):
"""Implement wait timeout support for Python 3."""
try:
return popen.wait(timeout=timeout)
except subprocess.TimeoutExpired:
# Silence TimeoutExpired errors.
return None
def _silence_resource_warning(popen):
"""Silence Popen's ResourceWarning.
Note this should only be used if the process was created as a daemon.
"""
# Set the returncode to avoid this warning when popen is garbage collected:
# "ResourceWarning: subprocess XXX is still running".
# See https://bugs.python.org/issue38890 and
# https://bugs.python.org/issue26741.
popen.returncode = 0
if sys.platform == 'win32':
# On Windows we spawn the daemon process simply by using DETACHED_PROCESS.
_DETACHED_PROCESS = getattr(subprocess, 'DETACHED_PROCESS', 0x00000008)
def _spawn_daemon(args):
"""Spawn a daemon process (Windows)."""
with open(os.devnull, 'r+b') as devnull:
popen = subprocess.Popen(
args,
creationflags=_DETACHED_PROCESS,
stdin=devnull, stderr=devnull, stdout=devnull)
_silence_resource_warning(popen)
else:
# On Unix we spawn the daemon process with a double Popen.
# 1) The first Popen runs this file as a Python script using the current
# interpreter.
# 2) The script then decouples itself and performs the second Popen to
# spawn the daemon process.
# 3) The original process waits up to 10 seconds for the script to exit.
#
# Note that we do not call fork() directly because we want this procedure
# to be safe to call from any thread. Using Popen instead of fork also
# avoids triggering the application's os.register_at_fork() callbacks when
# we spawn the mongocryptd daemon process.
def _spawn(args):
"""Spawn the process and silence stdout/stderr."""
with open(os.devnull, 'r+b') as devnull:
return subprocess.Popen(
args,
close_fds=True,
stdin=devnull, stderr=devnull, stdout=devnull)
def _spawn_daemon_double_popen(args):
"""Spawn a daemon process using a double subprocess.Popen."""
spawner_args = [sys.executable, _THIS_FILE]
spawner_args.extend(args)
temp_proc = subprocess.Popen(spawner_args, close_fds=True)
# Reap the intermediate child process to avoid creating zombie
# processes.
_popen_wait(temp_proc, _WAIT_TIMEOUT)
def _spawn_daemon(args):
"""Spawn a daemon process (Unix)."""
# "If Python is unable to retrieve the real path to its executable,
# sys.executable will be an empty string or None".
if sys.executable:
_spawn_daemon_double_popen(args)
else:
# Fallback to spawn a non-daemon process without silencing the
# resource warning. We do not use fork here because it is not
# safe to call from a thread on all systems.
# Unfortunately, this means that:
# 1) If the parent application is killed via Ctrl-C, the
# non-daemon process will also be killed.
# 2) Each non-daemon process will hang around as a zombie process
# until the main application exits.
_spawn(args)
if __name__ == '__main__':
# Attempt to start a new session to decouple from the parent.
if hasattr(os, 'setsid'):
try:
os.setsid()
except OSError:
pass
# We are performing a double fork (Popen) to spawn the process as a
# daemon so it is safe to ignore the resource warning.
_silence_resource_warning(_spawn(sys.argv[1:]))
os._exit(0)
......@@ -823,7 +823,7 @@ class Database(common.BaseObject):
For example, to list all non-system collections::
filter = {"name": {"$regex": r"^(?!system\\.)"}}
filter = {"name": {"$regex": r"^(?!system\.)"}}
db.list_collection_names(filter=filter)
:Parameters:
......
......@@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Support for explicit client-side field level encryption."""
"""Support for explicit client side encryption.
**Support for client side encryption is in beta. Backwards-breaking changes
may be made before the final release.**
"""
import contextlib
import os
import subprocess
import uuid
import weakref
......@@ -31,7 +34,7 @@ except ImportError:
_HAVE_PYMONGOCRYPT = False
MongoCryptCallback = object
from bson import _dict_to_bson, decode, encode
from bson import _bson_to_dict, _dict_to_bson, decode, encode
from bson.codec_options import CodecOptions
from bson.binary import (Binary,
STANDARD,
......@@ -46,13 +49,14 @@ from pymongo.errors import (ConfigurationError,
EncryptionError,
InvalidOperation,
ServerSelectionTimeoutError)
from pymongo.message import (_COMMAND_OVERHEAD,
_MAX_ENC_BSON_SIZE,
_raise_document_too_large)
from pymongo.mongo_client import MongoClient
from pymongo.pool import _configured_socket, PoolOptions
from pymongo.read_concern import ReadConcern
from pymongo.ssl_support import get_ssl_context
from pymongo.uri_parser import parse_host
from pymongo.write_concern import WriteConcern
from pymongo.daemon import _spawn_daemon
_HTTPS_PORT = 443
......@@ -106,12 +110,11 @@ class _EncryptionIO(MongoCryptCallback):
"""
endpoint = kms_context.endpoint
message = kms_context.message
host, port = parse_host(endpoint, _HTTPS_PORT)
ctx = get_ssl_context(None, None, None, None, None, None, True)
opts = PoolOptions(connect_timeout=_KMS_CONNECT_TIMEOUT,
socket_timeout=_KMS_CONNECT_TIMEOUT,
ssl_context=ctx)
conn = _configured_socket((host, port), opts)
conn = _configured_socket((endpoint, _HTTPS_PORT), opts)
try:
conn.sendall(message)
while kms_context.bytes_needed > 0:
......@@ -147,7 +150,7 @@ class _EncryptionIO(MongoCryptCallback):
self._spawned = True
args = [self.opts._mongocryptd_spawn_path or 'mongocryptd']
args.extend(self.opts._mongocryptd_spawn_args)
_spawn_daemon(args)
subprocess.Popen(args)
def mark_command(self, database, cmd):
"""Mark a command for encryption.
......@@ -199,13 +202,13 @@ class _EncryptionIO(MongoCryptCallback):
:Returns:
The _id of the inserted data key document.
"""
raw_doc = RawBSONDocument(data_key)
data_key_id = raw_doc.get('_id')
if not isinstance(data_key_id, uuid.UUID):
raise TypeError('data_key _id must be a UUID')
self.key_vault_coll.insert_one(raw_doc)
return Binary(data_key_id.bytes, subtype=UUID_SUBTYPE)
# insert does not return the inserted _id when given a RawBSONDocument.
doc = _bson_to_dict(data_key, _DATA_KEY_OPTS)
if not isinstance(doc.get('_id'), uuid.UUID):
raise TypeError(
'data_key _id must be a bson.binary.Binary with subtype 4')
res = self.key_vault_coll.insert_one(doc)
return Binary(res.inserted_id.bytes, subtype=UUID_SUBTYPE)
def bson_encode(self, doc):
"""Encode a document to BSON.
......@@ -269,6 +272,10 @@ class _Encrypter(object):
# check_keys.
cluster_time = check_keys and cmd.pop('$clusterTime', None)
encoded_cmd = _dict_to_bson(cmd, check_keys, codec_options)
max_cmd_size = _MAX_ENC_BSON_SIZE + _COMMAND_OVERHEAD
if len(encoded_cmd) > max_cmd_size:
raise _raise_document_too_large(
next(iter(cmd)), len(encoded_cmd), max_cmd_size)
with _wrap_encryption_errors():
encrypted_cmd = self._auto_encrypter.encrypt(database, encoded_cmd)
# TODO: PYTHON-1922 avoid decoding the encrypted_cmd.
......@@ -333,11 +340,11 @@ class Algorithm(object):
class ClientEncryption(object):
"""Explicit client-side field level encryption."""
"""Explicit client side encryption."""
def __init__(self, kms_providers, key_vault_namespace, key_vault_client,
codec_options):
"""Explicit client-side field level encryption.
"""Explicit client side encryption.
The ClientEncryption class encapsulates explicit operations on a key
vault collection that cannot be done directly on a MongoClient. Similar
......@@ -348,7 +355,8 @@ class ClientEncryption(object):
creating data keys. It does not provide an API to query keys from the
key vault collection, as this can be done directly on the MongoClient.
See :ref:`explicit-client-side-encryption` for an example.
.. note:: Support for client side encryption is in beta.
Backwards-breaking changes may be made before the final release.
:Parameters:
- `kms_providers`: Map of KMS provider options. Two KMS providers
......@@ -371,18 +379,15 @@ class ClientEncryption(object):
containing the `key_vault_namespace` collection.
- `codec_options`: An instance of
:class:`~bson.codec_options.CodecOptions` to use when encoding a
value for encryption and decoding the decrypted BSON value. This
should be the same CodecOptions instance configured on the
MongoClient, Database, or Collection used to access application
data.
value for encryption and decoding the decrypted BSON value.
.. versionadded:: 3.9
"""
if not _HAVE_PYMONGOCRYPT:
raise ConfigurationError(
"client-side field level encryption requires the pymongocrypt "
"library: install a compatible version with: "
"python -m pip install 'pymongo[encryption]'")
"client side encryption requires the pymongocrypt library: "
"install a compatible version with: "
"python -m pip install pymongo['encryption']")
if not isinstance(codec_options, CodecOptions):
raise TypeError("codec_options must be an instance of "
......@@ -407,17 +412,15 @@ class ClientEncryption(object):
:Parameters:
- `kms_provider`: The KMS provider to use. Supported values are
"aws" and "local".
- `master_key`: Identifies a KMS-specific key used to encrypt the
new data key. If the kmsProvider is "local" the `master_key` is
not applicable and may be omitted. If the `kms_provider` is "aws"
it is required and has the following fields::
- `region` (string): Required. The AWS region, e.g. "us-east-1".
- `key` (string): Required. The Amazon Resource Name (ARN) to
the AWS customer.
- `endpoint` (string): Optional. An alternate host to send KMS
requests to. May include port number, e.g.
"kms.us-east-1.amazonaws.com:443".
- `master_key`: The `master_key` identifies a KMS-specific key used
to encrypt the new data key. If the kmsProvider is "local" the
`master_key` is not applicable and may be omitted.
If the `kms_provider` is "aws", `master_key` is required and must
have the following fields:
- `region` (string): The AWS region as a string.
- `key` (string): The Amazon Resource Name (ARN) to the AWS
customer master key (CMK).
- `key_alt_names` (optional): An optional list of string alternate
names used to reference a key. If a key is created with alternate
......@@ -431,9 +434,7 @@ class ClientEncryption(object):
algorithm=Algorithm.Random)
:Returns:
The ``_id`` of the created data key document as a
:class:`~bson.binary.Binary` with subtype
:data:`~bson.binary.UUID_SUBTYPE`.
The ``_id`` of the created data key document.
"""
self._check_closed()
with _wrap_encryption_errors():
......
......@@ -12,7 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Support for automatic client-side field level encryption."""
"""Support for automatic client side encryption.
**Support for client side encryption is in beta. Backwards-breaking changes
may be made before the final release.**
"""
import copy
......@@ -26,7 +30,7 @@ from pymongo.errors import ConfigurationError
class AutoEncryptionOpts(object):
"""Options to configure automatic client-side field level encryption."""
"""Options to configure automatic encryption."""
def __init__(self, kms_providers, key_vault_namespace,
key_vault_client=None, schema_map=None,
......@@ -35,21 +39,21 @@ class AutoEncryptionOpts(object):
mongocryptd_bypass_spawn=False,
mongocryptd_spawn_path='mongocryptd',
mongocryptd_spawn_args=None):
"""Options to configure automatic client-side field level encryption.
"""Options to configure automatic encryption.
Automatic client-side field level encryption requires MongoDB 4.2
enterprise or a MongoDB 4.2 Atlas cluster. Automatic encryption is not
Automatic encryption is an enterprise only feature that only
applies to operations on a collection. Automatic encryption is not
supported for operations on a database or view and will result in
error.
error. To bypass automatic encryption (but enable automatic
decryption), set ``bypass_auto_encryption=True`` in
AutoEncryptionOpts.
Although automatic encryption requires MongoDB 4.2 enterprise or a
MongoDB 4.2 Atlas cluster, automatic *decryption* is supported for all
users. To configure automatic *decryption* without automatic
*encryption* set ``bypass_auto_encryption=True``. Explicit
encryption and explicit decryption is also supported for all users
with the :class:`~pymongo.encryption.ClientEncryption` class.
Explicit encryption/decryption and automatic decryption is a
community feature. A MongoClient configured with
bypassAutoEncryption=true will still automatically decrypt.
See :ref:`automatic-client-side-encryption` for an example.
.. note:: Support for client side encryption is in beta.
Backwards-breaking changes may be made before the final release.
:Parameters:
- `kms_providers`: Map of KMS provider options. Two KMS providers
......@@ -111,7 +115,7 @@ class AutoEncryptionOpts(object):
raise ConfigurationError(
"client side encryption requires the pymongocrypt library: "
"install a compatible version with: "
"python -m pip install 'pymongo[encryption]'")
"python -m pip install pymongo['encryption']")
self._kms_providers = kms_providers
self._key_vault_namespace = key_vault_namespace
......
......@@ -46,16 +46,10 @@ class PyMongoError(Exception):
"""Remove the given label from this error."""
self._error_labels.remove(label)
if sys.version_info[0] == 2:
def __str__(self):
if isinstance(self._message, unicode):
return self._message.encode('utf-8', errors='replace')
return str(self._message)
def __unicode__(self):
if isinstance(self._message, unicode):
return self._message
return unicode(self._message, 'utf-8', errors='replace')
def __str__(self):
if sys.version_info[0] == 2 and isinstance(self._message, unicode):
return self._message.encode('utf-8', errors='replace')
return str(self._message)
class ProtocolError(PyMongoError):
......
......@@ -26,8 +26,6 @@ import struct
import bson
from bson import (CodecOptions,
decode,
encode,
_dict_to_bson,
_make_c_string)
from bson.codec_options import DEFAULT_CODEC_OPTIONS
......@@ -205,7 +203,7 @@ def _gen_find_command(coll, spec, projection, skip, limit, batch_size, options,
cmd['singleBatch'] = True
if batch_size:
cmd['batchSize'] = batch_size
if read_concern.level and not (session and session.in_transaction):
if read_concern.level and not (session and session._in_transaction):
cmd['readConcern'] = read_concern.document
if collation:
cmd['collation'] = collation
......@@ -304,7 +302,7 @@ class _Query(object):
# Explain does not support readConcern.
if (not explain and session.options.causal_consistency
and session.operation_time is not None
and not session.in_transaction):
and not session._in_transaction):
cmd.setdefault(
'readConcern', {})[
'afterClusterTime'] = session.operation_time
......@@ -422,7 +420,7 @@ class _GetMore(object):
spec = self.as_command(sock_info)[0]
if sock_info.op_msg_enabled:
request_id, msg, size, _ = _op_msg(
0, spec, self.db, None,
0, spec, self.db, ReadPreference.PRIMARY,
False, False, self.codec_options,
ctx=sock_info.compression_context)
return request_id, msg, size
......@@ -685,8 +683,7 @@ def _op_msg(flags, command, dbname, read_preference, slave_ok, check_keys,
opts, ctx=None):
"""Get a OP_MSG message."""
command['$db'] = dbname
# getMore commands do not send $readPreference.
if read_preference is not None and "$readPreference" not in command:
if "$readPreference" not in command:
if slave_ok and not read_preference.mode:
command["$readPreference"] = (
ReadPreference.PRIMARY_PREFERRED.document)
......@@ -923,9 +920,6 @@ class _BulkWriteContext(object):
@property
def max_message_size(self):
"""A proxy for SockInfo.max_message_size."""
if self.compress:
# Subtract 16 bytes for the message header.
return self.sock_info.max_message_size - 16
return self.sock_info.max_message_size
@property
......@@ -933,11 +927,6 @@ class _BulkWriteContext(object):
"""A proxy for SockInfo.max_write_batch_size."""
return self.sock_info.max_write_batch_size
@property
def max_split_size(self):
"""The maximum size of a BSON command before batch splitting."""
return self.max_bson_size
def legacy_bulk_insert(
self, request_id, msg, max_doc_size, acknowledged, docs, compress):
if compress:
......@@ -1020,11 +1009,10 @@ class _BulkWriteContext(object):
request_id, self.sock_info.address, self.op_id)
# From the Client Side Encryption spec:
# Because automatic encryption increases the size of commands, the driver
# MUST split bulk writes at a reduced size limit before undergoing automatic
# encryption. The write payload MUST be split at 2MiB (2097152).
_MAX_SPLIT_SIZE_ENC = 2097152
# 2MiB
_MAX_ENC_BSON_SIZE = 2 * (1024 * 1024)
# 6MB
_MAX_ENC_MESSAGE_SIZE = 6 * (1000 * 1000)
class _EncryptedBulkWriteContext(_BulkWriteContext):
......@@ -1059,9 +1047,14 @@ class _EncryptedBulkWriteContext(_BulkWriteContext):
return to_send
@property
def max_split_size(self):
"""Reduce the batch splitting size."""
return _MAX_SPLIT_SIZE_ENC
def max_bson_size(self):
"""A proxy for SockInfo.max_bson_size."""
return min(self.sock_info.max_bson_size, _MAX_ENC_BSON_SIZE)
@property
def max_message_size(self):
"""A proxy for SockInfo.max_message_size."""
return min(self.sock_info.max_message_size, _MAX_ENC_MESSAGE_SIZE)
def _raise_document_too_large(operation, doc_size, max_size):
......@@ -1393,7 +1386,6 @@ def _batched_write_command_impl(
# Max BSON object size + 16k - 2 bytes for ending NUL bytes.
# Server guarantees there is enough room: SERVER-10643.
max_cmd_size = max_bson_size + _COMMAND_OVERHEAD
max_split_size = ctx.max_split_size
# No options
buf.write(_ZERO_32)
......@@ -1405,7 +1397,7 @@ def _batched_write_command_impl(
# Where to write command document length
command_start = buf.tell()
buf.write(encode(command))
buf.write(bson.BSON.encode(command))
# Start of payload
buf.seek(-1, 2)
......@@ -1426,17 +1418,16 @@ def _batched_write_command_impl(
for doc in docs:
# Encode the current operation
key = b(str(idx))
value = encode(doc, check_keys, opts)
value = bson.BSON.encode(doc, check_keys, opts)
# Is there enough room to add this document? max_cmd_size accounts for
# the two trailing null bytes.
doc_too_large = len(value) > max_cmd_size
enough_data = (buf.tell() + len(key) + len(value)) >= max_cmd_size
enough_documents = (idx >= max_write_batch_size)
if doc_too_large:
write_op = list(_FIELD_MAP.keys())[operation]
_raise_document_too_large(
write_op, len(value), max_bson_size)
enough_data = (idx >= 1 and
(buf.tell() + len(key) + len(value)) >= max_split_size)
enough_documents = (idx >= max_write_batch_size)
if enough_data or enough_documents:
break
buf.write(_BSONOBJ)
......
......@@ -481,8 +481,9 @@ class MongoClient(common.BaseObject):
- `auto_encryption_opts`: A
:class:`~pymongo.encryption_options.AutoEncryptionOpts` which
configures this client to automatically encrypt collection commands
and automatically decrypt results. See
:ref:`automatic-client-side-encryption` for an example.
and automatically decrypt results. **Support for client side
encryption is in beta. Backwards-breaking changes may be made
before the final release.**
.. mongodoc:: connections
......@@ -1165,10 +1166,10 @@ class MongoClient(common.BaseObject):
session_ids = self._topology.pop_all_sessions()
if session_ids:
self._end_sessions(session_ids)
# Stop the periodic task thread and then send pending killCursor
# requests before closing the topology.
# Stop the periodic task thread and then run _process_periodic_tasks
# to send pending killCursor requests before closing the topology.
self._kill_cursors_executor.close()
self._process_kill_cursors()
self._process_periodic_tasks()
self._topology.close()
if self._encrypter:
# TODO: PYTHON-1921 Encrypted MongoClients cannot be re-opened.
......@@ -1254,7 +1255,7 @@ class MongoClient(common.BaseObject):
# Pin this session to the selected server if it's performing a
# sharded transaction.
if server.description.mongos and (session and
session.in_transaction):
session._in_transaction):
session._pin_mongos(server)
return server
except PyMongoError as exc:
......@@ -1354,7 +1355,7 @@ class MongoClient(common.BaseObject):
Re-raises any exception thrown by func().
"""
retryable = (retryable and self.retry_writes
and session and not session.in_transaction)
and session and not session._in_transaction)
last_error = None
retrying = False
......@@ -1444,7 +1445,7 @@ class MongoClient(common.BaseObject):
"""
retryable = (retryable and
self.retry_reads
and not (session and session.in_transaction))
and not (session and session._in_transaction))
last_error = None
retrying = False
......@@ -1717,8 +1718,10 @@ class MongoClient(common.BaseObject):
duration, reply, 'killCursors', request_id,
tuple(address))
def _process_kill_cursors(self):
"""Process any pending kill cursors requests."""
# This method is run periodically by a background thread.
def _process_periodic_tasks(self):
"""Process any pending kill cursors requests and
maintain connection pool parameters."""
address_to_cursor_ids = defaultdict(list)
# Other threads or the GC may append to the queue concurrently.
......@@ -1739,12 +1742,6 @@ class MongoClient(common.BaseObject):
cursor_ids, address, topology, session=None)
except Exception:
helpers._handle_exception()
# This method is run periodically by a background thread.
def _process_periodic_tasks(self):
"""Process any pending kill cursors requests and
maintain connection pool parameters."""
self._process_kill_cursors()
try:
self._topology.update_pool()
except Exception:
......
......@@ -98,7 +98,7 @@ def command(sock, dbname, spec, slave_ok, is_mongos,
orig = spec
if is_mongos and not use_op_msg:
spec = message._maybe_add_read_preference(spec, read_preference)
if read_concern and not (session and session.in_transaction):
if read_concern and not (session and session._in_transaction):
if read_concern.level:
spec['readConcern'] = read_concern.document
if (session and session.options.causal_consistency
......
......@@ -1033,19 +1033,14 @@ class Pool:
def close(self):
self._reset(close=True)
def remove_stale_sockets(self, reference_pool_id):
"""Removes stale sockets then adds new ones if pool is too small and
has not been reset. The `reference_pool_id` argument specifies the
`pool_id` at the point in time this operation was requested on the
pool.
"""
def remove_stale_sockets(self):
"""Removes stale sockets then adds new ones if pool is too small."""
if self.opts.max_idle_time_seconds is not None:
with self.lock:
while (self.sockets and
self.sockets[-1].idle_time_seconds() > self.opts.max_idle_time_seconds):
sock_info = self.sockets.pop()
sock_info.close_socket(ConnectionClosedReason.IDLE)
while True:
with self.lock:
if (len(self.sockets) + self.active_sockets >=
......@@ -1059,11 +1054,6 @@ class Pool:
try:
sock_info = self.connect()
with self.lock:
# Close connection and return if the pool was reset during
# socket creation or while acquiring the pool lock.
if self.pool_id != reference_pool_id:
sock_info.close_socket(ConnectionClosedReason.STALE)
break
self.sockets.appendleft(sock_info)
finally:
self._socket_semaphore.release()
......
......@@ -156,10 +156,6 @@ class Topology(object):
"after forking. See PyMongo's documentation for details: "
"http://api.mongodb.org/python/current/faq.html#"
"is-pymongo-fork-safe")
with self._lock:
# Reset the session pool to avoid duplicate sessions in
# the child process.
self._session_pool.reset()
with self._lock:
self._ensure_opened()
......@@ -429,13 +425,9 @@ class Topology(object):
def update_pool(self):
# Remove any stale sockets and add new sockets if pool is too small.
servers = []
with self._lock:
for server in self._servers.values():
servers.append((server, server._pool.pool_id))
for server, pool_id in servers:
server._pool.remove_stale_sockets(pool_id)
server._pool.remove_stale_sockets()
def close(self):
"""Clear pools and terminate monitors. Topology reopens on demand."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment