__init__.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright 2009-2015 MongoDB, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Python driver for MongoDB."""
  15. ASCENDING = 1
  16. """Ascending sort order."""
  17. DESCENDING = -1
  18. """Descending sort order."""
  19. GEO2D = "2d"
  20. """Index specifier for a 2-dimensional `geospatial index`_.
  21. .. _geospatial index: http://docs.mongodb.org/manual/core/2d/
  22. """
  23. GEOHAYSTACK = "geoHaystack"
  24. """Index specifier for a 2-dimensional `haystack index`_.
  25. .. versionadded:: 2.1
  26. .. _haystack index: http://docs.mongodb.org/manual/core/geohaystack/
  27. """
  28. GEOSPHERE = "2dsphere"
  29. """Index specifier for a `spherical geospatial index`_.
  30. .. versionadded:: 2.5
  31. .. note:: 2dsphere indexing requires server version **>= 2.4.0**.
  32. .. _spherical geospatial index: http://docs.mongodb.org/manual/core/2dsphere/
  33. """
  34. HASHED = "hashed"
  35. """Index specifier for a `hashed index`_.
  36. .. versionadded:: 2.5
  37. .. note:: hashed indexing requires server version **>= 2.4.0**.
  38. .. _hashed index: http://docs.mongodb.org/manual/core/index-hashed/
  39. """
  40. TEXT = "text"
  41. """Index specifier for a `text index`_.
  42. .. versionadded:: 2.7.1
  43. .. note:: text search requires server version **>= 2.4.0**.
  44. .. _text index: http://docs.mongodb.org/manual/core/index-text/
  45. """
  46. OFF = 0
  47. """No database profiling."""
  48. SLOW_ONLY = 1
  49. """Only profile slow operations."""
  50. ALL = 2
  51. """Profile all operations."""
  52. version_tuple = (3, 0, 2)
  53. def get_version_string():
  54. if isinstance(version_tuple[-1], str):
  55. return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
  56. return '.'.join(map(str, version_tuple))
  57. version = get_version_string()
  58. """Current version of PyMongo."""
  59. from pymongo.collection import ReturnDocument
  60. from pymongo.common import (MIN_SUPPORTED_WIRE_VERSION,
  61. MAX_SUPPORTED_WIRE_VERSION)
  62. from pymongo.cursor import CursorType
  63. from pymongo.mongo_client import MongoClient
  64. from pymongo.mongo_replica_set_client import MongoReplicaSetClient
  65. from pymongo.operations import (IndexModel,
  66. InsertOne,
  67. DeleteOne,
  68. DeleteMany,
  69. UpdateOne,
  70. UpdateMany,
  71. ReplaceOne)
  72. from pymongo.read_preferences import ReadPreference
  73. from pymongo.write_concern import WriteConcern
  74. def has_c():
  75. """Is the C extension installed?"""
  76. try:
  77. from pymongo import _cmessage
  78. return True
  79. except ImportError:
  80. return False