autonomous-app 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. autonomous/__init__.py +1 -1
  2. autonomous/ai/audioagent.py +1 -1
  3. autonomous/ai/imageagent.py +1 -1
  4. autonomous/ai/jsonagent.py +1 -1
  5. autonomous/ai/models/openai.py +81 -53
  6. autonomous/ai/oaiagent.py +1 -14
  7. autonomous/ai/textagent.py +1 -1
  8. autonomous/auth/autoauth.py +10 -10
  9. autonomous/auth/user.py +17 -2
  10. autonomous/db/__init__.py +42 -0
  11. autonomous/db/base/__init__.py +33 -0
  12. autonomous/db/base/common.py +62 -0
  13. autonomous/db/base/datastructures.py +476 -0
  14. autonomous/db/base/document.py +1230 -0
  15. autonomous/db/base/fields.py +767 -0
  16. autonomous/db/base/metaclasses.py +468 -0
  17. autonomous/db/base/utils.py +22 -0
  18. autonomous/db/common.py +79 -0
  19. autonomous/db/connection.py +472 -0
  20. autonomous/db/context_managers.py +313 -0
  21. autonomous/db/dereference.py +291 -0
  22. autonomous/db/document.py +1141 -0
  23. autonomous/db/errors.py +165 -0
  24. autonomous/db/fields.py +2732 -0
  25. autonomous/db/mongodb_support.py +24 -0
  26. autonomous/db/pymongo_support.py +80 -0
  27. autonomous/db/queryset/__init__.py +28 -0
  28. autonomous/db/queryset/base.py +2033 -0
  29. autonomous/db/queryset/field_list.py +88 -0
  30. autonomous/db/queryset/manager.py +58 -0
  31. autonomous/db/queryset/queryset.py +189 -0
  32. autonomous/db/queryset/transform.py +527 -0
  33. autonomous/db/queryset/visitor.py +189 -0
  34. autonomous/db/signals.py +59 -0
  35. autonomous/logger.py +3 -0
  36. autonomous/model/autoattr.py +56 -41
  37. autonomous/model/automodel.py +95 -34
  38. autonomous/storage/imagestorage.py +49 -8
  39. {autonomous_app-0.3.0.dist-info → autonomous_app-0.3.2.dist-info}/METADATA +2 -2
  40. autonomous_app-0.3.2.dist-info/RECORD +60 -0
  41. {autonomous_app-0.3.0.dist-info → autonomous_app-0.3.2.dist-info}/WHEEL +1 -1
  42. autonomous_app-0.3.0.dist-info/RECORD +0 -35
  43. {autonomous_app-0.3.0.dist-info → autonomous_app-0.3.2.dist-info}/LICENSE +0 -0
  44. {autonomous_app-0.3.0.dist-info → autonomous_app-0.3.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,24 @@
1
+ """
2
+ Helper functions, constants, and types to aid with MongoDB version support
3
+ """
4
+
5
+ from autonomous.db.connection import get_connection
6
+
7
+ # Constant that can be used to compare the version retrieved with
8
+ # get_mongodb_version()
9
+ MONGODB_34 = (3, 4)
10
+ MONGODB_36 = (3, 6)
11
+ MONGODB_42 = (4, 2)
12
+ MONGODB_44 = (4, 4)
13
+ MONGODB_50 = (5, 0)
14
+ MONGODB_60 = (6, 0)
15
+ MONGODB_70 = (7, 0)
16
+
17
+
18
+ def get_mongodb_version():
19
+ """Return the version of the default connected mongoDB (first 2 digits)
20
+
21
+ :return: tuple(int, int)
22
+ """
23
+ version_list = get_connection().server_info()["versionArray"][:2] # e.g: (3, 2)
24
+ return tuple(version_list)
@@ -0,0 +1,80 @@
1
+ """
2
+ Helper functions, constants, and types to aid with PyMongo support.
3
+ """
4
+
5
+ import pymongo
6
+ from bson import binary, json_util
7
+ from pymongo.errors import OperationFailure
8
+
9
+ PYMONGO_VERSION = tuple(pymongo.version_tuple[:2])
10
+
11
+ # This will be changed to UuidRepresentation.UNSPECIFIED in a future
12
+ # (breaking) release.
13
+ if PYMONGO_VERSION >= (4,):
14
+ LEGACY_JSON_OPTIONS = json_util.LEGACY_JSON_OPTIONS.with_options(
15
+ uuid_representation=binary.UuidRepresentation.PYTHON_LEGACY,
16
+ )
17
+ else:
18
+ LEGACY_JSON_OPTIONS = json_util.DEFAULT_JSON_OPTIONS
19
+
20
+
21
+ def count_documents(
22
+ collection, filter, skip=None, limit=None, hint=None, collation=None
23
+ ):
24
+ """Pymongo>3.7 deprecates count in favour of count_documents"""
25
+ if limit == 0:
26
+ return 0 # Pymongo raises an OperationFailure if called with limit=0
27
+
28
+ kwargs = {}
29
+ if skip is not None:
30
+ kwargs["skip"] = skip
31
+ if limit is not None:
32
+ kwargs["limit"] = limit
33
+ if hint not in (-1, None):
34
+ kwargs["hint"] = hint
35
+ if collation is not None:
36
+ kwargs["collation"] = collation
37
+
38
+ # count_documents appeared in pymongo 3.7
39
+ if PYMONGO_VERSION >= (3, 7):
40
+ try:
41
+ if not filter and set(kwargs) <= {"max_time_ms"}:
42
+ # when no filter is provided, estimated_document_count
43
+ # is a lot faster as it uses the collection metadata
44
+ return collection.estimated_document_count(**kwargs)
45
+ else:
46
+ return collection.count_documents(filter=filter, **kwargs)
47
+ except OperationFailure as err:
48
+ if PYMONGO_VERSION >= (4,):
49
+ raise
50
+
51
+ # OperationFailure - accounts for some operators that used to work
52
+ # with .count but are no longer working with count_documents (i.e $geoNear, $near, and $nearSphere)
53
+ # fallback to deprecated Cursor.count
54
+ # Keeping this should be reevaluated the day pymongo removes .count entirely
55
+ if (
56
+ "$geoNear, $near, and $nearSphere are not allowed in this context"
57
+ not in str(err)
58
+ and "$where is not allowed in this context" not in str(err)
59
+ ):
60
+ raise
61
+
62
+ cursor = collection.find(filter)
63
+ for option, option_value in kwargs.items():
64
+ cursor_method = getattr(cursor, option)
65
+ cursor = cursor_method(option_value)
66
+ with_limit_and_skip = "skip" in kwargs or "limit" in kwargs
67
+ return cursor.count(with_limit_and_skip=with_limit_and_skip)
68
+
69
+
70
+ def list_collection_names(db, include_system_collections=False):
71
+ """Pymongo>3.7 deprecates collection_names in favour of list_collection_names"""
72
+ if PYMONGO_VERSION >= (3, 7):
73
+ collections = db.list_collection_names()
74
+ else:
75
+ collections = db.collection_names()
76
+
77
+ if not include_system_collections:
78
+ collections = [c for c in collections if not c.startswith("system.")]
79
+
80
+ return collections
@@ -0,0 +1,28 @@
1
+ from autonomous.db.errors import *
2
+ from autonomous.db.queryset.field_list import *
3
+ from autonomous.db.queryset.manager import *
4
+ from autonomous.db.queryset.queryset import *
5
+ from autonomous.db.queryset.transform import *
6
+ from autonomous.db.queryset.visitor import *
7
+
8
+ # Expose just the public subset of all imported objects and constants.
9
+ __all__ = (
10
+ "QuerySet",
11
+ "QuerySetNoCache",
12
+ "Q",
13
+ "queryset_manager",
14
+ "QuerySetManager",
15
+ "QueryFieldList",
16
+ "DO_NOTHING",
17
+ "NULLIFY",
18
+ "CASCADE",
19
+ "DENY",
20
+ "PULL",
21
+ # Errors that might be related to a queryset, mostly here for backward
22
+ # compatibility
23
+ "DoesNotExist",
24
+ "InvalidQueryError",
25
+ "MultipleObjectsReturned",
26
+ "NotUniqueError",
27
+ "OperationError",
28
+ )