SitongGong commited on
Commit
7158c40
·
verified ·
1 Parent(s): d49bf65

merge code dirs 1031 (part 12)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +15 -0
  2. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/INSTALLER +1 -0
  3. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/METADATA +39 -0
  4. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/RECORD +531 -0
  5. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/REQUESTED +0 -0
  6. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/WHEEL +5 -0
  7. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/entry_points.txt +3 -0
  8. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/licenses/LICENSE +24 -0
  9. Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/top_level.txt +1 -0
  10. Video-RSI/.venv/lib/python3.12/site-packages/distutils-precedence.pth +3 -0
  11. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/INSTALLER +1 -0
  12. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/METADATA +27 -0
  13. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/RECORD +26 -0
  14. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/REQUESTED +0 -0
  15. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/WHEEL +6 -0
  16. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/top_level.txt +1 -0
  17. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/__init__.py +19 -0
  18. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/_version.py +17 -0
  19. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/builder.py +858 -0
  20. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/compat.py +91 -0
  21. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/encode.py +45 -0
  22. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/flexbuffers.py +1592 -0
  23. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/number_types.py +182 -0
  24. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/packer.py +41 -0
  25. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/table.py +148 -0
  26. Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/util.py +47 -0
  27. Video-RSI/.venv/lib/python3.12/site-packages/google/_upb/_message.abi3.so +3 -0
  28. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/__init__.py +10 -0
  29. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/any.py +52 -0
  30. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/any_pb2.py +37 -0
  31. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/api_pb2.py +47 -0
  32. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/compiler/__init__.py +0 -0
  33. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/compiler/plugin_pb2.py +46 -0
  34. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor.py +1669 -0
  35. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor_database.py +186 -0
  36. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor_pb2.py +0 -0
  37. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor_pool.py +1468 -0
  38. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/duration.py +100 -0
  39. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/duration_pb2.py +37 -0
  40. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/empty_pb2.py +37 -0
  41. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/field_mask_pb2.py +37 -0
  42. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/__init__.py +6 -0
  43. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/api_implementation.py +143 -0
  44. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/builder.py +123 -0
  45. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/containers.py +826 -0
  46. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/decoder.py +1127 -0
  47. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/encoder.py +931 -0
  48. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/enum_type_wrapper.py +128 -0
  49. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/extension_dict.py +209 -0
  50. Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/field_mask.py +352 -0
.gitattributes CHANGED
@@ -214,3 +214,18 @@ Video-RSI/.venv/lib/python3.12/site-packages/charset_normalizer/md.cpython-312-x
214
  Video-RSI/.venv/lib/python3.12/site-packages/cv2/cv2.abi3.so filter=lfs diff=lfs merge=lfs -text
215
  Video-RSI/.venv/lib/python3.12/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
216
  Video-RSI/.venv/lib/python3.12/site-packages/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  Video-RSI/.venv/lib/python3.12/site-packages/cv2/cv2.abi3.so filter=lfs diff=lfs merge=lfs -text
215
  Video-RSI/.venv/lib/python3.12/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
216
  Video-RSI/.venv/lib/python3.12/site-packages/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
217
+ Video-RSI/.venv/lib/python3.12/site-packages/google/_upb/_message.abi3.so filter=lfs diff=lfs merge=lfs -text
218
+ Video-RSI/.venv/lib/python3.12/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux-x86_64-v7.0.2 filter=lfs diff=lfs merge=lfs -text
219
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/_core/_multiarray_tests.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
220
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/_core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
221
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/_core/_simd.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
222
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/fft/_pocketfft_umath.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
223
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/linalg/_umath_linalg.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
224
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/_bounded_integers.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
225
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/_common.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
226
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/_generator.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
227
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/_mt19937.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
228
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/_pcg64.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
229
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/_philox.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
230
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/bit_generator.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
231
+ Video-RSI/.venv/lib/python3.12/site-packages/numpy/random/mtrand.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/METADATA ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: debugpy
3
+ Version: 1.8.22
4
+ Summary: An implementation of the Debug Adapter Protocol for Python
5
+ Home-page: https://aka.ms/debugpy
6
+ Author: Microsoft Corporation
7
+ Author-email: ptvshelp@microsoft.com
8
+ License: MIT
9
+ Project-URL: Source, https://github.com/microsoft/debugpy
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
17
+ Classifier: Topic :: Software Development :: Debuggers
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: Operating System :: MacOS
20
+ Classifier: Operating System :: POSIX
21
+ Classifier: License :: OSI Approved :: MIT License
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Dynamic: author
26
+ Dynamic: author-email
27
+ Dynamic: classifier
28
+ Dynamic: description
29
+ Dynamic: description-content-type
30
+ Dynamic: home-page
31
+ Dynamic: license
32
+ Dynamic: license-file
33
+ Dynamic: project-url
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ debugpy is an implementation of the Debug Adapter Protocol for Python.
38
+
39
+ The source code and the issue tracker is [hosted on GitHub](https://github.com/microsoft/debugpy/).
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/RECORD ADDED
@@ -0,0 +1,531 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ../../../bin/debugpy,sha256=1QJN5hzzNhvr5jAgWHV63aDgGhZ_2haXRXln71QwmbM,193
2
+ ../../../bin/debugpy-adapter,sha256=K1QHRDs_RplwdTlHek1y_oO97RkiRzNWVEIzzS_vpyM,199
3
+ debugpy-1.8.22.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
4
+ debugpy-1.8.22.dist-info/METADATA,sha256=ydbvVxK14o0s0hRqD8dkJgOB8XKf8ODamwx33SIwvGQ,1382
5
+ debugpy-1.8.22.dist-info/RECORD,,
6
+ debugpy-1.8.22.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ debugpy-1.8.22.dist-info/WHEEL,sha256=bvJXIumTQjzfrG2ndSTqxWBEVRwm6IaiAAWvSc3d8AI,113
8
+ debugpy-1.8.22.dist-info/entry_points.txt,sha256=_TOrNxT85wBrs8Ah29jo4hfz4yaNfB5nKLabCB5PVos,100
9
+ debugpy-1.8.22.dist-info/licenses/LICENSE,sha256=g8PtOU5gAGfBe30cCb0-og8HA7jAcW5qn0FLmfy9-BA,1176
10
+ debugpy-1.8.22.dist-info/top_level.txt,sha256=6Om6JTEaqkWnj-9-7kJOJr988sTO6iSuiK4N9X6RLpg,8
11
+ debugpy/ThirdPartyNotices.txt,sha256=WzmT853BlHOtkEiV_xtk96iazYeVDKWB2tqKMtcm_jo,34345
12
+ debugpy/__init__.py,sha256=JB7LgIYnJCsxjFAotPGNt43kxNyWxSH91mL_PdzP_p8,1074
13
+ debugpy/__main__.py,sha256=a_DXjwzIJwPVnXlh7z_VnXqhSpuEr1vd1DzCwVt6tVQ,3187
14
+ debugpy/__pycache__/__init__.cpython-312.pyc,,
15
+ debugpy/__pycache__/__main__.cpython-312.pyc,,
16
+ debugpy/__pycache__/_version.cpython-312.pyc,,
17
+ debugpy/__pycache__/public_api.cpython-312.pyc,,
18
+ debugpy/_vendored/__init__.py,sha256=cQGcZObOjPcKFDQk06oWNgqBHh2rXDCv0JTNISv3_rg,3878
19
+ debugpy/_vendored/__pycache__/__init__.cpython-312.pyc,,
20
+ debugpy/_vendored/__pycache__/_pydevd_packaging.cpython-312.pyc,,
21
+ debugpy/_vendored/__pycache__/_util.cpython-312.pyc,,
22
+ debugpy/_vendored/__pycache__/force_pydevd.cpython-312.pyc,,
23
+ debugpy/_vendored/_pydevd_packaging.py,sha256=cYo9maxM8jNPj-vdvCtweaYAPX210Pg8-NHS8ZU02Mg,1245
24
+ debugpy/_vendored/_util.py,sha256=E5k-21l2RXQHxl0C5YF5ZmZr-Fzgd9eNl1c6UYYzjfg,1840
25
+ debugpy/_vendored/force_pydevd.py,sha256=spQVMTUrxCRoNiSKKIkK96AhEi0JX6vHxcBIJNcNQE0,3172
26
+ debugpy/_vendored/pydevd/__pycache__/pydev_app_engine_debug_startup.cpython-312.pyc,,
27
+ debugpy/_vendored/pydevd/__pycache__/pydev_coverage.cpython-312.pyc,,
28
+ debugpy/_vendored/pydevd/__pycache__/pydev_pysrc.cpython-312.pyc,,
29
+ debugpy/_vendored/pydevd/__pycache__/pydev_run_in_console.cpython-312.pyc,,
30
+ debugpy/_vendored/pydevd/__pycache__/pydevconsole.cpython-312.pyc,,
31
+ debugpy/_vendored/pydevd/__pycache__/pydevd.cpython-312.pyc,,
32
+ debugpy/_vendored/pydevd/__pycache__/pydevd_file_utils.cpython-312.pyc,,
33
+ debugpy/_vendored/pydevd/__pycache__/pydevd_tracing.cpython-312.pyc,,
34
+ debugpy/_vendored/pydevd/__pycache__/setup_pydevd_cython.cpython-312.pyc,,
35
+ debugpy/_vendored/pydevd/_pydev_bundle/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/__init__.cpython-312.pyc,,
37
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_calltip_util.cpython-312.pyc,,
38
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_completer.cpython-312.pyc,,
39
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_execfile.cpython-312.pyc,,
40
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_filesystem_encoding.cpython-312.pyc,,
41
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_getopt.cpython-312.pyc,,
42
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_imports_tipper.cpython-312.pyc,,
43
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_jy_imports_tipper.cpython-312.pyc,,
44
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_log.cpython-312.pyc,,
45
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_saved_modules.cpython-312.pyc,,
46
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_sys_patch.cpython-312.pyc,,
47
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/_pydev_tipper_common.cpython-312.pyc,,
48
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_console_utils.cpython-312.pyc,,
49
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_import_hook.cpython-312.pyc,,
50
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_imports.cpython-312.pyc,,
51
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_ipython_console.cpython-312.pyc,,
52
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_ipython_console_011.cpython-312.pyc,,
53
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_is_thread_alive.cpython-312.pyc,,
54
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_localhost.cpython-312.pyc,,
55
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_log.cpython-312.pyc,,
56
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_monkey.cpython-312.pyc,,
57
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_monkey_qt.cpython-312.pyc,,
58
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_override.cpython-312.pyc,,
59
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_umd.cpython-312.pyc,,
60
+ debugpy/_vendored/pydevd/_pydev_bundle/__pycache__/pydev_versioncheck.cpython-312.pyc,,
61
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_calltip_util.py,sha256=_-mStClIddbucgHHQWXHKJX0ee586RCK9OYyarLdC9Q,4685
62
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_completer.py,sha256=uTezSnBcGiiy1AhwehM1XzHOr7NbTHXQz_0C9uze674,8535
63
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_execfile.py,sha256=YeFIPF5nFVaA1seRIa_KAMM1ac5Qo43DS9iuyBe-tFo,485
64
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_filesystem_encoding.py,sha256=yp-aAAwAGrLlR7GyzAb0fbsNFLaEy1uMJPLg8ULFi64,1101
65
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_getopt.py,sha256=St7LkdI7n2bF4Xw_Kr-8t7_1YqfI0xAW8mkX_57ccv8,4429
66
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_imports_tipper.py,sha256=4Pgzh0yaDeQi1YKKopCgRu-eCcAL2zf9BaPMtJ4WSgQ,12312
67
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_jy_imports_tipper.py,sha256=nE9qiNXx3_ZIwFlpKFPB1KHhcvEphoSGhv8ALOYzPBE,16994
68
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_log.py,sha256=ENhSEv7ekEcaw-91a1EW6nqlDEO61qL6BvVSS29fshE,554
69
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py,sha256=wegdTSDGivI0gctzCr8N2ueFxXfztNP3Ehznao3RWP4,4740
70
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_sys_patch.py,sha256=u0Nl0sV-18ldTJu0okEeR-21l3Gju0aa2JiRfK9QliQ,2237
71
+ debugpy/_vendored/pydevd/_pydev_bundle/_pydev_tipper_common.py,sha256=jEVMSSg8ShzeGNaYIdPUxDNwo1tp1UfbUs_XrCh5ieY,1228
72
+ debugpy/_vendored/pydevd/_pydev_bundle/fsnotify/__init__.py,sha256=mONlEIwwBAC2v-pg-3vY6NH5e5op4IpkZskQiryogRU,12707
73
+ debugpy/_vendored/pydevd/_pydev_bundle/fsnotify/__pycache__/__init__.cpython-312.pyc,,
74
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_console_utils.py,sha256=t1lS1eqr5VYb7sy8SCfI9mUGrrCvKe8YdUFmlNe9eg0,23750
75
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_import_hook.py,sha256=gou6qpNq2AtOlV105_KjbRFGuLinxVxVmm-oJediz-M,1320
76
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_imports.py,sha256=BtBesnz6_ROgrRXhNsX3EOZ1wQdmYi8KzdYaUQPqvG4,403
77
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_ipython_console.py,sha256=1nRJShSTk7u7LFh9FD3Mmgx38b5N2OKljHuUMlXi0Oo,3773
78
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_ipython_console_011.py,sha256=0zWoaBvkW5imIR4-7T5W25gstU4WTPlXRDCR-gppitE,21192
79
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_is_thread_alive.py,sha256=pX02p_Xo3R0hI1Bpg2JDOClk8clDULnW78x3gym7MDM,1030
80
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_localhost.py,sha256=hdpf8wjIcwxImg_n9eyC3fTLLIpqXBCbICFZ_8ymVRA,2071
81
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_log.py,sha256=4DmESdPd4gu3HSjuwSZsO9A1mCMX-H3RlMjJSHbNuFY,9321
82
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py,sha256=W6H-k_6Ue5TO01radeGp-8yKxmQF_pch_vyu7C4EKtc,45379
83
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey_qt.py,sha256=08fPxniJEp63MqA_llPXlq5gfliXtwslmHQu3njcLTE,7310
84
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_override.py,sha256=RDNX5x3GQDkZvCYP_uzi_hQ17vLYPGFXM0OhEkfrbiY,871
85
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_umd.py,sha256=3a4qX92uJSnAPBzUEc0Pwxgufq-4Mw0VNrxjK5v6zBw,6228
86
+ debugpy/_vendored/pydevd/_pydev_bundle/pydev_versioncheck.py,sha256=vKCufGZ5intWqErkMxo1V_gwB1lIt1wtu5lzi0bfkaE,508
87
+ debugpy/_vendored/pydevd/_pydev_runfiles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
88
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/__init__.cpython-312.pyc,,
89
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles.cpython-312.pyc,,
90
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles_coverage.cpython-312.pyc,,
91
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles_nose.cpython-312.pyc,,
92
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles_parallel.cpython-312.pyc,,
93
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles_parallel_client.cpython-312.pyc,,
94
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles_pytest2.cpython-312.pyc,,
95
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles_unittest.cpython-312.pyc,,
96
+ debugpy/_vendored/pydevd/_pydev_runfiles/__pycache__/pydev_runfiles_xml_rpc.cpython-312.pyc,,
97
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles.py,sha256=j9CMZnmkYwtnBRakF7DWvLhTkiiuj82H9LyGUkS6SuM,32678
98
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_coverage.py,sha256=bHeJjZUZOt4Dc2a7S3jrRerth52qkWdOhUUTS5JZRl0,3408
99
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_nose.py,sha256=shYjBqxALylDKZjkSZRtf27dvBaooxhNshHizks0GxU,7556
100
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel.py,sha256=32dQKKeVuZsVPLWOGeHnrJFLLegs8r84RpLCvNpqXwU,9480
101
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel_client.py,sha256=eWV6nbYBpLwNOv1GIPr32VOkUscKHhZJaqFpNq9yDj8,7712
102
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_pytest2.py,sha256=L3H6rGDFd8ZCPwaR814uQtV6AAahO0WKK3FvSpO4j6k,9845
103
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_unittest.py,sha256=XOwg_BGkHh5DGQ4BhgHcCFWXPQHnW17llxpXuVElPV8,6566
104
+ debugpy/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_xml_rpc.py,sha256=IdgMXY3ubZaGuc7Ek2prf2KddciKX3E5CTC1SoC8E6I,10833
105
+ debugpy/_vendored/pydevd/_pydevd_bundle/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
106
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/__init__.cpython-312.pyc,,
107
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevconsole_code.cpython-312.pyc,,
108
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_additional_thread_info.cpython-312.pyc,,
109
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_additional_thread_info_regular.cpython-312.pyc,,
110
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_api.cpython-312.pyc,,
111
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_breakpoints.cpython-312.pyc,,
112
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_bytecode_utils.cpython-312.pyc,,
113
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_bytecode_utils_py311.cpython-312.pyc,,
114
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_code_to_source.cpython-312.pyc,,
115
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_collect_bytecode_info.cpython-312.pyc,,
116
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_comm.cpython-312.pyc,,
117
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_comm_constants.cpython-312.pyc,,
118
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_command_line_handling.cpython-312.pyc,,
119
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_console.cpython-312.pyc,,
120
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_constants.cpython-312.pyc,,
121
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_custom_frames.cpython-312.pyc,,
122
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_cython_wrapper.cpython-312.pyc,,
123
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_daemon_thread.cpython-312.pyc,,
124
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_defaults.cpython-312.pyc,,
125
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_dont_trace.cpython-312.pyc,,
126
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_dont_trace_files.cpython-312.pyc,,
127
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_exec2.cpython-312.pyc,,
128
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_extension_api.cpython-312.pyc,,
129
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_extension_utils.cpython-312.pyc,,
130
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_filtering.cpython-312.pyc,,
131
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_frame.cpython-312.pyc,,
132
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_frame_utils.cpython-312.pyc,,
133
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_gevent_integration.cpython-312.pyc,,
134
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_import_class.cpython-312.pyc,,
135
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_io.cpython-312.pyc,,
136
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_json_debug_options.cpython-312.pyc,,
137
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_net_command.cpython-312.pyc,,
138
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_net_command_factory_json.cpython-312.pyc,,
139
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_net_command_factory_xml.cpython-312.pyc,,
140
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_plugin_utils.cpython-312.pyc,,
141
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_process_net_command.cpython-312.pyc,,
142
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_process_net_command_json.cpython-312.pyc,,
143
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_referrers.cpython-312.pyc,,
144
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_reload.cpython-312.pyc,,
145
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_resolver.cpython-312.pyc,,
146
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_runpy.cpython-312.pyc,,
147
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_safe_repr.cpython-312.pyc,,
148
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_save_locals.cpython-312.pyc,,
149
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_signature.cpython-312.pyc,,
150
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_source_mapping.cpython-312.pyc,,
151
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_stackless.cpython-312.pyc,,
152
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_suspended_frames.cpython-312.pyc,,
153
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_thread_lifecycle.cpython-312.pyc,,
154
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_timeout.cpython-312.pyc,,
155
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_trace_dispatch.cpython-312.pyc,,
156
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_trace_dispatch_regular.cpython-312.pyc,,
157
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_traceproperty.cpython-312.pyc,,
158
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_utils.cpython-312.pyc,,
159
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_vars.cpython-312.pyc,,
160
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_vm_type.cpython-312.pyc,,
161
+ debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_xml.cpython-312.pyc,,
162
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
163
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__main__pydevd_gen_debug_adapter_protocol.py,sha256=AUrSO4NvkLu2y6zYuCoLJGxsLJaz-5dO7qwnuD7NUGc,23353
164
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__pycache__/__init__.cpython-312.pyc,,
165
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__pycache__/__main__pydevd_gen_debug_adapter_protocol.cpython-312.pyc,,
166
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__pycache__/pydevd_base_schema.cpython-312.pyc,,
167
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__pycache__/pydevd_schema.cpython-312.pyc,,
168
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__pycache__/pydevd_schema_log.cpython-312.pyc,,
169
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocol.json,sha256=ZK1DO5_0uSNgdx_I2sUNz5yslRwAV9CvDS-Ca0MIe_s,170390
170
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocolCustom.json,sha256=NmKM_bN5s6ozUPXIFc_Q3w6unk6Zf1hb1pgyjvxv4QM,10616
171
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_base_schema.py,sha256=BHq0SoUikbOeHAyM65ubD9jMBoB0vMCmvzuVzClBkPE,4000
172
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema.py,sha256=a6zohIFheZYlwweF7zbLPvSyNDwyy60rp70ltwIfUVQ,843038
173
+ debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema_log.py,sha256=123W8MKmZHTj7dNj7QT91n6HdYt_jDaWhk_WOc-X5Vk,1254
174
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevconsole_code.py,sha256=jpc0pWVCqQi6NLpmkfUpEFLCDSUuSzPjW7k6c2rFPS8,18936
175
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info.py,sha256=yZWzEG_rc-bLwcO-QDkwLm1gfxDkfsxRShOmR2vvEGI,1644
176
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info_regular.py,sha256=oe_ukTn5G7FNQPzH5yuHLKSgdSe3kORIXIRatxV_1jY,10901
177
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py,sha256=u1Ko9UyIROnyxdBO5hDuYTNGHf1loJVRsiZkAhl_-_I,51413
178
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_breakpoints.py,sha256=xI7cvPq0DxpUwxdPDA2mW4LWd6v1nbQjW0fhP1DGUfs,6244
179
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_bytecode_utils.py,sha256=pEUOkF9ZQYGOpFCn9xew3AuoJJda24mUD7uMGE3jmYE,29025
180
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_bytecode_utils_py311.py,sha256=bGoEjyxw9Cwiyh370B3f6e7jg3E-dBmNLvGMFrdtfYU,3600
181
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_code_to_source.py,sha256=g3pel_1S6KZJMMRoMGP1Q6WHm6arR85_z2UuQnagjdk,17560
182
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_collect_bytecode_info.py,sha256=qqh7Hvc6rB32Z6EQhj5xpL3_cEP7ZqoQ0fZhWEsZzP0,35706
183
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py,sha256=lQ37nCSAjth0H7D0S4iNZ1NoOHUjW_hIwYBFJpMNtcU,80631
184
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm_constants.py,sha256=KKGZxtVkEeEM5q0wx3T6FW1hffOCZShrzCU2z9f97dI,6076
185
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_command_line_handling.py,sha256=aOfHy9eRFV2qc3PjmSFd5AHyHU8UqXHObsetOmmBtas,6102
186
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_concurrency_analyser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
187
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_concurrency_analyser/__pycache__/__init__.cpython-312.pyc,,
188
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_concurrency_analyser/__pycache__/pydevd_concurrency_logger.cpython-312.pyc,,
189
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_concurrency_analyser/__pycache__/pydevd_thread_wrappers.cpython-312.pyc,,
190
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_concurrency_analyser/pydevd_concurrency_logger.py,sha256=6tBkRL4jF1ImM7rSh9zovvgf6Q6F7JQYdXuuvOZewjQ,20708
191
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_concurrency_analyser/pydevd_thread_wrappers.py,sha256=cBQ_QMkzxrWDrREe5t-QzRcxhPM-K_iyScKhP4uOWUU,2038
192
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_console.py,sha256=U4oOCD5VUBPVLUTxLAHoHKovtW1cinndpCAxDS-Vlso,10169
193
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_constants.py,sha256=eoTuSR0lxaUV8RMsSaMVrnJ-jBzeO1S_2YEffDsTp6s,29437
194
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_custom_frames.py,sha256=zfl--e0QFREouhGYO-_Gt1cQ8u6ueDiAoIJY7Hc2Ztg,4424
195
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.c,sha256=ENsx54HXBm0ZZUnF3Eyk6RxSFSCKhnXTVX_cZR8iAxI,2552835
196
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cpython-312-x86_64-linux-gnu.so,sha256=-_eS39e9PIlvG4ApBb_qTVdUIzeGUomdrh7g3y9lTlk,3058552
197
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pxd,sha256=lVkoAsOmQ75IXEdLWJoWEK1n8seR3jiTZZdAWlhgGvQ,1733
198
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pyx,sha256=Pek7VtmYGJznBP_011UwXwd45mi07SwuHSl7nkmJgMk,99298
199
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython_wrapper.py,sha256=sGHXLxVW9kKVS81I22ewZsrgsGJL1hbSv2mlKWOIogs,1850
200
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_daemon_thread.py,sha256=V93_fOxroEKto3Gi1mwTDNkqR_fXDKtu3oy3PkeECMM,8377
201
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_defaults.py,sha256=5nz2GRseE6ioxiJ_s1dCjBwvlI8j_d3szEQ9nArtfww,2294
202
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace.py,sha256=gLJnuCKPrRYrdkPum_xnEaGoSlB4XXC4_qmyZkm929E,3562
203
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace_files.py,sha256=rrwR9jMY2WDjgjAUJ25B6B3UklGpGqM3F7-6vwTm5ak,6363
204
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_exec2.py,sha256=t46OdHix6ySRWE7mawY8NMNXrwbSWmFum3rVV5sLpkE,160
205
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_extension_api.py,sha256=Y3TyC1OKxSiryduwI6_8jOhkQao0pKqHINa7mvAbQfQ,3906
206
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_extension_utils.py,sha256=iQtNDZKv-hGFSdUg9KnzJ-l_o0VarIFAMateVvj01ZY,2300
207
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py,sha256=GbysyFiirlmq7Tb_rEDTGmIjRA_zKRHDdyuu3b7EXC4,13033
208
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_frame.py,sha256=942Ro2qmb3nHY4rPoHqihYoW4P3cRMxbc2r9gFapKzw,64941
209
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_frame_utils.py,sha256=oT6EBBkB9O4eKFaoWD7sRBPg440E0dTAW1YOkhifjNI,15017
210
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_gevent_integration.py,sha256=AjOT4VSCd4iBxdTf7vCU4euSS6gWbhKZcQcFljyXkUw,3866
211
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_import_class.py,sha256=FxvE5zjfcmidba4rDih2relTmTHC7kQeHjoxsUijG8o,1779
212
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_io.py,sha256=Ap8jBhmOJd8NxYdsomRfFojXtEgxXH4CAU4t3K8LFcY,8115
213
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_json_debug_options.py,sha256=NGcRVk2hb2SuM6VKGp2QjDSEI3-47tSF-ZK2cGyluTM,6153
214
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py,sha256=J0K_BqDRpS5vKR0zV0aukoYNXJCBySm8KRdAhNNd2fI,4702
215
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_json.py,sha256=ROg83UzKxYLw5rTOWcIfvqQ9bmDXTwSmuBbjksZ3UcA,25820
216
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_xml.py,sha256=rpM8QOvlh0dqN6cO95cZLCzC5LqOs9sCiZmZEsvy5Vs,23784
217
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_plugin_utils.py,sha256=9VfpYUlhKfrh381AQBWAchBZ1-Xv6kebcLrB2zjKpdY,7219
218
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command.py,sha256=953VV4ntmcdRRKhhazI49uAn_j2Wm1cZrHbZtooPEZA,36009
219
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py,sha256=O9wc-tGus0Ir_kWDPGLBQjqUEtvVqrabyy_H399KLGI,60593
220
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_referrers.py,sha256=dhGMvpD2F0tFX6v9w4rXjtyKc4QOzpySKMWHAQ4RANM,9678
221
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_reload.py,sha256=oAITVx95bhFdDdAT6m6YZ_AeTa0GuAkuu4BwjLYil4Y,15912
222
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_resolver.py,sha256=0CrvMVD2iQQfJGWQ1ltNf9VQ6gNNRH8Hb8i3Rhqaoiw,30026
223
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py,sha256=781OAXhmRToNzlo7u4SzGWfPMYb1-IXkDfACw-AjLpM,13003
224
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_safe_repr.py,sha256=sPopHB3gqKdTZUbM8Dm2sEs9Tfp52ocnAxkA8kSQ98Y,14392
225
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_save_locals.py,sha256=9h9aJisgkUtB-nZ2CgRxXt4JQPmW0yTj5SQicAoBr-U,4160
226
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_signature.py,sha256=UjmfnYIfcofVeA-CdwPlXXRwWFJnsXPrLGoogYA5cO0,6877
227
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_source_mapping.py,sha256=5LCHce85kLWRQK_yv7neJEtzkQs6l4wuS9Pw1xS8DEk,6491
228
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_stackless.py,sha256=IKEjb4CWvnqi3Mn9dkZzmphx7nJPUND0esVmhswXXcU,16921
229
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_suspended_frames.py,sha256=r3Eepv0tSwBIxSjo1t5AjZ1T0FvlY35dYjhjHJ9hgSI,21750
230
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_thread_lifecycle.py,sha256=4uzjoUvBxtQJzhyDeuXBPkzGx3xBjEQjL6dBJ1v6fpE,4243
231
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_timeout.py,sha256=iTEiKxJJ15sY4rqnDMBnT0Cp0rPo2sTHSfy7RGZMB_k,8407
232
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch.py,sha256=grsHR472gmkJF6-qYOzHQPLhtnLkdkCY_I2Ie5uSiCk,3917
233
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch_regular.py,sha256=PyNvnDnWlgWeR7S6_DRgWv4aApKq-9HSWKxbTivgJZ4,23358
234
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_traceproperty.py,sha256=Uq9GZcRz9os8LPdaxKT2yQnIY6-YIu7gRVeffqPRHmQ,3256
235
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py,sha256=0hwVWSwFxeoyjskk0s8NELC1b_r57sIAiIypwUN8itU,17819
236
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py,sha256=8P4j-6L79IGP4i6Lru2w4CEMlLd4yPQZv_5V8KphZbc,33434
237
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vm_type.py,sha256=BEG4bhTNYPlwmdJe0hCvIU01TizoxhqbIMZR0L6H2Qo,1557
238
+ debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_xml.py,sha256=ekN1XZJ3v0xgPdarUAsZQ0nklq9Ks63FOMoZX2LIFAQ,15499
239
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/.gitignore,sha256=EKhbR-PpYtbvIYhIYeDDdUKDcU_kZf4kBzDgARh1Fgg,87
240
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
241
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/__pycache__/__init__.cpython-312.pyc,,
242
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/__pycache__/pydevd_frame_eval_cython_wrapper.cpython-312.pyc,,
243
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/__pycache__/pydevd_frame_eval_main.cpython-312.pyc,,
244
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/__pycache__/pydevd_frame_tracing.cpython-312.pyc,,
245
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/__pycache__/pydevd_modify_bytecode.cpython-312.pyc,,
246
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_cython_wrapper.py,sha256=dNoR--B9du5TXeycVvNkQwkBf9_utKATcJAKshhRTXE,1341
247
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_main.py,sha256=RY--kYB1fBBhr_uAF5ohaiB77VcnVf7XCcsE8FMVzdo,2444
248
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.c,sha256=t84E3AzjSGTg4-vzAX-d16D6NCxLoNKI_uQ8fiuCYOU,1174564
249
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.pxd,sha256=0pKrUK3YwQtlJk7vvhZzqnDCJvB6JOb4V23Zl8UrqYI,5324
250
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.template.pyx,sha256=YOHqtbizcUtC_jMeBlNQ6FLQZn-CZ3fcoqChyHF4h4g,24550
251
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_tracing.py,sha256=o-H1r3hMgoWEqiTyjfPMeJHWn87lQXTsqM44PYMEndw,4218
252
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_modify_bytecode.py,sha256=2NTPPo720-yNRYcpO_FXYUkZRbWrpFLPHnCVEksiv0E,13545
253
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/release_mem.h,sha256=MbMCNJQXkcJZ8UU7xoH44MwqE3QRWZX5WCAz7zCju6Y,79
254
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/README.txt,sha256=jgSPsMO3Gc8ncNUe5RwdxdVB-YHyAioWMPXHcD6KbQE,700
255
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
256
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/__pycache__/__init__.cpython-312.pyc,,
257
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/__pycache__/pydevd_fix_code.cpython-312.pyc,,
258
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__init__.py,sha256=lOOVD9sXmMmUhGrsHT-Hbfvxkkr_fksHhoK3MMRvO9w,4153
259
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__pycache__/__init__.cpython-312.pyc,,
260
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__pycache__/bytecode.cpython-312.pyc,,
261
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__pycache__/cfg.cpython-312.pyc,,
262
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__pycache__/concrete.cpython-312.pyc,,
263
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__pycache__/flags.cpython-312.pyc,,
264
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__pycache__/instr.cpython-312.pyc,,
265
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/__pycache__/peephole_opt.cpython-312.pyc,,
266
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/bytecode.py,sha256=T1SiYqbdmu-os-izJYwIiyLB_dhTHky5yRCg_k0F6sY,7053
267
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/cfg.py,sha256=QSPobKSNeeOb5qXHa8_2l6HhK2ZPsMYfJc6Q6OooyWY,15100
268
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/concrete.py,sha256=X2VANEjK955ex1D8R4Rb1ka4EkuCwWXAkZDYGVNliu8,22141
269
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/flags.py,sha256=Ft9oeD5mbALlYj7sfNXW0nFFklEz4IImQl0ESRO7XhY,5812
270
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/instr.py,sha256=5z7e5NJAn5Eg4zVXXlAzU0kLMVFR8cdrKoHKzvbHwqU,11292
271
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/peephole_opt.py,sha256=Mo5-PuspsGTSfcsaPPbQOmbTGYX7hZhmVBmybZmtSd4,15695
272
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__init__.py,sha256=Y9YYEfLXTsK-cawB_vGY5J-eS9zMlgQhrR8PgtAytzI,4944
273
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/__init__.cpython-312.pyc,,
274
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_bytecode.cpython-312.pyc,,
275
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_cfg.cpython-312.pyc,,
276
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_code.cpython-312.pyc,,
277
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_concrete.cpython-312.pyc,,
278
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_flags.cpython-312.pyc,,
279
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_instr.cpython-312.pyc,,
280
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_misc.cpython-312.pyc,,
281
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/test_peephole_opt.cpython-312.pyc,,
282
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/__pycache__/util_annotation.cpython-312.pyc,,
283
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_bytecode.py,sha256=dCNH33zllq0I1cdJJMiJMVSEPak59HudvPTfLQJ_pjI,15879
284
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_cfg.py,sha256=_Z5tIDVp1Sn5qvPwi8BCVHY8Qw5DiaairGi7OnGvhwg,28255
285
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_code.py,sha256=Zme1AIunMA3-8bI80UUz7N6b4XBTzGp8fbKplgh1oy8,2425
286
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_concrete.py,sha256=A2tz5Ok3Rc096nA4TicSLc4-p5_RegKZ2I0mWbxOMhM,49321
287
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_flags.py,sha256=jJZeKuoydHU8MysWEbRVFziUBpqEa8XckLjBt4iRrJQ,6007
288
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_instr.py,sha256=DXZCzcn-zTHdufz8jst0oA_szJyjD4I53kQYFk9iMc0,11537
289
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_misc.py,sha256=U-00FGCnM6lzxwrKsR6ky4bmwT72ixumWTEbggdNyLE,7017
290
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/test_peephole_opt.py,sha256=yFqYsN_9AJnWW6wifg-civ_1rdzXlJgEOosNWFqyJrs,32866
291
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/bytecode/tests/util_annotation.py,sha256=VULvmILaYyzOfOii8hHR-j0pnW04h0hgdk1-kwIMJ18,463
292
+ debugpy/_vendored/pydevd/_pydevd_frame_eval/vendored/pydevd_fix_code.py,sha256=01uudUsZpFPHvT234uV4oKSJBGgdl8jGolZ2oPjqy9M,1761
293
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/__pycache__/_pydevd_sys_monitoring.cpython-312.pyc,,
294
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/__pycache__/pydevd_sys_monitoring.cpython-312.pyc,,
295
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring.py,sha256=E1UxtIYt-x9PUhr25DumelU49ogoUML_hxkaucctof4,77593
296
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.c,sha256=uPF_TJCj0Ipalpu_7RuC1zy18R7cKMFMkyx3vUznB8A,1969306
297
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.cpython-312-x86_64-linux-gnu.so,sha256=L9kFGOjHEsv8jgLRzS1e__sSxDjKl-rEl5UmLrPsuJA,2521472
298
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.pxd,sha256=p9bIrp0Afnk7VI84PAyUkZ5-YmX0FHRDgUuD49jqNOg,2339
299
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.pyx,sha256=ezV44Dn8p2tZpM5v5LYw9GmRX9on2ay2z9eWyhDpu6Y,78327
300
+ debugpy/_vendored/pydevd/_pydevd_sys_monitoring/pydevd_sys_monitoring.py,sha256=r3vtANxiCWK4eyGAkh90n8hAEdFMkyKvgWHpxNpFahA,549
301
+ debugpy/_vendored/pydevd/pydev_app_engine_debug_startup.py,sha256=aUfyVkecqLGb2_lcEasx_0r_tfmBJ5ujI-oALs2OMWY,669
302
+ debugpy/_vendored/pydevd/pydev_coverage.py,sha256=MJgQy28Mmnnh58ToN0N6T0rrL5-pbBSWssXEcBtfjzc,3106
303
+ debugpy/_vendored/pydevd/pydev_ipython/README,sha256=rvIWDUoNsPxITSg6EUu3L9DihmZUCwx68vQsqo_FSQg,538
304
+ debugpy/_vendored/pydevd/pydev_ipython/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
305
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/__init__.cpython-312.pyc,,
306
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhook.cpython-312.pyc,,
307
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookglut.cpython-312.pyc,,
308
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookgtk.cpython-312.pyc,,
309
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookgtk3.cpython-312.pyc,,
310
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookpyglet.cpython-312.pyc,,
311
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookqt4.cpython-312.pyc,,
312
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookqt5.cpython-312.pyc,,
313
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookqt6.cpython-312.pyc,,
314
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhooktk.cpython-312.pyc,,
315
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/inputhookwx.cpython-312.pyc,,
316
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/matplotlibtools.cpython-312.pyc,,
317
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/qt.cpython-312.pyc,,
318
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/qt_for_kernel.cpython-312.pyc,,
319
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/qt_loaders.cpython-312.pyc,,
320
+ debugpy/_vendored/pydevd/pydev_ipython/__pycache__/version.cpython-312.pyc,,
321
+ debugpy/_vendored/pydevd/pydev_ipython/inputhook.py,sha256=AObjWOCN_FZqvlhxRRnAzPNvFyUd2CC9OPwh7SE8_Mw,19978
322
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookglut.py,sha256=EN3MwAQLeZPJ6YQGf9jPqf0Dt1yfzRy9vFI3KoTvxrY,5619
323
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookgtk.py,sha256=kwFRWRb4gU4wv39gkL-3JyR58W5wkwhFrQWh_a4WVZM,1114
324
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookgtk3.py,sha256=JXhh_JdEDCjFJVYaI-RIP5N4WS5bLUFhMObS_vf98cw,1112
325
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookpyglet.py,sha256=Z81MLqlQNqHOKgV9VVaplWLRx83-ESHx7NhyCK3ZnA4,3264
326
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookqt4.py,sha256=fmjiu01IGsgnGTNzsWNywwjRvKPAt2MnOTrhDP6KoTo,7251
327
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookqt5.py,sha256=w9SmF3s1AI6lQt6eOt0HubsuThlauHN3tardQdHcxZU,7297
328
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookqt6.py,sha256=lnZl_FKgPKpAtRVpssboxMdajYTAar6J7-eVsrSMcgY,7332
329
+ debugpy/_vendored/pydevd/pydev_ipython/inputhooktk.py,sha256=UwU5VCPtL6BayUy4VauXnzocDotgAA59nnHCVCTujks,754
330
+ debugpy/_vendored/pydevd/pydev_ipython/inputhookwx.py,sha256=HhX9S6aPZcyT21yvE_V2lmWiujKUY6PQfnbEpIXdlg0,6527
331
+ debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py,sha256=-DWE84AYzNnnA7uinzZ88s6zH3weVxc41sEqUYNKYHU,6458
332
+ debugpy/_vendored/pydevd/pydev_ipython/qt.py,sha256=TeVCKo2j9m2UVUYHWKPnNxYviNwYksQXqU6dVMuoGSQ,872
333
+ debugpy/_vendored/pydevd/pydev_ipython/qt_for_kernel.py,sha256=ascvuaRSEjDV_Qg1svDntW5dXizhDiZ7-JWa2C6in-U,3954
334
+ debugpy/_vendored/pydevd/pydev_ipython/qt_loaders.py,sha256=v590Z8zlJ29Rdb2DLEP4bXZ7tcPdySzOxgXielqfwyc,10525
335
+ debugpy/_vendored/pydevd/pydev_ipython/version.py,sha256=Dwjp3k3a_fdBFmSewViOYY1YT3h5duLNsbbNKKF7xWY,1496
336
+ debugpy/_vendored/pydevd/pydev_pysrc.py,sha256=dOUTYxOuRSKfHdc6ow5BINVU-xfhfhX0xf8jNIIJ4B0,101
337
+ debugpy/_vendored/pydevd/pydev_run_in_console.py,sha256=V3HQfKuyTVXz2piosoOqDCKVK1numOsuh5bdo3a9Z_w,4637
338
+ debugpy/_vendored/pydevd/pydev_sitecustomize/__not_in_default_pythonpath.txt,sha256=hnkTAuxSFW_Tilgw0Bt1RVLrfGRE3hYjAmTPm1k-sc8,21
339
+ debugpy/_vendored/pydevd/pydev_sitecustomize/__pycache__/sitecustomize.cpython-312.pyc,,
340
+ debugpy/_vendored/pydevd/pydev_sitecustomize/sitecustomize.py,sha256=yhY1Fm3ozbzqhSkcPYwjZyf-g94vAsp2ybCmTjxh2cM,9645
341
+ debugpy/_vendored/pydevd/pydevconsole.py,sha256=RA9k6VaVL5cmIQBE1qoAZAw5Kvk1TK0Va7xEEtxZ6ko,21119
342
+ debugpy/_vendored/pydevd/pydevd.py,sha256=0YCdAPqwtxpt6YvvafJ3Zp5LJ0wndmiTG1bCOPLaEoI,161761
343
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/README.txt,sha256=JibLodU4lzwvGyI8TNbfYhu626MPpYN3z4YAw82zTPU,960
344
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/__pycache__/_always_live_program.cpython-312.pyc,,
345
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/__pycache__/_check.cpython-312.pyc,,
346
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/__pycache__/_test_attach_to_process.cpython-312.pyc,,
347
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/__pycache__/_test_attach_to_process_linux.cpython-312.pyc,,
348
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/__pycache__/add_code_to_python_process.cpython-312.pyc,,
349
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/__pycache__/attach_pydevd.cpython-312.pyc,,
350
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/__pycache__/attach_script.cpython-312.pyc,,
351
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/_always_live_program.py,sha256=paautgjjZYWolomOWv4ti1K6_XumjSDDbrHPkXYC1Bs,687
352
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/_check.py,sha256=yL5p7qHGw-1aoESl1fbcwV6QXgHmtb3bTTFN0xV9108,136
353
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process.py,sha256=ETGZegNNorgxyYuJUviWu4hFm6946sv9ZGd7_N4doAw,299
354
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process_linux.py,sha256=NVKu3K_p9zzbHbULftrrxe-FvH4XIm7G7ipL8lXt0r8,2563
355
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/add_code_to_python_process.py,sha256=-zV83JjvxPaG-rkBgXVJhCJt0N7DC_H0-lFbQcumkyo,24155
356
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_linux_amd64.so,sha256=j6_sNmxqOzjTQpx6mtmVf9Ap8XDqyf03vey7vrs-lEE,20584
357
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_pydevd.py,sha256=Sqinii4iXCP4OPrn54queWZ7oyBmJDoyb8FY8n8FHMQ,2585
358
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_script.py,sha256=L7RA14Og8NhnR5bUFuPaNIXKoQb0d4ldEm_ppbI4KZo,8027
359
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_custom_pyeval_settrace.hpp,sha256=GCjlTIQW1wRoEpp1yCbeJiUaa9JDTbeOypJiZBRtxPE,8399
360
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_custom_pyeval_settrace_310.hpp,sha256=mNr6LVLPDoCRyxLPTdYb0JWDXSfRn7xuAzPOzZWvoFs,4062
361
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_custom_pyeval_settrace_311.hpp,sha256=_tpO9I0U0f2RqCYM8DIOPQJTLv8sL2NCxwKE2BnR0NE,4269
362
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_custom_pyeval_settrace_common.hpp,sha256=r1ch6UgwF4rxW8ehiNnAvJE18VCoUl2TujP7nTCy0vQ,1870
363
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_settrace.hpp,sha256=OKa2mC0dEpE3nAij3mA3sYyVlEXuj5nDI-C-fdW-mdM,7681
364
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_utils.hpp,sha256=7GKYwDPPvu5JhPtni2zB44r0Kh0bO2NZH-LAiFkY55A,3865
365
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_version.hpp,sha256=QHeS15AWoIWrkOFPW7wLvMDAcrCYCIui6h6jmPv95Xc,3207
366
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/python.h,sha256=ueIyBiClInxfKMlgAVMuxTvmhESadiWeA4uSwZAROeo,21631
367
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/common/ref_utils.hpp,sha256=8wDFQk9XoAnK2EdM4J-RErKfBYZn93uG6Rw5OCbLsA0,1475
368
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/.gitignore,sha256=r3rDatBumb9cRDhx35hsdJp9URPUmjgkynAQViLIoR4,82
369
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/__pycache__/lldb_prepare.cpython-312.pyc,,
370
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/attach.cpp,sha256=xG8NmOwfuhXN93spuG_uEfe0tOn32hnljCqY5f1z354,3703
371
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_linux.sh,sha256=vpuIN32yEaUMLDivDg99LxRPwuUtySZ0Z6f90q-Q1eQ,342
372
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_mac.sh,sha256=mFmRofgRcrDZ0Lc8cdu0B9o6lpOHf6WEMytSQ5wnrYo,699
373
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_manylinux.cmd,sha256=9MucLhZLPpq3i3TCHSqCyhQsg6nCwsKA3O6yWWNCgk8,673
374
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py,sha256=GqHCLbSBblmzU84bAmmyz5Qx_H8dvFupmTdINziqjxg,1679
375
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__init__.py,sha256=XA6hCWO9SoUtiuxV1v3HJkZa1BmIShgUprOgi4OlTUQ,6882
376
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/__init__.cpython-312.pyc,,
377
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/breakpoint.cpython-312.pyc,,
378
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/compat.cpython-312.pyc,,
379
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/crash.cpython-312.pyc,,
380
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/debug.cpython-312.pyc,,
381
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/disasm.cpython-312.pyc,,
382
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/event.cpython-312.pyc,,
383
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/interactive.cpython-312.pyc,,
384
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/module.cpython-312.pyc,,
385
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/process.cpython-312.pyc,,
386
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/registry.cpython-312.pyc,,
387
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/search.cpython-312.pyc,,
388
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/sql.cpython-312.pyc,,
389
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/system.cpython-312.pyc,,
390
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/textio.cpython-312.pyc,,
391
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/thread.cpython-312.pyc,,
392
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/util.cpython-312.pyc,,
393
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__pycache__/window.cpython-312.pyc,,
394
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/breakpoint.py,sha256=aEV2SMqFKQUO7RSk6DguGm0KXTqB55NncrFsg2v9fLs,165107
395
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/compat.py,sha256=ihE-Lzas1wWBRbIEBQA9LPvG3Jh7y4iPJuMlk-Kos_c,5269
396
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/crash.py,sha256=SI0ruZbchgv9LAUJJmf1v0R2wsjwcTp04WUeyjh_AEI,64753
397
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/debug.py,sha256=3phOGE-Nni0CIu8DhyTT7twSifVAGLraPtQx_gMyZhE,57656
398
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/disasm.py,sha256=vxpPWUYev0n_9KpgSOmahj8A4ODrx_IpVqTVLClVnAw,24356
399
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/event.py,sha256=GvRDRe222xjeZvBzfRoYMKw7A9nJiUIDrrWCJZTz-GM,65130
400
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/interactive.py,sha256=g0QZFxDRw10IG2TVsRzczOPnlt0pXVYSNAchpIsjP4Q,83656
401
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/module.py,sha256=KJHWzxNqkD3aRCR_Cwl-nDjPhlxOFIEn6xtrero3-Tk,69754
402
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/process.py,sha256=0gPACjeatJrHbQQv4LVKk0pRfOcaAfM-65KRfdBRqZA,179680
403
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/registry.py,sha256=uA6oYi_887R_ZnJ2vpTHczfExEEuFEDwAtbV9yNLfTg,21436
404
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/search.py,sha256=n5rySAFHiTgOfBQN1OoE5dPdinSglAQOfz2jLD-yiuc,23241
405
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/sql.py,sha256=q-F3auBoaXbJ2anapub8PhmFu__rqMxeDCffvYrulfg,33687
406
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/system.py,sha256=aSxN2gAYZcO1lQM-w9aEFbQyrVFTQDNslm_l-JLSwN8,44394
407
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/textio.py,sha256=xL7IV2tYCILF7vzyx__DZbj_32P5Eyym2mZBjc9RhPQ,59539
408
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/thread.py,sha256=ca1FgBLQgWFaK7YpdGH-_oTVCz1fLqH8SMHkwnYmbaY,74682
409
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/util.py,sha256=F94MaOk56bD9hw5IRRVU4HvVrgAFMjmUd428C_g_0No,35919
410
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__init__.py,sha256=ZtWZmRPUrihwFxg_CjXvQQAc7jhhgCjPoJmzrg8_coo,2813
411
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/__init__.cpython-312.pyc,,
412
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/advapi32.cpython-312.pyc,,
413
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/context_amd64.cpython-312.pyc,,
414
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/context_i386.cpython-312.pyc,,
415
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/dbghelp.cpython-312.pyc,,
416
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/defines.cpython-312.pyc,,
417
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/gdi32.cpython-312.pyc,,
418
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/kernel32.cpython-312.pyc,,
419
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/ntdll.cpython-312.pyc,,
420
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/peb_teb.cpython-312.pyc,,
421
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/psapi.cpython-312.pyc,,
422
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/shell32.cpython-312.pyc,,
423
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/shlwapi.cpython-312.pyc,,
424
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/user32.cpython-312.pyc,,
425
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/version.cpython-312.pyc,,
426
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__pycache__/wtsapi32.cpython-312.pyc,,
427
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/advapi32.py,sha256=ocN7LpTDO2iIVpciWimF6sqI90DVJwD7FMYR7M1JiSA,118442
428
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_amd64.py,sha256=S2-vrADxktXe25VdRuOy6Q4Dj8mxr1Dd4MIq9Vy-5V0,23649
429
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_i386.py,sha256=PamJv8oAvxylJJe4m5p-58VLUGY3ULTrIqhZdjedsGg,15408
430
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py,sha256=TESaeh8YTpsEKj9ZhWcpkuZ6RAHLjDdJAarB7qzNlMQ,44984
431
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/defines.py,sha256=bWZzQ-fHDgZWBbhe8-nTrq436brWZ39AFot351UvHLI,20900
432
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/gdi32.py,sha256=eerwd8qqKxNzlulR47vVf5p_WixeCFmaQLAkLiWRzA0,14155
433
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/kernel32.py,sha256=Cs_R4qfbCqvPZ4qY-IfrvNx4bu5rUhqccJwjFu3yftY,158759
434
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/ntdll.py,sha256=1oKu6H1P4R3CCi2DDNka5FaPmxO3uCCABx9HF1_oFP8,20553
435
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/peb_teb.py,sha256=PuHmAyFLTrkx2lpPTK9JNYT8YB7zHPcOAgapIlbmIm4,136048
436
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/psapi.py,sha256=gKLiFGbpmzJ36zj-CW0GWCrbrTwtomVysnLIDXmi80Y,13705
437
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shell32.py,sha256=NmlMKVF92SnCh4dIq7gX4LCV4qfdZJEWiK2XbL1u71c,12773
438
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shlwapi.py,sha256=iN18pyt4X9RCsQj_fxkCAyqCqIfmIYP4UV1Ftg0eylQ,25371
439
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/user32.py,sha256=gIX0gA0qSK_eenRqDUyPnnf6hMnvMnMHCWG3XutnWOs,51438
440
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/version.py,sha256=UAEkxj40ZltRTW4oaNGMZTfQW5-gRmGlVbz3C1e2E5A,33834
441
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/wtsapi32.py,sha256=-sDrGpAQv0y9VxFwbdDFH-ozfvE75R_uygva0L58Reo,10781
442
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/window.py,sha256=oBsxsI37NbQkLcDu_JVBRnyRBitXN4AI0Z1b4HSO2R8,24017
443
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/attach.cpp,sha256=hJY1byqijqru-q6167Akh20aOTLp19cGeANoFpWCTxw,27984
444
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/attach.h,sha256=rWBA3kdzfyHaE9X9Diub3cojoJlXjC3TKnLQv-nGCeA,1846
445
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/compile_windows.bat,sha256=t82UPuVZMjVly_JJH_S8OpDd2xZ7_9dRZp9U494Pn-c,2220
446
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/inject_dll.cpp,sha256=GQmZbpNBRMMW1WFcDFOlJaGLy1-oZ4qCCIyo5exPLBM,4792
447
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/py_win_helpers.hpp,sha256=45pO-c1ofub4nn0XY9kMsTm3s48_EPE-VWAhld3704I,2479
448
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/run_code_in_memory.hpp,sha256=zvDC9cVGZ6BXEsz_Im-QMIubdw6vX3BCIg2T11cVfvg,3355
449
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/run_code_on_dllmain.cpp,sha256=ApQza8ZJrfe2U4jTJPa8ItzvnHc7w2G6Yrfq4BT_56g,2516
450
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.cpp,sha256=NO8qlc7sKU6oHA_AnXJSodHupZLizp3npBTc-EGpBj8,999
451
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.h,sha256=l0tEIxxiv0XrIeiJ2zedTd4fYrdlxVTK8ECpBk881WM,1162
452
+ debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/targetver.h,sha256=fqw-iPopG_V-pFRxf33lVFL0uvWfDUB2ky0bibFblK0,1013
453
+ debugpy/_vendored/pydevd/pydevd_file_utils.py,sha256=CYbcNt6txfWuSOOPVUpJlJEpzxtO0QtRWe1dv0qWvGI,37456
454
+ debugpy/_vendored/pydevd/pydevd_plugins/__init__.py,sha256=_2bZAHuDVAx7MM7KA7pt3DYp641NY4RzSoRAwesWKfU,67
455
+ debugpy/_vendored/pydevd/pydevd_plugins/__pycache__/__init__.cpython-312.pyc,,
456
+ debugpy/_vendored/pydevd/pydevd_plugins/__pycache__/django_debug.cpython-312.pyc,,
457
+ debugpy/_vendored/pydevd/pydevd_plugins/__pycache__/jinja2_debug.cpython-312.pyc,,
458
+ debugpy/_vendored/pydevd/pydevd_plugins/__pycache__/pydevd_line_validation.cpython-312.pyc,,
459
+ debugpy/_vendored/pydevd/pydevd_plugins/django_debug.py,sha256=A_oSEpN5zvD0PB5e8UFslAknUDQ-3DaNObJ4DMI1PjY,22268
460
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/README.md,sha256=cxu8F295snUVNgqE5xXKnZTpbqbR3LTmm60pgK0IOTs,1183
461
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/__init__.py,sha256=_2bZAHuDVAx7MM7KA7pt3DYp641NY4RzSoRAwesWKfU,67
462
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/__pycache__/__init__.cpython-312.pyc,,
463
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/__init__.py,sha256=_2bZAHuDVAx7MM7KA7pt3DYp641NY4RzSoRAwesWKfU,67
464
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/__pycache__/__init__.cpython-312.pyc,,
465
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/__pycache__/pydevd_helpers.cpython-312.pyc,,
466
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/__pycache__/pydevd_plugin_numpy_types.cpython-312.pyc,,
467
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/__pycache__/pydevd_plugin_pandas_types.cpython-312.pyc,,
468
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/__pycache__/pydevd_plugins_django_form_str.cpython-312.pyc,,
469
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_helpers.py,sha256=F4ODS-1OYkAbKeIikE1y6hh4x2nMJueFtA-uRnQVrYY,642
470
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugin_numpy_types.py,sha256=uDczvkuJgBLb_ULhJ2CA6v5_3JJ9EvNy3ZF6z5i2f-8,3250
471
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugin_pandas_types.py,sha256=DNs8j07AA-OtDwQNIZVGqwWKqEHYFPSIgTa7HtGZVdI,6575
472
+ debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugins_django_form_str.py,sha256=-aj9h1rqP46DMilxMGwi1p3fDa47VxZkiLC3SlRs7nw,539
473
+ debugpy/_vendored/pydevd/pydevd_plugins/jinja2_debug.py,sha256=c2P3zYJlQHGgV-KzxOPetoFfboGBn1PWDGCdpqy9vzg,19043
474
+ debugpy/_vendored/pydevd/pydevd_plugins/pydevd_line_validation.py,sha256=YGJZ4SY2O6pY70mxSb36fFy0_9uxSDkrA1Z-MqUrYSU,6654
475
+ debugpy/_vendored/pydevd/pydevd_tracing.py,sha256=lLhYIGHCdM8Y121tjZI6OzLeR749Rmy5QX8UwryJXIo,15853
476
+ debugpy/_vendored/pydevd/setup_pydevd_cython.py,sha256=S_mnRoCEPx_Nuz3boT1XjDSmUPiEuipTJEeeyhCAx6A,13768
477
+ debugpy/_version.py,sha256=2O81GaG063DHHaIk8HdhgAk11b4w7cC5jA8kVuBkttQ,498
478
+ debugpy/adapter/__init__.py,sha256=ewTjlS3VAb6lypFWfGZjY7j2wiW6ApS3KSPJrm0xsEk,346
479
+ debugpy/adapter/__main__.py,sha256=_fTtIRO_R6DDyN1Ie0tYhaZr38DVt5C7L75vbMYQjfc,8670
480
+ debugpy/adapter/__pycache__/__init__.cpython-312.pyc,,
481
+ debugpy/adapter/__pycache__/__main__.cpython-312.pyc,,
482
+ debugpy/adapter/__pycache__/clients.cpython-312.pyc,,
483
+ debugpy/adapter/__pycache__/components.cpython-312.pyc,,
484
+ debugpy/adapter/__pycache__/launchers.cpython-312.pyc,,
485
+ debugpy/adapter/__pycache__/servers.cpython-312.pyc,,
486
+ debugpy/adapter/__pycache__/sessions.cpython-312.pyc,,
487
+ debugpy/adapter/clients.py,sha256=_euRPdbQguGUTf6MHQKbx5zJCHK8OeOE7A7xTd6FQOE,33115
488
+ debugpy/adapter/components.py,sha256=Hlavs3wY_QRXTHJvAgYzyPTKdFcQqzwGtdp20UtlEhA,6551
489
+ debugpy/adapter/launchers.py,sha256=3qhidH9NQxObD9mnutksxGPPuVoYgfZrLYmBCphtHO8,8399
490
+ debugpy/adapter/servers.py,sha256=vJOXz1-coaxtVEzGdEld1z17RPZKALeHn604rM7ITsU,25273
491
+ debugpy/adapter/sessions.py,sha256=lVqda33SCw8GLF7sxyiwBRHUWgWCfZIhY6gmVbDWUas,11659
492
+ debugpy/common/__init__.py,sha256=A9wk72d0JyUbZBXHLvMi7v65_5hy2chhoNTupk5mYYk,609
493
+ debugpy/common/__pycache__/__init__.cpython-312.pyc,,
494
+ debugpy/common/__pycache__/json.cpython-312.pyc,,
495
+ debugpy/common/__pycache__/log.cpython-312.pyc,,
496
+ debugpy/common/__pycache__/messaging.cpython-312.pyc,,
497
+ debugpy/common/__pycache__/singleton.cpython-312.pyc,,
498
+ debugpy/common/__pycache__/sockets.cpython-312.pyc,,
499
+ debugpy/common/__pycache__/stacks.cpython-312.pyc,,
500
+ debugpy/common/__pycache__/timestamp.cpython-312.pyc,,
501
+ debugpy/common/__pycache__/util.cpython-312.pyc,,
502
+ debugpy/common/json.py,sha256=QElOqLTtQlXfbdmZqMxVqRG82AP3pftVPuDlXA_6tao,10088
503
+ debugpy/common/log.py,sha256=KMZ-p1-BC7IUqcLGh1vBrjaamz8xu2B9IXC-hJTe5Ho,12185
504
+ debugpy/common/messaging.py,sha256=lSgp5WiQTqjPZ84C6TIVi5BxyhxZ0FYwi43caGFrwz4,59915
505
+ debugpy/common/singleton.py,sha256=94fXFVxOAzbmU0eyxTR5h5z-4K96yen0QmI0vyQGiiM,8135
506
+ debugpy/common/sockets.py,sha256=JBShK1FNvSf4LkpiTMkXBXXe0D8NH8IHZLbTquM2eSA,6296
507
+ debugpy/common/stacks.py,sha256=czZjqyY_5ntvOSpelZlJkpH4Gqq9JyZY7tcUqz4sWXA,1526
508
+ debugpy/common/timestamp.py,sha256=ZocK6sWz2JUD1hBAKj672ta8D3ze0Z3zJD_CWjeDq7A,410
509
+ debugpy/common/util.py,sha256=GQR0F-Uzn392BH5AzhH7u2HDH5VMBigSwNmvLDcaLok,4857
510
+ debugpy/launcher/__init__.py,sha256=Fglf772w3FZ5kwnW_RX2r6RzS0Ev-iP6JEnIEiP7C_Y,925
511
+ debugpy/launcher/__main__.py,sha256=OW8FZj8Kd6oqHcfcziqJ4M-u3kBhVj9Eg-vVjcpd84E,3863
512
+ debugpy/launcher/__pycache__/__init__.cpython-312.pyc,,
513
+ debugpy/launcher/__pycache__/__main__.cpython-312.pyc,,
514
+ debugpy/launcher/__pycache__/debuggee.cpython-312.pyc,,
515
+ debugpy/launcher/__pycache__/handlers.cpython-312.pyc,,
516
+ debugpy/launcher/__pycache__/output.cpython-312.pyc,,
517
+ debugpy/launcher/__pycache__/winapi.cpython-312.pyc,,
518
+ debugpy/launcher/debuggee.py,sha256=h2jbZcuu_MHuQRgMOgFBMeZWRiq3anPq1BdX19W5lmE,9140
519
+ debugpy/launcher/handlers.py,sha256=vsMHp4SKqbR1ar27RW7t-SbApXdWPfhS7qLlgr_cw8g,5728
520
+ debugpy/launcher/output.py,sha256=xBcqfe9sFI2_9Dh510A56XcsTgyg1j_GK-5OojK8Nmg,3806
521
+ debugpy/launcher/winapi.py,sha256=WzGJxRnfUaY48h5xIuGQ9Bf38OY_8qnY2lXikj_aky8,3221
522
+ debugpy/public_api.py,sha256=FZqbRh3mwKJClm1nGt2KE6Jp34PShQzdmCOISOYWSHw,9742
523
+ debugpy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
524
+ debugpy/server/__init__.py,sha256=mmPRoui4PkSeZxG3r5Gep6YB0MLMq_lIJru1pfGmKUY,323
525
+ debugpy/server/__pycache__/__init__.cpython-312.pyc,,
526
+ debugpy/server/__pycache__/api.cpython-312.pyc,,
527
+ debugpy/server/__pycache__/attach_pid_injected.cpython-312.pyc,,
528
+ debugpy/server/__pycache__/cli.cpython-312.pyc,,
529
+ debugpy/server/api.py,sha256=Jv0BRPVjf4CAxNDnCGALfOZyQbQARLIq3VSBGC_Xnp8,14299
530
+ debugpy/server/attach_pid_injected.py,sha256=dUdZn_5X3hK6rHv1t8UAyCUik3Z6-tFD1gHcNF5bZrc,2742
531
+ debugpy/server/cli.py,sha256=smRqpcQtXv2OzkQ3paF-IaAOxGo7zmgW48Q6WNIY224,19816
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/REQUESTED ADDED
File without changes
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/WHEEL ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-manylinux_2_34_x86_64
5
+
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/entry_points.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [console_scripts]
2
+ debugpy = debugpy.server.cli:main
3
+ debugpy-adapter = debugpy.adapter.__main__:main
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/licenses/LICENSE ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ debugpy
2
+
3
+ Copyright (c) Microsoft Corporation
4
+ All rights reserved.
5
+
6
+ MIT License
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
9
+ this software and associated documentation files (the "Software"), to deal in
10
+ the Software without restriction, including without limitation the rights to
11
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12
+ the Software, and to permit persons to whom the Software is furnished to do so,
13
+ subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
Video-RSI/.venv/lib/python3.12/site-packages/debugpy-1.8.22.dist-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ debugpy
Video-RSI/.venv/lib/python3.12/site-packages/distutils-precedence.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2638ce9e2500e572a5e0de7faed6661eb569d1b696fcba07b0dd223da5f5d224
3
+ size 151
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/METADATA ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: flatbuffers
3
+ Version: 25.12.19
4
+ Summary: The FlatBuffers serialization format for Python
5
+ Home-page: https://google.github.io/flatbuffers/
6
+ Author: Derek Bailey
7
+ Author-email: derekbailey@google.com
8
+ License: Apache 2.0
9
+ Project-URL: Documentation, https://google.github.io/flatbuffers/
10
+ Project-URL: Source, https://github.com/google/flatbuffers
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 2
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Dynamic: author
19
+ Dynamic: author-email
20
+ Dynamic: classifier
21
+ Dynamic: description
22
+ Dynamic: home-page
23
+ Dynamic: license
24
+ Dynamic: project-url
25
+ Dynamic: summary
26
+
27
+ Python runtime library for use with the `Flatbuffers <https://google.github.io/flatbuffers/>`_ serialization format.
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/RECORD ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ flatbuffers-25.12.19.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
2
+ flatbuffers-25.12.19.dist-info/METADATA,sha256=nzgjn5b6ohUipqratpEuHlYHCLvpyfaWoGeclAP6CJ4,1004
3
+ flatbuffers-25.12.19.dist-info/RECORD,,
4
+ flatbuffers-25.12.19.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ flatbuffers-25.12.19.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
6
+ flatbuffers-25.12.19.dist-info/top_level.txt,sha256=UXVWLA8ys6HeqTz6rfKesocUq6ln-ZL8mhZC_cq5BEc,12
7
+ flatbuffers/__init__.py,sha256=vJZrqZOOTKdBNMa_iTKUA6WJG_c_NzKGpFXOe1Igtiw,751
8
+ flatbuffers/__pycache__/__init__.cpython-312.pyc,,
9
+ flatbuffers/__pycache__/_version.cpython-312.pyc,,
10
+ flatbuffers/__pycache__/builder.cpython-312.pyc,,
11
+ flatbuffers/__pycache__/compat.cpython-312.pyc,,
12
+ flatbuffers/__pycache__/encode.cpython-312.pyc,,
13
+ flatbuffers/__pycache__/flexbuffers.cpython-312.pyc,,
14
+ flatbuffers/__pycache__/number_types.cpython-312.pyc,,
15
+ flatbuffers/__pycache__/packer.cpython-312.pyc,,
16
+ flatbuffers/__pycache__/table.cpython-312.pyc,,
17
+ flatbuffers/__pycache__/util.cpython-312.pyc,,
18
+ flatbuffers/_version.py,sha256=sk31rbYWDseoJxI9YQ1fYR-MMxRATyqsntKAEv7D7pI,696
19
+ flatbuffers/builder.py,sha256=HrG5KJ9rasiSTrMGeatkSdDs7fXV5fy_927Dsgakp4A,24567
20
+ flatbuffers/compat.py,sha256=ihBSpWDCSL-vgLSyZtcu8LX3ZI3wz9LhtqItY2GQZgg,2373
21
+ flatbuffers/encode.py,sha256=2Or3mgWRAkJiWg-GgYasDU4zIHpQU3W06fmIhwbz5uM,1550
22
+ flatbuffers/flexbuffers.py,sha256=yF8Wr4Lo8WJb-pj9NNaIYxLwzlHHyTroM0iO8fyDwbU,44454
23
+ flatbuffers/number_types.py,sha256=ijO0QcJiuxlQegoBOed0v9m0DdzTZHWxpTBZUqzsWHA,3762
24
+ flatbuffers/packer.py,sha256=LNWym8YgFRqHjcPeGpYY3inCGWH6XnbkQKtAPtFEVas,1164
25
+ flatbuffers/table.py,sha256=ciYTmq_CzAuYpb3KAVnl75M84ieChfbyKne-dFHzwwU,4818
26
+ flatbuffers/util.py,sha256=mRVQ1VoHp0MJMNtRTUGVzALwN4T_C-U14tMbj99py2A,1608
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/REQUESTED ADDED
File without changes
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/WHEEL ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers-25.12.19.dist-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ flatbuffers
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/__init__.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2014 Google Inc. All rights reserved.
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
+
15
+ from . import util
16
+ from ._version import __version__
17
+ from .builder import Builder
18
+ from .compat import range_func as compat_range
19
+ from .table import Table
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/_version.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2019 Google Inc. All rights reserved.
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
+
15
+ # Placeholder, to be updated during the release process
16
+ # by the setup.py
17
+ __version__ = "25.12.19"
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/builder.py ADDED
@@ -0,0 +1,858 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2014 Google Inc. All rights reserved.
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
+
15
+ import warnings
16
+
17
+ from . import compat
18
+ from . import encode
19
+ from . import number_types as N
20
+ from . import packer
21
+ from .compat import memoryview_type
22
+ from .compat import NumpyRequiredForThisFeature, import_numpy
23
+ from .compat import range_func
24
+ from .number_types import (SOffsetTFlags, UOffsetTFlags, VOffsetTFlags)
25
+
26
+ np = import_numpy()
27
+ ## @file
28
+ ## @addtogroup flatbuffers_python_api
29
+ ## @{
30
+
31
+
32
+ ## @cond FLATBUFFERS_INTERNAL
33
+ class OffsetArithmeticError(RuntimeError):
34
+ """Error caused by an Offset arithmetic error.
35
+
36
+ Probably caused by bad writing of fields. This is considered an unreachable
37
+ situation in normal circumstances.
38
+ """
39
+
40
+ pass
41
+
42
+
43
+ class IsNotNestedError(RuntimeError):
44
+ """Error caused by using a Builder to write Object data when not inside
45
+
46
+ an Object.
47
+ """
48
+
49
+ pass
50
+
51
+
52
+ class IsNestedError(RuntimeError):
53
+ """Error caused by using a Builder to begin an Object when an Object is
54
+
55
+ already being built.
56
+ """
57
+
58
+ pass
59
+
60
+
61
+ class StructIsNotInlineError(RuntimeError):
62
+ """Error caused by using a Builder to write a Struct at a location that
63
+
64
+ is not the current Offset.
65
+ """
66
+
67
+ pass
68
+
69
+
70
+ class BuilderSizeError(RuntimeError):
71
+ """Error caused by causing a Builder to exceed the hardcoded limit of 2
72
+
73
+ gigabytes.
74
+ """
75
+
76
+ pass
77
+
78
+
79
+ class BuilderNotFinishedError(RuntimeError):
80
+ """Error caused by not calling `Finish` before calling `Output`."""
81
+
82
+ pass
83
+
84
+
85
+ class EndVectorLengthMismatched(RuntimeError):
86
+ """The number of elements passed to EndVector does not match the number
87
+
88
+ specified in StartVector.
89
+ """
90
+
91
+ pass
92
+
93
+
94
+ # VtableMetadataFields is the count of metadata fields in each vtable.
95
+ VtableMetadataFields = 2
96
+ ## @endcond
97
+
98
+
99
+ class Builder(object):
100
+ """A Builder is used to construct one or more FlatBuffers.
101
+
102
+ Typically, Builder objects will be used from code generated by the `flatc`
103
+ compiler.
104
+
105
+ A Builder constructs byte buffers in a last-first manner for simplicity and
106
+ performance during reading.
107
+
108
+ Internally, a Builder is a state machine for creating FlatBuffer objects.
109
+
110
+ It holds the following internal state:
111
+ - Bytes: an array of bytes.
112
+ - current_vtable: a list of integers.
113
+ - vtables: a hash of vtable entries.
114
+
115
+ Attributes:
116
+ Bytes: The internal `bytearray` for the Builder.
117
+ finished: A boolean determining if the Builder has been finalized.
118
+ """
119
+
120
+ ## @cond FLATBUFFERS_INTENRAL
121
+ __slots__ = (
122
+ "Bytes",
123
+ "current_vtable",
124
+ "head",
125
+ "minalign",
126
+ "objectEnd",
127
+ "vtables",
128
+ "nested",
129
+ "forceDefaults",
130
+ "finished",
131
+ "vectorNumElems",
132
+ "sharedStrings",
133
+ )
134
+
135
+ """Maximum buffer size constant, in bytes.
136
+
137
+ Builder will never allow it's buffer grow over this size.
138
+ Currently equals 2Gb.
139
+ """
140
+ MAX_BUFFER_SIZE = 2**31
141
+ ## @endcond
142
+
143
+ def __init__(self, initialSize=1024):
144
+ """Initializes a Builder of size `initial_size`.
145
+
146
+ The internal buffer is grown as needed.
147
+ """
148
+
149
+ if not (0 <= initialSize <= Builder.MAX_BUFFER_SIZE):
150
+ msg = "flatbuffers: Cannot create Builder larger than 2 gigabytes."
151
+ raise BuilderSizeError(msg)
152
+
153
+ self.Bytes = bytearray(initialSize)
154
+ ## @cond FLATBUFFERS_INTERNAL
155
+ self.current_vtable = None
156
+ self.head = UOffsetTFlags.py_type(initialSize)
157
+ self.minalign = 1
158
+ self.objectEnd = None
159
+ self.vtables = {}
160
+ self.nested = False
161
+ self.forceDefaults = False
162
+ self.sharedStrings = None
163
+ ## @endcond
164
+ self.finished = False
165
+
166
+ def Clear(self):
167
+ ## @cond FLATBUFFERS_INTERNAL
168
+ self.current_vtable = None
169
+ self.head = len(self.Bytes)
170
+ self.minalign = 1
171
+ self.objectEnd = None
172
+ self.vtables = {}
173
+ self.nested = False
174
+ self.forceDefaults = False
175
+ self.sharedStrings = None
176
+ self.vectorNumElems = None
177
+ ## @endcond
178
+ self.finished = False
179
+
180
+ def Output(self):
181
+ """Return the portion of the buffer that has been used for writing data.
182
+
183
+ This is the typical way to access the FlatBuffer data inside the
184
+ builder. If you try to access `Builder.Bytes` directly, you would need
185
+ to manually index it with `Head()`, since the buffer is constructed
186
+ backwards.
187
+
188
+ It raises BuilderNotFinishedError if the buffer has not been finished
189
+ with `Finish`.
190
+ """
191
+
192
+ if not self.finished:
193
+ raise BuilderNotFinishedError()
194
+
195
+ return self.Bytes[self.head :]
196
+
197
+ ## @cond FLATBUFFERS_INTERNAL
198
+ def StartObject(self, numfields):
199
+ """StartObject initializes bookkeeping for writing a new object."""
200
+
201
+ self.assertNotNested()
202
+
203
+ # use 32-bit offsets so that arithmetic doesn't overflow.
204
+ self.current_vtable = [0] * numfields
205
+ self.objectEnd = self.Offset()
206
+ self.nested = True
207
+
208
+ def WriteVtable(self):
209
+ """WriteVtable serializes the vtable for the current object, if needed.
210
+
211
+ Before writing out the vtable, this checks pre-existing vtables for
212
+ equality to this one. If an equal vtable is found, point the object to
213
+ the existing vtable and return.
214
+
215
+ Because vtable values are sensitive to alignment of object data, not
216
+ all logically-equal vtables will be deduplicated.
217
+
218
+ A vtable has the following format:
219
+ <VOffsetT: size of the vtable in bytes, including this value>
220
+ <VOffsetT: size of the object in bytes, including the vtable offset>
221
+ <VOffsetT: offset for a field> * N, where N is the number of fields
222
+ in the schema for this type. Includes deprecated fields.
223
+ Thus, a vtable is made of 2 + N elements, each VOffsetT bytes wide.
224
+
225
+ An object has the following format:
226
+ <SOffsetT: offset to this object's vtable (may be negative)>
227
+ <byte: data>+
228
+ """
229
+
230
+ # Prepend a zero scalar to the object. Later in this function we'll
231
+ # write an offset here that points to the object's vtable:
232
+ self.PrependSOffsetTRelative(0)
233
+
234
+ objectOffset = self.Offset()
235
+
236
+ vtKey = []
237
+ trim = True
238
+ for elem in reversed(self.current_vtable):
239
+ if elem == 0:
240
+ if trim:
241
+ continue
242
+ else:
243
+ elem = objectOffset - elem
244
+ trim = False
245
+
246
+ vtKey.append(elem)
247
+
248
+ objectSize = UOffsetTFlags.py_type(objectOffset - self.objectEnd)
249
+ vtKey.append(objectSize)
250
+ vtKey = tuple(vtKey)
251
+ # calculate the size of the object
252
+ vt2Offset = self.vtables.get(vtKey)
253
+ if vt2Offset is None:
254
+ # Did not find a vtable, so write this one to the buffer.
255
+
256
+ # Write out the current vtable in reverse , because
257
+ # serialization occurs in last-first order:
258
+ i = len(self.current_vtable) - 1
259
+ trailing = 0
260
+ trim = True
261
+ while i >= 0:
262
+ off = 0
263
+ elem = self.current_vtable[i]
264
+ i -= 1
265
+
266
+ if elem == 0:
267
+ if trim:
268
+ trailing += 1
269
+ continue
270
+ else:
271
+ # Forward reference to field;
272
+ # use 32bit number to ensure no overflow:
273
+ off = objectOffset - elem
274
+ trim = False
275
+
276
+ self.PrependVOffsetT(off)
277
+
278
+ # The two metadata fields are written last.
279
+
280
+ # First, store the object bytesize:
281
+ self.PrependVOffsetT(VOffsetTFlags.py_type(objectSize))
282
+
283
+ # Second, store the vtable bytesize:
284
+ vBytes = len(self.current_vtable) - trailing + VtableMetadataFields
285
+ vBytes *= N.VOffsetTFlags.bytewidth
286
+ self.PrependVOffsetT(VOffsetTFlags.py_type(vBytes))
287
+
288
+ # Next, write the offset to the new vtable in the
289
+ # already-allocated SOffsetT at the beginning of this object:
290
+ objectStart = SOffsetTFlags.py_type(len(self.Bytes) - objectOffset)
291
+ encode.Write(
292
+ packer.soffset,
293
+ self.Bytes,
294
+ objectStart,
295
+ SOffsetTFlags.py_type(self.Offset() - objectOffset),
296
+ )
297
+
298
+ # Finally, store this vtable in memory for future
299
+ # deduplication:
300
+ self.vtables[vtKey] = self.Offset()
301
+ else:
302
+ # Found a duplicate vtable.
303
+ objectStart = SOffsetTFlags.py_type(len(self.Bytes) - objectOffset)
304
+ self.head = UOffsetTFlags.py_type(objectStart)
305
+
306
+ # Write the offset to the found vtable in the
307
+ # already-allocated SOffsetT at the beginning of this object:
308
+ encode.Write(
309
+ packer.soffset,
310
+ self.Bytes,
311
+ self.Head(),
312
+ SOffsetTFlags.py_type(vt2Offset - objectOffset),
313
+ )
314
+
315
+ self.current_vtable = None
316
+ return objectOffset
317
+
318
+ def EndObject(self):
319
+ """EndObject writes data necessary to finish object construction."""
320
+ self.assertNested()
321
+ self.nested = False
322
+ return self.WriteVtable()
323
+
324
+ def GrowByteBuffer(self):
325
+ """Doubles the size of the byteslice, and copies the old data towards
326
+
327
+ the end of the new buffer (since we build the buffer backwards).
328
+ """
329
+ if len(self.Bytes) == Builder.MAX_BUFFER_SIZE:
330
+ msg = "flatbuffers: cannot grow buffer beyond 2 gigabytes"
331
+ raise BuilderSizeError(msg)
332
+
333
+ newSize = min(len(self.Bytes) * 2, Builder.MAX_BUFFER_SIZE)
334
+ if newSize == 0:
335
+ newSize = 1
336
+ bytes2 = bytearray(newSize)
337
+ bytes2[newSize - len(self.Bytes) :] = self.Bytes
338
+ self.Bytes = bytes2
339
+
340
+ ## @endcond
341
+
342
+ def Head(self):
343
+ """Get the start of useful data in the underlying byte buffer.
344
+
345
+ Note: unlike other functions, this value is interpreted as from the
346
+ left.
347
+ """
348
+ ## @cond FLATBUFFERS_INTERNAL
349
+ return self.head
350
+ ## @endcond
351
+
352
+ ## @cond FLATBUFFERS_INTERNAL
353
+ def Offset(self):
354
+ """Offset relative to the end of the buffer."""
355
+ return len(self.Bytes) - self.head
356
+
357
+ def Pad(self, n):
358
+ """Pad places zeros at the current offset."""
359
+ if n <= 0:
360
+ return
361
+ new_head = self.head - n
362
+ self.Bytes[new_head : self.head] = b"\x00" * n
363
+ self.head = new_head
364
+
365
+ def Prep(self, size, additionalBytes):
366
+ """Prep prepares to write an element of `size` after `additional_bytes`
367
+
368
+ have been written, e.g. if you write a string, you need to align
369
+ such the int length field is aligned to SizeInt32, and the string
370
+ data follows it directly.
371
+ If all you need to do is align, `additionalBytes` will be 0.
372
+ """
373
+
374
+ # Track the biggest thing we've ever aligned to.
375
+ if size > self.minalign:
376
+ self.minalign = size
377
+
378
+ # Find the amount of alignment needed such that `size` is properly
379
+ # aligned after `additionalBytes`:
380
+ head = self.head
381
+ buf_len = len(self.Bytes)
382
+ alignSize = (~(buf_len - head + additionalBytes)) + 1
383
+ alignSize &= size - 1
384
+
385
+ # Reallocate the buffer if needed:
386
+ needed = alignSize + size + additionalBytes
387
+ while head < needed:
388
+ oldBufSize = buf_len
389
+ self.GrowByteBuffer()
390
+ buf_len = len(self.Bytes)
391
+ head += buf_len - oldBufSize
392
+ self.head = head
393
+ self.Pad(alignSize)
394
+
395
+ def PrependSOffsetTRelative(self, off):
396
+ """PrependSOffsetTRelative prepends an SOffsetT, relative to where it
397
+
398
+ will be written.
399
+ """
400
+
401
+ # Ensure alignment is already done:
402
+ self.Prep(N.SOffsetTFlags.bytewidth, 0)
403
+ if not (off <= self.Offset()):
404
+ msg = "flatbuffers: Offset arithmetic error."
405
+ raise OffsetArithmeticError(msg)
406
+ off2 = self.Offset() - off + N.SOffsetTFlags.bytewidth
407
+ self.PlaceSOffsetT(off2)
408
+
409
+ ## @endcond
410
+
411
+ def PrependUOffsetTRelative(self, off):
412
+ """Prepends an unsigned offset into vector data, relative to where it
413
+
414
+ will be written.
415
+ """
416
+
417
+ # Ensure alignment is already done:
418
+ self.Prep(N.UOffsetTFlags.bytewidth, 0)
419
+ if not (off <= self.Offset()):
420
+ msg = "flatbuffers: Offset arithmetic error."
421
+ raise OffsetArithmeticError(msg)
422
+ off2 = self.Offset() - off + N.UOffsetTFlags.bytewidth
423
+ self.PlaceUOffsetT(off2)
424
+
425
+ ## @cond FLATBUFFERS_INTERNAL
426
+ def StartVector(self, elemSize, numElems, alignment):
427
+ """StartVector initializes bookkeeping for writing a new vector.
428
+
429
+ A vector has the following format:
430
+ - <UOffsetT: number of elements in this vector>
431
+ - <T: data>+, where T is the type of elements of this vector.
432
+ """
433
+
434
+ self.assertNotNested()
435
+ self.nested = True
436
+ self.vectorNumElems = numElems
437
+ self.Prep(N.Uint32Flags.bytewidth, elemSize * numElems)
438
+ self.Prep(alignment, elemSize * numElems) # In case alignment > int.
439
+ return self.Offset()
440
+
441
+ ## @endcond
442
+
443
+ def EndVector(self, numElems=None):
444
+ """EndVector writes data necessary to finish vector construction."""
445
+
446
+ self.assertNested()
447
+ ## @cond FLATBUFFERS_INTERNAL
448
+ self.nested = False
449
+ ## @endcond
450
+
451
+ if numElems:
452
+ warnings.warn("numElems is deprecated.", DeprecationWarning, stacklevel=2)
453
+ if numElems != self.vectorNumElems:
454
+ raise EndVectorLengthMismatched()
455
+
456
+ # we already made space for this, so write without PrependUint32
457
+ self.PlaceUOffsetT(self.vectorNumElems)
458
+ self.vectorNumElems = None
459
+ return self.Offset()
460
+
461
+ def CreateSharedString(self, s, encoding="utf-8", errors="strict"):
462
+ """CreateSharedString checks if the string is already written to the buffer
463
+
464
+ before calling CreateString.
465
+ """
466
+
467
+ if not self.sharedStrings:
468
+ self.sharedStrings = {}
469
+ elif s in self.sharedStrings:
470
+ return self.sharedStrings[s]
471
+
472
+ off = self.CreateString(s, encoding, errors)
473
+ self.sharedStrings[s] = off
474
+
475
+ return off
476
+
477
+ def CreateString(self, s, encoding="utf-8", errors="strict"):
478
+ """CreateString writes a null-terminated byte string as a vector."""
479
+
480
+ self.assertNotNested()
481
+ ## @cond FLATBUFFERS_INTERNAL
482
+ self.nested = True
483
+ ## @endcond
484
+
485
+ if isinstance(s, compat.string_types):
486
+ x = s.encode(encoding, errors)
487
+ elif isinstance(s, compat.binary_types):
488
+ x = s
489
+ else:
490
+ raise TypeError("non-string passed to CreateString")
491
+
492
+ payload_len = len(x)
493
+ self.Prep(N.UOffsetTFlags.bytewidth, (payload_len + 1) * N.Uint8Flags.bytewidth)
494
+ self.Place(0, N.Uint8Flags)
495
+
496
+ new_head = self.head - payload_len
497
+ self.head = new_head
498
+ self.Bytes[new_head : new_head + payload_len] = x
499
+
500
+ self.vectorNumElems = payload_len
501
+ return self.EndVector()
502
+
503
+ def CreateByteVector(self, x):
504
+ """CreateString writes a byte vector."""
505
+
506
+ self.assertNotNested()
507
+ ## @cond FLATBUFFERS_INTERNAL
508
+ self.nested = True
509
+ ## @endcond
510
+
511
+ if not isinstance(x, compat.binary_types):
512
+ raise TypeError("non-byte vector passed to CreateByteVector")
513
+
514
+ data_len = len(x)
515
+ self.Prep(N.UOffsetTFlags.bytewidth, data_len * N.Uint8Flags.bytewidth)
516
+ new_head = self.head - data_len
517
+ self.head = new_head
518
+ self.Bytes[new_head : new_head + data_len] = x
519
+
520
+ self.vectorNumElems = data_len
521
+ return self.EndVector()
522
+
523
+ def CreateNumpyVector(self, x):
524
+ """CreateNumpyVector writes a numpy array into the buffer."""
525
+
526
+ if np is None:
527
+ # Numpy is required for this feature
528
+ raise NumpyRequiredForThisFeature("Numpy was not found.")
529
+
530
+ if not isinstance(x, np.ndarray):
531
+ raise TypeError("non-numpy-ndarray passed to CreateNumpyVector")
532
+
533
+ if x.dtype.kind not in ["b", "i", "u", "f"]:
534
+ raise TypeError("numpy-ndarray holds elements of unsupported datatype")
535
+
536
+ if x.ndim > 1:
537
+ raise TypeError("multidimensional-ndarray passed to CreateNumpyVector")
538
+
539
+ self.StartVector(x.itemsize, x.size, x.dtype.alignment)
540
+
541
+ # Ensure little endian byte ordering
542
+ if x.dtype.str[0] == "<":
543
+ x_lend = x
544
+ else:
545
+ x_lend = x.byteswap(inplace=False)
546
+
547
+ # tobytes ensures c_contiguous ordering
548
+ payload = x_lend.tobytes(order="C")
549
+
550
+ # Calculate total length
551
+ payload_len = len(payload)
552
+ new_head = self.head - payload_len
553
+ self.head = new_head
554
+ self.Bytes[new_head : new_head + payload_len] = payload
555
+
556
+ self.vectorNumElems = x.size
557
+ return self.EndVector()
558
+
559
+ ## @cond FLATBUFFERS_INTERNAL
560
+ def assertNested(self):
561
+ """Check that we are in the process of building an object."""
562
+
563
+ if not self.nested:
564
+ raise IsNotNestedError()
565
+
566
+ def assertNotNested(self):
567
+ """Check that no other objects are being built while making this object.
568
+
569
+ If not, raise an exception.
570
+ """
571
+
572
+ if self.nested:
573
+ raise IsNestedError()
574
+
575
+ def assertStructIsInline(self, obj):
576
+ """Structs are always stored inline, so need to be created right
577
+
578
+ where they are used. You'll get this error if you created it
579
+ elsewhere.
580
+ """
581
+
582
+ N.enforce_number(obj, N.UOffsetTFlags)
583
+ if obj != self.Offset():
584
+ msg = (
585
+ "flatbuffers: Tried to write a Struct at an Offset that "
586
+ "is different from the current Offset of the Builder."
587
+ )
588
+ raise StructIsNotInlineError(msg)
589
+
590
+ def Slot(self, slotnum):
591
+ """Slot sets the vtable key `voffset` to the current location in the
592
+
593
+ buffer.
594
+ """
595
+ self.assertNested()
596
+ self.current_vtable[slotnum] = self.Offset()
597
+
598
+ ## @endcond
599
+
600
+ def __Finish(self, rootTable, sizePrefix, file_identifier=None):
601
+ """Finish finalizes a buffer, pointing to the given `rootTable`."""
602
+ N.enforce_number(rootTable, N.UOffsetTFlags)
603
+
604
+ prepSize = N.UOffsetTFlags.bytewidth
605
+ if file_identifier is not None:
606
+ prepSize += N.Int32Flags.bytewidth
607
+ if sizePrefix:
608
+ prepSize += N.Int32Flags.bytewidth
609
+ self.Prep(self.minalign, prepSize)
610
+
611
+ if file_identifier is not None:
612
+ self.Prep(N.UOffsetTFlags.bytewidth, encode.FILE_IDENTIFIER_LENGTH)
613
+
614
+ # Convert bytes object file_identifier to an array of 4 8-bit integers,
615
+ # and use big-endian to enforce size compliance.
616
+ # https://docs.python.org/2/library/struct.html#format-characters
617
+ file_identifier = N.struct.unpack(">BBBB", file_identifier)
618
+ for i in range(encode.FILE_IDENTIFIER_LENGTH - 1, -1, -1):
619
+ # Place the bytes of the file_identifer in reverse order:
620
+ self.Place(file_identifier[i], N.Uint8Flags)
621
+
622
+ self.PrependUOffsetTRelative(rootTable)
623
+ if sizePrefix:
624
+ size = len(self.Bytes) - self.head
625
+ N.enforce_number(size, N.Int32Flags)
626
+ self.PrependInt32(size)
627
+ self.finished = True
628
+ return self.head
629
+
630
+ def Finish(self, rootTable, file_identifier=None):
631
+ """Finish finalizes a buffer, pointing to the given `rootTable`."""
632
+ return self.__Finish(rootTable, False, file_identifier=file_identifier)
633
+
634
+ def FinishSizePrefixed(self, rootTable, file_identifier=None):
635
+ """Finish finalizes a buffer, pointing to the given `rootTable`,
636
+
637
+ with the size prefixed.
638
+ """
639
+ return self.__Finish(rootTable, True, file_identifier=file_identifier)
640
+
641
+ ## @cond FLATBUFFERS_INTERNAL
642
+ def Prepend(self, flags, off):
643
+ self.Prep(flags.bytewidth, 0)
644
+ self.Place(off, flags)
645
+
646
+ def PrependSlot(self, flags, o, x, d):
647
+ if x is not None:
648
+ N.enforce_number(x, flags)
649
+ if d is not None:
650
+ N.enforce_number(d, flags)
651
+ if x != d or (self.forceDefaults and d is not None):
652
+ self.Prepend(flags, x)
653
+ self.Slot(o)
654
+
655
+ def PrependBoolSlot(self, *args):
656
+ self.PrependSlot(N.BoolFlags, *args)
657
+
658
+ def PrependByteSlot(self, *args):
659
+ self.PrependSlot(N.Uint8Flags, *args)
660
+
661
+ def PrependUint8Slot(self, *args):
662
+ self.PrependSlot(N.Uint8Flags, *args)
663
+
664
+ def PrependUint16Slot(self, *args):
665
+ self.PrependSlot(N.Uint16Flags, *args)
666
+
667
+ def PrependUint32Slot(self, *args):
668
+ self.PrependSlot(N.Uint32Flags, *args)
669
+
670
+ def PrependUint64Slot(self, *args):
671
+ self.PrependSlot(N.Uint64Flags, *args)
672
+
673
+ def PrependInt8Slot(self, *args):
674
+ self.PrependSlot(N.Int8Flags, *args)
675
+
676
+ def PrependInt16Slot(self, *args):
677
+ self.PrependSlot(N.Int16Flags, *args)
678
+
679
+ def PrependInt32Slot(self, *args):
680
+ self.PrependSlot(N.Int32Flags, *args)
681
+
682
+ def PrependInt64Slot(self, *args):
683
+ self.PrependSlot(N.Int64Flags, *args)
684
+
685
+ def PrependFloat32Slot(self, *args):
686
+ self.PrependSlot(N.Float32Flags, *args)
687
+
688
+ def PrependFloat64Slot(self, *args):
689
+ self.PrependSlot(N.Float64Flags, *args)
690
+
691
+ def PrependUOffsetTRelativeSlot(self, o, x, d):
692
+ """PrependUOffsetTRelativeSlot prepends an UOffsetT onto the object at
693
+
694
+ vtable slot `o`. If value `x` equals default `d`, then the slot will
695
+ be set to zero and no other data will be written.
696
+ """
697
+
698
+ if x != d or self.forceDefaults:
699
+ self.PrependUOffsetTRelative(x)
700
+ self.Slot(o)
701
+
702
+ def PrependStructSlot(self, v, x, d):
703
+ """PrependStructSlot prepends a struct onto the object at vtable slot `o`.
704
+
705
+ Structs are stored inline, so nothing additional is being added. In
706
+ generated code, `d` is always 0.
707
+ """
708
+
709
+ N.enforce_number(d, N.UOffsetTFlags)
710
+ if x != d:
711
+ self.assertStructIsInline(x)
712
+ self.Slot(v)
713
+
714
+ ## @endcond
715
+
716
+ def PrependBool(self, x):
717
+ """Prepend a `bool` to the Builder buffer.
718
+
719
+ Note: aligns and checks for space.
720
+ """
721
+ self.Prepend(N.BoolFlags, x)
722
+
723
+ def PrependByte(self, x):
724
+ """Prepend a `byte` to the Builder buffer.
725
+
726
+ Note: aligns and checks for space.
727
+ """
728
+ self.Prepend(N.Uint8Flags, x)
729
+
730
+ def PrependUint8(self, x):
731
+ """Prepend an `uint8` to the Builder buffer.
732
+
733
+ Note: aligns and checks for space.
734
+ """
735
+ self.Prepend(N.Uint8Flags, x)
736
+
737
+ def PrependUint16(self, x):
738
+ """Prepend an `uint16` to the Builder buffer.
739
+
740
+ Note: aligns and checks for space.
741
+ """
742
+ self.Prepend(N.Uint16Flags, x)
743
+
744
+ def PrependUint32(self, x):
745
+ """Prepend an `uint32` to the Builder buffer.
746
+
747
+ Note: aligns and checks for space.
748
+ """
749
+ self.Prepend(N.Uint32Flags, x)
750
+
751
+ def PrependUint64(self, x):
752
+ """Prepend an `uint64` to the Builder buffer.
753
+
754
+ Note: aligns and checks for space.
755
+ """
756
+ self.Prepend(N.Uint64Flags, x)
757
+
758
+ def PrependInt8(self, x):
759
+ """Prepend an `int8` to the Builder buffer.
760
+
761
+ Note: aligns and checks for space.
762
+ """
763
+ self.Prepend(N.Int8Flags, x)
764
+
765
+ def PrependInt16(self, x):
766
+ """Prepend an `int16` to the Builder buffer.
767
+
768
+ Note: aligns and checks for space.
769
+ """
770
+ self.Prepend(N.Int16Flags, x)
771
+
772
+ def PrependInt32(self, x):
773
+ """Prepend an `int32` to the Builder buffer.
774
+
775
+ Note: aligns and checks for space.
776
+ """
777
+ self.Prepend(N.Int32Flags, x)
778
+
779
+ def PrependInt64(self, x):
780
+ """Prepend an `int64` to the Builder buffer.
781
+
782
+ Note: aligns and checks for space.
783
+ """
784
+ self.Prepend(N.Int64Flags, x)
785
+
786
+ def PrependFloat32(self, x):
787
+ """Prepend a `float32` to the Builder buffer.
788
+
789
+ Note: aligns and checks for space.
790
+ """
791
+ self.Prepend(N.Float32Flags, x)
792
+
793
+ def PrependFloat64(self, x):
794
+ """Prepend a `float64` to the Builder buffer.
795
+
796
+ Note: aligns and checks for space.
797
+ """
798
+ self.Prepend(N.Float64Flags, x)
799
+
800
+ def ForceDefaults(self, forceDefaults):
801
+ """In order to save space, fields that are set to their default value
802
+
803
+ don't get serialized into the buffer. Forcing defaults provides a
804
+ way to manually disable this optimization. When set to `True`, will
805
+ always serialize default values.
806
+ """
807
+ self.forceDefaults = forceDefaults
808
+
809
+ ##############################################################
810
+
811
+ ## @cond FLATBUFFERS_INTERNAL
812
+ def PrependVOffsetT(self, x):
813
+ self.Prepend(N.VOffsetTFlags, x)
814
+
815
+ def Place(self, x, flags):
816
+ """Place prepends a value specified by `flags` to the Builder,
817
+
818
+ without checking for available space.
819
+ """
820
+
821
+ N.enforce_number(x, flags)
822
+ new_head = self.head - flags.bytewidth
823
+ self.head = new_head
824
+ encode.Write(flags.packer_type, self.Bytes, new_head, x)
825
+
826
+ def PlaceVOffsetT(self, x):
827
+ """PlaceVOffsetT prepends a VOffsetT to the Builder, without checking
828
+
829
+ for space.
830
+ """
831
+ N.enforce_number(x, N.VOffsetTFlags)
832
+ new_head = self.head - N.VOffsetTFlags.bytewidth
833
+ self.head = new_head
834
+ encode.Write(packer.voffset, self.Bytes, new_head, x)
835
+
836
+ def PlaceSOffsetT(self, x):
837
+ """PlaceSOffsetT prepends a SOffsetT to the Builder, without checking
838
+
839
+ for space.
840
+ """
841
+ N.enforce_number(x, N.SOffsetTFlags)
842
+ new_head = self.head - N.SOffsetTFlags.bytewidth
843
+ self.head = new_head
844
+ encode.Write(packer.soffset, self.Bytes, new_head, x)
845
+
846
+ def PlaceUOffsetT(self, x):
847
+ """PlaceUOffsetT prepends a UOffsetT to the Builder, without checking
848
+
849
+ for space.
850
+ """
851
+ N.enforce_number(x, N.UOffsetTFlags)
852
+ new_head = self.head - N.UOffsetTFlags.bytewidth
853
+ self.head = new_head
854
+ encode.Write(packer.uoffset, self.Bytes, new_head, x)
855
+
856
+ ## @endcond
857
+
858
+ ## @}
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/compat.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2016 Google Inc. All rights reserved.
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
+
15
+ """A tiny version of `six` to help with backwards compability.
16
+
17
+ Also includes compatibility helpers for numpy.
18
+ """
19
+
20
+ import sys
21
+
22
+ PY2 = sys.version_info[0] == 2
23
+ PY26 = sys.version_info[0:2] == (2, 6)
24
+ PY27 = sys.version_info[0:2] == (2, 7)
25
+ PY275 = sys.version_info[0:3] >= (2, 7, 5)
26
+ PY3 = sys.version_info[0] == 3
27
+ PY34 = sys.version_info[0:2] >= (3, 4)
28
+
29
+ if PY3:
30
+ import importlib.machinery
31
+
32
+ string_types = (str,)
33
+ binary_types = (bytes, bytearray)
34
+ range_func = range
35
+ memoryview_type = memoryview
36
+ struct_bool_decl = "?"
37
+ else:
38
+ import imp
39
+
40
+ string_types = (unicode,)
41
+ if PY26 or PY27:
42
+ binary_types = (str, bytearray)
43
+ else:
44
+ binary_types = (str,)
45
+ range_func = xrange
46
+ if PY26 or (PY27 and not PY275):
47
+ memoryview_type = buffer
48
+ struct_bool_decl = "<b"
49
+ else:
50
+ memoryview_type = memoryview
51
+ struct_bool_decl = "?"
52
+
53
+ # Helper functions to facilitate making numpy optional instead of required
54
+
55
+
56
+ def import_numpy():
57
+ """Returns the numpy module if it exists on the system,
58
+
59
+ otherwise returns None.
60
+ """
61
+ if PY3:
62
+ numpy_exists = importlib.machinery.PathFinder.find_spec("numpy") is not None
63
+ else:
64
+ try:
65
+ imp.find_module("numpy")
66
+ numpy_exists = True
67
+ except ImportError:
68
+ numpy_exists = False
69
+
70
+ if numpy_exists:
71
+ # We do this outside of try/except block in case numpy exists
72
+ # but is not installed correctly. We do not want to catch an
73
+ # incorrect installation which would manifest as an
74
+ # ImportError.
75
+ import numpy as np
76
+ else:
77
+ np = None
78
+
79
+ return np
80
+
81
+
82
+ class NumpyRequiredForThisFeature(RuntimeError):
83
+ """Error raised when user tries to use a feature that
84
+
85
+ requires numpy without having numpy installed.
86
+ """
87
+
88
+ pass
89
+
90
+
91
+ # NOTE: Future Jython support may require code here (look at `six`).
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/encode.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2014 Google Inc. All rights reserved.
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
+
15
+ from . import number_types as N
16
+ from . import packer
17
+ from .compat import memoryview_type
18
+ from .compat import NumpyRequiredForThisFeature, import_numpy
19
+
20
+ np = import_numpy()
21
+
22
+ FILE_IDENTIFIER_LENGTH = 4
23
+
24
+
25
+ def Get(packer_type, buf, head):
26
+ """Get decodes a value at buf[head] using `packer_type`."""
27
+ return packer_type.unpack_from(memoryview_type(buf), head)[0]
28
+
29
+
30
+ def GetVectorAsNumpy(numpy_type, buf, count, offset):
31
+ """GetVecAsNumpy decodes values starting at buf[head] as
32
+
33
+ `numpy_type`, where `numpy_type` is a numpy dtype.
34
+ """
35
+ if np is not None:
36
+ # TODO: could set .flags.writeable = False to make users jump through
37
+ # hoops before modifying...
38
+ return np.frombuffer(buf, dtype=numpy_type, count=count, offset=offset)
39
+ else:
40
+ raise NumpyRequiredForThisFeature('Numpy was not found.')
41
+
42
+
43
+ def Write(packer_type, buf, head, n):
44
+ """Write encodes `n` at buf[head] using `packer_type`."""
45
+ packer_type.pack_into(buf, head, n)
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/flexbuffers.py ADDED
@@ -0,0 +1,1592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Lint as: python3
2
+ # Copyright 2020 Google Inc. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Implementation of FlexBuffers binary format.
16
+
17
+ For more info check https://google.github.io/flatbuffers/flexbuffers.html and
18
+ corresponding C++ implementation at
19
+ https://github.com/google/flatbuffers/blob/master/include/flatbuffers/flexbuffers.h
20
+ """
21
+
22
+ # pylint: disable=invalid-name
23
+ # TODO(dkovalev): Add type hints everywhere, so tools like pytypes could work.
24
+
25
+ import array
26
+ import contextlib
27
+ import enum
28
+ import struct
29
+
30
+ __all__ = ('Type', 'Builder', 'GetRoot', 'Dumps', 'Loads')
31
+
32
+
33
+ class BitWidth(enum.IntEnum):
34
+ """Supported bit widths of value types.
35
+
36
+ These are used in the lower 2 bits of a type field to determine the size of
37
+ the elements (and or size field) of the item pointed to (e.g. vector).
38
+ """
39
+
40
+ W8 = 0 # 2^0 = 1 byte
41
+ W16 = 1 # 2^1 = 2 bytes
42
+ W32 = 2 # 2^2 = 4 bytes
43
+ W64 = 3 # 2^3 = 8 bytes
44
+
45
+ @staticmethod
46
+ def U(value):
47
+ """Returns the minimum `BitWidth` to encode unsigned integer value."""
48
+ assert value >= 0
49
+
50
+ if value < (1 << 8):
51
+ return BitWidth.W8
52
+ elif value < (1 << 16):
53
+ return BitWidth.W16
54
+ elif value < (1 << 32):
55
+ return BitWidth.W32
56
+ elif value < (1 << 64):
57
+ return BitWidth.W64
58
+ else:
59
+ raise ValueError('value is too big to encode: %s' % value)
60
+
61
+ @staticmethod
62
+ def I(value):
63
+ """Returns the minimum `BitWidth` to encode signed integer value."""
64
+ # -2^(n-1) <= value < 2^(n-1)
65
+ # -2^n <= 2 * value < 2^n
66
+ # 2 * value < 2^n, when value >= 0 or 2 * (-value) <= 2^n, when value < 0
67
+ # 2 * value < 2^n, when value >= 0 or 2 * (-value) - 1 < 2^n, when value < 0
68
+ #
69
+ # if value >= 0:
70
+ # return BitWidth.U(2 * value)
71
+ # else:
72
+ # return BitWidth.U(2 * (-value) - 1) # ~x = -x - 1
73
+ value *= 2
74
+ return BitWidth.U(value if value >= 0 else ~value)
75
+
76
+ @staticmethod
77
+ def F(value):
78
+ """Returns the `BitWidth` to encode floating point value."""
79
+ if struct.unpack('<f', struct.pack('<f', value))[0] == value:
80
+ return BitWidth.W32
81
+ return BitWidth.W64
82
+
83
+ @staticmethod
84
+ def B(byte_width):
85
+ return {1: BitWidth.W8, 2: BitWidth.W16, 4: BitWidth.W32, 8: BitWidth.W64}[
86
+ byte_width
87
+ ]
88
+
89
+
90
+ I = {1: 'b', 2: 'h', 4: 'i', 8: 'q'} # Integer formats
91
+ U = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'} # Unsigned integer formats
92
+ F = {4: 'f', 8: 'd'} # Floating point formats
93
+
94
+
95
+ def _Unpack(fmt, buf):
96
+ return struct.unpack('<%s' % fmt[len(buf)], buf)[0]
97
+
98
+
99
+ def _UnpackVector(fmt, buf, length):
100
+ byte_width = len(buf) // length
101
+ return struct.unpack('<%d%s' % (length, fmt[byte_width]), buf)
102
+
103
+
104
+ def _Pack(fmt, value, byte_width):
105
+ return struct.pack('<%s' % fmt[byte_width], value)
106
+
107
+
108
+ def _PackVector(fmt, values, byte_width):
109
+ return struct.pack('<%d%s' % (len(values), fmt[byte_width]), *values)
110
+
111
+
112
+ def _Mutate(fmt, buf, value, byte_width, value_bit_width):
113
+ if (1 << value_bit_width) <= byte_width:
114
+ buf[:byte_width] = _Pack(fmt, value, byte_width)
115
+ return True
116
+ return False
117
+
118
+
119
+ # Computes how many bytes you'd have to pad to be able to write an
120
+ # "scalar_size" scalar if the buffer had grown to "buf_size",
121
+ # "scalar_size" is a power of two.
122
+ def _PaddingBytes(buf_size, scalar_size):
123
+ # ((buf_size + (scalar_size - 1)) // scalar_size) * scalar_size - buf_size
124
+ return -buf_size & (scalar_size - 1)
125
+
126
+
127
+ def _ShiftSlice(s, offset, length):
128
+ start = offset + (0 if s.start is None else s.start)
129
+ stop = offset + (length if s.stop is None else s.stop)
130
+ return slice(start, stop, s.step)
131
+
132
+
133
+ # https://en.cppreference.com/w/cpp/algorithm/lower_bound
134
+ def _LowerBound(values, value, pred):
135
+ """Implementation of C++ std::lower_bound() algorithm."""
136
+ first, last = 0, len(values)
137
+ count = last - first
138
+ while count > 0:
139
+ i = first
140
+ step = count // 2
141
+ i += step
142
+ if pred(values[i], value):
143
+ i += 1
144
+ first = i
145
+ count -= step + 1
146
+ else:
147
+ count = step
148
+ return first
149
+
150
+
151
+ # https://en.cppreference.com/w/cpp/algorithm/binary_search
152
+ def _BinarySearch(values, value, pred=lambda x, y: x < y):
153
+ """Implementation of C++ std::binary_search() algorithm."""
154
+ index = _LowerBound(values, value, pred)
155
+ if index != len(values) and not pred(value, values[index]):
156
+ return index
157
+ return -1
158
+
159
+
160
+ class Type(enum.IntEnum):
161
+ """Supported types of encoded data.
162
+
163
+ These are used as the upper 6 bits of a type field to indicate the actual
164
+ type.
165
+ """
166
+
167
+ NULL = 0
168
+ INT = 1
169
+ UINT = 2
170
+ FLOAT = 3
171
+ # Types above stored inline, types below store an offset.
172
+ KEY = 4
173
+ STRING = 5
174
+ INDIRECT_INT = 6
175
+ INDIRECT_UINT = 7
176
+ INDIRECT_FLOAT = 8
177
+ MAP = 9
178
+ VECTOR = 10 # Untyped.
179
+
180
+ VECTOR_INT = 11 # Typed any size (stores no type table).
181
+ VECTOR_UINT = 12
182
+ VECTOR_FLOAT = 13
183
+ VECTOR_KEY = 14
184
+ # DEPRECATED, use VECTOR or VECTOR_KEY instead.
185
+ # Read test.cpp/FlexBuffersDeprecatedTest() for details on why.
186
+ VECTOR_STRING_DEPRECATED = 15
187
+
188
+ VECTOR_INT2 = 16 # Typed tuple (no type table, no size field).
189
+ VECTOR_UINT2 = 17
190
+ VECTOR_FLOAT2 = 18
191
+ VECTOR_INT3 = 19 # Typed triple (no type table, no size field).
192
+ VECTOR_UINT3 = 20
193
+ VECTOR_FLOAT3 = 21
194
+ VECTOR_INT4 = 22 # Typed quad (no type table, no size field).
195
+ VECTOR_UINT4 = 23
196
+ VECTOR_FLOAT4 = 24
197
+
198
+ BLOB = 25
199
+ BOOL = 26
200
+ VECTOR_BOOL = 36 # To do the same type of conversion of type to vector type
201
+
202
+ @staticmethod
203
+ def Pack(type_, bit_width):
204
+ return (int(type_) << 2) | bit_width
205
+
206
+ @staticmethod
207
+ def Unpack(packed_type):
208
+ return 1 << (packed_type & 0b11), Type(packed_type >> 2)
209
+
210
+ @staticmethod
211
+ def IsInline(type_):
212
+ return type_ <= Type.FLOAT or type_ == Type.BOOL
213
+
214
+ @staticmethod
215
+ def IsTypedVector(type_):
216
+ return (
217
+ Type.VECTOR_INT <= type_ <= Type.VECTOR_STRING_DEPRECATED
218
+ or type_ == Type.VECTOR_BOOL
219
+ )
220
+
221
+ @staticmethod
222
+ def IsTypedVectorElementType(type_):
223
+ return Type.INT <= type_ <= Type.STRING or type_ == Type.BOOL
224
+
225
+ @staticmethod
226
+ def ToTypedVectorElementType(type_):
227
+ if not Type.IsTypedVector(type_):
228
+ raise ValueError('must be typed vector type')
229
+
230
+ return Type(type_ - Type.VECTOR_INT + Type.INT)
231
+
232
+ @staticmethod
233
+ def IsFixedTypedVector(type_):
234
+ return Type.VECTOR_INT2 <= type_ <= Type.VECTOR_FLOAT4
235
+
236
+ @staticmethod
237
+ def IsFixedTypedVectorElementType(type_):
238
+ return Type.INT <= type_ <= Type.FLOAT
239
+
240
+ @staticmethod
241
+ def ToFixedTypedVectorElementType(type_):
242
+ if not Type.IsFixedTypedVector(type_):
243
+ raise ValueError('must be fixed typed vector type')
244
+
245
+ # 3 types each, starting from length 2.
246
+ fixed_type = type_ - Type.VECTOR_INT2
247
+ return Type(fixed_type % 3 + Type.INT), fixed_type // 3 + 2
248
+
249
+ @staticmethod
250
+ def ToTypedVector(element_type, fixed_len=0):
251
+ """Converts element type to corresponding vector type.
252
+
253
+ Args:
254
+ element_type: vector element type
255
+ fixed_len: number of elements: 0 for typed vector; 2, 3, or 4 for fixed
256
+ typed vector.
257
+
258
+ Returns:
259
+ Typed vector type or fixed typed vector type.
260
+ """
261
+ if fixed_len == 0:
262
+ if not Type.IsTypedVectorElementType(element_type):
263
+ raise ValueError('must be typed vector element type')
264
+ else:
265
+ if not Type.IsFixedTypedVectorElementType(element_type):
266
+ raise ValueError('must be fixed typed vector element type')
267
+
268
+ offset = element_type - Type.INT
269
+ if fixed_len == 0:
270
+ return Type(offset + Type.VECTOR_INT) # TypedVector
271
+ elif fixed_len == 2:
272
+ return Type(offset + Type.VECTOR_INT2) # FixedTypedVector
273
+ elif fixed_len == 3:
274
+ return Type(offset + Type.VECTOR_INT3) # FixedTypedVector
275
+ elif fixed_len == 4:
276
+ return Type(offset + Type.VECTOR_INT4) # FixedTypedVector
277
+ else:
278
+ raise ValueError('unsupported fixed_len: %s' % fixed_len)
279
+
280
+
281
+ class Buf:
282
+ """Class to access underlying buffer object starting from the given offset."""
283
+
284
+ def __init__(self, buf, offset):
285
+ self._buf = buf
286
+ self._offset = offset if offset >= 0 else len(buf) + offset
287
+ self._length = len(buf) - self._offset
288
+
289
+ def __getitem__(self, key):
290
+ if isinstance(key, slice):
291
+ return self._buf[_ShiftSlice(key, self._offset, self._length)]
292
+ elif isinstance(key, int):
293
+ return self._buf[self._offset + key]
294
+ else:
295
+ raise TypeError('invalid key type')
296
+
297
+ def __setitem__(self, key, value):
298
+ if isinstance(key, slice):
299
+ self._buf[_ShiftSlice(key, self._offset, self._length)] = value
300
+ elif isinstance(key, int):
301
+ self._buf[self._offset + key] = key
302
+ else:
303
+ raise TypeError('invalid key type')
304
+
305
+ def __repr__(self):
306
+ return 'buf[%d:]' % self._offset
307
+
308
+ def Find(self, sub):
309
+ """Returns the lowest index where the sub subsequence is found."""
310
+ return self._buf[self._offset :].find(sub)
311
+
312
+ def Slice(self, offset):
313
+ """Returns new `Buf` which starts from the given offset."""
314
+ return Buf(self._buf, self._offset + offset)
315
+
316
+ def Indirect(self, offset, byte_width):
317
+ """Return new `Buf` based on the encoded offset (indirect encoding)."""
318
+ return self.Slice(offset - _Unpack(U, self[offset : offset + byte_width]))
319
+
320
+
321
+ class Object:
322
+ """Base class for all non-trivial data accessors."""
323
+
324
+ __slots__ = '_buf', '_byte_width'
325
+
326
+ def __init__(self, buf, byte_width):
327
+ self._buf = buf
328
+ self._byte_width = byte_width
329
+
330
+ @property
331
+ def ByteWidth(self):
332
+ return self._byte_width
333
+
334
+
335
+ class Sized(Object):
336
+ """Base class for all data accessors which need to read encoded size."""
337
+
338
+ __slots__ = ('_size',)
339
+
340
+ def __init__(self, buf, byte_width, size=0):
341
+ super().__init__(buf, byte_width)
342
+ if size == 0:
343
+ self._size = _Unpack(U, self.SizeBytes)
344
+ else:
345
+ self._size = size
346
+
347
+ @property
348
+ def SizeBytes(self):
349
+ return self._buf[-self._byte_width : 0]
350
+
351
+ def __len__(self):
352
+ return self._size
353
+
354
+
355
+ class Blob(Sized):
356
+ """Data accessor for the encoded blob bytes."""
357
+
358
+ __slots__ = ()
359
+
360
+ @property
361
+ def Bytes(self):
362
+ return self._buf[0 : len(self)]
363
+
364
+ def __repr__(self):
365
+ return 'Blob(%s, size=%d)' % (self._buf, len(self))
366
+
367
+
368
+ class String(Sized):
369
+ """Data accessor for the encoded string bytes."""
370
+
371
+ __slots__ = ()
372
+
373
+ @property
374
+ def Bytes(self):
375
+ return self._buf[0 : len(self)]
376
+
377
+ def Mutate(self, value):
378
+ """Mutates underlying string bytes in place.
379
+
380
+ Args:
381
+ value: New string to replace the existing one. New string must have less
382
+ or equal UTF-8-encoded bytes than the existing one to successfully
383
+ mutate underlying byte buffer.
384
+
385
+ Returns:
386
+ Whether the value was mutated or not.
387
+ """
388
+ encoded = value.encode('utf-8')
389
+ n = len(encoded)
390
+ if n <= len(self):
391
+ self._buf[-self._byte_width : 0] = _Pack(U, n, self._byte_width)
392
+ self._buf[0:n] = encoded
393
+ self._buf[n : len(self)] = bytearray(len(self) - n)
394
+ return True
395
+ return False
396
+
397
+ def __str__(self):
398
+ return self.Bytes.decode('utf-8')
399
+
400
+ def __repr__(self):
401
+ return 'String(%s, size=%d)' % (self._buf, len(self))
402
+
403
+
404
+ class Key(Object):
405
+ """Data accessor for the encoded key bytes."""
406
+
407
+ __slots__ = ()
408
+
409
+ def __init__(self, buf, byte_width):
410
+ assert byte_width == 1
411
+ super().__init__(buf, byte_width)
412
+
413
+ @property
414
+ def Bytes(self):
415
+ return self._buf[0 : len(self)]
416
+
417
+ def __len__(self):
418
+ return self._buf.Find(0)
419
+
420
+ def __str__(self):
421
+ return self.Bytes.decode('ascii')
422
+
423
+ def __repr__(self):
424
+ return 'Key(%s, size=%d)' % (self._buf, len(self))
425
+
426
+
427
+ class Vector(Sized):
428
+ """Data accessor for the encoded vector bytes."""
429
+
430
+ __slots__ = ()
431
+
432
+ def __getitem__(self, index):
433
+ if index < 0 or index >= len(self):
434
+ raise IndexError(
435
+ 'vector index %s is out of [0, %d) range' % (index, len(self))
436
+ )
437
+
438
+ packed_type = self._buf[len(self) * self._byte_width + index]
439
+ buf = self._buf.Slice(index * self._byte_width)
440
+ return Ref.PackedType(buf, self._byte_width, packed_type)
441
+
442
+ @property
443
+ def Value(self):
444
+ """Returns the underlying encoded data as a list object."""
445
+ return [e.Value for e in self]
446
+
447
+ def __repr__(self):
448
+ return 'Vector(%s, byte_width=%d, size=%d)' % (
449
+ self._buf,
450
+ self._byte_width,
451
+ self._size,
452
+ )
453
+
454
+
455
+ class TypedVector(Sized):
456
+ """Data accessor for the encoded typed vector or fixed typed vector bytes."""
457
+
458
+ __slots__ = '_element_type', '_size'
459
+
460
+ def __init__(self, buf, byte_width, element_type, size=0):
461
+ super().__init__(buf, byte_width, size)
462
+
463
+ if element_type == Type.STRING:
464
+ # These can't be accessed as strings, since we don't know the bit-width
465
+ # of the size field, see the declaration of
466
+ # FBT_VECTOR_STRING_DEPRECATED above for details.
467
+ # We change the type here to be keys, which are a subtype of strings,
468
+ # and will ignore the size field. This will truncate strings with
469
+ # embedded nulls.
470
+ element_type = Type.KEY
471
+
472
+ self._element_type = element_type
473
+
474
+ @property
475
+ def Bytes(self):
476
+ return self._buf[: self._byte_width * len(self)]
477
+
478
+ @property
479
+ def ElementType(self):
480
+ return self._element_type
481
+
482
+ def __getitem__(self, index):
483
+ if index < 0 or index >= len(self):
484
+ raise IndexError(
485
+ 'vector index %s is out of [0, %d) range' % (index, len(self))
486
+ )
487
+
488
+ buf = self._buf.Slice(index * self._byte_width)
489
+ return Ref(buf, self._byte_width, 1, self._element_type)
490
+
491
+ @property
492
+ def Value(self):
493
+ """Returns underlying data as list object."""
494
+ if not self:
495
+ return []
496
+
497
+ if self._element_type is Type.BOOL:
498
+ return [bool(e) for e in _UnpackVector(U, self.Bytes, len(self))]
499
+ elif self._element_type is Type.INT:
500
+ return list(_UnpackVector(I, self.Bytes, len(self)))
501
+ elif self._element_type is Type.UINT:
502
+ return list(_UnpackVector(U, self.Bytes, len(self)))
503
+ elif self._element_type is Type.FLOAT:
504
+ return list(_UnpackVector(F, self.Bytes, len(self)))
505
+ elif self._element_type is Type.KEY:
506
+ return [e.AsKey for e in self]
507
+ elif self._element_type is Type.STRING:
508
+ return [e.AsString for e in self]
509
+ else:
510
+ raise TypeError('unsupported element_type: %s' % self._element_type)
511
+
512
+ def __repr__(self):
513
+ return 'TypedVector(%s, byte_width=%d, element_type=%s, size=%d)' % (
514
+ self._buf,
515
+ self._byte_width,
516
+ self._element_type,
517
+ self._size,
518
+ )
519
+
520
+
521
+ class Map(Vector):
522
+ """Data accessor for the encoded map bytes."""
523
+
524
+ @staticmethod
525
+ def CompareKeys(a, b):
526
+ if isinstance(a, Ref):
527
+ a = a.AsKeyBytes
528
+ if isinstance(b, Ref):
529
+ b = b.AsKeyBytes
530
+ return a < b
531
+
532
+ def __getitem__(self, key):
533
+ if isinstance(key, int):
534
+ return super().__getitem__(key)
535
+
536
+ index = _BinarySearch(self.Keys, key.encode('ascii'), self.CompareKeys)
537
+ if index != -1:
538
+ return super().__getitem__(index)
539
+
540
+ raise KeyError(key)
541
+
542
+ @property
543
+ def Keys(self):
544
+ byte_width = _Unpack(
545
+ U, self._buf[-2 * self._byte_width : -self._byte_width]
546
+ )
547
+ buf = self._buf.Indirect(-3 * self._byte_width, self._byte_width)
548
+ return TypedVector(buf, byte_width, Type.KEY)
549
+
550
+ @property
551
+ def Values(self):
552
+ return Vector(self._buf, self._byte_width)
553
+
554
+ @property
555
+ def Value(self):
556
+ return {k.Value: v.Value for k, v in zip(self.Keys, self.Values)}
557
+
558
+ def __repr__(self):
559
+ return 'Map(%s, size=%d)' % (self._buf, len(self))
560
+
561
+
562
+ class Ref:
563
+ """Data accessor for the encoded data bytes."""
564
+
565
+ __slots__ = '_buf', '_parent_width', '_byte_width', '_type'
566
+
567
+ @staticmethod
568
+ def PackedType(buf, parent_width, packed_type):
569
+ byte_width, type_ = Type.Unpack(packed_type)
570
+ return Ref(buf, parent_width, byte_width, type_)
571
+
572
+ def __init__(self, buf, parent_width, byte_width, type_):
573
+ self._buf = buf
574
+ self._parent_width = parent_width
575
+ self._byte_width = byte_width
576
+ self._type = type_
577
+
578
+ def __repr__(self):
579
+ return 'Ref(%s, parent_width=%d, byte_width=%d, type_=%s)' % (
580
+ self._buf,
581
+ self._parent_width,
582
+ self._byte_width,
583
+ self._type,
584
+ )
585
+
586
+ @property
587
+ def _Bytes(self):
588
+ return self._buf[: self._parent_width]
589
+
590
+ def _ConvertError(self, target_type):
591
+ raise TypeError('cannot convert %s to %s' % (self._type, target_type))
592
+
593
+ def _Indirect(self):
594
+ return self._buf.Indirect(0, self._parent_width)
595
+
596
+ @property
597
+ def IsNull(self):
598
+ return self._type is Type.NULL
599
+
600
+ @property
601
+ def IsBool(self):
602
+ return self._type is Type.BOOL
603
+
604
+ @property
605
+ def AsBool(self):
606
+ if self._type is Type.BOOL:
607
+ return bool(_Unpack(U, self._Bytes))
608
+ else:
609
+ return self.AsInt != 0
610
+
611
+ def MutateBool(self, value):
612
+ """Mutates underlying boolean value bytes in place.
613
+
614
+ Args:
615
+ value: New boolean value.
616
+
617
+ Returns:
618
+ Whether the value was mutated or not.
619
+ """
620
+ return self.IsBool and _Mutate(
621
+ U, self._buf, value, self._parent_width, BitWidth.W8
622
+ )
623
+
624
+ @property
625
+ def IsNumeric(self):
626
+ return self.IsInt or self.IsFloat
627
+
628
+ @property
629
+ def IsInt(self):
630
+ return self._type in (
631
+ Type.INT,
632
+ Type.INDIRECT_INT,
633
+ Type.UINT,
634
+ Type.INDIRECT_UINT,
635
+ )
636
+
637
+ @property
638
+ def AsInt(self):
639
+ """Returns current reference as integer value."""
640
+ if self.IsNull:
641
+ return 0
642
+ elif self.IsBool:
643
+ return int(self.AsBool)
644
+ elif self._type is Type.INT:
645
+ return _Unpack(I, self._Bytes)
646
+ elif self._type is Type.INDIRECT_INT:
647
+ return _Unpack(I, self._Indirect()[: self._byte_width])
648
+ if self._type is Type.UINT:
649
+ return _Unpack(U, self._Bytes)
650
+ elif self._type is Type.INDIRECT_UINT:
651
+ return _Unpack(U, self._Indirect()[: self._byte_width])
652
+ elif self.IsString:
653
+ return len(self.AsString)
654
+ elif self.IsKey:
655
+ return len(self.AsKey)
656
+ elif self.IsBlob:
657
+ return len(self.AsBlob)
658
+ elif self.IsVector:
659
+ return len(self.AsVector)
660
+ elif self.IsTypedVector:
661
+ return len(self.AsTypedVector)
662
+ elif self.IsFixedTypedVector:
663
+ return len(self.AsFixedTypedVector)
664
+ else:
665
+ raise self._ConvertError(Type.INT)
666
+
667
+ def MutateInt(self, value):
668
+ """Mutates underlying integer value bytes in place.
669
+
670
+ Args:
671
+ value: New integer value. It must fit to the byte size of the existing
672
+ encoded value.
673
+
674
+ Returns:
675
+ Whether the value was mutated or not.
676
+ """
677
+ if self._type is Type.INT:
678
+ return _Mutate(I, self._buf, value, self._parent_width, BitWidth.I(value))
679
+ elif self._type is Type.INDIRECT_INT:
680
+ return _Mutate(
681
+ I, self._Indirect(), value, self._byte_width, BitWidth.I(value)
682
+ )
683
+ elif self._type is Type.UINT:
684
+ return _Mutate(U, self._buf, value, self._parent_width, BitWidth.U(value))
685
+ elif self._type is Type.INDIRECT_UINT:
686
+ return _Mutate(
687
+ U, self._Indirect(), value, self._byte_width, BitWidth.U(value)
688
+ )
689
+ else:
690
+ return False
691
+
692
+ @property
693
+ def IsFloat(self):
694
+ return self._type in (Type.FLOAT, Type.INDIRECT_FLOAT)
695
+
696
+ @property
697
+ def AsFloat(self):
698
+ """Returns current reference as floating point value."""
699
+ if self.IsNull:
700
+ return 0.0
701
+ elif self.IsBool:
702
+ return float(self.AsBool)
703
+ elif self.IsInt:
704
+ return float(self.AsInt)
705
+ elif self._type is Type.FLOAT:
706
+ return _Unpack(F, self._Bytes)
707
+ elif self._type is Type.INDIRECT_FLOAT:
708
+ return _Unpack(F, self._Indirect()[: self._byte_width])
709
+ elif self.IsString:
710
+ return float(self.AsString)
711
+ elif self.IsVector:
712
+ return float(len(self.AsVector))
713
+ elif self.IsTypedVector():
714
+ return float(len(self.AsTypedVector))
715
+ elif self.IsFixedTypedVector():
716
+ return float(len(self.FixedTypedVector))
717
+ else:
718
+ raise self._ConvertError(Type.FLOAT)
719
+
720
+ def MutateFloat(self, value):
721
+ """Mutates underlying floating point value bytes in place.
722
+
723
+ Args:
724
+ value: New float value. It must fit to the byte size of the existing
725
+ encoded value.
726
+
727
+ Returns:
728
+ Whether the value was mutated or not.
729
+ """
730
+ if self._type is Type.FLOAT:
731
+ return _Mutate(
732
+ F,
733
+ self._buf,
734
+ value,
735
+ self._parent_width,
736
+ BitWidth.B(self._parent_width),
737
+ )
738
+ elif self._type is Type.INDIRECT_FLOAT:
739
+ return _Mutate(
740
+ F,
741
+ self._Indirect(),
742
+ value,
743
+ self._byte_width,
744
+ BitWidth.B(self._byte_width),
745
+ )
746
+ else:
747
+ return False
748
+
749
+ @property
750
+ def IsKey(self):
751
+ return self._type is Type.KEY
752
+
753
+ @property
754
+ def AsKeyBytes(self):
755
+ if self.IsKey:
756
+ return Key(self._Indirect(), self._byte_width).Bytes
757
+ else:
758
+ raise self._ConvertError(Type.KEY)
759
+
760
+ @property
761
+ def AsKey(self):
762
+ if self.IsKey:
763
+ return str(Key(self._Indirect(), self._byte_width))
764
+ else:
765
+ raise self._ConvertError(Type.KEY)
766
+
767
+ @property
768
+ def IsString(self):
769
+ return self._type is Type.STRING
770
+
771
+ @property
772
+ def AsStringBytes(self):
773
+ if self.IsString:
774
+ return String(self._Indirect(), self._byte_width).Bytes
775
+ elif self.IsKey:
776
+ return self.AsKeyBytes
777
+ else:
778
+ raise self._ConvertError(Type.STRING)
779
+
780
+ @property
781
+ def AsString(self):
782
+ if self.IsString:
783
+ return str(String(self._Indirect(), self._byte_width))
784
+ elif self.IsKey:
785
+ return self.AsKey
786
+ else:
787
+ raise self._ConvertError(Type.STRING)
788
+
789
+ def MutateString(self, value):
790
+ return String(self._Indirect(), self._byte_width).Mutate(value)
791
+
792
+ @property
793
+ def IsBlob(self):
794
+ return self._type is Type.BLOB
795
+
796
+ @property
797
+ def AsBlob(self):
798
+ if self.IsBlob:
799
+ return Blob(self._Indirect(), self._byte_width).Bytes
800
+ else:
801
+ raise self._ConvertError(Type.BLOB)
802
+
803
+ @property
804
+ def IsAnyVector(self):
805
+ return self.IsVector or self.IsTypedVector or self.IsFixedTypedVector()
806
+
807
+ @property
808
+ def IsVector(self):
809
+ return self._type in (Type.VECTOR, Type.MAP)
810
+
811
+ @property
812
+ def AsVector(self):
813
+ if self.IsVector:
814
+ return Vector(self._Indirect(), self._byte_width)
815
+ else:
816
+ raise self._ConvertError(Type.VECTOR)
817
+
818
+ @property
819
+ def IsTypedVector(self):
820
+ return Type.IsTypedVector(self._type)
821
+
822
+ @property
823
+ def AsTypedVector(self):
824
+ if self.IsTypedVector:
825
+ return TypedVector(
826
+ self._Indirect(),
827
+ self._byte_width,
828
+ Type.ToTypedVectorElementType(self._type),
829
+ )
830
+ else:
831
+ raise self._ConvertError('TYPED_VECTOR')
832
+
833
+ @property
834
+ def IsFixedTypedVector(self):
835
+ return Type.IsFixedTypedVector(self._type)
836
+
837
+ @property
838
+ def AsFixedTypedVector(self):
839
+ if self.IsFixedTypedVector:
840
+ element_type, size = Type.ToFixedTypedVectorElementType(self._type)
841
+ return TypedVector(self._Indirect(), self._byte_width, element_type, size)
842
+ else:
843
+ raise self._ConvertError('FIXED_TYPED_VECTOR')
844
+
845
+ @property
846
+ def IsMap(self):
847
+ return self._type is Type.MAP
848
+
849
+ @property
850
+ def AsMap(self):
851
+ if self.IsMap:
852
+ return Map(self._Indirect(), self._byte_width)
853
+ else:
854
+ raise self._ConvertError(Type.MAP)
855
+
856
+ @property
857
+ def Value(self):
858
+ """Converts current reference to value of corresponding type.
859
+
860
+ This is equivalent to calling `AsInt` for integer values, `AsFloat` for
861
+ floating point values, etc.
862
+
863
+ Returns:
864
+ Value of corresponding type.
865
+ """
866
+ if self.IsNull:
867
+ return None
868
+ elif self.IsBool:
869
+ return self.AsBool
870
+ elif self.IsInt:
871
+ return self.AsInt
872
+ elif self.IsFloat:
873
+ return self.AsFloat
874
+ elif self.IsString:
875
+ return self.AsString
876
+ elif self.IsKey:
877
+ return self.AsKey
878
+ elif self.IsBlob:
879
+ return self.AsBlob
880
+ elif self.IsMap:
881
+ return self.AsMap.Value
882
+ elif self.IsVector:
883
+ return self.AsVector.Value
884
+ elif self.IsTypedVector:
885
+ return self.AsTypedVector.Value
886
+ elif self.IsFixedTypedVector:
887
+ return self.AsFixedTypedVector.Value
888
+ else:
889
+ raise TypeError('cannot convert %r to value' % self)
890
+
891
+
892
+ def _IsIterable(obj):
893
+ try:
894
+ iter(obj)
895
+ return True
896
+ except TypeError:
897
+ return False
898
+
899
+
900
+ class Value:
901
+ """Class to represent given value during the encoding process."""
902
+
903
+ @staticmethod
904
+ def Null():
905
+ return Value(0, Type.NULL, BitWidth.W8)
906
+
907
+ @staticmethod
908
+ def Bool(value):
909
+ return Value(value, Type.BOOL, BitWidth.W8)
910
+
911
+ @staticmethod
912
+ def Int(value, bit_width):
913
+ return Value(value, Type.INT, bit_width)
914
+
915
+ @staticmethod
916
+ def UInt(value, bit_width):
917
+ return Value(value, Type.UINT, bit_width)
918
+
919
+ @staticmethod
920
+ def Float(value, bit_width):
921
+ return Value(value, Type.FLOAT, bit_width)
922
+
923
+ @staticmethod
924
+ def Key(offset):
925
+ return Value(offset, Type.KEY, BitWidth.W8)
926
+
927
+ def __init__(self, value, type_, min_bit_width):
928
+ self._value = value
929
+ self._type = type_
930
+
931
+ # For scalars: of itself, for vector: of its elements, for string: length.
932
+ self._min_bit_width = min_bit_width
933
+
934
+ @property
935
+ def Value(self):
936
+ return self._value
937
+
938
+ @property
939
+ def Type(self):
940
+ return self._type
941
+
942
+ @property
943
+ def MinBitWidth(self):
944
+ return self._min_bit_width
945
+
946
+ def StoredPackedType(self, parent_bit_width=BitWidth.W8):
947
+ return Type.Pack(self._type, self.StoredWidth(parent_bit_width))
948
+
949
+ # We have an absolute offset, but want to store a relative offset
950
+ # elem_index elements beyond the current buffer end. Since whether
951
+ # the relative offset fits in a certain byte_width depends on
952
+ # the size of the elements before it (and their alignment), we have
953
+ # to test for each size in turn.
954
+ def ElemWidth(self, buf_size, elem_index=0):
955
+ if Type.IsInline(self._type):
956
+ return self._min_bit_width
957
+ for byte_width in 1, 2, 4, 8:
958
+ offset_loc = (
959
+ buf_size
960
+ + _PaddingBytes(buf_size, byte_width)
961
+ + elem_index * byte_width
962
+ )
963
+ bit_width = BitWidth.U(offset_loc - self._value)
964
+ if byte_width == (1 << bit_width):
965
+ return bit_width
966
+ raise ValueError('relative offset is too big')
967
+
968
+ def StoredWidth(self, parent_bit_width=BitWidth.W8):
969
+ if Type.IsInline(self._type):
970
+ return max(self._min_bit_width, parent_bit_width)
971
+ return self._min_bit_width
972
+
973
+ def __repr__(self):
974
+ return 'Value(%s, %s, %s)' % (self._value, self._type, self._min_bit_width)
975
+
976
+ def __str__(self):
977
+ return str(self._value)
978
+
979
+
980
+ def InMap(func):
981
+ def wrapper(self, *args, **kwargs):
982
+ if isinstance(args[0], str):
983
+ self.Key(args[0])
984
+ func(self, *args[1:], **kwargs)
985
+ else:
986
+ func(self, *args, **kwargs)
987
+
988
+ return wrapper
989
+
990
+
991
+ def InMapForString(func):
992
+ def wrapper(self, *args):
993
+ if len(args) == 1:
994
+ func(self, args[0])
995
+ elif len(args) == 2:
996
+ self.Key(args[0])
997
+ func(self, args[1])
998
+ else:
999
+ raise ValueError('invalid number of arguments')
1000
+
1001
+ return wrapper
1002
+
1003
+
1004
+ class Pool:
1005
+ """Collection of (data, offset) pairs sorted by data for quick access."""
1006
+
1007
+ def __init__(self):
1008
+ self._pool = [] # sorted list of (data, offset) tuples
1009
+
1010
+ def FindOrInsert(self, data, offset):
1011
+ do = data, offset
1012
+ index = _BinarySearch(self._pool, do, lambda a, b: a[0] < b[0])
1013
+ if index != -1:
1014
+ _, offset = self._pool[index]
1015
+ return offset
1016
+ self._pool.insert(index, do)
1017
+ return None
1018
+
1019
+ def Clear(self):
1020
+ self._pool = []
1021
+
1022
+ @property
1023
+ def Elements(self):
1024
+ return [data for data, _ in self._pool]
1025
+
1026
+
1027
+ class Builder:
1028
+ """Helper class to encode structural data into flexbuffers format."""
1029
+
1030
+ def __init__(
1031
+ self,
1032
+ share_strings=False,
1033
+ share_keys=True,
1034
+ force_min_bit_width=BitWidth.W8,
1035
+ ):
1036
+ self._share_strings = share_strings
1037
+ self._share_keys = share_keys
1038
+ self._force_min_bit_width = force_min_bit_width
1039
+
1040
+ self._string_pool = Pool()
1041
+ self._key_pool = Pool()
1042
+
1043
+ self._finished = False
1044
+ self._buf = bytearray()
1045
+ self._stack = []
1046
+
1047
+ def __len__(self):
1048
+ return len(self._buf)
1049
+
1050
+ @property
1051
+ def StringPool(self):
1052
+ return self._string_pool
1053
+
1054
+ @property
1055
+ def KeyPool(self):
1056
+ return self._key_pool
1057
+
1058
+ def Clear(self):
1059
+ self._string_pool.Clear()
1060
+ self._key_pool.Clear()
1061
+ self._finished = False
1062
+ self._buf = bytearray()
1063
+ self._stack = []
1064
+
1065
+ def Finish(self):
1066
+ """Finishes encoding process and returns underlying buffer."""
1067
+ if self._finished:
1068
+ raise RuntimeError('builder has been already finished')
1069
+
1070
+ # If you hit this exception, you likely have objects that were never
1071
+ # included in a parent. You need to have exactly one root to finish a
1072
+ # buffer. Check your Start/End calls are matched, and all objects are inside
1073
+ # some other object.
1074
+ if len(self._stack) != 1:
1075
+ raise RuntimeError('internal stack size must be one')
1076
+
1077
+ value = self._stack[0]
1078
+ byte_width = self._Align(value.ElemWidth(len(self._buf)))
1079
+ self._WriteAny(value, byte_width=byte_width) # Root value
1080
+ self._Write(U, value.StoredPackedType(), byte_width=1) # Root type
1081
+ self._Write(U, byte_width, byte_width=1) # Root size
1082
+
1083
+ self.finished = True
1084
+ return self._buf
1085
+
1086
+ def _ReadKey(self, offset):
1087
+ key = self._buf[offset:]
1088
+ return key[: key.find(0)]
1089
+
1090
+ def _Align(self, alignment):
1091
+ byte_width = 1 << alignment
1092
+ self._buf.extend(b'\x00' * _PaddingBytes(len(self._buf), byte_width))
1093
+ return byte_width
1094
+
1095
+ def _Write(self, fmt, value, byte_width):
1096
+ self._buf.extend(_Pack(fmt, value, byte_width))
1097
+
1098
+ def _WriteVector(self, fmt, values, byte_width):
1099
+ self._buf.extend(_PackVector(fmt, values, byte_width))
1100
+
1101
+ def _WriteOffset(self, offset, byte_width):
1102
+ relative_offset = len(self._buf) - offset
1103
+ assert byte_width == 8 or relative_offset < (1 << (8 * byte_width))
1104
+ self._Write(U, relative_offset, byte_width)
1105
+
1106
+ def _WriteAny(self, value, byte_width):
1107
+ fmt = {
1108
+ Type.NULL: U,
1109
+ Type.BOOL: U,
1110
+ Type.INT: I,
1111
+ Type.UINT: U,
1112
+ Type.FLOAT: F,
1113
+ }.get(value.Type)
1114
+ if fmt:
1115
+ self._Write(fmt, value.Value, byte_width)
1116
+ else:
1117
+ self._WriteOffset(value.Value, byte_width)
1118
+
1119
+ def _WriteBlob(self, data, append_zero, type_):
1120
+ bit_width = BitWidth.U(len(data))
1121
+ byte_width = self._Align(bit_width)
1122
+ self._Write(U, len(data), byte_width)
1123
+ loc = len(self._buf)
1124
+ self._buf.extend(data)
1125
+ if append_zero:
1126
+ self._buf.append(0)
1127
+ self._stack.append(Value(loc, type_, bit_width))
1128
+ return loc
1129
+
1130
+ def _WriteScalarVector(self, element_type, byte_width, elements, fixed):
1131
+ """Writes scalar vector elements to the underlying buffer."""
1132
+ bit_width = BitWidth.B(byte_width)
1133
+ # If you get this exception, you're trying to write a vector with a size
1134
+ # field that is bigger than the scalars you're trying to write (e.g. a
1135
+ # byte vector > 255 elements). For such types, write a "blob" instead.
1136
+ if BitWidth.U(len(elements)) > bit_width:
1137
+ raise ValueError('too many elements for the given byte_width')
1138
+
1139
+ self._Align(bit_width)
1140
+ if not fixed:
1141
+ self._Write(U, len(elements), byte_width)
1142
+
1143
+ loc = len(self._buf)
1144
+
1145
+ fmt = {Type.INT: I, Type.UINT: U, Type.FLOAT: F}.get(element_type)
1146
+ if not fmt:
1147
+ raise TypeError('unsupported element_type')
1148
+ self._WriteVector(fmt, elements, byte_width)
1149
+
1150
+ type_ = Type.ToTypedVector(element_type, len(elements) if fixed else 0)
1151
+ self._stack.append(Value(loc, type_, bit_width))
1152
+ return loc
1153
+
1154
+ def _CreateVector(self, elements, typed, fixed, keys=None):
1155
+ """Writes vector elements to the underlying buffer."""
1156
+ length = len(elements)
1157
+
1158
+ if fixed and not typed:
1159
+ raise ValueError('fixed vector must be typed')
1160
+
1161
+ # Figure out smallest bit width we can store this vector with.
1162
+ bit_width = max(self._force_min_bit_width, BitWidth.U(length))
1163
+ prefix_elems = 1 # Vector size
1164
+ if keys:
1165
+ bit_width = max(bit_width, keys.ElemWidth(len(self._buf)))
1166
+ prefix_elems += 2 # Offset to the keys vector and its byte width.
1167
+
1168
+ vector_type = Type.KEY
1169
+ # Check bit widths and types for all elements.
1170
+ for i, e in enumerate(elements):
1171
+ bit_width = max(bit_width, e.ElemWidth(len(self._buf), prefix_elems + i))
1172
+
1173
+ if typed:
1174
+ if i == 0:
1175
+ vector_type = e.Type
1176
+ else:
1177
+ if vector_type != e.Type:
1178
+ raise RuntimeError('typed vector elements must be of the same type')
1179
+
1180
+ if fixed and not Type.IsFixedTypedVectorElementType(vector_type):
1181
+ raise RuntimeError('must be fixed typed vector element type')
1182
+
1183
+ byte_width = self._Align(bit_width)
1184
+ # Write vector. First the keys width/offset if available, and size.
1185
+ if keys:
1186
+ self._WriteOffset(keys.Value, byte_width)
1187
+ self._Write(U, 1 << keys.MinBitWidth, byte_width)
1188
+
1189
+ if not fixed:
1190
+ self._Write(U, length, byte_width)
1191
+
1192
+ # Then the actual data.
1193
+ loc = len(self._buf)
1194
+ for e in elements:
1195
+ self._WriteAny(e, byte_width)
1196
+
1197
+ # Then the types.
1198
+ if not typed:
1199
+ for e in elements:
1200
+ self._buf.append(e.StoredPackedType(bit_width))
1201
+
1202
+ if keys:
1203
+ type_ = Type.MAP
1204
+ else:
1205
+ if typed:
1206
+ type_ = Type.ToTypedVector(vector_type, length if fixed else 0)
1207
+ else:
1208
+ type_ = Type.VECTOR
1209
+
1210
+ return Value(loc, type_, bit_width)
1211
+
1212
+ def _PushIndirect(self, value, type_, bit_width):
1213
+ byte_width = self._Align(bit_width)
1214
+ loc = len(self._buf)
1215
+ fmt = {Type.INDIRECT_INT: I, Type.INDIRECT_UINT: U, Type.INDIRECT_FLOAT: F}[
1216
+ type_
1217
+ ]
1218
+ self._Write(fmt, value, byte_width)
1219
+ self._stack.append(Value(loc, type_, bit_width))
1220
+
1221
+ @InMapForString
1222
+ def String(self, value):
1223
+ """Encodes string value."""
1224
+ reset_to = len(self._buf)
1225
+ encoded = value.encode('utf-8')
1226
+ loc = self._WriteBlob(encoded, append_zero=True, type_=Type.STRING)
1227
+ if self._share_strings:
1228
+ prev_loc = self._string_pool.FindOrInsert(encoded, loc)
1229
+ if prev_loc is not None:
1230
+ del self._buf[reset_to:]
1231
+ self._stack[-1]._value = loc = prev_loc # pylint: disable=protected-access
1232
+
1233
+ return loc
1234
+
1235
+ @InMap
1236
+ def Blob(self, value):
1237
+ """Encodes binary blob value.
1238
+
1239
+ Args:
1240
+ value: A byte/bytearray value to encode
1241
+
1242
+ Returns:
1243
+ Offset of the encoded value in underlying the byte buffer.
1244
+ """
1245
+ return self._WriteBlob(value, append_zero=False, type_=Type.BLOB)
1246
+
1247
+ def Key(self, value):
1248
+ """Encodes key value.
1249
+
1250
+ Args:
1251
+ value: A byte/bytearray/str value to encode. Byte object must not contain
1252
+ zero bytes. String object must be convertible to ASCII.
1253
+
1254
+ Returns:
1255
+ Offset of the encoded value in the underlying byte buffer.
1256
+ """
1257
+ if isinstance(value, (bytes, bytearray)):
1258
+ encoded = value
1259
+ else:
1260
+ encoded = value.encode('ascii')
1261
+
1262
+ if 0 in encoded:
1263
+ raise ValueError('key contains zero byte')
1264
+
1265
+ loc = len(self._buf)
1266
+ self._buf.extend(encoded)
1267
+ self._buf.append(0)
1268
+ if self._share_keys:
1269
+ prev_loc = self._key_pool.FindOrInsert(encoded, loc)
1270
+ if prev_loc is not None:
1271
+ del self._buf[loc:]
1272
+ loc = prev_loc
1273
+
1274
+ self._stack.append(Value.Key(loc))
1275
+ return loc
1276
+
1277
+ def Null(self, key=None):
1278
+ """Encodes None value."""
1279
+ if key:
1280
+ self.Key(key)
1281
+ self._stack.append(Value.Null())
1282
+
1283
+ @InMap
1284
+ def Bool(self, value):
1285
+ """Encodes boolean value.
1286
+
1287
+ Args:
1288
+ value: A boolean value.
1289
+ """
1290
+ self._stack.append(Value.Bool(value))
1291
+
1292
+ @InMap
1293
+ def Int(self, value, byte_width=0):
1294
+ """Encodes signed integer value.
1295
+
1296
+ Args:
1297
+ value: A signed integer value.
1298
+ byte_width: Number of bytes to use: 1, 2, 4, or 8.
1299
+ """
1300
+ bit_width = BitWidth.I(value) if byte_width == 0 else BitWidth.B(byte_width)
1301
+ self._stack.append(Value.Int(value, bit_width))
1302
+
1303
+ @InMap
1304
+ def IndirectInt(self, value, byte_width=0):
1305
+ """Encodes signed integer value indirectly.
1306
+
1307
+ Args:
1308
+ value: A signed integer value.
1309
+ byte_width: Number of bytes to use: 1, 2, 4, or 8.
1310
+ """
1311
+ bit_width = BitWidth.I(value) if byte_width == 0 else BitWidth.B(byte_width)
1312
+ self._PushIndirect(value, Type.INDIRECT_INT, bit_width)
1313
+
1314
+ @InMap
1315
+ def UInt(self, value, byte_width=0):
1316
+ """Encodes unsigned integer value.
1317
+
1318
+ Args:
1319
+ value: An unsigned integer value.
1320
+ byte_width: Number of bytes to use: 1, 2, 4, or 8.
1321
+ """
1322
+ bit_width = BitWidth.U(value) if byte_width == 0 else BitWidth.B(byte_width)
1323
+ self._stack.append(Value.UInt(value, bit_width))
1324
+
1325
+ @InMap
1326
+ def IndirectUInt(self, value, byte_width=0):
1327
+ """Encodes unsigned integer value indirectly.
1328
+
1329
+ Args:
1330
+ value: An unsigned integer value.
1331
+ byte_width: Number of bytes to use: 1, 2, 4, or 8.
1332
+ """
1333
+ bit_width = BitWidth.U(value) if byte_width == 0 else BitWidth.B(byte_width)
1334
+ self._PushIndirect(value, Type.INDIRECT_UINT, bit_width)
1335
+
1336
+ @InMap
1337
+ def Float(self, value, byte_width=0):
1338
+ """Encodes floating point value.
1339
+
1340
+ Args:
1341
+ value: A floating point value.
1342
+ byte_width: Number of bytes to use: 4 or 8.
1343
+ """
1344
+ bit_width = BitWidth.F(value) if byte_width == 0 else BitWidth.B(byte_width)
1345
+ self._stack.append(Value.Float(value, bit_width))
1346
+
1347
+ @InMap
1348
+ def IndirectFloat(self, value, byte_width=0):
1349
+ """Encodes floating point value indirectly.
1350
+
1351
+ Args:
1352
+ value: A floating point value.
1353
+ byte_width: Number of bytes to use: 4 or 8.
1354
+ """
1355
+ bit_width = BitWidth.F(value) if byte_width == 0 else BitWidth.B(byte_width)
1356
+ self._PushIndirect(value, Type.INDIRECT_FLOAT, bit_width)
1357
+
1358
+ def _StartVector(self):
1359
+ """Starts vector construction."""
1360
+ return len(self._stack)
1361
+
1362
+ def _EndVector(self, start, typed, fixed):
1363
+ """Finishes vector construction by encodung its elements."""
1364
+ vec = self._CreateVector(self._stack[start:], typed, fixed)
1365
+ del self._stack[start:]
1366
+ self._stack.append(vec)
1367
+ return vec.Value
1368
+
1369
+ @contextlib.contextmanager
1370
+ def Vector(self, key=None):
1371
+ if key:
1372
+ self.Key(key)
1373
+
1374
+ try:
1375
+ start = self._StartVector()
1376
+ yield self
1377
+ finally:
1378
+ self._EndVector(start, typed=False, fixed=False)
1379
+
1380
+ @InMap
1381
+ def VectorFromElements(self, elements):
1382
+ """Encodes sequence of any elements as a vector.
1383
+
1384
+ Args:
1385
+ elements: sequence of elements, they may have different types.
1386
+ """
1387
+ with self.Vector():
1388
+ for e in elements:
1389
+ self.Add(e)
1390
+
1391
+ @contextlib.contextmanager
1392
+ def TypedVector(self, key=None):
1393
+ if key:
1394
+ self.Key(key)
1395
+
1396
+ try:
1397
+ start = self._StartVector()
1398
+ yield self
1399
+ finally:
1400
+ self._EndVector(start, typed=True, fixed=False)
1401
+
1402
+ @InMap
1403
+ def TypedVectorFromElements(self, elements, element_type=None):
1404
+ """Encodes sequence of elements of the same type as typed vector.
1405
+
1406
+ Args:
1407
+ elements: Sequence of elements, they must be of the same type.
1408
+ element_type: Suggested element type. Setting it to None means determining
1409
+ correct value automatically based on the given elements.
1410
+ """
1411
+ if isinstance(elements, array.array):
1412
+ if elements.typecode == 'f':
1413
+ self._WriteScalarVector(Type.FLOAT, 4, elements, fixed=False)
1414
+ elif elements.typecode == 'd':
1415
+ self._WriteScalarVector(Type.FLOAT, 8, elements, fixed=False)
1416
+ elif elements.typecode in ('b', 'h', 'i', 'l', 'q'):
1417
+ self._WriteScalarVector(
1418
+ Type.INT, elements.itemsize, elements, fixed=False
1419
+ )
1420
+ elif elements.typecode in ('B', 'H', 'I', 'L', 'Q'):
1421
+ self._WriteScalarVector(
1422
+ Type.UINT, elements.itemsize, elements, fixed=False
1423
+ )
1424
+ else:
1425
+ raise ValueError('unsupported array typecode: %s' % elements.typecode)
1426
+ else:
1427
+ add = self.Add if element_type is None else self.Adder(element_type)
1428
+ with self.TypedVector():
1429
+ for e in elements:
1430
+ add(e)
1431
+
1432
+ @InMap
1433
+ def FixedTypedVectorFromElements(
1434
+ self, elements, element_type=None, byte_width=0
1435
+ ):
1436
+ """Encodes sequence of elements of the same type as fixed typed vector.
1437
+
1438
+ Args:
1439
+ elements: Sequence of elements, they must be of the same type. Allowed
1440
+ types are `Type.INT`, `Type.UINT`, `Type.FLOAT`. Allowed number of
1441
+ elements are 2, 3, or 4.
1442
+ element_type: Suggested element type. Setting it to None means determining
1443
+ correct value automatically based on the given elements.
1444
+ byte_width: Number of bytes to use per element. For `Type.INT` and
1445
+ `Type.UINT`: 1, 2, 4, or 8. For `Type.FLOAT`: 4 or 8. Setting it to 0
1446
+ means determining correct value automatically based on the given
1447
+ elements.
1448
+ """
1449
+ if not 2 <= len(elements) <= 4:
1450
+ raise ValueError('only 2, 3, or 4 elements are supported')
1451
+
1452
+ types = {type(e) for e in elements}
1453
+ if len(types) != 1:
1454
+ raise TypeError('all elements must be of the same type')
1455
+
1456
+ (type_,) = types
1457
+
1458
+ if element_type is None:
1459
+ element_type = {int: Type.INT, float: Type.FLOAT}.get(type_)
1460
+ if not element_type:
1461
+ raise TypeError('unsupported element_type: %s' % type_)
1462
+
1463
+ if byte_width == 0:
1464
+ width = {
1465
+ Type.UINT: BitWidth.U,
1466
+ Type.INT: BitWidth.I,
1467
+ Type.FLOAT: BitWidth.F,
1468
+ }[element_type]
1469
+ byte_width = 1 << max(width(e) for e in elements)
1470
+
1471
+ self._WriteScalarVector(element_type, byte_width, elements, fixed=True)
1472
+
1473
+ def _StartMap(self):
1474
+ """Starts map construction."""
1475
+ return len(self._stack)
1476
+
1477
+ def _EndMap(self, start):
1478
+ """Finishes map construction by encodung its elements."""
1479
+ # Interleaved keys and values on the stack.
1480
+ stack = self._stack[start:]
1481
+
1482
+ if len(stack) % 2 != 0:
1483
+ raise RuntimeError('must be even number of keys and values')
1484
+
1485
+ for key in stack[::2]:
1486
+ if key.Type is not Type.KEY:
1487
+ raise RuntimeError('all map keys must be of %s type' % Type.KEY)
1488
+
1489
+ pairs = zip(stack[::2], stack[1::2]) # [(key, value), ...]
1490
+ pairs = sorted(pairs, key=lambda pair: self._ReadKey(pair[0].Value))
1491
+
1492
+ del self._stack[start:]
1493
+ for pair in pairs:
1494
+ self._stack.extend(pair)
1495
+
1496
+ keys = self._CreateVector(self._stack[start::2], typed=True, fixed=False)
1497
+ values = self._CreateVector(
1498
+ self._stack[start + 1 :: 2], typed=False, fixed=False, keys=keys
1499
+ )
1500
+
1501
+ del self._stack[start:]
1502
+ self._stack.append(values)
1503
+ return values.Value
1504
+
1505
+ @contextlib.contextmanager
1506
+ def Map(self, key=None):
1507
+ if key:
1508
+ self.Key(key)
1509
+
1510
+ try:
1511
+ start = self._StartMap()
1512
+ yield self
1513
+ finally:
1514
+ self._EndMap(start)
1515
+
1516
+ def MapFromElements(self, elements):
1517
+ start = self._StartMap()
1518
+ for k, v in elements.items():
1519
+ self.Key(k)
1520
+ self.Add(v)
1521
+ self._EndMap(start)
1522
+
1523
+ def Adder(self, type_):
1524
+ return {
1525
+ Type.BOOL: self.Bool,
1526
+ Type.INT: self.Int,
1527
+ Type.INDIRECT_INT: self.IndirectInt,
1528
+ Type.UINT: self.UInt,
1529
+ Type.INDIRECT_UINT: self.IndirectUInt,
1530
+ Type.FLOAT: self.Float,
1531
+ Type.INDIRECT_FLOAT: self.IndirectFloat,
1532
+ Type.KEY: self.Key,
1533
+ Type.BLOB: self.Blob,
1534
+ Type.STRING: self.String,
1535
+ }[type_]
1536
+
1537
+ @InMapForString
1538
+ def Add(self, value):
1539
+ """Encodes value of any supported type."""
1540
+ if value is None:
1541
+ self.Null()
1542
+ elif isinstance(value, bool):
1543
+ self.Bool(value)
1544
+ elif isinstance(value, int):
1545
+ self.Int(value)
1546
+ elif isinstance(value, float):
1547
+ self.Float(value)
1548
+ elif isinstance(value, str):
1549
+ self.String(value)
1550
+ elif isinstance(value, (bytes, bytearray)):
1551
+ self.Blob(value)
1552
+ elif isinstance(value, dict):
1553
+ with self.Map():
1554
+ for k, v in value.items():
1555
+ self.Key(k)
1556
+ self.Add(v)
1557
+ elif isinstance(value, array.array):
1558
+ self.TypedVectorFromElements(value)
1559
+ elif _IsIterable(value):
1560
+ self.VectorFromElements(value)
1561
+ else:
1562
+ raise TypeError('unsupported python type: %s' % type(value))
1563
+
1564
+ @property
1565
+ def LastValue(self):
1566
+ return self._stack[-1]
1567
+
1568
+ @InMap
1569
+ def ReuseValue(self, value):
1570
+ self._stack.append(value)
1571
+
1572
+
1573
+ def GetRoot(buf):
1574
+ """Returns root `Ref` object for the given buffer."""
1575
+ if len(buf) < 3:
1576
+ raise ValueError('buffer is too small')
1577
+ byte_width = buf[-1]
1578
+ return Ref.PackedType(
1579
+ Buf(buf, -(2 + byte_width)), byte_width, packed_type=buf[-2]
1580
+ )
1581
+
1582
+
1583
+ def Dumps(obj):
1584
+ """Returns bytearray with the encoded python object."""
1585
+ fbb = Builder()
1586
+ fbb.Add(obj)
1587
+ return fbb.Finish()
1588
+
1589
+
1590
+ def Loads(buf):
1591
+ """Returns python object decoded from the buffer."""
1592
+ return GetRoot(buf).Value
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/number_types.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2014 Google Inc. All rights reserved.
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
+
15
+ import collections
16
+ import struct
17
+
18
+ from . import packer
19
+ from .compat import NumpyRequiredForThisFeature, import_numpy
20
+
21
+ np = import_numpy()
22
+
23
+ # For reference, see:
24
+ # https://docs.python.org/2/library/ctypes.html#ctypes-fundamental-data-types-2
25
+
26
+ # These classes could be collections.namedtuple instances, but those are new
27
+ # in 2.6 and we want to work towards 2.5 compatability.
28
+
29
+
30
+ class BoolFlags(object):
31
+ bytewidth = 1
32
+ min_val = False
33
+ max_val = True
34
+ py_type = bool
35
+ name = "bool"
36
+ packer_type = packer.boolean
37
+
38
+
39
+ class Uint8Flags(object):
40
+ bytewidth = 1
41
+ min_val = 0
42
+ max_val = (2**8) - 1
43
+ py_type = int
44
+ name = "uint8"
45
+ packer_type = packer.uint8
46
+
47
+
48
+ class Uint16Flags(object):
49
+ bytewidth = 2
50
+ min_val = 0
51
+ max_val = (2**16) - 1
52
+ py_type = int
53
+ name = "uint16"
54
+ packer_type = packer.uint16
55
+
56
+
57
+ class Uint32Flags(object):
58
+ bytewidth = 4
59
+ min_val = 0
60
+ max_val = (2**32) - 1
61
+ py_type = int
62
+ name = "uint32"
63
+ packer_type = packer.uint32
64
+
65
+
66
+ class Uint64Flags(object):
67
+ bytewidth = 8
68
+ min_val = 0
69
+ max_val = (2**64) - 1
70
+ py_type = int
71
+ name = "uint64"
72
+ packer_type = packer.uint64
73
+
74
+
75
+ class Int8Flags(object):
76
+ bytewidth = 1
77
+ min_val = -(2**7)
78
+ max_val = (2**7) - 1
79
+ py_type = int
80
+ name = "int8"
81
+ packer_type = packer.int8
82
+
83
+
84
+ class Int16Flags(object):
85
+ bytewidth = 2
86
+ min_val = -(2**15)
87
+ max_val = (2**15) - 1
88
+ py_type = int
89
+ name = "int16"
90
+ packer_type = packer.int16
91
+
92
+
93
+ class Int32Flags(object):
94
+ bytewidth = 4
95
+ min_val = -(2**31)
96
+ max_val = (2**31) - 1
97
+ py_type = int
98
+ name = "int32"
99
+ packer_type = packer.int32
100
+
101
+
102
+ class Int64Flags(object):
103
+ bytewidth = 8
104
+ min_val = -(2**63)
105
+ max_val = (2**63) - 1
106
+ py_type = int
107
+ name = "int64"
108
+ packer_type = packer.int64
109
+
110
+
111
+ class Float32Flags(object):
112
+ bytewidth = 4
113
+ min_val = None
114
+ max_val = None
115
+ py_type = float
116
+ name = "float32"
117
+ packer_type = packer.float32
118
+
119
+
120
+ class Float64Flags(object):
121
+ bytewidth = 8
122
+ min_val = None
123
+ max_val = None
124
+ py_type = float
125
+ name = "float64"
126
+ packer_type = packer.float64
127
+
128
+
129
+ class SOffsetTFlags(Int32Flags):
130
+ pass
131
+
132
+
133
+ class UOffsetTFlags(Uint32Flags):
134
+ pass
135
+
136
+
137
+ class VOffsetTFlags(Uint16Flags):
138
+ pass
139
+
140
+
141
+ def valid_number(n, flags):
142
+ if flags.min_val is None and flags.max_val is None:
143
+ return True
144
+ return flags.min_val <= n <= flags.max_val
145
+
146
+
147
+ def enforce_number(n, flags):
148
+ if flags.min_val is None and flags.max_val is None:
149
+ return
150
+ if not flags.min_val <= n <= flags.max_val:
151
+ raise TypeError("bad number %s for type %s" % (str(n), flags.name))
152
+
153
+
154
+ def float32_to_uint32(n):
155
+ packed = struct.pack("<1f", n)
156
+ (converted,) = struct.unpack("<1L", packed)
157
+ return converted
158
+
159
+
160
+ def uint32_to_float32(n):
161
+ packed = struct.pack("<1L", n)
162
+ (unpacked,) = struct.unpack("<1f", packed)
163
+ return unpacked
164
+
165
+
166
+ def float64_to_uint64(n):
167
+ packed = struct.pack("<1d", n)
168
+ (converted,) = struct.unpack("<1Q", packed)
169
+ return converted
170
+
171
+
172
+ def uint64_to_float64(n):
173
+ packed = struct.pack("<1Q", n)
174
+ (unpacked,) = struct.unpack("<1d", packed)
175
+ return unpacked
176
+
177
+
178
+ def to_numpy_type(number_type):
179
+ if np is not None:
180
+ return np.dtype(number_type.name).newbyteorder("<")
181
+ else:
182
+ raise NumpyRequiredForThisFeature("Numpy was not found.")
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/packer.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2016 Google Inc. All rights reserved.
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
+
15
+ """Provide pre-compiled struct packers for encoding and decoding.
16
+
17
+ See: https://docs.python.org/2/library/struct.html#format-characters
18
+ """
19
+
20
+ import struct
21
+ from . import compat
22
+
23
+
24
+ boolean = struct.Struct(compat.struct_bool_decl)
25
+
26
+ uint8 = struct.Struct("<B")
27
+ uint16 = struct.Struct("<H")
28
+ uint32 = struct.Struct("<I")
29
+ uint64 = struct.Struct("<Q")
30
+
31
+ int8 = struct.Struct("<b")
32
+ int16 = struct.Struct("<h")
33
+ int32 = struct.Struct("<i")
34
+ int64 = struct.Struct("<q")
35
+
36
+ float32 = struct.Struct("<f")
37
+ float64 = struct.Struct("<d")
38
+
39
+ uoffset = uint32
40
+ soffset = int32
41
+ voffset = uint16
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/table.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2014 Google Inc. All rights reserved.
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
+
15
+ from . import encode
16
+ from . import number_types as N
17
+
18
+
19
+ class Table(object):
20
+ """Table wraps a byte slice and provides read access to its data.
21
+
22
+ The variable `Pos` indicates the root of the FlatBuffers object therein.
23
+ """
24
+
25
+ __slots__ = ("Bytes", "Pos")
26
+
27
+ def __init__(self, buf, pos):
28
+ N.enforce_number(pos, N.UOffsetTFlags)
29
+
30
+ self.Bytes = buf
31
+ self.Pos = pos
32
+
33
+ def Offset(self, vtableOffset):
34
+ """Offset provides access into the Table's vtable.
35
+
36
+ Deprecated fields are ignored by checking the vtable's length.
37
+ """
38
+
39
+ vtable = self.Pos - self.Get(N.SOffsetTFlags, self.Pos)
40
+ vtableEnd = self.Get(N.VOffsetTFlags, vtable)
41
+ if vtableOffset < vtableEnd:
42
+ return self.Get(N.VOffsetTFlags, vtable + vtableOffset)
43
+ return 0
44
+
45
+ def Indirect(self, off):
46
+ """Indirect retrieves the relative offset stored at `offset`."""
47
+ N.enforce_number(off, N.UOffsetTFlags)
48
+ return off + encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
49
+
50
+ def String(self, off):
51
+ """String gets a string from data stored inside the flatbuffer."""
52
+ N.enforce_number(off, N.UOffsetTFlags)
53
+ off += encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
54
+ start = off + N.UOffsetTFlags.bytewidth
55
+ length = encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
56
+ return bytes(self.Bytes[start : start + length])
57
+
58
+ def VectorLen(self, off):
59
+ """VectorLen retrieves the length of the vector whose offset is stored
60
+
61
+ at "off" in this object.
62
+ """
63
+ N.enforce_number(off, N.UOffsetTFlags)
64
+
65
+ off += self.Pos
66
+ off += encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
67
+ ret = encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
68
+ return ret
69
+
70
+ def Vector(self, off):
71
+ """Vector retrieves the start of data of the vector whose offset is
72
+
73
+ stored at "off" in this object.
74
+ """
75
+ N.enforce_number(off, N.UOffsetTFlags)
76
+
77
+ off += self.Pos
78
+ x = off + self.Get(N.UOffsetTFlags, off)
79
+ # data starts after metadata containing the vector length
80
+ x += N.UOffsetTFlags.bytewidth
81
+ return x
82
+
83
+ def Union(self, t2, off):
84
+ """Union initializes any Table-derived type to point to the union at
85
+
86
+ the given offset.
87
+ """
88
+ assert type(t2) is Table
89
+ N.enforce_number(off, N.UOffsetTFlags)
90
+
91
+ off += self.Pos
92
+ t2.Pos = off + self.Get(N.UOffsetTFlags, off)
93
+ t2.Bytes = self.Bytes
94
+
95
+ def Get(self, flags, off):
96
+ """Get retrieves a value of the type specified by `flags` at the
97
+
98
+ given offset.
99
+ """
100
+ N.enforce_number(off, N.UOffsetTFlags)
101
+ return flags.py_type(encode.Get(flags.packer_type, self.Bytes, off))
102
+
103
+ def GetSlot(self, slot, d, validator_flags):
104
+ N.enforce_number(slot, N.VOffsetTFlags)
105
+ if validator_flags is not None:
106
+ N.enforce_number(d, validator_flags)
107
+ off = self.Offset(slot)
108
+ if off == 0:
109
+ return d
110
+ return self.Get(validator_flags, self.Pos + off)
111
+
112
+ def GetVectorAsNumpy(self, flags, off):
113
+ """GetVectorAsNumpy returns the vector that starts at `Vector(off)`
114
+
115
+ as a numpy array with the type specified by `flags`. The array is
116
+ a `view` into Bytes, so modifying the returned array will
117
+ modify Bytes in place.
118
+ """
119
+ offset = self.Vector(off)
120
+ length = self.VectorLen(off) # TODO: length accounts for bytewidth, right?
121
+ numpy_dtype = N.to_numpy_type(flags)
122
+ return encode.GetVectorAsNumpy(numpy_dtype, self.Bytes, length, offset)
123
+
124
+ def GetArrayAsNumpy(self, flags, off, length):
125
+ """GetArrayAsNumpy returns the array with fixed width that starts at `Vector(offset)`
126
+
127
+ with length `length` as a numpy array with the type specified by `flags`.
128
+ The
129
+ array is a `view` into Bytes so modifying the returned will modify Bytes in
130
+ place.
131
+ """
132
+ numpy_dtype = N.to_numpy_type(flags)
133
+ return encode.GetVectorAsNumpy(numpy_dtype, self.Bytes, length, off)
134
+
135
+ def GetVOffsetTSlot(self, slot, d):
136
+ """GetVOffsetTSlot retrieves the VOffsetT that the given vtable location
137
+
138
+ points to. If the vtable value is zero, the default value `d`
139
+ will be returned.
140
+ """
141
+
142
+ N.enforce_number(slot, N.VOffsetTFlags)
143
+ N.enforce_number(d, N.VOffsetTFlags)
144
+
145
+ off = self.Offset(slot)
146
+ if off == 0:
147
+ return d
148
+ return off
Video-RSI/.venv/lib/python3.12/site-packages/flatbuffers/util.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017 Google Inc. All rights reserved.
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
+
15
+ from . import encode
16
+ from . import number_types
17
+ from . import packer
18
+
19
+
20
+ def GetSizePrefix(buf, offset):
21
+ """Extract the size prefix from a buffer."""
22
+ return encode.Get(packer.int32, buf, offset)
23
+
24
+
25
+ def GetBufferIdentifier(buf, offset, size_prefixed=False):
26
+ """Extract the file_identifier from a buffer"""
27
+ if size_prefixed:
28
+ # increase offset by size of UOffsetTFlags
29
+ offset += number_types.UOffsetTFlags.bytewidth
30
+ # increase offset by size of root table pointer
31
+ offset += number_types.UOffsetTFlags.bytewidth
32
+ # end of FILE_IDENTIFIER
33
+ end = offset + encode.FILE_IDENTIFIER_LENGTH
34
+ return buf[offset:end]
35
+
36
+
37
+ def BufferHasIdentifier(buf, offset, file_identifier, size_prefixed=False):
38
+ got = GetBufferIdentifier(buf, offset, size_prefixed=size_prefixed)
39
+ return got == file_identifier
40
+
41
+
42
+ def RemoveSizePrefix(buf, offset):
43
+ """Create a slice of a size-prefixed buffer that has
44
+
45
+ its position advanced just past the size prefix.
46
+ """
47
+ return buf, offset + number_types.Int32Flags.bytewidth
Video-RSI/.venv/lib/python3.12/site-packages/google/_upb/_message.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ac1622d643ff188f4f355cc89a439f6881c397d766911e1246f9f4a215d051d
3
+ size 421992
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/__init__.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ # Copyright 2007 Google Inc. All Rights Reserved.
9
+
10
+ __version__ = '7.36.1'
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/any.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ """Contains the Any helper APIs."""
9
+
10
+ from typing import Optional, TypeVar
11
+
12
+ from google.protobuf import descriptor
13
+ from google.protobuf.message import Message
14
+
15
+ from google.protobuf.any_pb2 import Any
16
+
17
+ _MessageT = TypeVar('_MessageT', bound=Message)
18
+
19
+
20
+ def pack(
21
+ msg: Message,
22
+ type_url_prefix: Optional[str] = 'type.googleapis.com/',
23
+ deterministic: Optional[bool] = None,
24
+ ) -> Any:
25
+ any_msg = Any()
26
+ any_msg.Pack(
27
+ msg=msg, type_url_prefix=type_url_prefix, deterministic=deterministic
28
+ )
29
+ return any_msg
30
+
31
+
32
+ def unpack(any_msg: Any, msg: Message) -> bool:
33
+ return any_msg.Unpack(msg=msg)
34
+
35
+
36
+ def unpack_as(any_msg: Any, message_type: type[_MessageT]) -> _MessageT:
37
+ unpacked = message_type()
38
+ if unpack(any_msg, unpacked):
39
+ return unpacked
40
+ else:
41
+ raise TypeError(
42
+ f'Attempted to unpack {type_name(any_msg)} to'
43
+ f' {message_type.__qualname__}'
44
+ )
45
+
46
+
47
+ def type_name(any_msg: Any) -> str:
48
+ return any_msg.TypeName()
49
+
50
+
51
+ def is_type(any_msg: Any, des: descriptor.Descriptor) -> bool:
52
+ return any_msg.Is(des)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/any_pb2.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/any.proto
5
+ # Protobuf Python Version: 7.36.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 7,
15
+ 36,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/any.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x19google/protobuf/any.proto\x12\x0fgoogle.protobuf\"6\n\x03\x41ny\x12\x19\n\x08type_url\x18\x01 \x01(\tR\x07typeUrl\x12\x14\n\x05value\x18\x02 \x01(\x0cR\x05valueBv\n\x13\x63om.google.protobufB\x08\x41nyProtoP\x01Z,google.golang.org/protobuf/types/known/anypb\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.any_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\010AnyProtoP\001Z,google.golang.org/protobuf/types/known/anypb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
35
+ _globals['_ANY']._serialized_start=46
36
+ _globals['_ANY']._serialized_end=100
37
+ # @@protoc_insertion_point(module_scope)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/api_pb2.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/api.proto
5
+ # Protobuf Python Version: 7.36.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 7,
15
+ 36,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/api.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ from google.protobuf import source_context_pb2 as google_dot_protobuf_dot_source__context__pb2
26
+ from google.protobuf import type_pb2 as google_dot_protobuf_dot_type__pb2
27
+
28
+
29
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x19google/protobuf/api.proto\x12\x0fgoogle.protobuf\x1a$google/protobuf/source_context.proto\x1a\x1agoogle/protobuf/type.proto\"\xdb\x02\n\x03\x41pi\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\x31\n\x07methods\x18\x02 \x03(\x0b\x32\x17.google.protobuf.MethodR\x07methods\x12\x31\n\x07options\x18\x03 \x03(\x0b\x32\x17.google.protobuf.OptionR\x07options\x12\x18\n\x07version\x18\x04 \x01(\tR\x07version\x12\x45\n\x0esource_context\x18\x05 \x01(\x0b\x32\x1e.google.protobuf.SourceContextR\rsourceContext\x12.\n\x06mixins\x18\x06 \x03(\x0b\x32\x16.google.protobuf.MixinR\x06mixins\x12/\n\x06syntax\x18\x07 \x01(\x0e\x32\x17.google.protobuf.SyntaxR\x06syntax\x12\x18\n\x07\x65\x64ition\x18\x08 \x01(\tR\x07\x65\x64ition\"\xd4\x02\n\x06Method\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12(\n\x10request_type_url\x18\x02 \x01(\tR\x0erequestTypeUrl\x12+\n\x11request_streaming\x18\x03 \x01(\x08R\x10requestStreaming\x12*\n\x11response_type_url\x18\x04 \x01(\tR\x0fresponseTypeUrl\x12-\n\x12response_streaming\x18\x05 \x01(\x08R\x11responseStreaming\x12\x31\n\x07options\x18\x06 \x03(\x0b\x32\x17.google.protobuf.OptionR\x07options\x12\x33\n\x06syntax\x18\x07 \x01(\x0e\x32\x17.google.protobuf.SyntaxB\x02\x18\x01R\x06syntax\x12\x1c\n\x07\x65\x64ition\x18\x08 \x01(\tB\x02\x18\x01R\x07\x65\x64ition\"/\n\x05Mixin\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\x12\n\x04root\x18\x02 \x01(\tR\x04rootBv\n\x13\x63om.google.protobufB\x08\x41piProtoP\x01Z,google.golang.org/protobuf/types/known/apipb\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
30
+
31
+ _globals = globals()
32
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
33
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.api_pb2', _globals)
34
+ if not _descriptor._USE_C_DESCRIPTORS:
35
+ _globals['DESCRIPTOR']._loaded_options = None
36
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\010ApiProtoP\001Z,google.golang.org/protobuf/types/known/apipb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
37
+ _globals['_METHOD'].fields_by_name['syntax']._loaded_options = None
38
+ _globals['_METHOD'].fields_by_name['syntax']._serialized_options = b'\030\001'
39
+ _globals['_METHOD'].fields_by_name['edition']._loaded_options = None
40
+ _globals['_METHOD'].fields_by_name['edition']._serialized_options = b'\030\001'
41
+ _globals['_API']._serialized_start=113
42
+ _globals['_API']._serialized_end=460
43
+ _globals['_METHOD']._serialized_start=463
44
+ _globals['_METHOD']._serialized_end=803
45
+ _globals['_MIXIN']._serialized_start=805
46
+ _globals['_MIXIN']._serialized_end=852
47
+ # @@protoc_insertion_point(module_scope)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/compiler/__init__.py ADDED
File without changes
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/compiler/plugin_pb2.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/compiler/plugin.proto
5
+ # Protobuf Python Version: 7.36.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 7,
15
+ 36,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/compiler/plugin.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2
26
+
27
+
28
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n%google/protobuf/compiler/plugin.proto\x12\x18google.protobuf.compiler\x1a google/protobuf/descriptor.proto\"c\n\x07Version\x12\x14\n\x05major\x18\x01 \x01(\x05R\x05major\x12\x14\n\x05minor\x18\x02 \x01(\x05R\x05minor\x12\x14\n\x05patch\x18\x03 \x01(\x05R\x05patch\x12\x16\n\x06suffix\x18\x04 \x01(\tR\x06suffix\"\xcf\x02\n\x14\x43odeGeneratorRequest\x12(\n\x10\x66ile_to_generate\x18\x01 \x03(\tR\x0e\x66ileToGenerate\x12\x1c\n\tparameter\x18\x02 \x01(\tR\tparameter\x12\x43\n\nproto_file\x18\x0f \x03(\x0b\x32$.google.protobuf.FileDescriptorProtoR\tprotoFile\x12\\\n\x17source_file_descriptors\x18\x11 \x03(\x0b\x32$.google.protobuf.FileDescriptorProtoR\x15sourceFileDescriptors\x12L\n\x10\x63ompiler_version\x18\x03 \x01(\x0b\x32!.google.protobuf.compiler.VersionR\x0f\x63ompilerVersion\"\x85\x04\n\x15\x43odeGeneratorResponse\x12\x14\n\x05\x65rror\x18\x01 \x01(\tR\x05\x65rror\x12-\n\x12supported_features\x18\x02 \x01(\x04R\x11supportedFeatures\x12\'\n\x0fminimum_edition\x18\x03 \x01(\x05R\x0eminimumEdition\x12\'\n\x0fmaximum_edition\x18\x04 \x01(\x05R\x0emaximumEdition\x12H\n\x04\x66ile\x18\x0f \x03(\x0b\x32\x34.google.protobuf.compiler.CodeGeneratorResponse.FileR\x04\x66ile\x1a\xb1\x01\n\x04\x46ile\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\'\n\x0finsertion_point\x18\x02 \x01(\tR\x0einsertionPoint\x12\x18\n\x07\x63ontent\x18\x0f \x01(\tR\x07\x63ontent\x12R\n\x13generated_code_info\x18\x10 \x01(\x0b\x32\".google.protobuf.GeneratedCodeInfoR\x11generatedCodeInfo\"W\n\x07\x46\x65\x61ture\x12\x10\n\x0c\x46\x45\x41TURE_NONE\x10\x00\x12\x1b\n\x17\x46\x45\x41TURE_PROTO3_OPTIONAL\x10\x01\x12\x1d\n\x19\x46\x45\x41TURE_SUPPORTS_EDITIONS\x10\x02\x42r\n\x1c\x63om.google.protobuf.compilerB\x0cPluginProtosZ)google.golang.org/protobuf/types/pluginpb\xaa\x02\x18Google.Protobuf.Compiler')
29
+
30
+ _globals = globals()
31
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
32
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.compiler.plugin_pb2', _globals)
33
+ if not _descriptor._USE_C_DESCRIPTORS:
34
+ _globals['DESCRIPTOR']._loaded_options = None
35
+ _globals['DESCRIPTOR']._serialized_options = b'\n\034com.google.protobuf.compilerB\014PluginProtosZ)google.golang.org/protobuf/types/pluginpb\252\002\030Google.Protobuf.Compiler'
36
+ _globals['_VERSION']._serialized_start=101
37
+ _globals['_VERSION']._serialized_end=200
38
+ _globals['_CODEGENERATORREQUEST']._serialized_start=203
39
+ _globals['_CODEGENERATORREQUEST']._serialized_end=538
40
+ _globals['_CODEGENERATORRESPONSE']._serialized_start=541
41
+ _globals['_CODEGENERATORRESPONSE']._serialized_end=1058
42
+ _globals['_CODEGENERATORRESPONSE_FILE']._serialized_start=792
43
+ _globals['_CODEGENERATORRESPONSE_FILE']._serialized_end=969
44
+ _globals['_CODEGENERATORRESPONSE_FEATURE']._serialized_start=971
45
+ _globals['_CODEGENERATORRESPONSE_FEATURE']._serialized_end=1058
46
+ # @@protoc_insertion_point(module_scope)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor.py ADDED
@@ -0,0 +1,1669 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Descriptors essentially contain exactly the information found in a .proto
8
+
9
+ file, in types that make this information accessible in Python.
10
+ """
11
+
12
+ __author__ = 'robinson@google.com (Will Robinson)'
13
+
14
+ import abc
15
+ import binascii
16
+ import os
17
+ import threading
18
+ import warnings
19
+
20
+ from google.protobuf.internal import api_implementation
21
+
22
+ _USE_C_DESCRIPTORS = False
23
+ if api_implementation.Type() != 'python':
24
+ # pylint: disable=protected-access
25
+ _message = api_implementation._c_module
26
+ # TODO: Remove this import after fix api_implementation
27
+ if _message is None:
28
+ from google.protobuf.pyext import _message
29
+ _USE_C_DESCRIPTORS = True
30
+
31
+
32
+ class Error(Exception):
33
+ """Base error for this module."""
34
+
35
+
36
+ class TypeTransformationError(Error):
37
+ """Error transforming between python proto type and corresponding C++ type."""
38
+
39
+
40
+ if _USE_C_DESCRIPTORS:
41
+ # This metaclass allows to override the behavior of code like
42
+ # isinstance(my_descriptor, FieldDescriptor)
43
+ # and make it return True when the descriptor is an instance of the extension
44
+ # type written in C++.
45
+ class DescriptorMetaclass(type):
46
+
47
+ def __instancecheck__(cls, obj):
48
+ if super(DescriptorMetaclass, cls).__instancecheck__(obj):
49
+ return True
50
+ if isinstance(obj, cls._C_DESCRIPTOR_CLASS):
51
+ return True
52
+ return False
53
+
54
+ else:
55
+ # The standard metaclass; nothing changes.
56
+ DescriptorMetaclass = abc.ABCMeta
57
+
58
+
59
+ class _Lock(object):
60
+ """Wrapper class of threading.Lock(), which is allowed by 'with'."""
61
+
62
+ def __new__(cls):
63
+ self = object.__new__(cls)
64
+ self._lock = threading.Lock() # pylint: disable=protected-access
65
+ return self
66
+
67
+ def __enter__(self):
68
+ self._lock.acquire()
69
+
70
+ def __exit__(self, exc_type, exc_value, exc_tb):
71
+ self._lock.release()
72
+
73
+
74
+ _lock = threading.Lock()
75
+
76
+
77
+ def _Deprecated(
78
+ name,
79
+ alternative='get/find descriptors from generated code or query the descriptor_pool',
80
+ ):
81
+ if _Deprecated.count > 0:
82
+ _Deprecated.count -= 1
83
+ warnings.warn(
84
+ 'Call to deprecated %s, use %s instead.' % (name, alternative),
85
+ category=DeprecationWarning,
86
+ stacklevel=3,
87
+ )
88
+
89
+
90
+ # These must match the values in descriptor.proto, but we can't use them
91
+ # directly because we sometimes need to reference them in feature helpers
92
+ # below *during* the build of descriptor.proto.
93
+ _FEATURESET_MESSAGE_ENCODING_DELIMITED = 2
94
+ _FEATURESET_FIELD_PRESENCE_IMPLICIT = 2
95
+ _FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED = 3
96
+ _FEATURESET_REPEATED_FIELD_ENCODING_PACKED = 1
97
+ _FEATURESET_ENUM_TYPE_CLOSED = 2
98
+
99
+ # Deprecated warnings will print 100 times at most which should be enough for
100
+ # users to notice and do not cause timeout.
101
+ _Deprecated.count = 100
102
+
103
+ _internal_create_key = object()
104
+
105
+
106
+ class DescriptorBase(metaclass=DescriptorMetaclass):
107
+ """Descriptors base class.
108
+
109
+ This class is the base of all descriptor classes. It provides common options
110
+ related functionality.
111
+
112
+ Attributes:
113
+ has_options: True if the descriptor has non-default options. Usually it is
114
+ not necessary to read this -- just call GetOptions() which will happily
115
+ return the default instance. However, it's sometimes useful for
116
+ efficiency, and also useful inside the protobuf implementation to avoid
117
+ some bootstrapping issues.
118
+ file (FileDescriptor): Reference to file info.
119
+ """
120
+
121
+ if _USE_C_DESCRIPTORS:
122
+ # The class, or tuple of classes, that are considered as "virtual
123
+ # subclasses" of this descriptor class.
124
+ _C_DESCRIPTOR_CLASS = ()
125
+
126
+ def __init__(self, file, options, serialized_options, options_class_name):
127
+ """Initialize the descriptor given its options message and the name of the
128
+
129
+ class of the options message. The name of the class is required in case
130
+ the options message is None and has to be created.
131
+ """
132
+ self._features = None
133
+ self.file = file
134
+ self._original_options = options
135
+ # These two fields are duplicated as a compatibility shim for old gencode
136
+ # that resets them. In 26.x (cl/580304039) we renamed _options to,
137
+ # _loaded_options breaking backwards compatibility.
138
+ self._options = self._loaded_options = None
139
+ self._options_class_name = options_class_name
140
+ self._serialized_options = serialized_options
141
+
142
+ # Does this descriptor have non-default options?
143
+ self.has_options = (self._original_options is not None) or (
144
+ self._serialized_options is not None
145
+ )
146
+
147
+ @property
148
+ @abc.abstractmethod
149
+ def _parent(self):
150
+ pass
151
+
152
+ def _InferLegacyFeatures(self, edition, options, features):
153
+ """Infers features from proto2/proto3 syntax so that editions logic can be used everywhere.
154
+
155
+ Args:
156
+ edition: The edition to infer features for.
157
+ options: The options for this descriptor that are being processed.
158
+ features: The feature set object to modify with inferred features.
159
+ """
160
+ pass
161
+
162
+ def _GetFeatures(self):
163
+ if not self._features:
164
+ self._LazyLoadOptions()
165
+ return self._features
166
+
167
+ def _ResolveFeatures(self, edition, raw_options):
168
+ """Resolves features from the raw options of this descriptor.
169
+
170
+ Args:
171
+ edition: The edition to use for feature defaults.
172
+ raw_options: The options for this descriptor that are being processed.
173
+
174
+ Returns:
175
+ A fully resolved feature set for making runtime decisions.
176
+ """
177
+ # pylint: disable=g-import-not-at-top
178
+ from google.protobuf import descriptor_pb2
179
+
180
+ if self._parent:
181
+ features = descriptor_pb2.FeatureSet()
182
+ features.CopyFrom(self._parent._GetFeatures())
183
+ else:
184
+ features = self.file.pool._CreateDefaultFeatures(edition)
185
+ unresolved = descriptor_pb2.FeatureSet()
186
+ unresolved.CopyFrom(raw_options.features)
187
+ self._InferLegacyFeatures(edition, raw_options, unresolved)
188
+ features.MergeFrom(unresolved)
189
+
190
+ # Use the feature cache to reduce memory bloat.
191
+ return self.file.pool._InternFeatures(features)
192
+
193
+ def _LazyLoadOptions(self):
194
+ """Lazily initializes descriptor options towards the end of the build."""
195
+ if self._options and self._loaded_options == self._options:
196
+ # If neither has been reset by gencode, use the cache.
197
+ return
198
+
199
+ # pylint: disable=g-import-not-at-top
200
+ from google.protobuf import descriptor_pb2
201
+
202
+ if not hasattr(descriptor_pb2, self._options_class_name):
203
+ raise RuntimeError(
204
+ 'Unknown options class name %s!' % self._options_class_name
205
+ )
206
+ options_class = getattr(descriptor_pb2, self._options_class_name)
207
+ features = None
208
+ edition = self.file._edition
209
+
210
+ if not self.has_options:
211
+ if not self._features:
212
+ features = self._ResolveFeatures(
213
+ descriptor_pb2.Edition.Value(edition), options_class()
214
+ )
215
+ with _lock:
216
+ self._options = self._loaded_options = options_class()
217
+ if not self._features:
218
+ self._features = features
219
+ else:
220
+ if not self._serialized_options:
221
+ options = self._original_options
222
+ else:
223
+ options = _ParseOptions(options_class(), self._serialized_options)
224
+
225
+ if not self._features:
226
+ features = self._ResolveFeatures(
227
+ descriptor_pb2.Edition.Value(edition), options
228
+ )
229
+ with _lock:
230
+ self._options = self._loaded_options = options
231
+ if not self._features:
232
+ self._features = features
233
+ if options.HasField('features'):
234
+ options.ClearField('features')
235
+ if not options.SerializeToString():
236
+ self._options = self._loaded_options = options_class()
237
+ self.has_options = False
238
+
239
+ def GetOptions(self):
240
+ """Retrieves descriptor options.
241
+
242
+ Returns:
243
+ The options set on this descriptor.
244
+ """
245
+ # If either has been reset by gencode, reload options.
246
+ if not self._options or not self._loaded_options:
247
+ self._LazyLoadOptions()
248
+ if (
249
+ self._options
250
+ and hasattr(self._options, '_SetFrozen')
251
+ and not getattr(self._options, '_frozen', False)
252
+ ):
253
+ self._options._SetFrozen()
254
+ return self._options
255
+
256
+
257
+ class _NestedDescriptorBase(DescriptorBase):
258
+ """Common class for descriptors that can be nested."""
259
+
260
+ def __init__(
261
+ self,
262
+ options,
263
+ options_class_name,
264
+ name,
265
+ full_name,
266
+ file,
267
+ containing_type,
268
+ serialized_start=None,
269
+ serialized_end=None,
270
+ serialized_options=None,
271
+ ):
272
+ """Constructor.
273
+
274
+ Args:
275
+ options: Protocol message options or None to use default message options.
276
+ options_class_name (str): The class name of the above options.
277
+ name (str): Name of this protocol message type.
278
+ full_name (str): Fully-qualified name of this protocol message type, which
279
+ will include protocol "package" name and the name of any enclosing
280
+ types.
281
+ containing_type: if provided, this is a nested descriptor, with this
282
+ descriptor as parent, otherwise None.
283
+ serialized_start: The start index (inclusive) in block in the
284
+ file.serialized_pb that describes this descriptor.
285
+ serialized_end: The end index (exclusive) in block in the
286
+ file.serialized_pb that describes this descriptor.
287
+ serialized_options: Protocol message serialized options or None.
288
+ """
289
+ super(_NestedDescriptorBase, self).__init__(
290
+ file, options, serialized_options, options_class_name
291
+ )
292
+
293
+ self.name = name
294
+ # TODO: Add function to calculate full_name instead of having it in
295
+ # memory?
296
+ self.full_name = full_name
297
+ self.containing_type = containing_type
298
+
299
+ self._serialized_start = serialized_start
300
+ self._serialized_end = serialized_end
301
+
302
+ def CopyToProto(self, proto):
303
+ """Copies this to the matching proto in descriptor_pb2.
304
+
305
+ Args:
306
+ proto: An empty proto instance from descriptor_pb2.
307
+
308
+ Raises:
309
+ Error: If self couldn't be serialized, due to to few constructor
310
+ arguments.
311
+ """
312
+ if (
313
+ self.file is not None
314
+ and self._serialized_start is not None
315
+ and self._serialized_end is not None
316
+ ):
317
+ proto.ParseFromString(
318
+ self.file.serialized_pb[self._serialized_start : self._serialized_end]
319
+ )
320
+ else:
321
+ raise Error('Descriptor does not contain serialization.')
322
+
323
+
324
+ class Descriptor(_NestedDescriptorBase):
325
+ """Descriptor for a protocol message type.
326
+
327
+ Attributes:
328
+ name (str): Name of this protocol message type.
329
+ full_name (str): Fully-qualified name of this protocol message type, which
330
+ will include protocol "package" name and the name of any enclosing
331
+ types.
332
+ containing_type (Descriptor): Reference to the descriptor of the type
333
+ containing us, or None if this is top-level.
334
+ fields (list[FieldDescriptor]): Field descriptors for all fields in this
335
+ type.
336
+ fields_by_number (dict(int, FieldDescriptor)): Same
337
+ :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed by
338
+ "number" attribute in each FieldDescriptor.
339
+ fields_by_name (dict(str, FieldDescriptor)): Same :class:`FieldDescriptor`
340
+ objects as in :attr:`fields`, but indexed by "name" attribute in each
341
+ :class:`FieldDescriptor`.
342
+ nested_types (list[Descriptor]): Descriptor references for all protocol
343
+ message types nested within this one.
344
+ nested_types_by_name (dict(str, Descriptor)): Same Descriptor objects as
345
+ in :attr:`nested_types`, but indexed by "name" attribute in each
346
+ Descriptor.
347
+ enum_types (list[EnumDescriptor]): :class:`EnumDescriptor` references for
348
+ all enums contained within this type.
349
+ enum_types_by_name (dict(str, EnumDescriptor)): Same
350
+ :class:`EnumDescriptor` objects as in :attr:`enum_types`, but indexed by
351
+ "name" attribute in each EnumDescriptor.
352
+ enum_values_by_name (dict(str, EnumValueDescriptor)): Dict mapping from
353
+ enum value name to :class:`EnumValueDescriptor` for that value.
354
+ extensions (list[FieldDescriptor]): All extensions defined directly within
355
+ this message type (NOT within a nested type).
356
+ extensions_by_name (dict(str, FieldDescriptor)): Same FieldDescriptor
357
+ objects as :attr:`extensions`, but indexed by "name" attribute of each
358
+ FieldDescriptor.
359
+ is_extendable (bool): Does this type define any extension ranges?
360
+ oneofs (list[OneofDescriptor]): The list of descriptors for oneof fields
361
+ in this message.
362
+ oneofs_by_name (dict(str, OneofDescriptor)): Same objects as in
363
+ :attr:`oneofs`, but indexed by "name" attribute.
364
+ file (FileDescriptor): Reference to file descriptor.
365
+ is_map_entry: If the message type is a map entry.
366
+ """
367
+
368
+ if _USE_C_DESCRIPTORS:
369
+ _C_DESCRIPTOR_CLASS = _message.Descriptor
370
+
371
+ def __new__(
372
+ cls,
373
+ name=None,
374
+ full_name=None,
375
+ filename=None,
376
+ containing_type=None,
377
+ fields=None,
378
+ nested_types=None,
379
+ enum_types=None,
380
+ extensions=None,
381
+ options=None,
382
+ serialized_options=None,
383
+ is_extendable=True,
384
+ extension_ranges=None,
385
+ oneofs=None,
386
+ file=None, # pylint: disable=redefined-builtin
387
+ serialized_start=None,
388
+ serialized_end=None,
389
+ syntax=None,
390
+ is_map_entry=False,
391
+ create_key=None,
392
+ ):
393
+ _message.Message._CheckCalledFromGeneratedFile()
394
+ return _message.default_pool.FindMessageTypeByName(full_name)
395
+
396
+ # NOTE: The file argument redefining a builtin is nothing we can
397
+ # fix right now since we don't know how many clients already rely on the
398
+ # name of the argument.
399
+ def __init__(
400
+ self,
401
+ name,
402
+ full_name,
403
+ filename,
404
+ containing_type,
405
+ fields,
406
+ nested_types,
407
+ enum_types,
408
+ extensions,
409
+ options=None,
410
+ serialized_options=None,
411
+ is_extendable=True,
412
+ extension_ranges=None,
413
+ oneofs=None,
414
+ file=None,
415
+ serialized_start=None,
416
+ serialized_end=None, # pylint: disable=redefined-builtin
417
+ syntax=None,
418
+ is_map_entry=False,
419
+ create_key=None,
420
+ ):
421
+ """Arguments to __init__() are as described in the description
422
+
423
+ of Descriptor fields above.
424
+
425
+ Note that filename is an obsolete argument, that is not used anymore.
426
+ Please use file.name to access this as an attribute.
427
+ """
428
+ if create_key is not _internal_create_key:
429
+ _Deprecated('create function Descriptor()')
430
+
431
+ super(Descriptor, self).__init__(
432
+ options,
433
+ 'MessageOptions',
434
+ name,
435
+ full_name,
436
+ file,
437
+ containing_type,
438
+ serialized_start=serialized_start,
439
+ serialized_end=serialized_end,
440
+ serialized_options=serialized_options,
441
+ )
442
+
443
+ # We have fields in addition to fields_by_name and fields_by_number,
444
+ # so that:
445
+ # 1. Clients can index fields by "order in which they're listed."
446
+ # 2. Clients can easily iterate over all fields with the terse
447
+ # syntax: for f in descriptor.fields: ...
448
+ self.fields = fields
449
+ for field in self.fields:
450
+ field.containing_type = self
451
+ field.file = file
452
+ self.fields_by_number = dict((f.number, f) for f in fields)
453
+ self.fields_by_name = dict((f.name, f) for f in fields)
454
+ self._fields_by_camelcase_name = None
455
+
456
+ self.nested_types = nested_types
457
+ for nested_type in nested_types:
458
+ nested_type.containing_type = self
459
+ self.nested_types_by_name = dict((t.name, t) for t in nested_types)
460
+
461
+ self.enum_types = enum_types
462
+ for enum_type in self.enum_types:
463
+ enum_type.containing_type = self
464
+ self.enum_types_by_name = dict((t.name, t) for t in enum_types)
465
+ self.enum_values_by_name = dict(
466
+ (v.name, v) for t in enum_types for v in t.values
467
+ )
468
+
469
+ self.extensions = extensions
470
+ for extension in self.extensions:
471
+ extension.extension_scope = self
472
+ self.extensions_by_name = dict((f.name, f) for f in extensions)
473
+ self.is_extendable = is_extendable
474
+ self.extension_ranges = extension_ranges
475
+ self.oneofs = oneofs if oneofs is not None else []
476
+ self.oneofs_by_name = dict((o.name, o) for o in self.oneofs)
477
+ for oneof in self.oneofs:
478
+ oneof.containing_type = self
479
+ oneof.file = file
480
+ self._is_map_entry = is_map_entry
481
+
482
+ @property
483
+ def _parent(self):
484
+ return self.containing_type or self.file
485
+
486
+ @property
487
+ def fields_by_camelcase_name(self):
488
+ """Same FieldDescriptor objects as in :attr:`fields`, but indexed by
489
+
490
+ :attr:`FieldDescriptor.camelcase_name`.
491
+ """
492
+ if self._fields_by_camelcase_name is None:
493
+ self._fields_by_camelcase_name = dict(
494
+ (f.camelcase_name, f) for f in self.fields
495
+ )
496
+ return self._fields_by_camelcase_name
497
+
498
+ def EnumValueName(self, enum, value):
499
+ """Returns the string name of an enum value.
500
+
501
+ This is just a small helper method to simplify a common operation.
502
+
503
+ Args:
504
+ enum: string name of the Enum.
505
+ value: int, value of the enum.
506
+
507
+ Returns:
508
+ string name of the enum value.
509
+
510
+ Raises:
511
+ KeyError if either the Enum doesn't exist or the value is not a valid
512
+ value for the enum.
513
+ """
514
+ return self.enum_types_by_name[enum].values_by_number[value].name
515
+
516
+ def CopyToProto(self, proto):
517
+ """Copies this to a descriptor_pb2.DescriptorProto.
518
+
519
+ Args:
520
+ proto: An empty descriptor_pb2.DescriptorProto.
521
+ """
522
+ # This function is overridden to give a better doc comment.
523
+ super(Descriptor, self).CopyToProto(proto)
524
+
525
+
526
+ # TODO: We should have aggressive checking here,
527
+ # for example:
528
+ # * If you specify a repeated field, you should not be allowed
529
+ # to specify a default value.
530
+ # * [Other examples here as needed].
531
+ #
532
+ # TODO: for this and other *Descriptor classes, we
533
+ # might also want to lock things down aggressively (e.g.,
534
+ # prevent clients from setting the attributes). Having
535
+ # stronger invariants here in general will reduce the number
536
+ # of runtime checks we must do in reflection.py...
537
+ class FieldDescriptor(DescriptorBase):
538
+ """Descriptor for a single field in a .proto file.
539
+
540
+ Attributes:
541
+ name (str): Name of this field, exactly as it appears in .proto.
542
+ full_name (str): Name of this field, including containing scope. This is
543
+ particularly relevant for extensions.
544
+ index (int): Dense, 0-indexed index giving the order that this field
545
+ textually appears within its message in the .proto file.
546
+ number (int): Tag number declared for this field in the .proto file.
547
+ type (int): (One of the TYPE_* constants below) Declared type.
548
+ cpp_type (int): (One of the CPPTYPE_* constants below) C++ type used to
549
+ represent this field.
550
+ label (int): (One of the LABEL_* constants below) Tells whether this field
551
+ is optional, required, or repeated.
552
+ has_default_value (bool): True if this field has a default value defined,
553
+ otherwise false.
554
+ default_value (Varies): Default value of this field. Only meaningful for
555
+ non-repeated scalar fields. Repeated fields should always set this to [],
556
+ and non-repeated composite fields should always set this to None.
557
+ containing_type (Descriptor): Descriptor of the protocol message type that
558
+ contains this field. Set by the Descriptor constructor if we're passed
559
+ into one. Somewhat confusingly, for extension fields, this is the
560
+ descriptor of the EXTENDED message, not the descriptor of the message
561
+ containing this field. (See is_extension and extension_scope below).
562
+ message_type (Descriptor): If a composite field, a descriptor of the message
563
+ type contained in this field. Otherwise, this is None.
564
+ enum_type (EnumDescriptor): If this field contains an enum, a descriptor of
565
+ that enum. Otherwise, this is None.
566
+ is_extension: True iff this describes an extension field.
567
+ extension_scope (Descriptor): Only meaningful if is_extension is True. Gives
568
+ the message that immediately contains this extension field. Will be None
569
+ iff we're a top-level (file-level) extension field.
570
+ options (descriptor_pb2.FieldOptions): Protocol message field options or
571
+ None to use default field options.
572
+ containing_oneof (OneofDescriptor): If the field is a member of a oneof
573
+ union, contains its descriptor. Otherwise, None.
574
+ file (FileDescriptor): Reference to file descriptor.
575
+ """
576
+
577
+ # Must be consistent with C++ FieldDescriptor::Type enum in
578
+ # descriptor.h.
579
+ #
580
+ # TODO: Find a way to eliminate this repetition.
581
+ TYPE_DOUBLE = 1
582
+ TYPE_FLOAT = 2
583
+ TYPE_INT64 = 3
584
+ TYPE_UINT64 = 4
585
+ TYPE_INT32 = 5
586
+ TYPE_FIXED64 = 6
587
+ TYPE_FIXED32 = 7
588
+ TYPE_BOOL = 8
589
+ TYPE_STRING = 9
590
+ TYPE_GROUP = 10
591
+ TYPE_MESSAGE = 11
592
+ TYPE_BYTES = 12
593
+ TYPE_UINT32 = 13
594
+ TYPE_ENUM = 14
595
+ TYPE_SFIXED32 = 15
596
+ TYPE_SFIXED64 = 16
597
+ TYPE_SINT32 = 17
598
+ TYPE_SINT64 = 18
599
+ MAX_TYPE = 18
600
+
601
+ # Must be consistent with C++ FieldDescriptor::CppType enum in
602
+ # descriptor.h.
603
+ #
604
+ # TODO: Find a way to eliminate this repetition.
605
+ CPPTYPE_INT32 = 1
606
+ CPPTYPE_INT64 = 2
607
+ CPPTYPE_UINT32 = 3
608
+ CPPTYPE_UINT64 = 4
609
+ CPPTYPE_DOUBLE = 5
610
+ CPPTYPE_FLOAT = 6
611
+ CPPTYPE_BOOL = 7
612
+ CPPTYPE_ENUM = 8
613
+ CPPTYPE_STRING = 9
614
+ CPPTYPE_MESSAGE = 10
615
+ MAX_CPPTYPE = 10
616
+
617
+ _PYTHON_TO_CPP_PROTO_TYPE_MAP = {
618
+ TYPE_DOUBLE: CPPTYPE_DOUBLE,
619
+ TYPE_FLOAT: CPPTYPE_FLOAT,
620
+ TYPE_ENUM: CPPTYPE_ENUM,
621
+ TYPE_INT64: CPPTYPE_INT64,
622
+ TYPE_SINT64: CPPTYPE_INT64,
623
+ TYPE_SFIXED64: CPPTYPE_INT64,
624
+ TYPE_UINT64: CPPTYPE_UINT64,
625
+ TYPE_FIXED64: CPPTYPE_UINT64,
626
+ TYPE_INT32: CPPTYPE_INT32,
627
+ TYPE_SFIXED32: CPPTYPE_INT32,
628
+ TYPE_SINT32: CPPTYPE_INT32,
629
+ TYPE_UINT32: CPPTYPE_UINT32,
630
+ TYPE_FIXED32: CPPTYPE_UINT32,
631
+ TYPE_BYTES: CPPTYPE_STRING,
632
+ TYPE_STRING: CPPTYPE_STRING,
633
+ TYPE_BOOL: CPPTYPE_BOOL,
634
+ TYPE_MESSAGE: CPPTYPE_MESSAGE,
635
+ TYPE_GROUP: CPPTYPE_MESSAGE,
636
+ }
637
+
638
+ # Must be consistent with C++ FieldDescriptor::Label enum in
639
+ # descriptor.h.
640
+ #
641
+ # TODO: Find a way to eliminate this repetition.
642
+ LABEL_OPTIONAL = 1
643
+ LABEL_REQUIRED = 2
644
+ LABEL_REPEATED = 3
645
+ MAX_LABEL = 3
646
+
647
+ # Must be consistent with C++ constants kMaxNumber, kFirstReservedNumber,
648
+ # and kLastReservedNumber in descriptor.h
649
+ MAX_FIELD_NUMBER = (1 << 29) - 1
650
+ FIRST_RESERVED_FIELD_NUMBER = 19000
651
+ LAST_RESERVED_FIELD_NUMBER = 19999
652
+
653
+ if _USE_C_DESCRIPTORS:
654
+ _C_DESCRIPTOR_CLASS = _message.FieldDescriptor
655
+
656
+ def __new__(
657
+ cls,
658
+ name,
659
+ full_name,
660
+ index,
661
+ number,
662
+ type,
663
+ cpp_type,
664
+ label,
665
+ default_value,
666
+ message_type,
667
+ enum_type,
668
+ containing_type,
669
+ is_extension,
670
+ extension_scope,
671
+ options=None,
672
+ serialized_options=None,
673
+ has_default_value=True,
674
+ containing_oneof=None,
675
+ json_name=None,
676
+ file=None,
677
+ create_key=None,
678
+ ): # pylint: disable=redefined-builtin
679
+ _message.Message._CheckCalledFromGeneratedFile()
680
+ if is_extension:
681
+ return _message.default_pool.FindExtensionByName(full_name)
682
+ else:
683
+ return _message.default_pool.FindFieldByName(full_name)
684
+
685
+ def __init__(
686
+ self,
687
+ name,
688
+ full_name,
689
+ index,
690
+ number,
691
+ type,
692
+ cpp_type,
693
+ label,
694
+ default_value,
695
+ message_type,
696
+ enum_type,
697
+ containing_type,
698
+ is_extension,
699
+ extension_scope,
700
+ options=None,
701
+ serialized_options=None,
702
+ has_default_value=True,
703
+ containing_oneof=None,
704
+ json_name=None,
705
+ file=None,
706
+ create_key=None,
707
+ ): # pylint: disable=redefined-builtin
708
+ """The arguments are as described in the description of FieldDescriptor
709
+
710
+ attributes above.
711
+
712
+ Note that containing_type may be None, and may be set later if necessary
713
+ (to deal with circular references between message types, for example).
714
+ Likewise for extension_scope.
715
+ """
716
+ if create_key is not _internal_create_key:
717
+ _Deprecated('create function FieldDescriptor()')
718
+
719
+ super(FieldDescriptor, self).__init__(
720
+ file, options, serialized_options, 'FieldOptions'
721
+ )
722
+ self.name = name
723
+ self.full_name = full_name
724
+ self._camelcase_name = None
725
+ if json_name is None:
726
+ self.json_name = _ToJsonName(name)
727
+ else:
728
+ self.json_name = json_name
729
+ self.index = index
730
+ self.number = number
731
+ self._type = type
732
+ self.cpp_type = cpp_type
733
+ self._label = label
734
+ self.has_default_value = has_default_value
735
+ self.default_value = default_value
736
+ self.containing_type = containing_type
737
+ self.message_type = message_type
738
+ self.enum_type = enum_type
739
+ self.is_extension = is_extension
740
+ self.extension_scope = extension_scope
741
+ self.containing_oneof = containing_oneof
742
+ if api_implementation.Type() == 'python':
743
+ self._cdescriptor = None
744
+ else:
745
+ if is_extension:
746
+ self._cdescriptor = _message.default_pool.FindExtensionByName(full_name)
747
+ else:
748
+ self._cdescriptor = _message.default_pool.FindFieldByName(full_name)
749
+
750
+ @property
751
+ def _parent(self):
752
+ if self.containing_oneof:
753
+ return self.containing_oneof
754
+ if self.is_extension:
755
+ return self.extension_scope or self.file
756
+ return self.containing_type
757
+
758
+ def _InferLegacyFeatures(self, edition, options, features):
759
+ # pylint: disable=g-import-not-at-top
760
+ from google.protobuf import descriptor_pb2
761
+
762
+ if edition >= descriptor_pb2.Edition.EDITION_2023:
763
+ return
764
+
765
+ if self._label == FieldDescriptor.LABEL_REQUIRED:
766
+ features.field_presence = (
767
+ descriptor_pb2.FeatureSet.FieldPresence.LEGACY_REQUIRED
768
+ )
769
+
770
+ if self._type == FieldDescriptor.TYPE_GROUP:
771
+ features.message_encoding = (
772
+ descriptor_pb2.FeatureSet.MessageEncoding.DELIMITED
773
+ )
774
+
775
+ if options.HasField('packed'):
776
+ features.repeated_field_encoding = (
777
+ descriptor_pb2.FeatureSet.RepeatedFieldEncoding.PACKED
778
+ if options.packed
779
+ else descriptor_pb2.FeatureSet.RepeatedFieldEncoding.EXPANDED
780
+ )
781
+
782
+ @property
783
+ def type(self):
784
+ if (
785
+ self._GetFeatures().message_encoding
786
+ == _FEATURESET_MESSAGE_ENCODING_DELIMITED
787
+ and self.message_type
788
+ and not self.message_type.GetOptions().map_entry
789
+ and not self.containing_type.GetOptions().map_entry
790
+ ):
791
+ return FieldDescriptor.TYPE_GROUP
792
+ return self._type
793
+
794
+ @type.setter
795
+ def type(self, val):
796
+ self._type = val
797
+
798
+ @property
799
+ def is_required(self):
800
+ """Returns if the field is required."""
801
+ return (
802
+ self._GetFeatures().field_presence
803
+ == _FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED
804
+ )
805
+
806
+ @property
807
+ def is_repeated(self):
808
+ """Returns if the field is repeated."""
809
+ return self._label == FieldDescriptor.LABEL_REPEATED
810
+
811
+ @property
812
+ def camelcase_name(self):
813
+ """Camelcase name of this field.
814
+
815
+ Returns:
816
+ str: the name in CamelCase.
817
+ """
818
+ if self._camelcase_name is None:
819
+ self._camelcase_name = _ToCamelCase(self.name)
820
+ return self._camelcase_name
821
+
822
+ @property
823
+ def has_presence(self):
824
+ """Whether the field distinguishes between unpopulated and default values.
825
+
826
+ Raises:
827
+ RuntimeError: singular field that is not linked with message nor file.
828
+ """
829
+ if self.is_repeated:
830
+ return False
831
+ if (
832
+ self.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE
833
+ or self.is_extension
834
+ or self.containing_oneof
835
+ ):
836
+ return True
837
+
838
+ return (
839
+ self._GetFeatures().field_presence
840
+ != _FEATURESET_FIELD_PRESENCE_IMPLICIT
841
+ )
842
+
843
+ @property
844
+ def is_packed(self):
845
+ """Returns if the field is packed."""
846
+ if not self.is_repeated:
847
+ return False
848
+ field_type = self.type
849
+ if (
850
+ field_type == FieldDescriptor.TYPE_STRING
851
+ or field_type == FieldDescriptor.TYPE_GROUP
852
+ or field_type == FieldDescriptor.TYPE_MESSAGE
853
+ or field_type == FieldDescriptor.TYPE_BYTES
854
+ ):
855
+ return False
856
+
857
+ return (
858
+ self._GetFeatures().repeated_field_encoding
859
+ == _FEATURESET_REPEATED_FIELD_ENCODING_PACKED
860
+ )
861
+
862
+ @staticmethod
863
+ def ProtoTypeToCppProtoType(proto_type):
864
+ """Converts from a Python proto type to a C++ Proto Type.
865
+
866
+ The Python ProtocolBuffer classes specify both the 'Python' datatype and the
867
+ 'C++' datatype - and they're not the same. This helper method should
868
+ translate from one to another.
869
+
870
+ Args:
871
+ proto_type: the Python proto type (descriptor.FieldDescriptor.TYPE_*)
872
+
873
+ Returns:
874
+ int: descriptor.FieldDescriptor.CPPTYPE_*, the C++ type.
875
+ Raises:
876
+ TypeTransformationError: when the Python proto type isn't known.
877
+ """
878
+ try:
879
+ return FieldDescriptor._PYTHON_TO_CPP_PROTO_TYPE_MAP[proto_type]
880
+ except KeyError:
881
+ raise TypeTransformationError('Unknown proto_type: %s' % proto_type)
882
+
883
+
884
+ class EnumDescriptor(_NestedDescriptorBase):
885
+ """Descriptor for an enum defined in a .proto file.
886
+
887
+ Attributes:
888
+ name (str): Name of the enum type.
889
+ full_name (str): Full name of the type, including package name and any
890
+ enclosing type(s).
891
+ values (list[EnumValueDescriptor]): List of the values in this enum.
892
+ values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`, but
893
+ indexed by the "name" field of each EnumValueDescriptor.
894
+ values_by_number (dict(int, EnumValueDescriptor)): Same as :attr:`values`,
895
+ but indexed by the "number" field of each EnumValueDescriptor.
896
+ containing_type (Descriptor): Descriptor of the immediate containing type of
897
+ this enum, or None if this is an enum defined at the top level in a .proto
898
+ file. Set by Descriptor's constructor if we're passed into one.
899
+ file (FileDescriptor): Reference to file descriptor.
900
+ options (descriptor_pb2.EnumOptions): Enum options message or None to use
901
+ default enum options.
902
+ """
903
+
904
+ if _USE_C_DESCRIPTORS:
905
+ _C_DESCRIPTOR_CLASS = _message.EnumDescriptor
906
+
907
+ def __new__(
908
+ cls,
909
+ name,
910
+ full_name,
911
+ filename,
912
+ values,
913
+ containing_type=None,
914
+ options=None,
915
+ serialized_options=None,
916
+ file=None, # pylint: disable=redefined-builtin
917
+ serialized_start=None,
918
+ serialized_end=None,
919
+ create_key=None,
920
+ ):
921
+ _message.Message._CheckCalledFromGeneratedFile()
922
+ return _message.default_pool.FindEnumTypeByName(full_name)
923
+
924
+ def __init__(
925
+ self,
926
+ name,
927
+ full_name,
928
+ filename,
929
+ values,
930
+ containing_type=None,
931
+ options=None,
932
+ serialized_options=None,
933
+ file=None, # pylint: disable=redefined-builtin
934
+ serialized_start=None,
935
+ serialized_end=None,
936
+ create_key=None,
937
+ ):
938
+ """Arguments are as described in the attribute description above.
939
+
940
+ Note that filename is an obsolete argument, that is not used anymore.
941
+ Please use file.name to access this as an attribute.
942
+ """
943
+ if create_key is not _internal_create_key:
944
+ _Deprecated('create function EnumDescriptor()')
945
+
946
+ super(EnumDescriptor, self).__init__(
947
+ options,
948
+ 'EnumOptions',
949
+ name,
950
+ full_name,
951
+ file,
952
+ containing_type,
953
+ serialized_start=serialized_start,
954
+ serialized_end=serialized_end,
955
+ serialized_options=serialized_options,
956
+ )
957
+
958
+ self.values = values
959
+ for value in self.values:
960
+ value.file = file
961
+ value.type = self
962
+ self.values_by_name = dict((v.name, v) for v in values)
963
+ # Values are reversed to ensure that the first alias is retained.
964
+ self.values_by_number = dict((v.number, v) for v in reversed(values))
965
+
966
+ @property
967
+ def _parent(self):
968
+ return self.containing_type or self.file
969
+
970
+ @property
971
+ def is_closed(self):
972
+ """Returns true whether this is a "closed" enum.
973
+
974
+ This means that it:
975
+ - Has a fixed set of values, rather than being equivalent to an int32.
976
+ - Encountering values not in this set causes them to be treated as unknown
977
+ fields.
978
+ - The first value (i.e., the default) may be nonzero.
979
+
980
+ WARNING: Some runtimes currently have a quirk where non-closed enums are
981
+ treated as closed when used as the type of fields defined in a
982
+ `syntax = proto2;` file. This quirk is not present in all runtimes; as of
983
+ writing, we know that:
984
+
985
+ - C++, Java, and C++-based Python share this quirk.
986
+ - UPB and UPB-based Python do not.
987
+ - PHP and Ruby treat all enums as open regardless of declaration.
988
+
989
+ Care should be taken when using this function to respect the target
990
+ runtime's enum handling quirks.
991
+ """
992
+ return self._GetFeatures().enum_type == _FEATURESET_ENUM_TYPE_CLOSED
993
+
994
+ def CopyToProto(self, proto):
995
+ """Copies this to a descriptor_pb2.EnumDescriptorProto.
996
+
997
+ Args:
998
+ proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto.
999
+ """
1000
+ # This function is overridden to give a better doc comment.
1001
+ super(EnumDescriptor, self).CopyToProto(proto)
1002
+
1003
+
1004
+ class EnumValueDescriptor(DescriptorBase):
1005
+ """Descriptor for a single value within an enum.
1006
+
1007
+ Attributes:
1008
+ name (str): Name of this value.
1009
+ index (int): Dense, 0-indexed index giving the order that this value appears
1010
+ textually within its enum in the .proto file.
1011
+ number (int): Actual number assigned to this enum value.
1012
+ type (EnumDescriptor): :class:`EnumDescriptor` to which this value belongs.
1013
+ Set by :class:`EnumDescriptor`'s constructor if we're passed into one.
1014
+ options (descriptor_pb2.EnumValueOptions): Enum value options message or
1015
+ None to use default enum value options options.
1016
+ """
1017
+
1018
+ if _USE_C_DESCRIPTORS:
1019
+ _C_DESCRIPTOR_CLASS = _message.EnumValueDescriptor
1020
+
1021
+ def __new__(
1022
+ cls,
1023
+ name,
1024
+ index,
1025
+ number,
1026
+ type=None, # pylint: disable=redefined-builtin
1027
+ options=None,
1028
+ serialized_options=None,
1029
+ create_key=None,
1030
+ ):
1031
+ _message.Message._CheckCalledFromGeneratedFile()
1032
+ # There is no way we can build a complete EnumValueDescriptor with the
1033
+ # given parameters (the name of the Enum is not known, for example).
1034
+ # Fortunately generated files just pass it to the EnumDescriptor()
1035
+ # constructor, which will ignore it, so returning None is good enough.
1036
+ return None
1037
+
1038
+ def __init__(
1039
+ self,
1040
+ name,
1041
+ index,
1042
+ number,
1043
+ type=None, # pylint: disable=redefined-builtin
1044
+ options=None,
1045
+ serialized_options=None,
1046
+ create_key=None,
1047
+ ):
1048
+ """Arguments are as described in the attribute description above."""
1049
+ if create_key is not _internal_create_key:
1050
+ _Deprecated('create function EnumValueDescriptor()')
1051
+
1052
+ super(EnumValueDescriptor, self).__init__(
1053
+ type.file if type else None,
1054
+ options,
1055
+ serialized_options,
1056
+ 'EnumValueOptions',
1057
+ )
1058
+ self.name = name
1059
+ self.index = index
1060
+ self.number = number
1061
+ self.type = type
1062
+
1063
+ @property
1064
+ def _parent(self):
1065
+ return self.type
1066
+
1067
+
1068
+ class OneofDescriptor(DescriptorBase):
1069
+ """Descriptor for a oneof field.
1070
+
1071
+ Attributes:
1072
+ name (str): Name of the oneof field.
1073
+ full_name (str): Full name of the oneof field, including package name.
1074
+ index (int): 0-based index giving the order of the oneof field inside its
1075
+ containing type.
1076
+ containing_type (Descriptor): :class:`Descriptor` of the protocol message
1077
+ type that contains this field. Set by the :class:`Descriptor` constructor
1078
+ if we're passed into one.
1079
+ fields (list[FieldDescriptor]): The list of field descriptors this oneof can
1080
+ contain.
1081
+ """
1082
+
1083
+ if _USE_C_DESCRIPTORS:
1084
+ _C_DESCRIPTOR_CLASS = _message.OneofDescriptor
1085
+
1086
+ def __new__(
1087
+ cls,
1088
+ name,
1089
+ full_name,
1090
+ index,
1091
+ containing_type,
1092
+ fields,
1093
+ options=None,
1094
+ serialized_options=None,
1095
+ create_key=None,
1096
+ ):
1097
+ _message.Message._CheckCalledFromGeneratedFile()
1098
+ return _message.default_pool.FindOneofByName(full_name)
1099
+
1100
+ def __init__(
1101
+ self,
1102
+ name,
1103
+ full_name,
1104
+ index,
1105
+ containing_type,
1106
+ fields,
1107
+ options=None,
1108
+ serialized_options=None,
1109
+ create_key=None,
1110
+ ):
1111
+ """Arguments are as described in the attribute description above."""
1112
+ if create_key is not _internal_create_key:
1113
+ _Deprecated('create function OneofDescriptor()')
1114
+
1115
+ super(OneofDescriptor, self).__init__(
1116
+ containing_type.file if containing_type else None,
1117
+ options,
1118
+ serialized_options,
1119
+ 'OneofOptions',
1120
+ )
1121
+ self.name = name
1122
+ self.full_name = full_name
1123
+ self.index = index
1124
+ self.containing_type = containing_type
1125
+ self.fields = fields
1126
+
1127
+ @property
1128
+ def _parent(self):
1129
+ return self.containing_type
1130
+
1131
+
1132
+ class ServiceDescriptor(_NestedDescriptorBase):
1133
+ """Descriptor for a service.
1134
+
1135
+ Attributes:
1136
+ name (str): Name of the service.
1137
+ full_name (str): Full name of the service, including package name.
1138
+ index (int): 0-indexed index giving the order that this services definition
1139
+ appears within the .proto file.
1140
+ methods (list[MethodDescriptor]): List of methods provided by this service.
1141
+ methods_by_name (dict(str, MethodDescriptor)): Same
1142
+ :class:`MethodDescriptor` objects as in :attr:`methods_by_name`, but
1143
+ indexed by "name" attribute in each :class:`MethodDescriptor`.
1144
+ options (descriptor_pb2.ServiceOptions): Service options message or None to
1145
+ use default service options.
1146
+ file (FileDescriptor): Reference to file info.
1147
+ """
1148
+
1149
+ if _USE_C_DESCRIPTORS:
1150
+ _C_DESCRIPTOR_CLASS = _message.ServiceDescriptor
1151
+
1152
+ def __new__(
1153
+ cls,
1154
+ name=None,
1155
+ full_name=None,
1156
+ index=None,
1157
+ methods=None,
1158
+ options=None,
1159
+ serialized_options=None,
1160
+ file=None, # pylint: disable=redefined-builtin
1161
+ serialized_start=None,
1162
+ serialized_end=None,
1163
+ create_key=None,
1164
+ ):
1165
+ _message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
1166
+ return _message.default_pool.FindServiceByName(full_name)
1167
+
1168
+ def __init__(
1169
+ self,
1170
+ name,
1171
+ full_name,
1172
+ index,
1173
+ methods,
1174
+ options=None,
1175
+ serialized_options=None,
1176
+ file=None, # pylint: disable=redefined-builtin
1177
+ serialized_start=None,
1178
+ serialized_end=None,
1179
+ create_key=None,
1180
+ ):
1181
+ if create_key is not _internal_create_key:
1182
+ _Deprecated('create function ServiceDescriptor()')
1183
+
1184
+ super(ServiceDescriptor, self).__init__(
1185
+ options,
1186
+ 'ServiceOptions',
1187
+ name,
1188
+ full_name,
1189
+ file,
1190
+ None,
1191
+ serialized_start=serialized_start,
1192
+ serialized_end=serialized_end,
1193
+ serialized_options=serialized_options,
1194
+ )
1195
+ self.index = index
1196
+ self.methods = methods
1197
+ self.methods_by_name = dict((m.name, m) for m in methods)
1198
+ # Set the containing service for each method in this service.
1199
+ for method in self.methods:
1200
+ method.file = self.file
1201
+ method.containing_service = self
1202
+
1203
+ @property
1204
+ def _parent(self):
1205
+ return self.file
1206
+
1207
+ def FindMethodByName(self, name):
1208
+ """Searches for the specified method, and returns its descriptor.
1209
+
1210
+ Args:
1211
+ name (str): Name of the method.
1212
+
1213
+ Returns:
1214
+ MethodDescriptor: The descriptor for the requested method.
1215
+
1216
+ Raises:
1217
+ KeyError: if the method cannot be found in the service.
1218
+ """
1219
+ return self.methods_by_name[name]
1220
+
1221
+ def CopyToProto(self, proto):
1222
+ """Copies this to a descriptor_pb2.ServiceDescriptorProto.
1223
+
1224
+ Args:
1225
+ proto (descriptor_pb2.ServiceDescriptorProto): An empty descriptor proto.
1226
+ """
1227
+ # This function is overridden to give a better doc comment.
1228
+ super(ServiceDescriptor, self).CopyToProto(proto)
1229
+
1230
+
1231
+ class MethodDescriptor(DescriptorBase):
1232
+ """Descriptor for a method in a service.
1233
+
1234
+ Attributes:
1235
+ name (str): Name of the method within the service.
1236
+ full_name (str): Full name of method.
1237
+ index (int): 0-indexed index of the method inside the service.
1238
+ containing_service (ServiceDescriptor): The service that contains this
1239
+ method.
1240
+ input_type (Descriptor): The descriptor of the message that this method
1241
+ accepts.
1242
+ output_type (Descriptor): The descriptor of the message that this method
1243
+ returns.
1244
+ client_streaming (bool): Whether this method uses client streaming.
1245
+ server_streaming (bool): Whether this method uses server streaming.
1246
+ options (descriptor_pb2.MethodOptions or None): Method options message, or
1247
+ None to use default method options.
1248
+ """
1249
+
1250
+ if _USE_C_DESCRIPTORS:
1251
+ _C_DESCRIPTOR_CLASS = _message.MethodDescriptor
1252
+
1253
+ def __new__(
1254
+ cls,
1255
+ name,
1256
+ full_name,
1257
+ index,
1258
+ containing_service,
1259
+ input_type,
1260
+ output_type,
1261
+ client_streaming=False,
1262
+ server_streaming=False,
1263
+ options=None,
1264
+ serialized_options=None,
1265
+ create_key=None,
1266
+ ):
1267
+ _message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
1268
+ return _message.default_pool.FindMethodByName(full_name)
1269
+
1270
+ def __init__(
1271
+ self,
1272
+ name,
1273
+ full_name,
1274
+ index,
1275
+ containing_service,
1276
+ input_type,
1277
+ output_type,
1278
+ client_streaming=False,
1279
+ server_streaming=False,
1280
+ options=None,
1281
+ serialized_options=None,
1282
+ create_key=None,
1283
+ ):
1284
+ """The arguments are as described in the description of MethodDescriptor
1285
+
1286
+ attributes above.
1287
+
1288
+ Note that containing_service may be None, and may be set later if necessary.
1289
+ """
1290
+ if create_key is not _internal_create_key:
1291
+ _Deprecated('create function MethodDescriptor()')
1292
+
1293
+ super(MethodDescriptor, self).__init__(
1294
+ containing_service.file if containing_service else None,
1295
+ options,
1296
+ serialized_options,
1297
+ 'MethodOptions',
1298
+ )
1299
+ self.name = name
1300
+ self.full_name = full_name
1301
+ self.index = index
1302
+ self.containing_service = containing_service
1303
+ self.input_type = input_type
1304
+ self.output_type = output_type
1305
+ self.client_streaming = client_streaming
1306
+ self.server_streaming = server_streaming
1307
+
1308
+ @property
1309
+ def _parent(self):
1310
+ return self.containing_service
1311
+
1312
+ def CopyToProto(self, proto):
1313
+ """Copies this to a descriptor_pb2.MethodDescriptorProto.
1314
+
1315
+ Args:
1316
+ proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.
1317
+
1318
+ Raises:
1319
+ Error: If self couldn't be serialized, due to too few constructor
1320
+ arguments.
1321
+ """
1322
+ if self.containing_service is not None:
1323
+ from google.protobuf import descriptor_pb2
1324
+
1325
+ service_proto = descriptor_pb2.ServiceDescriptorProto()
1326
+ self.containing_service.CopyToProto(service_proto)
1327
+ proto.CopyFrom(service_proto.method[self.index])
1328
+ else:
1329
+ raise Error('Descriptor does not contain a service.')
1330
+
1331
+
1332
+ class FileDescriptor(DescriptorBase):
1333
+ """Descriptor for a file. Mimics the descriptor_pb2.FileDescriptorProto.
1334
+
1335
+ Note that :attr:`enum_types_by_name`, :attr:`extensions_by_name`, and
1336
+ :attr:`dependencies` fields are only set by the
1337
+ :py:mod:`google.protobuf.message_factory` module, and not by the generated
1338
+ proto code.
1339
+
1340
+ Attributes:
1341
+ name (str): Name of file, relative to root of source tree.
1342
+ package (str): Name of the package
1343
+ edition (Edition): Enum value indicating edition of the file
1344
+ serialized_pb (bytes): Byte string of serialized
1345
+ :class:`descriptor_pb2.FileDescriptorProto`.
1346
+ dependencies (list[FileDescriptor]): List of other :class:`FileDescriptor`
1347
+ objects this :class:`FileDescriptor` depends on.
1348
+ public_dependencies (list[FileDescriptor]): A subset of
1349
+ :attr:`dependencies`, which were declared as "public".
1350
+ message_types_by_name (dict(str, Descriptor)): Mapping from message names to
1351
+ their :class:`Descriptor`.
1352
+ enum_types_by_name (dict(str, EnumDescriptor)): Mapping from enum names to
1353
+ their :class:`EnumDescriptor`.
1354
+ extensions_by_name (dict(str, FieldDescriptor)): Mapping from extension
1355
+ names declared at file scope to their :class:`FieldDescriptor`.
1356
+ services_by_name (dict(str, ServiceDescriptor)): Mapping from services'
1357
+ names to their :class:`ServiceDescriptor`.
1358
+ pool (DescriptorPool): The pool this descriptor belongs to. When not passed
1359
+ to the constructor, the global default pool is used.
1360
+ """
1361
+
1362
+ if _USE_C_DESCRIPTORS:
1363
+ _C_DESCRIPTOR_CLASS = _message.FileDescriptor
1364
+
1365
+ def __new__(
1366
+ cls,
1367
+ name,
1368
+ package,
1369
+ options=None,
1370
+ serialized_options=None,
1371
+ serialized_pb=None,
1372
+ dependencies=None,
1373
+ public_dependencies=None,
1374
+ syntax=None,
1375
+ edition=None,
1376
+ pool=None,
1377
+ create_key=None,
1378
+ ):
1379
+ # FileDescriptor() is called from various places, not only from generated
1380
+ # files, to register dynamic proto files and messages.
1381
+ # pylint: disable=g-explicit-bool-comparison
1382
+ if serialized_pb:
1383
+ return _message.default_pool.AddSerializedFile(serialized_pb)
1384
+ else:
1385
+ return super(FileDescriptor, cls).__new__(cls)
1386
+
1387
+ def __init__(
1388
+ self,
1389
+ name,
1390
+ package,
1391
+ options=None,
1392
+ serialized_options=None,
1393
+ serialized_pb=None,
1394
+ dependencies=None,
1395
+ public_dependencies=None,
1396
+ syntax=None,
1397
+ edition=None,
1398
+ pool=None,
1399
+ create_key=None,
1400
+ ):
1401
+ """Constructor."""
1402
+ if create_key is not _internal_create_key:
1403
+ _Deprecated('create function FileDescriptor()')
1404
+
1405
+ super(FileDescriptor, self).__init__(
1406
+ self, options, serialized_options, 'FileOptions'
1407
+ )
1408
+
1409
+ if edition and edition != 'EDITION_UNKNOWN':
1410
+ self._edition = edition
1411
+ elif syntax == 'proto3':
1412
+ self._edition = 'EDITION_PROTO3'
1413
+ else:
1414
+ self._edition = 'EDITION_PROTO2'
1415
+
1416
+ if pool is None:
1417
+ from google.protobuf import descriptor_pool
1418
+
1419
+ pool = descriptor_pool.Default()
1420
+ self.pool = pool
1421
+ self.message_types_by_name = {}
1422
+ self.name = name
1423
+ self.package = package
1424
+ self.serialized_pb = serialized_pb
1425
+
1426
+ self.enum_types_by_name = {}
1427
+ self.extensions_by_name = {}
1428
+ self.services_by_name = {}
1429
+ self.dependencies = dependencies or []
1430
+ self.public_dependencies = public_dependencies or []
1431
+
1432
+ def CopyToProto(self, proto):
1433
+ """Copies this to a descriptor_pb2.FileDescriptorProto.
1434
+
1435
+ Args:
1436
+ proto: An empty descriptor_pb2.FileDescriptorProto.
1437
+ """
1438
+ proto.ParseFromString(self.serialized_pb)
1439
+
1440
+ @property
1441
+ def _parent(self):
1442
+ return None
1443
+
1444
+
1445
+ def _ParseOptions(message, string):
1446
+ """Parses serialized options.
1447
+
1448
+ This helper function is used to parse serialized options in generated
1449
+ proto2 files. It must not be used outside proto2.
1450
+ """
1451
+ message.ParseFromString(string)
1452
+ return message
1453
+
1454
+
1455
+ def _ToCamelCase(name):
1456
+ """Converts name to camel-case and returns it."""
1457
+ capitalize_next = False
1458
+ result = []
1459
+
1460
+ for c in name:
1461
+ if c == '_':
1462
+ if result:
1463
+ capitalize_next = True
1464
+ elif capitalize_next:
1465
+ result.append(c.upper())
1466
+ capitalize_next = False
1467
+ else:
1468
+ result += c
1469
+
1470
+ # Lower-case the first letter.
1471
+ if result and result[0].isupper():
1472
+ result[0] = result[0].lower()
1473
+ return ''.join(result)
1474
+
1475
+
1476
+ def _OptionsOrNone(descriptor_proto):
1477
+ """Returns the value of the field `options`, or None if it is not set."""
1478
+ if descriptor_proto.HasField('options'):
1479
+ return descriptor_proto.options
1480
+ else:
1481
+ return None
1482
+
1483
+
1484
+ def _ToJsonName(name):
1485
+ """Converts name to Json name and returns it."""
1486
+ capitalize_next = False
1487
+ result = []
1488
+
1489
+ for c in name:
1490
+ if c == '_':
1491
+ capitalize_next = True
1492
+ elif capitalize_next:
1493
+ result.append(c.upper())
1494
+ capitalize_next = False
1495
+ else:
1496
+ result += c
1497
+
1498
+ return ''.join(result)
1499
+
1500
+
1501
+ def MakeDescriptor(
1502
+ desc_proto,
1503
+ package='',
1504
+ build_file_if_cpp=True,
1505
+ syntax=None,
1506
+ edition=None,
1507
+ file_desc=None,
1508
+ ):
1509
+ """Make a protobuf Descriptor given a DescriptorProto protobuf.
1510
+
1511
+ Handles nested descriptors. Note that this is limited to the scope of defining
1512
+ a message inside of another message. Composite fields can currently only be
1513
+ resolved if the message is defined in the same scope as the field.
1514
+
1515
+ Args:
1516
+ desc_proto: The descriptor_pb2.DescriptorProto protobuf message.
1517
+ package: Optional package name for the new message Descriptor (string).
1518
+ build_file_if_cpp: Update the C++ descriptor pool if api matches. Set to
1519
+ False on recursion, so no duplicates are created.
1520
+ syntax: The syntax/semantics that should be used. Set to "proto3" to get
1521
+ proto3 field presence semantics.
1522
+ edition: The edition that should be used if syntax is "edition".
1523
+ file_desc: A FileDescriptor to place this descriptor into.
1524
+
1525
+ Returns:
1526
+ A Descriptor for protobuf messages.
1527
+ """
1528
+ # pylint: disable=g-import-not-at-top
1529
+ from google.protobuf import descriptor_pb2
1530
+
1531
+ # Generate a random name for this proto file to prevent conflicts with any
1532
+ # imported ones. We need to specify a file name so the descriptor pool
1533
+ # accepts our FileDescriptorProto, but it is not important what that file
1534
+ # name is actually set to.
1535
+ proto_name = binascii.hexlify(os.urandom(16)).decode('ascii')
1536
+
1537
+ if package:
1538
+ file_name = os.path.join(package.replace('.', '/'), proto_name + '.proto')
1539
+ else:
1540
+ file_name = proto_name + '.proto'
1541
+
1542
+ if api_implementation.Type() != 'python' and build_file_if_cpp:
1543
+ # The C++ implementation requires all descriptors to be backed by the same
1544
+ # definition in the C++ descriptor pool. To do this, we build a
1545
+ # FileDescriptorProto with the same definition as this descriptor and build
1546
+ # it into the pool.
1547
+ file_descriptor_proto = descriptor_pb2.FileDescriptorProto()
1548
+ file_descriptor_proto.message_type.add().MergeFrom(desc_proto)
1549
+
1550
+ if package:
1551
+ file_descriptor_proto.package = package
1552
+ file_descriptor_proto.name = file_name
1553
+
1554
+ _message.default_pool.Add(file_descriptor_proto)
1555
+ result = _message.default_pool.FindFileByName(file_descriptor_proto.name)
1556
+
1557
+ if _USE_C_DESCRIPTORS:
1558
+ return result.message_types_by_name[desc_proto.name]
1559
+
1560
+ if file_desc is None:
1561
+ file_desc = FileDescriptor(
1562
+ pool=None,
1563
+ name=file_name,
1564
+ package=package,
1565
+ syntax=syntax,
1566
+ edition=edition,
1567
+ options=None,
1568
+ serialized_pb='',
1569
+ dependencies=[],
1570
+ public_dependencies=[],
1571
+ create_key=_internal_create_key,
1572
+ )
1573
+ full_message_name = [desc_proto.name]
1574
+ if package:
1575
+ full_message_name.insert(0, package)
1576
+
1577
+ # Create Descriptors for enum types
1578
+ enum_types = {}
1579
+ for enum_proto in desc_proto.enum_type:
1580
+ full_name = '.'.join(full_message_name + [enum_proto.name])
1581
+ enum_desc = EnumDescriptor(
1582
+ enum_proto.name,
1583
+ full_name,
1584
+ None,
1585
+ [
1586
+ EnumValueDescriptor(
1587
+ enum_val.name,
1588
+ ii,
1589
+ enum_val.number,
1590
+ create_key=_internal_create_key,
1591
+ )
1592
+ for ii, enum_val in enumerate(enum_proto.value)
1593
+ ],
1594
+ file=file_desc,
1595
+ create_key=_internal_create_key,
1596
+ )
1597
+ enum_types[full_name] = enum_desc
1598
+
1599
+ # Create Descriptors for nested types
1600
+ nested_types = {}
1601
+ for nested_proto in desc_proto.nested_type:
1602
+ full_name = '.'.join(full_message_name + [nested_proto.name])
1603
+ # Nested types are just those defined inside of the message, not all types
1604
+ # used by fields in the message, so no loops are possible here.
1605
+ nested_desc = MakeDescriptor(
1606
+ nested_proto,
1607
+ package='.'.join(full_message_name),
1608
+ build_file_if_cpp=False,
1609
+ syntax=syntax,
1610
+ edition=edition,
1611
+ file_desc=file_desc,
1612
+ )
1613
+ nested_types[full_name] = nested_desc
1614
+
1615
+ fields = []
1616
+ for field_proto in desc_proto.field:
1617
+ full_name = '.'.join(full_message_name + [field_proto.name])
1618
+ enum_desc = None
1619
+ nested_desc = None
1620
+ if field_proto.json_name:
1621
+ json_name = field_proto.json_name
1622
+ else:
1623
+ json_name = None
1624
+ if field_proto.HasField('type_name'):
1625
+ type_name = field_proto.type_name
1626
+ full_type_name = '.'.join(
1627
+ full_message_name + [type_name[type_name.rfind('.') + 1 :]]
1628
+ )
1629
+ if full_type_name in nested_types:
1630
+ nested_desc = nested_types[full_type_name]
1631
+ elif full_type_name in enum_types:
1632
+ enum_desc = enum_types[full_type_name]
1633
+ # Else type_name references a non-local type, which isn't implemented
1634
+ field = FieldDescriptor(
1635
+ field_proto.name,
1636
+ full_name,
1637
+ field_proto.number - 1,
1638
+ field_proto.number,
1639
+ field_proto.type,
1640
+ FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type),
1641
+ field_proto.label,
1642
+ None,
1643
+ nested_desc,
1644
+ enum_desc,
1645
+ None,
1646
+ False,
1647
+ None,
1648
+ options=_OptionsOrNone(field_proto),
1649
+ has_default_value=False,
1650
+ json_name=json_name,
1651
+ file=file_desc,
1652
+ create_key=_internal_create_key,
1653
+ )
1654
+ fields.append(field)
1655
+
1656
+ desc_name = '.'.join(full_message_name)
1657
+ return Descriptor(
1658
+ desc_proto.name,
1659
+ desc_name,
1660
+ None,
1661
+ None,
1662
+ fields,
1663
+ list(nested_types.values()),
1664
+ list(enum_types.values()),
1665
+ [],
1666
+ options=_OptionsOrNone(desc_proto),
1667
+ file=file_desc,
1668
+ create_key=_internal_create_key,
1669
+ )
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor_database.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Provides a container for DescriptorProtos."""
8
+
9
+ __author__ = 'matthewtoia@google.com (Matt Toia)'
10
+
11
+ from typing import Dict, Iterator, Optional
12
+ import warnings
13
+
14
+
15
+ class Error(Exception):
16
+ pass
17
+
18
+
19
+ class DescriptorDatabaseConflictingDefinitionError(Error):
20
+ """Raised when a proto is added with the same name & different descriptor."""
21
+
22
+
23
+ class DescriptorDatabase(object):
24
+ """A container accepting FileDescriptorProtos and maps DescriptorProtos."""
25
+
26
+ def __init__(self) -> None:
27
+ self._file_desc_protos_by_file: Dict[
28
+ str, 'descriptor_pb2.FileDescriptorProto'
29
+ ] = {}
30
+ self._file_desc_protos_by_symbol: Dict[
31
+ str, 'descriptor_pb2.FileDescriptorProto'
32
+ ] = {}
33
+
34
+ def Add(self, file_desc_proto: 'descriptor_pb2.FileDescriptorProto') -> None:
35
+ """Adds the FileDescriptorProto and its types to this database.
36
+
37
+ Args:
38
+ file_desc_proto: The FileDescriptorProto to add.
39
+
40
+ Raises:
41
+ DescriptorDatabaseConflictingDefinitionError: if an attempt is made to
42
+ add a proto with the same name but different definition than an
43
+ existing proto in the database.
44
+ """
45
+ proto_name = file_desc_proto.name
46
+ if proto_name not in self._file_desc_protos_by_file:
47
+ self._file_desc_protos_by_file[proto_name] = file_desc_proto
48
+ elif self._file_desc_protos_by_file[proto_name] != file_desc_proto:
49
+ raise DescriptorDatabaseConflictingDefinitionError(
50
+ '%s already added, but with different descriptor.' % proto_name
51
+ )
52
+ else:
53
+ return
54
+
55
+ # Add all the top-level descriptors to the index.
56
+ package = file_desc_proto.package
57
+ for message in file_desc_proto.message_type:
58
+ for name in _ExtractSymbols(message, package):
59
+ self._AddSymbol(name, file_desc_proto)
60
+ for enum in file_desc_proto.enum_type:
61
+ self._AddSymbol(
62
+ ('.'.join((package, enum.name)) if package else enum.name),
63
+ file_desc_proto,
64
+ )
65
+ for enum_value in enum.value:
66
+ self._file_desc_protos_by_symbol[
67
+ '.'.join((package, enum_value.name)) if package else enum_value.name
68
+ ] = file_desc_proto
69
+ for extension in file_desc_proto.extension:
70
+ self._AddSymbol(
71
+ ('.'.join((package, extension.name)) if package else extension.name),
72
+ file_desc_proto,
73
+ )
74
+ for service in file_desc_proto.service:
75
+ self._AddSymbol(
76
+ ('.'.join((package, service.name)) if package else service.name),
77
+ file_desc_proto,
78
+ )
79
+
80
+ def FindFileByName(self, name: str) -> 'descriptor_pb2.FileDescriptorProto':
81
+ """Finds the file descriptor proto by file name.
82
+
83
+ Typically the file name is a relative path ending to a .proto file. The
84
+ proto with the given name will have to have been added to this database
85
+ using the Add method or else an error will be raised.
86
+
87
+ Args:
88
+ name: The file name to find.
89
+
90
+ Returns:
91
+ The file descriptor proto matching the name.
92
+
93
+ Raises:
94
+ KeyError if no file by the given name was added.
95
+ """
96
+
97
+ return self._file_desc_protos_by_file[name]
98
+
99
+ def FindFileContainingSymbol(
100
+ self, symbol: str
101
+ ) -> 'descriptor_pb2.FileDescriptorProto':
102
+ """Finds the file descriptor proto containing the specified symbol.
103
+
104
+ The symbol should be a fully qualified name including the file descriptor's
105
+ package and any containing messages. Some examples:
106
+
107
+ 'some.package.name.Message'
108
+ 'some.package.name.Message.NestedEnum'
109
+ 'some.package.name.Message.some_field'
110
+
111
+ The file descriptor proto containing the specified symbol must be added to
112
+ this database using the Add method or else an error will be raised.
113
+
114
+ Args:
115
+ symbol: The fully qualified symbol name.
116
+
117
+ Returns:
118
+ The file descriptor proto containing the symbol.
119
+
120
+ Raises:
121
+ KeyError if no file contains the specified symbol.
122
+ """
123
+ symbol = symbol.lstrip('.')
124
+ try:
125
+ return self._file_desc_protos_by_symbol[symbol]
126
+ except KeyError:
127
+ # Fields, enum values, and nested extensions are not in
128
+ # _file_desc_protos_by_symbol. Try to find the top level
129
+ # descriptor. Non-existent nested symbol under a valid top level
130
+ # descriptor can also be found. The behavior is the same with
131
+ # protobuf C++.
132
+ top_level, _, _ = symbol.rpartition('.')
133
+ try:
134
+ return self._file_desc_protos_by_symbol[top_level]
135
+ except KeyError:
136
+ # Raise the original symbol as a KeyError for better diagnostics.
137
+ raise KeyError(symbol)
138
+
139
+ def FindFileContainingExtension(
140
+ self,
141
+ extendee_name: str,
142
+ extension_number: int, # pylint: disable=unused-argument
143
+ ) -> Optional['descriptor_pb2.FileDescriptorProto']:
144
+ # TODO: implement this API.
145
+ return None
146
+
147
+ def FindAllExtensionNumbers(self, extendee_name: str) -> list[int]: # pylint: disable=unused-argument
148
+ # TODO: implement this API.
149
+ return []
150
+
151
+ def _AddSymbol(
152
+ self, name: str, file_desc_proto: 'descriptor_pb2.FileDescriptorProto'
153
+ ) -> None:
154
+ if name in self._file_desc_protos_by_symbol:
155
+ warn_msg = (
156
+ 'Conflict register for file "'
157
+ + file_desc_proto.name
158
+ + '": '
159
+ + name
160
+ + ' is already defined in file "'
161
+ + self._file_desc_protos_by_symbol[name].name
162
+ + '"'
163
+ )
164
+ warnings.warn(warn_msg, RuntimeWarning)
165
+ self._file_desc_protos_by_symbol[name] = file_desc_proto
166
+
167
+
168
+ def _ExtractSymbols(
169
+ desc_proto: 'descriptor_pb2.DescriptorProto', package: str
170
+ ) -> Iterator[str]:
171
+ """Pulls out all the symbols from a descriptor proto.
172
+
173
+ Args:
174
+ desc_proto: The proto to extract symbols from.
175
+ package: The package containing the descriptor type.
176
+
177
+ Yields:
178
+ The fully qualified name found in the descriptor.
179
+ """
180
+ message_name = package + '.' + desc_proto.name if package else desc_proto.name
181
+ yield message_name
182
+ for nested_type in desc_proto.nested_type:
183
+ for symbol in _ExtractSymbols(nested_type, message_name):
184
+ yield symbol
185
+ for enum_type in desc_proto.enum_type:
186
+ yield '.'.join((message_name, enum_type.name))
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor_pb2.py ADDED
The diff for this file is too large to render. See raw diff
 
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/descriptor_pool.py ADDED
@@ -0,0 +1,1468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Provides DescriptorPool to use as a container for proto2 descriptors.
8
+
9
+ The DescriptorPool is used in conjection with a DescriptorDatabase to maintain
10
+ a collection of protocol buffer descriptors for use when dynamically creating
11
+ message types at runtime.
12
+
13
+ For most applications protocol buffers should be used via modules generated by
14
+ the protocol buffer compiler tool. This should only be used when the type of
15
+ protocol buffers used in an application or library cannot be predetermined.
16
+
17
+ Below is a straightforward example on how to use this class::
18
+
19
+ pool = DescriptorPool()
20
+ file_descriptor_protos = [ ... ]
21
+ for file_descriptor_proto in file_descriptor_protos:
22
+ pool.Add(file_descriptor_proto)
23
+ my_message_descriptor = pool.FindMessageTypeByName('some.package.MessageType')
24
+
25
+ The message descriptor can be used in conjunction with the message_factory
26
+ module in order to create a protocol buffer class that can be encoded and
27
+ decoded.
28
+
29
+ If you want to get a Python class for the specified proto, use the
30
+ helper functions inside google.protobuf.message_factory
31
+ directly instead of this class.
32
+ """
33
+
34
+ __author__ = 'matthewtoia@google.com (Matt Toia)'
35
+
36
+ import collections
37
+ import threading
38
+ import warnings
39
+
40
+ from google.protobuf import descriptor
41
+ from google.protobuf import descriptor_database
42
+ from google.protobuf import text_encoding
43
+ from google.protobuf.internal import python_edition_defaults
44
+ from google.protobuf.internal import python_message
45
+
46
+ _USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS # pylint: disable=protected-access
47
+
48
+
49
+ def _NormalizeFullyQualifiedName(name):
50
+ """Remove leading period from fully-qualified type name.
51
+
52
+ Due to b/13860351 in descriptor_database.py, types in the root namespace are
53
+ generated with a leading period. This function removes that prefix.
54
+
55
+ Args:
56
+ name (str): The fully-qualified symbol name.
57
+
58
+ Returns:
59
+ str: The normalized fully-qualified symbol name.
60
+ """
61
+ return name.lstrip('.')
62
+
63
+
64
+ def _OptionsOrNone(descriptor_proto):
65
+ """Returns the value of the field `options`, or None if it is not set."""
66
+ if descriptor_proto.HasField('options'):
67
+ return descriptor_proto.options
68
+ else:
69
+ return None
70
+
71
+
72
+ def _IsMessageSetExtension(field):
73
+ return (
74
+ field.is_extension
75
+ and field.containing_type.has_options
76
+ and field.containing_type.GetOptions().message_set_wire_format
77
+ and field.type == descriptor.FieldDescriptor.TYPE_MESSAGE
78
+ and not field.is_required
79
+ and not field.is_repeated
80
+ )
81
+
82
+
83
+ _edition_defaults_lock = threading.Lock()
84
+
85
+
86
+ class DescriptorPool(object):
87
+ """A collection of protobufs dynamically constructed by descriptor protos."""
88
+
89
+ if _USE_C_DESCRIPTORS:
90
+
91
+ def __new__(cls, descriptor_db=None):
92
+ # pylint: disable=protected-access
93
+ return descriptor._message.DescriptorPool(descriptor_db)
94
+
95
+ def __init__(
96
+ self, descriptor_db=None, use_deprecated_legacy_json_field_conflicts=False
97
+ ):
98
+ """Initializes a Pool of proto buffs.
99
+
100
+ The descriptor_db argument to the constructor is provided to allow
101
+ specialized file descriptor proto lookup code to be triggered on demand. An
102
+ example would be an implementation which will read and compile a file
103
+ specified in a call to FindFileByName() and not require the call to Add()
104
+ at all. Results from this database will be cached internally here as well.
105
+
106
+ Args:
107
+ descriptor_db: A secondary source of file descriptors.
108
+ use_deprecated_legacy_json_field_conflicts: Unused, for compatibility with
109
+ C++.
110
+ """
111
+
112
+ self._internal_db = descriptor_database.DescriptorDatabase()
113
+ self._descriptor_db = descriptor_db
114
+ self._descriptors = {}
115
+ self._enum_descriptors = {}
116
+ self._service_descriptors = {}
117
+ self._file_descriptors = {}
118
+ self._toplevel_extensions = {}
119
+ self._top_enum_values = {}
120
+ # We store extensions in two two-level mappings: The first key is the
121
+ # descriptor of the message being extended, the second key is the extension
122
+ # full name or its tag number.
123
+ self._extensions_by_name = collections.defaultdict(dict)
124
+ self._extensions_by_number = collections.defaultdict(dict)
125
+ self._serialized_edition_defaults = (
126
+ python_edition_defaults._PROTOBUF_INTERNAL_PYTHON_EDITION_DEFAULTS
127
+ )
128
+ self._edition_defaults = None
129
+ self._feature_cache = dict()
130
+
131
+ def _CheckConflictRegister(self, desc, desc_name, file_name):
132
+ """Check if the descriptor name conflicts with another of the same name.
133
+
134
+ Args:
135
+ desc: Descriptor of a message, enum, service, extension or enum value.
136
+ desc_name (str): the full name of desc.
137
+ file_name (str): The file name of descriptor.
138
+ """
139
+ for register, descriptor_type in [
140
+ (self._descriptors, descriptor.Descriptor),
141
+ (self._enum_descriptors, descriptor.EnumDescriptor),
142
+ (self._service_descriptors, descriptor.ServiceDescriptor),
143
+ (self._toplevel_extensions, descriptor.FieldDescriptor),
144
+ (self._top_enum_values, descriptor.EnumValueDescriptor),
145
+ ]:
146
+ if desc_name in register:
147
+ old_desc = register[desc_name]
148
+ if isinstance(old_desc, descriptor.EnumValueDescriptor):
149
+ old_file = old_desc.type.file.name
150
+ else:
151
+ old_file = old_desc.file.name
152
+
153
+ if not isinstance(desc, descriptor_type) or (old_file != file_name):
154
+ error_msg = (
155
+ 'Conflict register for file "'
156
+ + file_name
157
+ + '": '
158
+ + desc_name
159
+ + ' is already defined in file "'
160
+ + old_file
161
+ + '". Please fix the conflict by adding '
162
+ 'package name on the proto file, or use different '
163
+ 'name for the duplication.'
164
+ )
165
+ if isinstance(desc, descriptor.EnumValueDescriptor):
166
+ error_msg += (
167
+ '\nNote: enum values appear as '
168
+ 'siblings of the enum type instead of '
169
+ 'children of it.'
170
+ )
171
+
172
+ raise TypeError(error_msg)
173
+
174
+ return
175
+
176
+ def Add(self, file_desc_proto):
177
+ """Adds the FileDescriptorProto and its types to this pool.
178
+
179
+ Args:
180
+ file_desc_proto (FileDescriptorProto): The file descriptor to add.
181
+ """
182
+
183
+ self._internal_db.Add(file_desc_proto)
184
+
185
+ def AddSerializedFile(self, serialized_file_desc_proto):
186
+ """Adds the FileDescriptorProto and its types to this pool.
187
+
188
+ Args:
189
+ serialized_file_desc_proto (bytes): A bytes string, serialization of the
190
+ :class:`FileDescriptorProto` to add.
191
+
192
+ Returns:
193
+ FileDescriptor: Descriptor for the added file.
194
+ """
195
+
196
+ # pylint: disable=g-import-not-at-top
197
+ from google.protobuf import descriptor_pb2
198
+
199
+ file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString(
200
+ serialized_file_desc_proto
201
+ )
202
+ file_desc = self._ConvertFileProtoToFileDescriptor(file_desc_proto)
203
+ file_desc.serialized_pb = serialized_file_desc_proto
204
+ return file_desc
205
+
206
+ # Never call this method. It is for internal usage only.
207
+ def _AddDescriptor(self, desc):
208
+ """Adds a Descriptor to the pool, non-recursively.
209
+
210
+ If the Descriptor contains nested messages or enums, the caller must
211
+ explicitly register them. This method also registers the FileDescriptor
212
+ associated with the message.
213
+
214
+ Args:
215
+ desc: A Descriptor.
216
+ """
217
+ if not isinstance(desc, descriptor.Descriptor):
218
+ raise TypeError('Expected instance of descriptor.Descriptor.')
219
+
220
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
221
+
222
+ self._descriptors[desc.full_name] = desc
223
+ self._AddFileDescriptor(desc.file)
224
+
225
+ # Never call this method. It is for internal usage only.
226
+ def _AddEnumDescriptor(self, enum_desc):
227
+ """Adds an EnumDescriptor to the pool.
228
+
229
+ This method also registers the FileDescriptor associated with the enum.
230
+
231
+ Args:
232
+ enum_desc: An EnumDescriptor.
233
+ """
234
+
235
+ if not isinstance(enum_desc, descriptor.EnumDescriptor):
236
+ raise TypeError('Expected instance of descriptor.EnumDescriptor.')
237
+
238
+ file_name = enum_desc.file.name
239
+ self._CheckConflictRegister(enum_desc, enum_desc.full_name, file_name)
240
+ self._enum_descriptors[enum_desc.full_name] = enum_desc
241
+
242
+ # Top enum values need to be indexed.
243
+ # Count the number of dots to see whether the enum is toplevel or nested
244
+ # in a message. We cannot use enum_desc.containing_type at this stage.
245
+ if enum_desc.file.package:
246
+ top_level = (
247
+ enum_desc.full_name.count('.') - enum_desc.file.package.count('.')
248
+ == 1
249
+ )
250
+ else:
251
+ top_level = enum_desc.full_name.count('.') == 0
252
+ if top_level:
253
+ file_name = enum_desc.file.name
254
+ package = enum_desc.file.package
255
+ for enum_value in enum_desc.values:
256
+ full_name = _NormalizeFullyQualifiedName(
257
+ '.'.join((package, enum_value.name))
258
+ )
259
+ self._CheckConflictRegister(enum_value, full_name, file_name)
260
+ self._top_enum_values[full_name] = enum_value
261
+ self._AddFileDescriptor(enum_desc.file)
262
+
263
+ # Never call this method. It is for internal usage only.
264
+ def _AddServiceDescriptor(self, service_desc):
265
+ """Adds a ServiceDescriptor to the pool.
266
+
267
+ Args:
268
+ service_desc: A ServiceDescriptor.
269
+ """
270
+
271
+ if not isinstance(service_desc, descriptor.ServiceDescriptor):
272
+ raise TypeError('Expected instance of descriptor.ServiceDescriptor.')
273
+
274
+ self._CheckConflictRegister(
275
+ service_desc, service_desc.full_name, service_desc.file.name
276
+ )
277
+ self._service_descriptors[service_desc.full_name] = service_desc
278
+
279
+ # Never call this method. It is for internal usage only.
280
+ def _AddExtensionDescriptor(self, extension):
281
+ """Adds a FieldDescriptor describing an extension to the pool.
282
+
283
+ Args:
284
+ extension: A FieldDescriptor.
285
+
286
+ Raises:
287
+ AssertionError: when another extension with the same number extends the
288
+ same message.
289
+ TypeError: when the specified extension is not a
290
+ descriptor.FieldDescriptor.
291
+ """
292
+ if not (
293
+ isinstance(extension, descriptor.FieldDescriptor)
294
+ and extension.is_extension
295
+ ):
296
+ raise TypeError('Expected an extension descriptor.')
297
+
298
+ if extension.extension_scope is None:
299
+ self._CheckConflictRegister(
300
+ extension, extension.full_name, extension.file.name
301
+ )
302
+ self._toplevel_extensions[extension.full_name] = extension
303
+
304
+ try:
305
+ existing_desc = self._extensions_by_number[extension.containing_type][
306
+ extension.number
307
+ ]
308
+ except KeyError:
309
+ pass
310
+ else:
311
+ if extension is not existing_desc:
312
+ raise AssertionError(
313
+ 'Extensions "%s" and "%s" both try to extend message type "%s" '
314
+ 'with field number %d.'
315
+ % (
316
+ extension.full_name,
317
+ existing_desc.full_name,
318
+ extension.containing_type.full_name,
319
+ extension.number,
320
+ )
321
+ )
322
+
323
+ self._extensions_by_number[extension.containing_type][
324
+ extension.number
325
+ ] = extension
326
+ self._extensions_by_name[extension.containing_type][
327
+ extension.full_name
328
+ ] = extension
329
+
330
+ # Also register MessageSet extensions with the type name.
331
+ if _IsMessageSetExtension(extension):
332
+ self._extensions_by_name[extension.containing_type][
333
+ extension.message_type.full_name
334
+ ] = extension
335
+
336
+ if hasattr(extension.containing_type, '_concrete_class'):
337
+ python_message._AttachFieldHelpers(
338
+ extension.containing_type._concrete_class, extension
339
+ )
340
+
341
+ # Never call this method. It is for internal usage only.
342
+ def _InternalAddFileDescriptor(self, file_desc):
343
+ """Adds a FileDescriptor to the pool, non-recursively.
344
+
345
+ If the FileDescriptor contains messages or enums, the caller must explicitly
346
+ register them.
347
+
348
+ Args:
349
+ file_desc: A FileDescriptor.
350
+ """
351
+
352
+ self._AddFileDescriptor(file_desc)
353
+
354
+ def _AddFileDescriptor(self, file_desc):
355
+ """Adds a FileDescriptor to the pool, non-recursively.
356
+
357
+ If the FileDescriptor contains messages or enums, the caller must explicitly
358
+ register them.
359
+
360
+ Args:
361
+ file_desc: A FileDescriptor.
362
+ """
363
+
364
+ if not isinstance(file_desc, descriptor.FileDescriptor):
365
+ raise TypeError('Expected instance of descriptor.FileDescriptor.')
366
+ self._file_descriptors[file_desc.name] = file_desc
367
+
368
+ def FindFileByName(self, file_name):
369
+ """Gets a FileDescriptor by file name.
370
+
371
+ Args:
372
+ file_name (str): The path to the file to get a descriptor for.
373
+
374
+ Returns:
375
+ FileDescriptor: The descriptor for the named file.
376
+
377
+ Raises:
378
+ KeyError: if the file cannot be found in the pool.
379
+ """
380
+
381
+ try:
382
+ return self._file_descriptors[file_name]
383
+ except KeyError:
384
+ pass
385
+
386
+ try:
387
+ file_proto = self._internal_db.FindFileByName(file_name)
388
+ except KeyError as error:
389
+ if self._descriptor_db:
390
+ file_proto = self._descriptor_db.FindFileByName(file_name)
391
+ else:
392
+ raise error
393
+ if not file_proto:
394
+ raise KeyError('Cannot find a file named %s' % file_name)
395
+ return self._ConvertFileProtoToFileDescriptor(file_proto)
396
+
397
+ def FindFileContainingSymbol(self, symbol):
398
+ """Gets the FileDescriptor for the file containing the specified symbol.
399
+
400
+ Args:
401
+ symbol (str): The name of the symbol to search for.
402
+
403
+ Returns:
404
+ FileDescriptor: Descriptor for the file that contains the specified
405
+ symbol.
406
+
407
+ Raises:
408
+ KeyError: if the file cannot be found in the pool.
409
+ """
410
+
411
+ symbol = _NormalizeFullyQualifiedName(symbol)
412
+ try:
413
+ return self._InternalFindFileContainingSymbol(symbol)
414
+ except KeyError:
415
+ pass
416
+
417
+ try:
418
+ # Try fallback database. Build and find again if possible.
419
+ self._FindFileContainingSymbolInDb(symbol)
420
+ return self._InternalFindFileContainingSymbol(symbol)
421
+ except KeyError:
422
+ raise KeyError('Cannot find a file containing %s' % symbol)
423
+
424
+ def _InternalFindFileContainingSymbol(self, symbol):
425
+ """Gets the already built FileDescriptor containing the specified symbol.
426
+
427
+ Args:
428
+ symbol (str): The name of the symbol to search for.
429
+
430
+ Returns:
431
+ FileDescriptor: Descriptor for the file that contains the specified
432
+ symbol.
433
+
434
+ Raises:
435
+ KeyError: if the file cannot be found in the pool.
436
+ """
437
+ try:
438
+ return self._descriptors[symbol].file
439
+ except KeyError:
440
+ pass
441
+
442
+ try:
443
+ return self._enum_descriptors[symbol].file
444
+ except KeyError:
445
+ pass
446
+
447
+ try:
448
+ return self._service_descriptors[symbol].file
449
+ except KeyError:
450
+ pass
451
+
452
+ try:
453
+ return self._top_enum_values[symbol].type.file
454
+ except KeyError:
455
+ pass
456
+
457
+ try:
458
+ return self._toplevel_extensions[symbol].file
459
+ except KeyError:
460
+ pass
461
+
462
+ # Try fields, enum values and nested extensions inside a message.
463
+ top_name, _, sub_name = symbol.rpartition('.')
464
+ try:
465
+ message = self.FindMessageTypeByName(top_name)
466
+ assert (
467
+ sub_name in message.extensions_by_name
468
+ or sub_name in message.fields_by_name
469
+ or sub_name in message.enum_values_by_name
470
+ )
471
+ return message.file
472
+ except (KeyError, AssertionError):
473
+ raise KeyError('Cannot find a file containing %s' % symbol)
474
+
475
+ def FindMessageTypeByName(self, full_name):
476
+ """Loads the named descriptor from the pool.
477
+
478
+ Args:
479
+ full_name (str): The full name of the descriptor to load.
480
+
481
+ Returns:
482
+ Descriptor: The descriptor for the named type.
483
+
484
+ Raises:
485
+ KeyError: if the message cannot be found in the pool.
486
+ """
487
+
488
+ full_name = _NormalizeFullyQualifiedName(full_name)
489
+ if full_name not in self._descriptors:
490
+ self._FindFileContainingSymbolInDb(full_name)
491
+ return self._descriptors[full_name]
492
+
493
+ def FindEnumTypeByName(self, full_name):
494
+ """Loads the named enum descriptor from the pool.
495
+
496
+ Args:
497
+ full_name (str): The full name of the enum descriptor to load.
498
+
499
+ Returns:
500
+ EnumDescriptor: The enum descriptor for the named type.
501
+
502
+ Raises:
503
+ KeyError: if the enum cannot be found in the pool.
504
+ """
505
+
506
+ full_name = _NormalizeFullyQualifiedName(full_name)
507
+ if full_name not in self._enum_descriptors:
508
+ self._FindFileContainingSymbolInDb(full_name)
509
+ return self._enum_descriptors[full_name]
510
+
511
+ def FindFieldByName(self, full_name):
512
+ """Loads the named field descriptor from the pool.
513
+
514
+ Args:
515
+ full_name (str): The full name of the field descriptor to load.
516
+
517
+ Returns:
518
+ FieldDescriptor: The field descriptor for the named field.
519
+
520
+ Raises:
521
+ KeyError: if the field cannot be found in the pool.
522
+ """
523
+ full_name = _NormalizeFullyQualifiedName(full_name)
524
+ message_name, _, field_name = full_name.rpartition('.')
525
+ message_descriptor = self.FindMessageTypeByName(message_name)
526
+ return message_descriptor.fields_by_name[field_name]
527
+
528
+ def FindOneofByName(self, full_name):
529
+ """Loads the named oneof descriptor from the pool.
530
+
531
+ Args:
532
+ full_name (str): The full name of the oneof descriptor to load.
533
+
534
+ Returns:
535
+ OneofDescriptor: The oneof descriptor for the named oneof.
536
+
537
+ Raises:
538
+ KeyError: if the oneof cannot be found in the pool.
539
+ """
540
+ full_name = _NormalizeFullyQualifiedName(full_name)
541
+ message_name, _, oneof_name = full_name.rpartition('.')
542
+ message_descriptor = self.FindMessageTypeByName(message_name)
543
+ return message_descriptor.oneofs_by_name[oneof_name]
544
+
545
+ def FindExtensionByName(self, full_name):
546
+ """Loads the named extension descriptor from the pool.
547
+
548
+ Args:
549
+ full_name (str): The full name of the extension descriptor to load.
550
+
551
+ Returns:
552
+ FieldDescriptor: The field descriptor for the named extension.
553
+
554
+ Raises:
555
+ KeyError: if the extension cannot be found in the pool.
556
+ """
557
+ full_name = _NormalizeFullyQualifiedName(full_name)
558
+ try:
559
+ # The proto compiler does not give any link between the FileDescriptor
560
+ # and top-level extensions unless the FileDescriptorProto is added to
561
+ # the DescriptorDatabase, but this can impact memory usage.
562
+ # So we registered these extensions by name explicitly.
563
+ return self._toplevel_extensions[full_name]
564
+ except KeyError:
565
+ pass
566
+ message_name, _, extension_name = full_name.rpartition('.')
567
+ try:
568
+ # Most extensions are nested inside a message.
569
+ scope = self.FindMessageTypeByName(message_name)
570
+ except KeyError:
571
+ # Some extensions are defined at file scope.
572
+ scope = self._FindFileContainingSymbolInDb(full_name)
573
+ return scope.extensions_by_name[extension_name]
574
+
575
+ def FindExtensionByNumber(self, message_descriptor, number):
576
+ """Gets the extension of the specified message with the specified number.
577
+
578
+ Extensions have to be registered to this pool by calling :func:`Add` or
579
+ :func:`AddExtensionDescriptor`.
580
+
581
+ Args:
582
+ message_descriptor (Descriptor): descriptor of the extended message.
583
+ number (int): Number of the extension field.
584
+
585
+ Returns:
586
+ FieldDescriptor: The descriptor for the extension.
587
+
588
+ Raises:
589
+ KeyError: when no extension with the given number is known for the
590
+ specified message.
591
+ """
592
+ try:
593
+ return self._extensions_by_number[message_descriptor][number]
594
+ except KeyError:
595
+ self._TryLoadExtensionFromDB(message_descriptor, number)
596
+ return self._extensions_by_number[message_descriptor][number]
597
+
598
+ def FindAllExtensions(self, message_descriptor):
599
+ """Gets all the known extensions of a given message.
600
+
601
+ Extensions have to be registered to this pool by build related
602
+ :func:`Add` or :func:`AddExtensionDescriptor`.
603
+
604
+ Args:
605
+ message_descriptor (Descriptor): Descriptor of the extended message.
606
+
607
+ Returns:
608
+ list[FieldDescriptor]: Field descriptors describing the extensions.
609
+ """
610
+ # Fallback to descriptor db if FindAllExtensionNumbers is provided.
611
+ if self._descriptor_db and hasattr(
612
+ self._descriptor_db, 'FindAllExtensionNumbers'
613
+ ):
614
+ full_name = message_descriptor.full_name
615
+ try:
616
+ all_numbers = self._descriptor_db.FindAllExtensionNumbers(full_name)
617
+ except:
618
+ pass
619
+ else:
620
+ if isinstance(all_numbers, list):
621
+ for number in all_numbers:
622
+ if number in self._extensions_by_number[message_descriptor]:
623
+ continue
624
+ self._TryLoadExtensionFromDB(message_descriptor, number)
625
+ else:
626
+ warnings.warn(
627
+ 'FindAllExtensionNumbers() on fall back DB must return a list,'
628
+ ' not {0}'.format(type(all_numbers))
629
+ )
630
+
631
+ return list(self._extensions_by_number[message_descriptor].values())
632
+
633
+ def _TryLoadExtensionFromDB(self, message_descriptor, number):
634
+ """Try to Load extensions from descriptor db.
635
+
636
+ Args:
637
+ message_descriptor: descriptor of the extended message.
638
+ number: the extension number that needs to be loaded.
639
+ """
640
+ if not self._descriptor_db:
641
+ return
642
+ # Only supported when FindFileContainingExtension is provided.
643
+ if not hasattr(self._descriptor_db, 'FindFileContainingExtension'):
644
+ return
645
+
646
+ full_name = message_descriptor.full_name
647
+ file_proto = None
648
+ try:
649
+ file_proto = self._descriptor_db.FindFileContainingExtension(
650
+ full_name, number
651
+ )
652
+ except:
653
+ return
654
+
655
+ if file_proto is None:
656
+ return
657
+
658
+ try:
659
+ self._ConvertFileProtoToFileDescriptor(file_proto)
660
+ except:
661
+ warn_msg = 'Unable to load proto file %s for extension number %d.' % (
662
+ file_proto.name,
663
+ number,
664
+ )
665
+ warnings.warn(warn_msg, RuntimeWarning)
666
+
667
+ def FindServiceByName(self, full_name):
668
+ """Loads the named service descriptor from the pool.
669
+
670
+ Args:
671
+ full_name (str): The full name of the service descriptor to load.
672
+
673
+ Returns:
674
+ ServiceDescriptor: The service descriptor for the named service.
675
+
676
+ Raises:
677
+ KeyError: if the service cannot be found in the pool.
678
+ """
679
+ full_name = _NormalizeFullyQualifiedName(full_name)
680
+ if full_name not in self._service_descriptors:
681
+ self._FindFileContainingSymbolInDb(full_name)
682
+ return self._service_descriptors[full_name]
683
+
684
+ def FindMethodByName(self, full_name):
685
+ """Loads the named service method descriptor from the pool.
686
+
687
+ Args:
688
+ full_name (str): The full name of the method descriptor to load.
689
+
690
+ Returns:
691
+ MethodDescriptor: The method descriptor for the service method.
692
+
693
+ Raises:
694
+ KeyError: if the method cannot be found in the pool.
695
+ """
696
+ full_name = _NormalizeFullyQualifiedName(full_name)
697
+ service_name, _, method_name = full_name.rpartition('.')
698
+ service_descriptor = self.FindServiceByName(service_name)
699
+ return service_descriptor.methods_by_name[method_name]
700
+
701
+ def SetFeatureSetDefaults(self, defaults):
702
+ """Sets the default feature mappings used during the build.
703
+
704
+ Args:
705
+ defaults: a FeatureSetDefaults message containing the new mappings.
706
+ """
707
+ if self._edition_defaults is not None:
708
+ raise ValueError(
709
+ "Feature set defaults can't be changed once the pool has started"
710
+ ' building!'
711
+ )
712
+
713
+ # pylint: disable=g-import-not-at-top
714
+ from google.protobuf import descriptor_pb2
715
+
716
+ if not isinstance(defaults, descriptor_pb2.FeatureSetDefaults):
717
+ raise TypeError('SetFeatureSetDefaults called with invalid type')
718
+
719
+ if defaults.minimum_edition > defaults.maximum_edition:
720
+ raise ValueError(
721
+ 'Invalid edition range %s to %s'
722
+ % (
723
+ descriptor_pb2.Edition.Name(defaults.minimum_edition),
724
+ descriptor_pb2.Edition.Name(defaults.maximum_edition),
725
+ )
726
+ )
727
+
728
+ prev_edition = descriptor_pb2.Edition.EDITION_UNKNOWN
729
+ for d in defaults.defaults:
730
+ if d.edition == descriptor_pb2.Edition.EDITION_UNKNOWN:
731
+ raise ValueError('Invalid edition EDITION_UNKNOWN specified')
732
+ if prev_edition >= d.edition:
733
+ raise ValueError(
734
+ 'Feature set defaults are not strictly increasing. %s is greater'
735
+ ' than or equal to %s'
736
+ % (
737
+ descriptor_pb2.Edition.Name(prev_edition),
738
+ descriptor_pb2.Edition.Name(d.edition),
739
+ )
740
+ )
741
+ prev_edition = d.edition
742
+ self._edition_defaults = defaults
743
+
744
+ def _CreateDefaultFeatures(self, edition):
745
+ """Creates a FeatureSet message with defaults for a specific edition.
746
+
747
+ Args:
748
+ edition: the edition to generate defaults for.
749
+
750
+ Returns:
751
+ A FeatureSet message with defaults for a specific edition.
752
+ """
753
+ # pylint: disable=g-import-not-at-top
754
+ from google.protobuf import descriptor_pb2
755
+
756
+ with _edition_defaults_lock:
757
+ if not self._edition_defaults:
758
+ self._edition_defaults = descriptor_pb2.FeatureSetDefaults()
759
+ self._edition_defaults.ParseFromString(
760
+ self._serialized_edition_defaults
761
+ )
762
+
763
+ if edition < self._edition_defaults.minimum_edition:
764
+ raise TypeError(
765
+ 'Edition %s is earlier than the minimum supported edition %s!'
766
+ % (
767
+ descriptor_pb2.Edition.Name(edition),
768
+ descriptor_pb2.Edition.Name(
769
+ self._edition_defaults.minimum_edition
770
+ ),
771
+ )
772
+ )
773
+ if (
774
+ edition > self._edition_defaults.maximum_edition
775
+ and edition != descriptor_pb2.EDITION_UNSTABLE
776
+ ):
777
+ raise TypeError(
778
+ 'Edition %s is later than the maximum supported edition %s!'
779
+ % (
780
+ descriptor_pb2.Edition.Name(edition),
781
+ descriptor_pb2.Edition.Name(
782
+ self._edition_defaults.maximum_edition
783
+ ),
784
+ )
785
+ )
786
+ found = None
787
+ for d in self._edition_defaults.defaults:
788
+ if d.edition > edition:
789
+ break
790
+ found = d
791
+ if found is None:
792
+ raise TypeError(
793
+ 'No valid default found for edition %s!'
794
+ % descriptor_pb2.Edition.Name(edition)
795
+ )
796
+
797
+ defaults = descriptor_pb2.FeatureSet()
798
+ defaults.CopyFrom(found.fixed_features)
799
+ defaults.MergeFrom(found.overridable_features)
800
+ return defaults
801
+
802
+ def _InternFeatures(self, features):
803
+ serialized = features.SerializeToString()
804
+ with _edition_defaults_lock:
805
+ cached = self._feature_cache.get(serialized)
806
+ if cached is None:
807
+ self._feature_cache[serialized] = features
808
+ cached = features
809
+ return cached
810
+
811
+ def _FindFileContainingSymbolInDb(self, symbol):
812
+ """Finds the file in descriptor DB containing the specified symbol.
813
+
814
+ Args:
815
+ symbol (str): The name of the symbol to search for.
816
+
817
+ Returns:
818
+ FileDescriptor: The file that contains the specified symbol.
819
+
820
+ Raises:
821
+ KeyError: if the file cannot be found in the descriptor database.
822
+ """
823
+ try:
824
+ file_proto = self._internal_db.FindFileContainingSymbol(symbol)
825
+ except KeyError as error:
826
+ if self._descriptor_db:
827
+ file_proto = self._descriptor_db.FindFileContainingSymbol(symbol)
828
+ else:
829
+ raise error
830
+ if not file_proto:
831
+ raise KeyError('Cannot find a file containing %s' % symbol)
832
+ return self._ConvertFileProtoToFileDescriptor(file_proto)
833
+
834
+ def _ConvertFileProtoToFileDescriptor(self, file_proto):
835
+ """Creates a FileDescriptor from a proto or returns a cached copy.
836
+
837
+ This method also has the side effect of loading all the symbols found in
838
+ the file into the appropriate dictionaries in the pool.
839
+
840
+ Args:
841
+ file_proto: The proto to convert.
842
+
843
+ Returns:
844
+ A FileDescriptor matching the passed in proto.
845
+ """
846
+ if file_proto.name not in self._file_descriptors:
847
+ built_deps = list(self._GetDeps(file_proto.dependency))
848
+ direct_deps = [self.FindFileByName(n) for n in file_proto.dependency]
849
+ public_deps = [direct_deps[i] for i in file_proto.public_dependency]
850
+
851
+ # pylint: disable=g-import-not-at-top
852
+ from google.protobuf import descriptor_pb2
853
+
854
+ file_descriptor = descriptor.FileDescriptor(
855
+ pool=self,
856
+ name=file_proto.name,
857
+ package=file_proto.package,
858
+ syntax=file_proto.syntax,
859
+ edition=descriptor_pb2.Edition.Name(file_proto.edition),
860
+ options=_OptionsOrNone(file_proto),
861
+ serialized_pb=file_proto.SerializeToString(),
862
+ dependencies=direct_deps,
863
+ public_dependencies=public_deps,
864
+ # pylint: disable=protected-access
865
+ create_key=descriptor._internal_create_key,
866
+ )
867
+ scope = {}
868
+
869
+ # This loop extracts all the message and enum types from all the
870
+ # dependencies of the file_proto. This is necessary to create the
871
+ # scope of available message types when defining the passed in
872
+ # file proto.
873
+ for dependency in built_deps:
874
+ scope.update(
875
+ self._ExtractSymbols(dependency.message_types_by_name.values())
876
+ )
877
+ scope.update(
878
+ (_PrefixWithDot(enum.full_name), enum)
879
+ for enum in dependency.enum_types_by_name.values()
880
+ )
881
+
882
+ for message_type in file_proto.message_type:
883
+ message_desc = self._ConvertMessageDescriptor(
884
+ message_type,
885
+ file_proto.package,
886
+ file_descriptor,
887
+ scope,
888
+ file_proto.syntax,
889
+ )
890
+ file_descriptor.message_types_by_name[message_desc.name] = message_desc
891
+
892
+ for enum_type in file_proto.enum_type:
893
+ file_descriptor.enum_types_by_name[enum_type.name] = (
894
+ self._ConvertEnumDescriptor(
895
+ enum_type,
896
+ file_proto.package,
897
+ file_descriptor,
898
+ None,
899
+ scope,
900
+ True,
901
+ )
902
+ )
903
+
904
+ for index, extension_proto in enumerate(file_proto.extension):
905
+ extension_desc = self._MakeFieldDescriptor(
906
+ extension_proto,
907
+ file_proto.package,
908
+ index,
909
+ file_descriptor,
910
+ is_extension=True,
911
+ )
912
+ extension_desc.containing_type = self._GetTypeFromScope(
913
+ file_descriptor.package, extension_proto.extendee, scope
914
+ )
915
+ self._SetFieldType(
916
+ extension_proto, extension_desc, file_descriptor.package, scope
917
+ )
918
+ file_descriptor.extensions_by_name[extension_desc.name] = extension_desc
919
+
920
+ for desc_proto in file_proto.message_type:
921
+ self._SetAllFieldTypes(file_proto.package, desc_proto, scope)
922
+
923
+ if file_proto.package:
924
+ desc_proto_prefix = _PrefixWithDot(file_proto.package)
925
+ else:
926
+ desc_proto_prefix = ''
927
+
928
+ for desc_proto in file_proto.message_type:
929
+ desc = self._GetTypeFromScope(desc_proto_prefix, desc_proto.name, scope)
930
+ file_descriptor.message_types_by_name[desc_proto.name] = desc
931
+
932
+ for index, service_proto in enumerate(file_proto.service):
933
+ file_descriptor.services_by_name[service_proto.name] = (
934
+ self._MakeServiceDescriptor(
935
+ service_proto, index, scope, file_proto.package, file_descriptor
936
+ )
937
+ )
938
+
939
+ self._file_descriptors[file_proto.name] = file_descriptor
940
+
941
+ # Add extensions to the pool
942
+ def AddExtensionForNested(message_type):
943
+ for nested in message_type.nested_types:
944
+ AddExtensionForNested(nested)
945
+ for extension in message_type.extensions:
946
+ self._AddExtensionDescriptor(extension)
947
+
948
+ file_desc = self._file_descriptors[file_proto.name]
949
+ for extension in file_desc.extensions_by_name.values():
950
+ self._AddExtensionDescriptor(extension)
951
+ for message_type in file_desc.message_types_by_name.values():
952
+ AddExtensionForNested(message_type)
953
+
954
+ return file_desc
955
+
956
+ def _ConvertMessageDescriptor(
957
+ self, desc_proto, package=None, file_desc=None, scope=None, syntax=None
958
+ ):
959
+ """Adds the proto to the pool in the specified package.
960
+
961
+ Args:
962
+ desc_proto: The descriptor_pb2.DescriptorProto protobuf message.
963
+ package: The package the proto should be located in.
964
+ file_desc: The file containing this message.
965
+ scope: Dict mapping short and full symbols to message and enum types.
966
+ syntax: string indicating syntax of the file ("proto2" or "proto3")
967
+
968
+ Returns:
969
+ The added descriptor.
970
+ """
971
+
972
+ if package:
973
+ desc_name = '.'.join((package, desc_proto.name))
974
+ else:
975
+ desc_name = desc_proto.name
976
+
977
+ if file_desc is None:
978
+ file_name = None
979
+ else:
980
+ file_name = file_desc.name
981
+
982
+ if scope is None:
983
+ scope = {}
984
+
985
+ nested = [
986
+ self._ConvertMessageDescriptor(
987
+ nested, desc_name, file_desc, scope, syntax
988
+ )
989
+ for nested in desc_proto.nested_type
990
+ ]
991
+ enums = [
992
+ self._ConvertEnumDescriptor(
993
+ enum, desc_name, file_desc, None, scope, False
994
+ )
995
+ for enum in desc_proto.enum_type
996
+ ]
997
+ fields = [
998
+ self._MakeFieldDescriptor(field, desc_name, index, file_desc)
999
+ for index, field in enumerate(desc_proto.field)
1000
+ ]
1001
+ extensions = [
1002
+ self._MakeFieldDescriptor(
1003
+ extension, desc_name, index, file_desc, is_extension=True
1004
+ )
1005
+ for index, extension in enumerate(desc_proto.extension)
1006
+ ]
1007
+ oneofs = [
1008
+ # pylint: disable=g-complex-comprehension
1009
+ descriptor.OneofDescriptor(
1010
+ desc.name,
1011
+ '.'.join((desc_name, desc.name)),
1012
+ index,
1013
+ None,
1014
+ [],
1015
+ _OptionsOrNone(desc),
1016
+ # pylint: disable=protected-access
1017
+ create_key=descriptor._internal_create_key,
1018
+ )
1019
+ for index, desc in enumerate(desc_proto.oneof_decl)
1020
+ ]
1021
+ extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
1022
+ if extension_ranges:
1023
+ is_extendable = True
1024
+ else:
1025
+ is_extendable = False
1026
+ desc = descriptor.Descriptor(
1027
+ name=desc_proto.name,
1028
+ full_name=desc_name,
1029
+ filename=file_name,
1030
+ containing_type=None,
1031
+ fields=fields,
1032
+ oneofs=oneofs,
1033
+ nested_types=nested,
1034
+ enum_types=enums,
1035
+ extensions=extensions,
1036
+ options=_OptionsOrNone(desc_proto),
1037
+ is_extendable=is_extendable,
1038
+ extension_ranges=extension_ranges,
1039
+ file=file_desc,
1040
+ serialized_start=None,
1041
+ serialized_end=None,
1042
+ is_map_entry=desc_proto.options.map_entry,
1043
+ # pylint: disable=protected-access
1044
+ create_key=descriptor._internal_create_key,
1045
+ )
1046
+ for nested in desc.nested_types:
1047
+ nested.containing_type = desc
1048
+ for enum in desc.enum_types:
1049
+ enum.containing_type = desc
1050
+ for field_index, field_desc in enumerate(desc_proto.field):
1051
+ if field_desc.HasField('oneof_index'):
1052
+ oneof_index = field_desc.oneof_index
1053
+ oneofs[oneof_index].fields.append(fields[field_index])
1054
+ fields[field_index].containing_oneof = oneofs[oneof_index]
1055
+
1056
+ scope[_PrefixWithDot(desc_name)] = desc
1057
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
1058
+ self._descriptors[desc_name] = desc
1059
+ return desc
1060
+
1061
+ def _ConvertEnumDescriptor(
1062
+ self,
1063
+ enum_proto,
1064
+ package=None,
1065
+ file_desc=None,
1066
+ containing_type=None,
1067
+ scope=None,
1068
+ top_level=False,
1069
+ ):
1070
+ """Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.
1071
+
1072
+ Args:
1073
+ enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message.
1074
+ package: Optional package name for the new message EnumDescriptor.
1075
+ file_desc: The file containing the enum descriptor.
1076
+ containing_type: The type containing this enum.
1077
+ scope: Scope containing available types.
1078
+ top_level: If True, the enum is a top level symbol. If False, the enum is
1079
+ defined inside a message.
1080
+
1081
+ Returns:
1082
+ The added descriptor
1083
+ """
1084
+
1085
+ if package:
1086
+ enum_name = '.'.join((package, enum_proto.name))
1087
+ else:
1088
+ enum_name = enum_proto.name
1089
+
1090
+ if file_desc is None:
1091
+ file_name = None
1092
+ else:
1093
+ file_name = file_desc.name
1094
+
1095
+ values = [
1096
+ self._MakeEnumValueDescriptor(value, index)
1097
+ for index, value in enumerate(enum_proto.value)
1098
+ ]
1099
+ desc = descriptor.EnumDescriptor(
1100
+ name=enum_proto.name,
1101
+ full_name=enum_name,
1102
+ filename=file_name,
1103
+ file=file_desc,
1104
+ values=values,
1105
+ containing_type=containing_type,
1106
+ options=_OptionsOrNone(enum_proto),
1107
+ # pylint: disable=protected-access
1108
+ create_key=descriptor._internal_create_key,
1109
+ )
1110
+ scope['.%s' % enum_name] = desc
1111
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
1112
+ self._enum_descriptors[enum_name] = desc
1113
+
1114
+ # Add top level enum values.
1115
+ if top_level:
1116
+ for value in values:
1117
+ full_name = _NormalizeFullyQualifiedName(
1118
+ '.'.join((package, value.name))
1119
+ )
1120
+ self._CheckConflictRegister(value, full_name, file_name)
1121
+ self._top_enum_values[full_name] = value
1122
+
1123
+ return desc
1124
+
1125
+ def _MakeFieldDescriptor(
1126
+ self, field_proto, message_name, index, file_desc, is_extension=False
1127
+ ):
1128
+ """Creates a field descriptor from a FieldDescriptorProto.
1129
+
1130
+ For message and enum type fields, this method will do a look up
1131
+ in the pool for the appropriate descriptor for that type. If it
1132
+ is unavailable, it will fall back to the _source function to
1133
+ create it. If this type is still unavailable, construction will
1134
+ fail.
1135
+
1136
+ Args:
1137
+ field_proto: The proto describing the field.
1138
+ message_name: The name of the containing message.
1139
+ index: Index of the field
1140
+ file_desc: The file containing the field descriptor.
1141
+ is_extension: Indication that this field is for an extension.
1142
+
1143
+ Returns:
1144
+ An initialized FieldDescriptor object
1145
+ """
1146
+
1147
+ if message_name:
1148
+ full_name = '.'.join((message_name, field_proto.name))
1149
+ else:
1150
+ full_name = field_proto.name
1151
+
1152
+ if field_proto.json_name:
1153
+ json_name = field_proto.json_name
1154
+ else:
1155
+ json_name = None
1156
+
1157
+ return descriptor.FieldDescriptor(
1158
+ name=field_proto.name,
1159
+ full_name=full_name,
1160
+ index=index,
1161
+ number=field_proto.number,
1162
+ type=field_proto.type,
1163
+ cpp_type=None,
1164
+ message_type=None,
1165
+ enum_type=None,
1166
+ containing_type=None,
1167
+ label=field_proto.label,
1168
+ has_default_value=False,
1169
+ default_value=None,
1170
+ is_extension=is_extension,
1171
+ extension_scope=None,
1172
+ options=_OptionsOrNone(field_proto),
1173
+ json_name=json_name,
1174
+ file=file_desc,
1175
+ # pylint: disable=protected-access
1176
+ create_key=descriptor._internal_create_key,
1177
+ )
1178
+
1179
+ def _SetAllFieldTypes(self, package, desc_proto, scope):
1180
+ """Sets all the descriptor's fields's types.
1181
+
1182
+ This method also sets the containing types on any extensions.
1183
+
1184
+ Args:
1185
+ package: The current package of desc_proto.
1186
+ desc_proto: The message descriptor to update.
1187
+ scope: Enclosing scope of available types.
1188
+ """
1189
+
1190
+ package = _PrefixWithDot(package)
1191
+
1192
+ main_desc = self._GetTypeFromScope(package, desc_proto.name, scope)
1193
+
1194
+ if package == '.':
1195
+ nested_package = _PrefixWithDot(desc_proto.name)
1196
+ else:
1197
+ nested_package = '.'.join([package, desc_proto.name])
1198
+
1199
+ for field_proto, field_desc in zip(desc_proto.field, main_desc.fields):
1200
+ self._SetFieldType(field_proto, field_desc, nested_package, scope)
1201
+
1202
+ for extension_proto, extension_desc in zip(
1203
+ desc_proto.extension, main_desc.extensions
1204
+ ):
1205
+ extension_desc.containing_type = self._GetTypeFromScope(
1206
+ nested_package, extension_proto.extendee, scope
1207
+ )
1208
+ self._SetFieldType(extension_proto, extension_desc, nested_package, scope)
1209
+
1210
+ for nested_type in desc_proto.nested_type:
1211
+ self._SetAllFieldTypes(nested_package, nested_type, scope)
1212
+
1213
+ def _SetFieldType(self, field_proto, field_desc, package, scope):
1214
+ """Sets the field's type, cpp_type, message_type and enum_type.
1215
+
1216
+ Args:
1217
+ field_proto: Data about the field in proto format.
1218
+ field_desc: The descriptor to modify.
1219
+ package: The package the field's container is in.
1220
+ scope: Enclosing scope of available types.
1221
+ """
1222
+ if field_proto.type_name:
1223
+ desc = self._GetTypeFromScope(package, field_proto.type_name, scope)
1224
+ else:
1225
+ desc = None
1226
+
1227
+ if not field_proto.HasField('type'):
1228
+ if isinstance(desc, descriptor.Descriptor):
1229
+ field_proto.type = descriptor.FieldDescriptor.TYPE_MESSAGE
1230
+ else:
1231
+ field_proto.type = descriptor.FieldDescriptor.TYPE_ENUM
1232
+
1233
+ field_desc.cpp_type = descriptor.FieldDescriptor.ProtoTypeToCppProtoType(
1234
+ field_proto.type
1235
+ )
1236
+
1237
+ if (
1238
+ field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE
1239
+ or field_proto.type == descriptor.FieldDescriptor.TYPE_GROUP
1240
+ ):
1241
+ field_desc.message_type = desc
1242
+
1243
+ if field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:
1244
+ field_desc.enum_type = desc
1245
+
1246
+ if field_proto.label == descriptor.FieldDescriptor.LABEL_REPEATED:
1247
+ field_desc.has_default_value = False
1248
+ field_desc.default_value = []
1249
+ elif field_proto.HasField('default_value'):
1250
+ field_desc.has_default_value = True
1251
+ if (
1252
+ field_proto.type == descriptor.FieldDescriptor.TYPE_DOUBLE
1253
+ or field_proto.type == descriptor.FieldDescriptor.TYPE_FLOAT
1254
+ ):
1255
+ field_desc.default_value = float(field_proto.default_value)
1256
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_STRING:
1257
+ field_desc.default_value = field_proto.default_value
1258
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_BOOL:
1259
+ field_desc.default_value = field_proto.default_value.lower() == 'true'
1260
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:
1261
+ field_desc.default_value = field_desc.enum_type.values_by_name[
1262
+ field_proto.default_value
1263
+ ].number
1264
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:
1265
+ field_desc.default_value = text_encoding.CUnescape(
1266
+ field_proto.default_value
1267
+ )
1268
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
1269
+ field_desc.default_value = None
1270
+ else:
1271
+ # All other types are of the "int" type.
1272
+ field_desc.default_value = int(field_proto.default_value)
1273
+ else:
1274
+ field_desc.has_default_value = False
1275
+ if (
1276
+ field_proto.type == descriptor.FieldDescriptor.TYPE_DOUBLE
1277
+ or field_proto.type == descriptor.FieldDescriptor.TYPE_FLOAT
1278
+ ):
1279
+ field_desc.default_value = 0.0
1280
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_STRING:
1281
+ field_desc.default_value = ''
1282
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_BOOL:
1283
+ field_desc.default_value = False
1284
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:
1285
+ field_desc.default_value = field_desc.enum_type.values[0].number
1286
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:
1287
+ field_desc.default_value = b''
1288
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
1289
+ field_desc.default_value = None
1290
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_GROUP:
1291
+ field_desc.default_value = None
1292
+ else:
1293
+ # All other types are of the "int" type.
1294
+ field_desc.default_value = 0
1295
+
1296
+ field_desc.type = field_proto.type
1297
+
1298
+ def _MakeEnumValueDescriptor(self, value_proto, index):
1299
+ """Creates a enum value descriptor object from a enum value proto.
1300
+
1301
+ Args:
1302
+ value_proto: The proto describing the enum value.
1303
+ index: The index of the enum value.
1304
+
1305
+ Returns:
1306
+ An initialized EnumValueDescriptor object.
1307
+ """
1308
+
1309
+ return descriptor.EnumValueDescriptor(
1310
+ name=value_proto.name,
1311
+ index=index,
1312
+ number=value_proto.number,
1313
+ options=_OptionsOrNone(value_proto),
1314
+ type=None,
1315
+ # pylint: disable=protected-access
1316
+ create_key=descriptor._internal_create_key,
1317
+ )
1318
+
1319
+ def _MakeServiceDescriptor(
1320
+ self, service_proto, service_index, scope, package, file_desc
1321
+ ):
1322
+ """Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.
1323
+
1324
+ Args:
1325
+ service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
1326
+ service_index: The index of the service in the File.
1327
+ scope: Dict mapping short and full symbols to message and enum types.
1328
+ package: Optional package name for the new message EnumDescriptor.
1329
+ file_desc: The file containing the service descriptor.
1330
+
1331
+ Returns:
1332
+ The added descriptor.
1333
+ """
1334
+
1335
+ if package:
1336
+ service_name = '.'.join((package, service_proto.name))
1337
+ else:
1338
+ service_name = service_proto.name
1339
+
1340
+ methods = [
1341
+ self._MakeMethodDescriptor(
1342
+ method_proto, service_name, package, scope, index
1343
+ )
1344
+ for index, method_proto in enumerate(service_proto.method)
1345
+ ]
1346
+ desc = descriptor.ServiceDescriptor(
1347
+ name=service_proto.name,
1348
+ full_name=service_name,
1349
+ index=service_index,
1350
+ methods=methods,
1351
+ options=_OptionsOrNone(service_proto),
1352
+ file=file_desc,
1353
+ # pylint: disable=protected-access
1354
+ create_key=descriptor._internal_create_key,
1355
+ )
1356
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
1357
+ self._service_descriptors[service_name] = desc
1358
+ return desc
1359
+
1360
+ def _MakeMethodDescriptor(
1361
+ self, method_proto, service_name, package, scope, index
1362
+ ):
1363
+ """Creates a method descriptor from a MethodDescriptorProto.
1364
+
1365
+ Args:
1366
+ method_proto: The proto describing the method.
1367
+ service_name: The name of the containing service.
1368
+ package: Optional package name to look up for types.
1369
+ scope: Scope containing available types.
1370
+ index: Index of the method in the service.
1371
+
1372
+ Returns:
1373
+ An initialized MethodDescriptor object.
1374
+ """
1375
+ full_name = '.'.join((service_name, method_proto.name))
1376
+ input_type = self._GetTypeFromScope(package, method_proto.input_type, scope)
1377
+ output_type = self._GetTypeFromScope(
1378
+ package, method_proto.output_type, scope
1379
+ )
1380
+ return descriptor.MethodDescriptor(
1381
+ name=method_proto.name,
1382
+ full_name=full_name,
1383
+ index=index,
1384
+ containing_service=None,
1385
+ input_type=input_type,
1386
+ output_type=output_type,
1387
+ client_streaming=method_proto.client_streaming,
1388
+ server_streaming=method_proto.server_streaming,
1389
+ options=_OptionsOrNone(method_proto),
1390
+ # pylint: disable=protected-access
1391
+ create_key=descriptor._internal_create_key,
1392
+ )
1393
+
1394
+ def _ExtractSymbols(self, descriptors):
1395
+ """Pulls out all the symbols from descriptor protos.
1396
+
1397
+ Args:
1398
+ descriptors: The messages to extract descriptors from.
1399
+
1400
+ Yields:
1401
+ A two element tuple of the type name and descriptor object.
1402
+ """
1403
+
1404
+ for desc in descriptors:
1405
+ yield (_PrefixWithDot(desc.full_name), desc)
1406
+ for symbol in self._ExtractSymbols(desc.nested_types):
1407
+ yield symbol
1408
+ for enum in desc.enum_types:
1409
+ yield (_PrefixWithDot(enum.full_name), enum)
1410
+
1411
+ def _GetDeps(self, dependencies, visited=None):
1412
+ """Recursively finds dependencies for file protos.
1413
+
1414
+ Args:
1415
+ dependencies: The names of the files being depended on.
1416
+ visited: The names of files already found.
1417
+
1418
+ Yields:
1419
+ Each direct and indirect dependency.
1420
+ """
1421
+
1422
+ visited = visited or set()
1423
+ for dependency in dependencies:
1424
+ if dependency not in visited:
1425
+ visited.add(dependency)
1426
+ dep_desc = self.FindFileByName(dependency)
1427
+ yield dep_desc
1428
+ public_files = [d.name for d in dep_desc.public_dependencies]
1429
+ yield from self._GetDeps(public_files, visited)
1430
+
1431
+ def _GetTypeFromScope(self, package, type_name, scope):
1432
+ """Finds a given type name in the current scope.
1433
+
1434
+ Args:
1435
+ package: The package the proto should be located in.
1436
+ type_name: The name of the type to be found in the scope.
1437
+ scope: Dict mapping short and full symbols to message and enum types.
1438
+
1439
+ Returns:
1440
+ The descriptor for the requested type.
1441
+ """
1442
+ if type_name not in scope:
1443
+ components = _PrefixWithDot(package).split('.')
1444
+ while components:
1445
+ possible_match = '.'.join(components + [type_name])
1446
+ if possible_match in scope:
1447
+ type_name = possible_match
1448
+ break
1449
+ else:
1450
+ components.pop(-1)
1451
+ return scope[type_name]
1452
+
1453
+
1454
+ def _PrefixWithDot(name):
1455
+ return name if name.startswith('.') else '.%s' % name
1456
+
1457
+
1458
+ if _USE_C_DESCRIPTORS:
1459
+ # TODO: This pool could be constructed from Python code, when we
1460
+ # support a flag like 'use_cpp_generated_pool=True'.
1461
+ # pylint: disable=protected-access
1462
+ _DEFAULT = descriptor._message.default_pool
1463
+ else:
1464
+ _DEFAULT = DescriptorPool()
1465
+
1466
+
1467
+ def Default():
1468
+ return _DEFAULT
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/duration.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ """Contains the Duration helper APIs."""
9
+
10
+ import datetime
11
+
12
+ from google.protobuf.duration_pb2 import Duration
13
+
14
+
15
+ def from_json_string(value: str) -> Duration:
16
+ """Converts a string to Duration.
17
+
18
+ Args:
19
+ value: A string to be converted. The string must end with 's'. Any
20
+ fractional digits (or none) are accepted as long as they fit into
21
+ precision. For example: "1s", "1.01s", "1.0000001s", "-3.100s"
22
+
23
+ Raises:
24
+ ValueError: On parsing problems.
25
+ """
26
+ duration = Duration()
27
+ duration.FromJsonString(value)
28
+ return duration
29
+
30
+
31
+ def from_microseconds(micros: float) -> Duration:
32
+ """Converts microseconds to Duration."""
33
+ duration = Duration()
34
+ duration.FromMicroseconds(micros)
35
+ return duration
36
+
37
+
38
+ def from_milliseconds(millis: float) -> Duration:
39
+ """Converts milliseconds to Duration."""
40
+ duration = Duration()
41
+ duration.FromMilliseconds(millis)
42
+ return duration
43
+
44
+
45
+ def from_nanoseconds(nanos: float) -> Duration:
46
+ """Converts nanoseconds to Duration."""
47
+ duration = Duration()
48
+ duration.FromNanoseconds(nanos)
49
+ return duration
50
+
51
+
52
+ def from_seconds(seconds: float) -> Duration:
53
+ """Converts seconds to Duration."""
54
+ duration = Duration()
55
+ duration.FromSeconds(seconds)
56
+ return duration
57
+
58
+
59
+ def from_timedelta(td: datetime.timedelta) -> Duration:
60
+ """Converts timedelta to Duration."""
61
+ duration = Duration()
62
+ duration.FromTimedelta(td)
63
+ return duration
64
+
65
+
66
+ def to_json_string(duration: Duration) -> str:
67
+ """Converts Duration to string format.
68
+
69
+ Returns:
70
+ A string converted from self. The string format will contains
71
+ 3, 6, or 9 fractional digits depending on the precision required to
72
+ represent the exact Duration value. For example: "1s", "1.010s",
73
+ "1.000000100s", "-3.100s"
74
+ """
75
+ return duration.ToJsonString()
76
+
77
+
78
+ def to_microseconds(duration: Duration) -> int:
79
+ """Converts a Duration to microseconds."""
80
+ return duration.ToMicroseconds()
81
+
82
+
83
+ def to_milliseconds(duration: Duration) -> int:
84
+ """Converts a Duration to milliseconds."""
85
+ return duration.ToMilliseconds()
86
+
87
+
88
+ def to_nanoseconds(duration: Duration) -> int:
89
+ """Converts a Duration to nanoseconds."""
90
+ return duration.ToNanoseconds()
91
+
92
+
93
+ def to_seconds(duration: Duration) -> int:
94
+ """Converts a Duration to seconds."""
95
+ return duration.ToSeconds()
96
+
97
+
98
+ def to_timedelta(duration: Duration) -> datetime.timedelta:
99
+ """Converts Duration to timedelta."""
100
+ return duration.ToTimedelta()
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/duration_pb2.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/duration.proto
5
+ # Protobuf Python Version: 7.36.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 7,
15
+ 36,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/duration.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1egoogle/protobuf/duration.proto\x12\x0fgoogle.protobuf\":\n\x08\x44uration\x12\x18\n\x07seconds\x18\x01 \x01(\x03R\x07seconds\x12\x14\n\x05nanos\x18\x02 \x01(\x05R\x05nanosB\x83\x01\n\x13\x63om.google.protobufB\rDurationProtoP\x01Z1google.golang.org/protobuf/types/known/durationpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.duration_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\rDurationProtoP\001Z1google.golang.org/protobuf/types/known/durationpb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
35
+ _globals['_DURATION']._serialized_start=51
36
+ _globals['_DURATION']._serialized_end=109
37
+ # @@protoc_insertion_point(module_scope)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/empty_pb2.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/empty.proto
5
+ # Protobuf Python Version: 7.36.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 7,
15
+ 36,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/empty.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bgoogle/protobuf/empty.proto\x12\x0fgoogle.protobuf\"\x07\n\x05\x45mptyB}\n\x13\x63om.google.protobufB\nEmptyProtoP\x01Z.google.golang.org/protobuf/types/known/emptypb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.empty_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\nEmptyProtoP\001Z.google.golang.org/protobuf/types/known/emptypb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
35
+ _globals['_EMPTY']._serialized_start=48
36
+ _globals['_EMPTY']._serialized_end=55
37
+ # @@protoc_insertion_point(module_scope)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/field_mask_pb2.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/field_mask.proto
5
+ # Protobuf Python Version: 7.36.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 7,
15
+ 36,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/field_mask.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n google/protobuf/field_mask.proto\x12\x0fgoogle.protobuf\"!\n\tFieldMask\x12\x14\n\x05paths\x18\x01 \x03(\tR\x05pathsB\x85\x01\n\x13\x63om.google.protobufB\x0e\x46ieldMaskProtoP\x01Z2google.golang.org/protobuf/types/known/fieldmaskpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.field_mask_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\016FieldMaskProtoP\001Z2google.golang.org/protobuf/types/known/fieldmaskpb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
35
+ _globals['_FIELDMASK']._serialized_start=53
36
+ _globals['_FIELDMASK']._serialized_end=86
37
+ # @@protoc_insertion_point(module_scope)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/__init__.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/api_implementation.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Determine which implementation of the protobuf API is used in this process."""
8
+
9
+ import importlib
10
+ import os
11
+ import sys
12
+ import warnings
13
+
14
+ _GOOGLE3_PYTHON_UPB_DEFAULT = True
15
+
16
+
17
+ def _ApiVersionToImplementationType(api_version):
18
+ if api_version == 2:
19
+ return 'cpp'
20
+ if api_version == 1:
21
+ raise ValueError('api_version=1 is no longer supported.')
22
+ if api_version == 0:
23
+ return 'python'
24
+ return None
25
+
26
+
27
+ _implementation_type = None
28
+ try:
29
+ # pylint: disable=g-import-not-at-top
30
+ from google.protobuf.internal import _api_implementation
31
+ # The compile-time constants in the _api_implementation module can be used to
32
+ # switch to a certain implementation of the Python API at build time.
33
+ _implementation_type = _ApiVersionToImplementationType(
34
+ _api_implementation.api_version
35
+ )
36
+ except ImportError:
37
+ pass # Unspecified by compiler flags.
38
+
39
+
40
+ def _CanImport(mod_name):
41
+ try:
42
+ mod = importlib.import_module(mod_name)
43
+ # Work around a known issue in the classic bootstrap .par import hook.
44
+ if not mod:
45
+ raise ImportError(mod_name + ' import succeeded but was None')
46
+ return True
47
+ except ImportError:
48
+ return False
49
+
50
+
51
+ if _implementation_type is None:
52
+ if _CanImport('google._upb._message'):
53
+ _implementation_type = 'upb'
54
+ elif _CanImport('google.protobuf.pyext._message'):
55
+ _implementation_type = 'cpp'
56
+ else:
57
+ _implementation_type = 'python'
58
+
59
+ # This environment variable can be used to switch to a certain implementation
60
+ # of the Python API, overriding the compile-time constants in the
61
+ # _api_implementation module. Right now only 'python', 'cpp' and 'upb' are
62
+ # valid values. Any other value will raise error.
63
+ _implementation_type = os.getenv(
64
+ 'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION', _implementation_type
65
+ )
66
+
67
+ if _implementation_type not in ('python', 'cpp', 'upb'):
68
+ raise ValueError(
69
+ 'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION {0} is not '
70
+ "supported. Please set to 'python', 'cpp' or "
71
+ "'upb'.".format(_implementation_type)
72
+ )
73
+
74
+ if 'PyPy' in sys.version and _implementation_type == 'cpp':
75
+ warnings.warn(
76
+ 'PyPy does not work yet with cpp protocol buffers. '
77
+ 'Falling back to the python implementation.'
78
+ )
79
+ _implementation_type = 'python'
80
+
81
+ _c_module = None
82
+
83
+ if _implementation_type == 'cpp':
84
+ try:
85
+ # pylint: disable=g-import-not-at-top
86
+ from google.protobuf.pyext import _message
87
+
88
+ sys.modules['google3.net.proto2.python.internal.cpp._message'] = _message
89
+ _c_module = _message
90
+ del _message
91
+ except ImportError:
92
+ # TODO: fail back to python
93
+ warnings.warn('Selected implementation cpp is not available.')
94
+ pass
95
+
96
+ if _implementation_type == 'upb':
97
+ try:
98
+ # pylint: disable=g-import-not-at-top
99
+ from google._upb import _message
100
+
101
+ _c_module = _message
102
+ del _message
103
+ except ImportError:
104
+ warnings.warn(
105
+ 'Selected implementation upb is not available. '
106
+ 'Falling back to the python implementation.'
107
+ )
108
+ _implementation_type = 'python'
109
+ pass
110
+
111
+ # Detect if serialization should be deterministic by default
112
+ try:
113
+ # The presence of this module in a build allows the proto implementation to
114
+ # be upgraded merely via build deps.
115
+ #
116
+ # NOTE: Merely importing this automatically enables deterministic proto
117
+ # serialization for C++ code, but we still need to export it as a boolean so
118
+ # that we can do the same for `_implementation_type == 'python'`.
119
+ #
120
+ # NOTE2: It is possible for C++ code to enable deterministic serialization by
121
+ # default _without_ affecting Python code, if the C++ implementation is not in
122
+ # use by this module. That is intended behavior, so we don't actually expose
123
+ # this boolean outside of this module.
124
+ #
125
+ # pylint: disable=g-import-not-at-top,unused-import
126
+ from google.protobuf import enable_deterministic_proto_serialization
127
+
128
+ _python_deterministic_proto_serialization = True
129
+ except ImportError:
130
+ _python_deterministic_proto_serialization = False
131
+
132
+
133
+ # Usage of this function is discouraged. Clients shouldn't care which
134
+ # implementation of the API is in use. Note that there is no guarantee
135
+ # that differences between APIs will be maintained.
136
+ # Please don't use this function if possible.
137
+ def Type():
138
+ return _implementation_type
139
+
140
+
141
+ # For internal use only
142
+ def IsPythonDefaultSerializationDeterministic():
143
+ return _python_deterministic_proto_serialization
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/builder.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Builds descriptors, message classes and services for generated _pb2.py.
8
+
9
+ This file is only called in python generated _pb2.py files. It builds
10
+ descriptors, message classes and services that users can directly use
11
+ in generated code.
12
+ """
13
+
14
+ __author__ = 'jieluo@google.com (Jie Luo)'
15
+
16
+ from google.protobuf import message as _message
17
+ from google.protobuf import reflection as _reflection
18
+ from google.protobuf import symbol_database as _symbol_database
19
+ from google.protobuf.internal import enum_type_wrapper
20
+ from google.protobuf.internal import python_message
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ def _BuildNestedDescriptors(module, msg_des, prefix):
26
+ for name, nested_msg in msg_des.nested_types_by_name.items():
27
+ module_name = prefix + name.upper()
28
+ module[module_name] = nested_msg
29
+ _BuildNestedDescriptors(module, nested_msg, module_name + '_')
30
+ for enum_des in msg_des.enum_types:
31
+ module[prefix + enum_des.name.upper()] = enum_des
32
+
33
+
34
+ def BuildMessageAndEnumDescriptors(file_des, module):
35
+ """Builds message and enum descriptors.
36
+
37
+ Args:
38
+ file_des: FileDescriptor of the .proto file
39
+ module: Generated _pb2 module
40
+ """
41
+ for name, msg_des in file_des.message_types_by_name.items():
42
+ module_name = '_' + name.upper()
43
+ module[module_name] = msg_des
44
+ _BuildNestedDescriptors(module, msg_des, module_name + '_')
45
+
46
+
47
+ def _BuildMessage(module_name, msg_des, prefix):
48
+ create_dict = {}
49
+ for name, nested_msg in msg_des.nested_types_by_name.items():
50
+ create_dict[name] = _BuildMessage(
51
+ module_name, nested_msg, prefix + msg_des.name + '.'
52
+ )
53
+ create_dict['DESCRIPTOR'] = msg_des
54
+ create_dict['__module__'] = module_name
55
+ create_dict['__qualname__'] = prefix + msg_des.name
56
+ message_class = _reflection.GeneratedProtocolMessageType(
57
+ msg_des.name, (_message.Message,), create_dict
58
+ )
59
+ _sym_db.RegisterMessage(message_class)
60
+ return message_class
61
+
62
+
63
+ def BuildTopDescriptorsAndMessages(file_des, module_name, module):
64
+ """Builds top level descriptors and message classes.
65
+
66
+ Args:
67
+ file_des: FileDescriptor of the .proto file
68
+ module_name: str, the name of generated _pb2 module
69
+ module: Generated _pb2 module
70
+ """
71
+
72
+ # top level enums
73
+ for name, enum_des in file_des.enum_types_by_name.items():
74
+ module['_' + name.upper()] = enum_des
75
+ module[name] = enum_type_wrapper.EnumTypeWrapper(enum_des)
76
+ for enum_value in enum_des.values:
77
+ module[enum_value.name] = enum_value.number
78
+
79
+ # top level extensions
80
+ for name, extension_des in file_des.extensions_by_name.items():
81
+ module[name.upper() + '_FIELD_NUMBER'] = extension_des.number
82
+ module[name] = extension_des
83
+
84
+ # services
85
+ for name, service in file_des.services_by_name.items():
86
+ module['_' + name.upper()] = service
87
+
88
+ # Build messages.
89
+ for name, msg_des in file_des.message_types_by_name.items():
90
+ module[name] = _BuildMessage(module_name, msg_des, '')
91
+
92
+
93
+ def AddHelpersToExtensions(file_des):
94
+ """no-op to keep old generated code work with new runtime.
95
+
96
+ Args:
97
+ file_des: FileDescriptor of the .proto file
98
+ """
99
+ # TODO: Remove this on-op
100
+ return
101
+
102
+
103
+ def BuildServices(file_des, module_name, module):
104
+ """Builds services classes and services stub class.
105
+
106
+ Args:
107
+ file_des: FileDescriptor of the .proto file
108
+ module_name: str, the name of generated _pb2 module
109
+ module: Generated _pb2 module
110
+ """
111
+ # pylint: disable=g-import-not-at-top
112
+ from google.protobuf import service_reflection
113
+ # pylint: enable=g-import-not-at-top
114
+ for name, service in file_des.services_by_name.items():
115
+ module[name] = service_reflection.GeneratedServiceType(
116
+ name, (), dict(DESCRIPTOR=service, __module__=module_name)
117
+ )
118
+ stub_name = name + '_Stub'
119
+ module[stub_name] = service_reflection.GeneratedServiceStubType(
120
+ stub_name,
121
+ (module[name],),
122
+ dict(DESCRIPTOR=service, __module__=module_name),
123
+ )
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/containers.py ADDED
@@ -0,0 +1,826 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Contains container classes to represent different protocol buffer types.
8
+
9
+ This file defines container classes which represent categories of protocol
10
+ buffer field types which need extra maintenance. Currently these categories
11
+ are:
12
+
13
+ - Repeated scalar fields - These are all repeated fields which aren't
14
+ composite (e.g. they are of simple types like int32, string, etc).
15
+ - Repeated composite fields - Repeated fields which are composite. This
16
+ includes groups and nested messages.
17
+ """
18
+
19
+ import collections.abc
20
+ import copy
21
+ import pickle
22
+ import warnings
23
+ from typing import (
24
+ Any,
25
+ Iterable,
26
+ Iterator,
27
+ List,
28
+ MutableMapping,
29
+ MutableSequence,
30
+ NoReturn,
31
+ Optional,
32
+ Sequence,
33
+ TypeVar,
34
+ Union,
35
+ overload,
36
+ )
37
+
38
+ _T = TypeVar('_T')
39
+ _K = TypeVar('_K')
40
+ _V = TypeVar('_V')
41
+
42
+ from google.protobuf.descriptor import FieldDescriptor
43
+ from google.protobuf import message
44
+
45
+
46
+ def _CheckFrozen(is_frozen: bool, msg: str) -> None:
47
+ if is_frozen:
48
+ warnings.warn(
49
+ 'Mutating messages or containers returned by GetOptions() is'
50
+ ' deprecated and will raise an exception in a future release.',
51
+ category=FutureWarning,
52
+ stacklevel=3,
53
+ )
54
+
55
+
56
+ class BaseContainer(Sequence[_T]):
57
+ """Base container class."""
58
+
59
+ # Minimizes memory usage and disallows assignment to other attributes.
60
+ __slots__ = ['_message_listener', '_values', '_frozen']
61
+
62
+ def __init__(self, message_listener: Any) -> None:
63
+ """Args:
64
+
65
+ message_listener: A MessageListener implementation.
66
+ The RepeatedScalarFieldContainer will call this object's
67
+ Modified() method when it is modified.
68
+ """
69
+ self._message_listener = message_listener
70
+ self._values = []
71
+ self._frozen = False
72
+
73
+ @overload
74
+ def __getitem__(self, key: int) -> _T:
75
+ ...
76
+
77
+ @overload
78
+ def __getitem__(self, key: slice) -> List[_T]:
79
+ ...
80
+
81
+ def __getitem__(self, key):
82
+ """Retrieves item by the specified key."""
83
+ return self._values[key]
84
+
85
+ def __len__(self) -> int:
86
+ """Returns the number of elements in the container."""
87
+ return len(self._values)
88
+
89
+ def __ne__(self, other: Any) -> bool:
90
+ """Checks if another instance isn't equal to this one."""
91
+ # The concrete classes should define __eq__.
92
+ return not self == other
93
+
94
+ __hash__ = None
95
+
96
+ def __repr__(self) -> str:
97
+ return repr(self._values)
98
+
99
+ def _SetFrozen(self) -> None:
100
+ self._frozen = True
101
+
102
+ def _AssureWritable(self) -> 'BaseContainer[_T]':
103
+ _CheckFrozen(self._frozen, 'Container is immutable')
104
+ return self
105
+
106
+ def sort(self, *args, **kwargs) -> None:
107
+ self._AssureWritable()
108
+ # Continue to support the old sort_function keyword argument.
109
+ # This is expected to be a rare occurrence, so use LBYL to avoid
110
+ # the overhead of actually catching KeyError.
111
+ if 'sort_function' in kwargs:
112
+ kwargs['cmp'] = kwargs.pop('sort_function')
113
+ self._values.sort(*args, **kwargs)
114
+
115
+ def reverse(self) -> None:
116
+ self._AssureWritable()
117
+ self._values.reverse()
118
+
119
+
120
+ # TODO: Remove this. BaseContainer does *not* conform to
121
+ # MutableSequence, only its subclasses do.
122
+ collections.abc.MutableSequence.register(BaseContainer)
123
+
124
+
125
+ class RepeatedScalarFieldContainer(BaseContainer[_T], MutableSequence[_T]):
126
+ """Simple, type-checked, list-like container for holding repeated scalars."""
127
+
128
+ # Disallows assignment to other attributes.
129
+ __slots__ = ['_type_checker', '_field']
130
+
131
+ def __init__(
132
+ self,
133
+ message_listener: Any,
134
+ type_checker: Any,
135
+ field: Any = None,
136
+ ) -> None:
137
+ """Args:
138
+
139
+ message_listener: A MessageListener implementation. The
140
+ RepeatedScalarFieldContainer will call this object's Modified() method
141
+ when it is modified.
142
+ type_checker: A type_checkers.ValueChecker instance to run on elements
143
+ inserted into this container.
144
+ """
145
+ super().__init__(message_listener)
146
+ self._type_checker = type_checker
147
+ self._field = field
148
+
149
+ def append(self, value: _T) -> None:
150
+ """Appends an item to the list. Similar to list.append()."""
151
+ self._AssureWritable()
152
+ self._values.append(self._type_checker.CheckValue(value))
153
+ if not self._message_listener.dirty:
154
+ self._message_listener.Modified()
155
+
156
+ def insert(self, key: int, value: _T) -> None:
157
+ """Inserts the item at the specified position. Similar to list.insert()."""
158
+ self._AssureWritable()
159
+ self._values.insert(key, self._type_checker.CheckValue(value))
160
+ if not self._message_listener.dirty:
161
+ self._message_listener.Modified()
162
+
163
+ def extend(self, elem_seq: Iterable[_T]) -> None:
164
+ """Extends by appending the given iterable. Similar to list.extend()."""
165
+ self._AssureWritable()
166
+ elem_seq_iter = iter(elem_seq)
167
+ new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
168
+ if new_values:
169
+ self._values.extend(new_values)
170
+ self._message_listener.Modified()
171
+
172
+ def MergeFrom(
173
+ self,
174
+ other: Union['RepeatedScalarFieldContainer[_T]', Iterable[_T]],
175
+ ) -> None:
176
+ """Appends the contents of another repeated field of the same type to this
177
+
178
+ one. We do not check the types of the individual fields.
179
+ """
180
+ self._AssureWritable()
181
+ self._values.extend(other)
182
+ self._message_listener.Modified()
183
+
184
+ def remove(self, elem: _T):
185
+ """Removes an item from the list. Similar to list.remove()."""
186
+ self._AssureWritable()
187
+ self._values.remove(elem)
188
+ self._message_listener.Modified()
189
+
190
+ def pop(self, key: Optional[int] = -1) -> _T:
191
+ """Removes and returns an item at a given index. Similar to list.pop()."""
192
+ self._AssureWritable()
193
+ value = self._values[key]
194
+ self.__delitem__(key)
195
+ return value
196
+
197
+ @overload
198
+ def __setitem__(self, key: int, value: _T) -> None:
199
+ ...
200
+
201
+ @overload
202
+ def __setitem__(self, key: slice, value: Iterable[_T]) -> None:
203
+ ...
204
+
205
+ def __setitem__(self, key, value) -> None:
206
+ """Sets the item on the specified position."""
207
+ self._AssureWritable()
208
+ if isinstance(key, slice):
209
+ if key.step is not None:
210
+ raise ValueError('Extended slices not supported')
211
+ self._values[key] = map(self._type_checker.CheckValue, value)
212
+ self._message_listener.Modified()
213
+ else:
214
+ self._values[key] = self._type_checker.CheckValue(value)
215
+ self._message_listener.Modified()
216
+
217
+ def __delitem__(self, key: Union[int, slice]) -> None:
218
+ """Deletes the item at the specified position."""
219
+ self._AssureWritable()
220
+ del self._values[key]
221
+ self._message_listener.Modified()
222
+
223
+ def __eq__(self, other: Any) -> bool:
224
+ """Compares the current instance with another one."""
225
+ if self is other:
226
+ return True
227
+ # Special case for the same type which should be common and fast.
228
+ if isinstance(other, self.__class__):
229
+ return other._values == self._values
230
+ # We are presumably comparing against some other sequence type.
231
+ return other == self._values
232
+
233
+ def __deepcopy__(
234
+ self,
235
+ unused_memo: Any = None,
236
+ ) -> 'RepeatedScalarFieldContainer[_T]':
237
+ clone = RepeatedScalarFieldContainer(
238
+ copy.deepcopy(self._message_listener), self._type_checker, self._field
239
+ )
240
+ clone.MergeFrom(self)
241
+ return clone
242
+
243
+ def __reduce__(self, **kwargs) -> NoReturn:
244
+ raise pickle.PickleError(
245
+ "Can't pickle repeated scalar fields, convert to list first"
246
+ )
247
+
248
+ def __array__(self, dtype=None, copy=None):
249
+ import numpy as np
250
+
251
+ if dtype is None:
252
+ cpp_type = self._field.cpp_type
253
+ if cpp_type == FieldDescriptor.CPPTYPE_INT32:
254
+ dtype = np.int32
255
+ elif cpp_type == FieldDescriptor.CPPTYPE_INT64:
256
+ dtype = np.int64
257
+ elif cpp_type == FieldDescriptor.CPPTYPE_UINT32:
258
+ dtype = np.uint32
259
+ elif cpp_type == FieldDescriptor.CPPTYPE_UINT64:
260
+ dtype = np.uint64
261
+ elif cpp_type == FieldDescriptor.CPPTYPE_DOUBLE:
262
+ dtype = np.float64
263
+ elif cpp_type == FieldDescriptor.CPPTYPE_FLOAT:
264
+ dtype = np.float32
265
+ elif cpp_type == FieldDescriptor.CPPTYPE_BOOL:
266
+ dtype = np.bool
267
+ elif cpp_type == FieldDescriptor.CPPTYPE_ENUM:
268
+ dtype = np.int32
269
+ elif self._field.type == FieldDescriptor.TYPE_BYTES:
270
+ dtype = 'S'
271
+ elif self._field.type == FieldDescriptor.TYPE_STRING:
272
+ dtype = str
273
+ else:
274
+ raise SystemError(
275
+ 'Code should never reach here: message type detected in'
276
+ ' RepeatedScalarFieldContainer'
277
+ )
278
+ return np.array(self._values, dtype=dtype, copy=True)
279
+
280
+
281
+ # TODO: Constrain T to be a subtype of Message.
282
+ class RepeatedCompositeFieldContainer(BaseContainer[_T], MutableSequence[_T]):
283
+ """Simple, list-like container for holding repeated composite fields."""
284
+
285
+ # Disallows assignment to other attributes.
286
+ __slots__ = ['_message_descriptor']
287
+
288
+ def __init__(self, message_listener: Any, message_descriptor: Any) -> None:
289
+ """Note that we pass in a descriptor instead of the generated directly,
290
+
291
+ since at the time we construct a _RepeatedCompositeFieldContainer we
292
+ haven't yet necessarily initialized the type that will be contained in the
293
+ container.
294
+
295
+ Args:
296
+ message_listener: A MessageListener implementation. The
297
+ RepeatedCompositeFieldContainer will call this object's Modified()
298
+ method when it is modified.
299
+ message_descriptor: A Descriptor instance describing the protocol type
300
+ that should be present in this container. We'll use the _concrete_class
301
+ field of this descriptor when the client calls add().
302
+ """
303
+ super().__init__(message_listener)
304
+ self._message_descriptor = message_descriptor
305
+
306
+ def _SetFrozen(self) -> None:
307
+ super()._SetFrozen()
308
+ for val in self._values:
309
+ val._SetFrozen()
310
+
311
+ def add(self, **kwargs: Any) -> _T:
312
+ """Adds a new element at the end of the list and returns it.
313
+
314
+ Keyword arguments may be used to initialize the element.
315
+ """
316
+ self._AssureWritable()
317
+ new_element = self._message_descriptor._concrete_class(**kwargs)
318
+ new_element._SetListener(self._message_listener)
319
+ self._values.append(new_element)
320
+ if not self._message_listener.dirty:
321
+ self._message_listener.Modified()
322
+ return new_element
323
+
324
+ def append(self, value: _T) -> None:
325
+ """Appends one element by copying the message."""
326
+ self._AssureWritable()
327
+ new_element = self._message_descriptor._concrete_class()
328
+ new_element._SetListener(self._message_listener)
329
+ new_element.CopyFrom(value)
330
+ self._values.append(new_element)
331
+ if not self._message_listener.dirty:
332
+ self._message_listener.Modified()
333
+
334
+ def insert(self, key: int, value: _T) -> None:
335
+ """Inserts the item at the specified position by copying."""
336
+ self._AssureWritable()
337
+ new_element = self._message_descriptor._concrete_class()
338
+ new_element._SetListener(self._message_listener)
339
+ new_element.CopyFrom(value)
340
+ self._values.insert(key, new_element)
341
+ if not self._message_listener.dirty:
342
+ self._message_listener.Modified()
343
+
344
+ def extend(self, elem_seq: Iterable[_T]) -> None:
345
+ """Extends by appending the given sequence of elements of the same type
346
+
347
+ as this one, copying each individual message.
348
+ """
349
+ self._AssureWritable()
350
+ message_class = self._message_descriptor._concrete_class
351
+ listener = self._message_listener
352
+ values = self._values
353
+ for message in elem_seq:
354
+ new_element = message_class()
355
+ new_element._SetListener(listener)
356
+ new_element.MergeFrom(message)
357
+ values.append(new_element)
358
+ listener.Modified()
359
+
360
+ def MergeFrom(
361
+ self,
362
+ other: Union['RepeatedCompositeFieldContainer[_T]', Iterable[_T]],
363
+ ) -> None:
364
+ """Appends the contents of another repeated field of the same type to this
365
+
366
+ one, copying each individual message.
367
+ """
368
+ self._AssureWritable()
369
+ self.extend(other)
370
+
371
+ def remove(self, elem: _T) -> None:
372
+ """Removes an item from the list. Similar to list.remove()."""
373
+ self._AssureWritable()
374
+ self._values.remove(elem)
375
+ self._message_listener.Modified()
376
+
377
+ def pop(self, key: Optional[int] = -1) -> _T:
378
+ """Removes and returns an item at a given index. Similar to list.pop()."""
379
+ self._AssureWritable()
380
+ value = self._values[key]
381
+ self.__delitem__(key)
382
+ return value
383
+
384
+ @overload
385
+ def __setitem__(self, key: int, value: _T) -> None:
386
+ ...
387
+
388
+ @overload
389
+ def __setitem__(self, key: slice, value: Iterable[_T]) -> None:
390
+ ...
391
+
392
+ def __setitem__(self, key, value):
393
+ # This method is implemented to make RepeatedCompositeFieldContainer
394
+ # structurally compatible with typing.MutableSequence. It is
395
+ # otherwise unsupported and will always raise an error.
396
+ raise TypeError(
397
+ f'{self.__class__.__name__} object does not support item assignment'
398
+ )
399
+
400
+ def __delitem__(self, key: Union[int, slice]) -> None:
401
+ """Deletes the item at the specified position."""
402
+ self._AssureWritable()
403
+ del self._values[key]
404
+ self._message_listener.Modified()
405
+
406
+ def __eq__(self, other: Any) -> bool:
407
+ """Compares the current instance with another one."""
408
+ if self is other:
409
+ return True
410
+ if not isinstance(other, self.__class__):
411
+ raise TypeError(
412
+ 'Can only compare repeated composite fields against '
413
+ 'other repeated composite fields.'
414
+ )
415
+ return self._values == other._values
416
+
417
+
418
+ class ScalarMap(MutableMapping[_K, _V]):
419
+ """Simple, type-checked, dict-like container for holding repeated scalars."""
420
+
421
+ # Disallows assignment to other attributes.
422
+ __slots__ = [
423
+ '_key_checker',
424
+ '_value_checker',
425
+ '_values',
426
+ '_message_listener',
427
+ '_entry_descriptor',
428
+ '_frozen',
429
+ ]
430
+
431
+ def __init__(
432
+ self,
433
+ message_listener: Any,
434
+ key_checker: Any,
435
+ value_checker: Any,
436
+ entry_descriptor: Any,
437
+ ) -> None:
438
+ """Args:
439
+
440
+ message_listener: A MessageListener implementation.
441
+ The ScalarMap will call this object's Modified() method when it
442
+ is modified.
443
+ key_checker: A type_checkers.ValueChecker instance to run on keys
444
+ inserted into this container.
445
+ value_checker: A type_checkers.ValueChecker instance to run on values
446
+ inserted into this container.
447
+ entry_descriptor: The MessageDescriptor of a map entry: key and value.
448
+ """
449
+ self._message_listener = message_listener
450
+ self._key_checker = key_checker
451
+ self._value_checker = value_checker
452
+ self._entry_descriptor = entry_descriptor
453
+ self._values = {}
454
+ self._frozen = False
455
+
456
+ def _SetFrozen(self) -> None:
457
+ self._frozen = True
458
+
459
+ def _AssureWritable(self) -> 'ScalarMap[_K, _V]':
460
+ _CheckFrozen(self._frozen, 'Map is immutable')
461
+ return self
462
+
463
+ def __getitem__(self, key: _K) -> _V:
464
+ key = self._key_checker.CheckValue(key)
465
+ try:
466
+ return self._values[key]
467
+ except KeyError:
468
+ self._AssureWritable()
469
+ val = self._value_checker.DefaultValue()
470
+ self._values[key] = val
471
+ return val
472
+
473
+ def __contains__(self, item: _K) -> bool:
474
+ # We check the key's type to match the strong-typing flavor of the API.
475
+ # Also this makes it easier to match the behavior of the C++ implementation.
476
+ item = self._key_checker.CheckValue(item)
477
+ return item in self._values
478
+
479
+ @overload
480
+ def get(self, key: _K) -> Optional[_V]:
481
+ ...
482
+
483
+ @overload
484
+ def get(self, key: _K, default: _T) -> Union[_V, _T]:
485
+ ...
486
+
487
+ # We need to override this explicitly, because our defaultdict-like behavior
488
+ # will make the default implementation (from our base class) always insert
489
+ # the key.
490
+ def get(self, key, default=None):
491
+ checked_key = self._key_checker.CheckValue(key)
492
+ if checked_key in self._values:
493
+ return self[checked_key]
494
+ else:
495
+ return default
496
+
497
+ def __setitem__(self, key: _K, value: _V) -> _T:
498
+ self._AssureWritable()
499
+ checked_key = self._key_checker.CheckValue(key)
500
+ checked_value = self._value_checker.CheckValue(value)
501
+ self._values[checked_key] = checked_value
502
+ self._message_listener.Modified()
503
+
504
+ def __delitem__(self, key: _K) -> None:
505
+ self._AssureWritable()
506
+ checked_key = self._key_checker.CheckValue(key)
507
+ del self._values[checked_key]
508
+ self._message_listener.Modified()
509
+
510
+ def __len__(self) -> int:
511
+ return len(self._values)
512
+
513
+ def __iter__(self) -> Iterator[_K]:
514
+ return iter(self._values)
515
+
516
+ def __repr__(self) -> str:
517
+ return repr(self._values)
518
+
519
+ def setdefault(self, key: _K, value: Optional[_V] = None) -> _V:
520
+ self._AssureWritable()
521
+ checked_key = self._key_checker.CheckValue(key)
522
+ if value == None:
523
+ raise ValueError('The value for scalar map setdefault must be set.')
524
+ if checked_key not in self._values:
525
+ self.__setitem__(checked_key, value)
526
+ return self[key]
527
+
528
+ def MergeFrom(self, other: 'ScalarMap[_K, _V]') -> None:
529
+ self._AssureWritable()
530
+ self._values.update(other._values)
531
+ self._message_listener.Modified()
532
+
533
+ def InvalidateIterators(self) -> None:
534
+ # It appears that the only way to reliably invalidate iterators to
535
+ # self._values is to ensure that its size changes.
536
+ original = self._values
537
+ self._values = original.copy()
538
+ original[None] = None
539
+
540
+ # This is defined in the abstract base, but we can do it much more cheaply.
541
+ def clear(self) -> None:
542
+ self._AssureWritable()
543
+ self._values.clear()
544
+ self._message_listener.Modified()
545
+
546
+ def GetEntryClass(self) -> Any:
547
+ return self._entry_descriptor._concrete_class
548
+
549
+
550
+ class MessageMap(MutableMapping[_K, _V]):
551
+ """Simple, type-checked, dict-like container for with submessage values."""
552
+
553
+ # Disallows assignment to other attributes.
554
+ __slots__ = [
555
+ '_key_checker',
556
+ '_values',
557
+ '_message_listener',
558
+ '_message_descriptor',
559
+ '_entry_descriptor',
560
+ '_frozen',
561
+ ]
562
+
563
+ def __init__(
564
+ self,
565
+ message_listener: Any,
566
+ message_descriptor: Any,
567
+ key_checker: Any,
568
+ entry_descriptor: Any,
569
+ ) -> None:
570
+ """Args:
571
+
572
+ message_listener: A MessageListener implementation.
573
+ The ScalarMap will call this object's Modified() method when it
574
+ is modified.
575
+ key_checker: A type_checkers.ValueChecker instance to run on keys
576
+ inserted into this container.
577
+ value_checker: A type_checkers.ValueChecker instance to run on values
578
+ inserted into this container.
579
+ entry_descriptor: The MessageDescriptor of a map entry: key and value.
580
+ """
581
+ self._message_listener = message_listener
582
+ self._message_descriptor = message_descriptor
583
+ self._key_checker = key_checker
584
+ self._entry_descriptor = entry_descriptor
585
+ self._values = {}
586
+ self._frozen = False
587
+
588
+ def _SetFrozen(self) -> None:
589
+ self._frozen = True
590
+ for val in self._values.values():
591
+ val._SetFrozen()
592
+
593
+ def _AssureWritable(self) -> 'MessageMap[_K, _V]':
594
+ _CheckFrozen(self._frozen, 'Map is immutable')
595
+ return self
596
+
597
+ def __getitem__(self, key: _K) -> _V:
598
+ key = self._key_checker.CheckValue(key)
599
+ try:
600
+ return self._values[key]
601
+ except KeyError:
602
+ self._AssureWritable()
603
+ new_element = self._message_descriptor._concrete_class()
604
+ new_element._SetListener(self._message_listener)
605
+ self._values[key] = new_element
606
+ self._message_listener.Modified()
607
+ return new_element
608
+
609
+ def get_or_create(self, key: _K) -> _V:
610
+ """get_or_create() is an alias for getitem (ie. map[key]).
611
+
612
+ Args:
613
+ key: The key to get or create in the map.
614
+
615
+ This is useful in cases where you want to be explicit that the call is
616
+ mutating the map. This can avoid lint errors for statements like this
617
+ that otherwise would appear to be pointless statements:
618
+
619
+ msg.my_map[key]
620
+ """
621
+ return self[key]
622
+
623
+ @overload
624
+ def get(self, key: _K) -> Optional[_V]:
625
+ ...
626
+
627
+ @overload
628
+ def get(self, key: _K, default: _T) -> Union[_V, _T]:
629
+ ...
630
+
631
+ # We need to override this explicitly, because our defaultdict-like behavior
632
+ # will make the default implementation (from our base class) always insert
633
+ # the key.
634
+ def get(self, key, default=None):
635
+ if key in self:
636
+ return self[key]
637
+ else:
638
+ return default
639
+
640
+ def __contains__(self, item: _K) -> bool:
641
+ item = self._key_checker.CheckValue(item)
642
+ return item in self._values
643
+
644
+ def __setitem__(self, key: _K, value: _V) -> NoReturn:
645
+ self._AssureWritable()
646
+ raise ValueError('May not set values directly, call my_map[key].foo = 5')
647
+
648
+ def __delitem__(self, key: _K) -> None:
649
+ self._AssureWritable()
650
+ key = self._key_checker.CheckValue(key)
651
+ del self._values[key]
652
+ self._message_listener.Modified()
653
+
654
+ def __len__(self) -> int:
655
+ return len(self._values)
656
+
657
+ def __iter__(self) -> Iterator[_K]:
658
+ return iter(self._values)
659
+
660
+ def __repr__(self) -> str:
661
+ return repr(self._values)
662
+
663
+ def setdefault(self, key: _K, value: Optional[_V] = None) -> _V:
664
+ self._AssureWritable()
665
+ raise NotImplementedError(
666
+ 'Set message map value directly is not supported, call'
667
+ ' my_map[key].foo = 5'
668
+ )
669
+
670
+ def MergeFrom(self, other: 'MessageMap[_K, _V]') -> None:
671
+ self._AssureWritable()
672
+ # pylint: disable=protected-access
673
+ for key in other._values:
674
+ # According to documentation: "When parsing from the wire or when merging,
675
+ # if there are duplicate map keys the last key seen is used".
676
+ if key in self:
677
+ del self[key]
678
+ self[key].CopyFrom(other[key])
679
+ # self._message_listener.Modified() not required here, because
680
+ # mutations to submessages already propagate.
681
+
682
+ def InvalidateIterators(self) -> None:
683
+ # It appears that the only way to reliably invalidate iterators to
684
+ # self._values is to ensure that its size changes.
685
+ original = self._values
686
+ self._values = original.copy()
687
+ original[None] = None
688
+
689
+ # This is defined in the abstract base, but we can do it much more cheaply.
690
+ def clear(self) -> None:
691
+ self._AssureWritable()
692
+ self._values.clear()
693
+ self._message_listener.Modified()
694
+
695
+ def GetEntryClass(self) -> Any:
696
+ return self._entry_descriptor._concrete_class
697
+
698
+
699
+ class _UnknownField:
700
+ """A parsed unknown field."""
701
+
702
+ # Disallows assignment to other attributes.
703
+ __slots__ = ['_field_number', '_wire_type', '_data']
704
+
705
+ def __init__(self, field_number, wire_type, data):
706
+ self._field_number = field_number
707
+ self._wire_type = wire_type
708
+ self._data = data
709
+ return
710
+
711
+ def __lt__(self, other):
712
+ # pylint: disable=protected-access
713
+ return self._field_number < other._field_number
714
+
715
+ def __eq__(self, other):
716
+ if self is other:
717
+ return True
718
+ # pylint: disable=protected-access
719
+ return (
720
+ self._field_number == other._field_number
721
+ and self._wire_type == other._wire_type
722
+ and self._data == other._data
723
+ )
724
+
725
+
726
+ class UnknownFieldRef: # pylint: disable=missing-class-docstring
727
+
728
+ def __init__(self, parent, index):
729
+ self._parent = parent
730
+ self._index = index
731
+
732
+ def _check_valid(self):
733
+ if not self._parent:
734
+ raise ValueError(
735
+ 'UnknownField does not exist. The parent message might be cleared.'
736
+ )
737
+ if self._index >= len(self._parent):
738
+ raise ValueError(
739
+ 'UnknownField does not exist. The parent message might be cleared.'
740
+ )
741
+
742
+ @property
743
+ def field_number(self):
744
+ self._check_valid()
745
+ # pylint: disable=protected-access
746
+ return self._parent._internal_get(self._index)._field_number
747
+
748
+ @property
749
+ def wire_type(self):
750
+ self._check_valid()
751
+ # pylint: disable=protected-access
752
+ return self._parent._internal_get(self._index)._wire_type
753
+
754
+ @property
755
+ def data(self):
756
+ self._check_valid()
757
+ # pylint: disable=protected-access
758
+ return self._parent._internal_get(self._index)._data
759
+
760
+
761
+ class UnknownFieldSet:
762
+ """UnknownField container"""
763
+
764
+ # Disallows assignment to other attributes.
765
+ __slots__ = ['_values']
766
+
767
+ def __init__(self):
768
+ self._values = []
769
+
770
+ def __getitem__(self, index):
771
+ if self._values is None:
772
+ raise ValueError(
773
+ 'UnknownFields does not exist. The parent message might be cleared.'
774
+ )
775
+ size = len(self._values)
776
+ if index < 0:
777
+ index += size
778
+ if index < 0 or index >= size:
779
+ raise IndexError('index %d out of range'.index)
780
+
781
+ return UnknownFieldRef(self, index)
782
+
783
+ def _internal_get(self, index):
784
+ return self._values[index]
785
+
786
+ def __len__(self):
787
+ if self._values is None:
788
+ raise ValueError(
789
+ 'UnknownFields does not exist. The parent message might be cleared.'
790
+ )
791
+ return len(self._values)
792
+
793
+ def _add(self, field_number, wire_type, data):
794
+ unknown_field = _UnknownField(field_number, wire_type, data)
795
+ self._values.append(unknown_field)
796
+ return unknown_field
797
+
798
+ def __iter__(self):
799
+ for i in range(len(self)):
800
+ yield UnknownFieldRef(self, i)
801
+
802
+ def _extend(self, other):
803
+ if other is None:
804
+ return
805
+ # pylint: disable=protected-access
806
+ self._values.extend(other._values)
807
+
808
+ def __eq__(self, other):
809
+ if self is other:
810
+ return True
811
+ # Sort unknown fields because their order shouldn't
812
+ # affect equality test.
813
+ values = list(self._values)
814
+ if other is None:
815
+ return not values
816
+ values.sort()
817
+ # pylint: disable=protected-access
818
+ other_values = sorted(other._values)
819
+ return values == other_values
820
+
821
+ def _clear(self):
822
+ for value in self._values:
823
+ # pylint: disable=protected-access
824
+ if isinstance(value._data, UnknownFieldSet):
825
+ value._data._clear() # pylint: disable=protected-access
826
+ self._values = None
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/decoder.py ADDED
@@ -0,0 +1,1127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Code for decoding protocol buffer primitives.
8
+
9
+ This code is very similar to encoder.py -- read the docs for that module first.
10
+
11
+ A "decoder" is a function with the signature:
12
+ Decode(buffer, pos, end, message, field_dict)
13
+ The arguments are:
14
+ buffer: The string containing the encoded message.
15
+ pos: The current position in the string.
16
+ end: The position in the string where the current message ends. May be
17
+ less than len(buffer) if we're reading a sub-message.
18
+ message: The message object into which we're parsing.
19
+ field_dict: message._fields (avoids a hashtable lookup).
20
+ The decoder reads the field and stores it into field_dict, returning the new
21
+ buffer position. A decoder for a repeated field may proactively decode all of
22
+ the elements of that field, if they appear consecutively.
23
+
24
+ Note that decoders may throw any of the following:
25
+ IndexError: Indicates a truncated message.
26
+ struct.error: Unpacking of a fixed-width field failed.
27
+ message.DecodeError: Other errors.
28
+
29
+ Decoders are expected to raise an exception if they are called with pos > end.
30
+ This allows callers to be lax about bounds checking: it's fineto read past
31
+ "end" as long as you are sure that someone else will notice and throw an
32
+ exception later on.
33
+
34
+ Something up the call stack is expected to catch IndexError and struct.error
35
+ and convert them to message.DecodeError.
36
+
37
+ Decoders are constructed using decoder constructors with the signature:
38
+ MakeDecoder(field_number, is_repeated, is_packed, key, new_default)
39
+ The arguments are:
40
+ field_number: The field number of the field we want to decode.
41
+ is_repeated: Is the field a repeated field? (bool)
42
+ is_packed: Is the field a packed field? (bool)
43
+ key: The key to use when looking up the field within field_dict.
44
+ (This is actually the FieldDescriptor but nothing in this
45
+ file should depend on that.)
46
+ new_default: A function which takes a message object as a parameter and
47
+ returns a new instance of the default value for this field.
48
+ (This is called for repeated fields and sub-messages, when an
49
+ instance does not already exist.)
50
+
51
+ As with encoders, we define a decoder constructor for every type of field.
52
+ Then, for every field of every message class we construct an actual decoder.
53
+ That decoder goes into a dict indexed by tag, so when we decode a message
54
+ we repeatedly read a tag, look up the corresponding decoder, and invoke it.
55
+ """
56
+
57
+ __author__ = 'kenton@google.com (Kenton Varda)'
58
+
59
+ import math
60
+ import numbers
61
+ import struct
62
+
63
+ from google.protobuf import message
64
+ from google.protobuf.internal import containers
65
+ from google.protobuf.internal import encoder
66
+ from google.protobuf.internal import wire_format
67
+
68
+ # This is not for optimization, but rather to avoid conflicts with local
69
+ # variables named "message".
70
+ _DecodeError = message.DecodeError
71
+
72
+
73
+ def IsDefaultScalarValue(value):
74
+ """Returns whether or not a scalar value is the default value of its type.
75
+
76
+ Specifically, this should be used to determine presence of implicit-presence
77
+ fields, where we disallow custom defaults.
78
+
79
+ Args:
80
+ value: A scalar value to check.
81
+
82
+ Returns:
83
+ True if the value is equivalent to a default value, False otherwise.
84
+ """
85
+ if isinstance(value, numbers.Number) and math.copysign(1.0, value) < 0:
86
+ # Special case for negative zero, where "truthiness" fails to give the right
87
+ # answer.
88
+ return False
89
+
90
+ # Normally, we can just use Python's boolean conversion.
91
+ return not value
92
+
93
+
94
+ def _VarintDecoder(mask, result_type):
95
+ """Return an encoder for a basic varint value (does not include tag).
96
+
97
+ Decoded values will be bitwise-anded with the given mask before being
98
+ returned, e.g. to limit them to 32 bits. The returned decoder does not
99
+ take the usual "end" parameter -- the caller is expected to do bounds checking
100
+ after the fact (often the caller can defer such checking until later). The
101
+ decoder returns a (value, new_pos) pair.
102
+ """
103
+
104
+ def DecodeVarint(buffer, pos: int = None):
105
+ result = 0
106
+ shift = 0
107
+ while 1:
108
+ if pos is None:
109
+ # Read from BytesIO
110
+ try:
111
+ b = buffer.read(1)[0]
112
+ except IndexError as e:
113
+ if shift == 0:
114
+ # End of BytesIO.
115
+ return None
116
+ else:
117
+ raise ValueError('Fail to read varint %s' % str(e))
118
+ else:
119
+ b = buffer[pos]
120
+ pos += 1
121
+ result |= (b & 0x7F) << shift
122
+ if not (b & 0x80):
123
+ result &= mask
124
+ result = result_type(result)
125
+ return result if pos is None else (result, pos)
126
+ shift += 7
127
+ if shift >= 64:
128
+ raise _DecodeError('Too many bytes when decoding varint.')
129
+
130
+ return DecodeVarint
131
+
132
+
133
+ def _SignedVarintDecoder(bits, result_type):
134
+ """Like _VarintDecoder() but decodes signed values."""
135
+
136
+ signbit = 1 << (bits - 1)
137
+ mask = (1 << bits) - 1
138
+
139
+ def DecodeVarint(buffer, pos):
140
+ result = 0
141
+ shift = 0
142
+ while 1:
143
+ b = buffer[pos]
144
+ result |= (b & 0x7F) << shift
145
+ pos += 1
146
+ if not (b & 0x80):
147
+ result &= mask
148
+ result = (result ^ signbit) - signbit
149
+ result = result_type(result)
150
+ return (result, pos)
151
+ shift += 7
152
+ if shift >= 64:
153
+ raise _DecodeError('Too many bytes when decoding varint.')
154
+
155
+ return DecodeVarint
156
+
157
+
158
+ # All 32-bit and 64-bit values are represented as int.
159
+ _DecodeVarint = _VarintDecoder((1 << 64) - 1, int)
160
+ _DecodeSignedVarint = _SignedVarintDecoder(64, int)
161
+
162
+ # Use these versions for values which must be limited to 32 bits.
163
+ _DecodeVarint32 = _VarintDecoder((1 << 32) - 1, int)
164
+ _DecodeSignedVarint32 = _SignedVarintDecoder(32, int)
165
+
166
+
167
+ def ReadTag(buffer, pos):
168
+ """Read a tag from the memoryview, and return a (tag_bytes, new_pos) tuple.
169
+
170
+ We return the raw bytes of the tag rather than decoding them. The raw
171
+ bytes can then be used to look up the proper decoder. This effectively allows
172
+ us to trade some work that would be done in pure-python (decoding a varint)
173
+ for work that is done in C (searching for a byte string in a hash table).
174
+ In a low-level language it would be much cheaper to decode the varint and
175
+ use that, but not in Python.
176
+
177
+ Args:
178
+ buffer: memoryview object of the encoded bytes
179
+ pos: int of the current position to start from
180
+
181
+ Returns:
182
+ Tuple[bytes, int] of the tag data and new position.
183
+ """
184
+ start = pos
185
+ while buffer[pos] & 0x80:
186
+ pos += 1
187
+ pos += 1
188
+
189
+ tag_bytes = buffer[start:pos].tobytes()
190
+ return tag_bytes, pos
191
+
192
+
193
+ def DecodeTag(tag_bytes):
194
+ """Decode a tag from the bytes.
195
+
196
+ Args:
197
+ tag_bytes: the bytes of the tag
198
+
199
+ Returns:
200
+ Tuple[int, int] of the tag field number and wire type.
201
+ """
202
+ tag, _ = _DecodeVarint(tag_bytes, 0)
203
+ return wire_format.UnpackTag(tag)
204
+
205
+
206
+ # --------------------------------------------------------------------
207
+
208
+
209
+ def _SimpleDecoder(wire_type, decode_value):
210
+ """Return a constructor for a decoder for fields of a particular type.
211
+
212
+ Args:
213
+ wire_type: The field's wire type.
214
+ decode_value: A function which decodes an individual value, e.g.
215
+ _DecodeVarint()
216
+ """
217
+
218
+ def SpecificDecoder(
219
+ field_number,
220
+ is_repeated,
221
+ is_packed,
222
+ key,
223
+ new_default,
224
+ clear_if_default=False,
225
+ ):
226
+ if is_packed:
227
+ local_DecodeVarint = _DecodeVarint
228
+
229
+ def DecodePackedField(
230
+ buffer, pos, end, message, field_dict, current_depth=0
231
+ ):
232
+ del current_depth # unused
233
+ value = field_dict.get(key)
234
+ if value is None:
235
+ value = field_dict.setdefault(key, new_default(message))
236
+ endpoint, pos = local_DecodeVarint(buffer, pos)
237
+ endpoint += pos
238
+ if endpoint > end:
239
+ raise _DecodeError('Truncated message.')
240
+ while pos < endpoint:
241
+ element, pos = decode_value(buffer, pos)
242
+ value.append(element)
243
+ if pos > endpoint:
244
+ del value[-1] # Discard corrupt value.
245
+ raise _DecodeError('Packed element was truncated.')
246
+ return pos
247
+
248
+ return DecodePackedField
249
+ elif is_repeated:
250
+ tag_bytes = encoder.TagBytes(field_number, wire_type)
251
+ tag_len = len(tag_bytes)
252
+
253
+ def DecodeRepeatedField(
254
+ buffer, pos, end, message, field_dict, current_depth=0
255
+ ):
256
+ del current_depth # unused
257
+ value = field_dict.get(key)
258
+ if value is None:
259
+ value = field_dict.setdefault(key, new_default(message))
260
+ while 1:
261
+ element, new_pos = decode_value(buffer, pos)
262
+ value.append(element)
263
+ # Predict that the next tag is another copy of the same repeated
264
+ # field.
265
+ pos = new_pos + tag_len
266
+ if buffer[new_pos:pos] != tag_bytes or new_pos >= end:
267
+ # Prediction failed. Return.
268
+ if new_pos > end:
269
+ raise _DecodeError('Truncated message.')
270
+ return new_pos
271
+
272
+ return DecodeRepeatedField
273
+ else:
274
+
275
+ def DecodeField(buffer, pos, end, message, field_dict, current_depth=0):
276
+ del current_depth # unused
277
+ new_value, pos = decode_value(buffer, pos)
278
+ if pos > end:
279
+ raise _DecodeError('Truncated message.')
280
+ if clear_if_default and IsDefaultScalarValue(new_value):
281
+ field_dict.pop(key, None)
282
+ else:
283
+ field_dict[key] = new_value
284
+ return pos
285
+
286
+ return DecodeField
287
+
288
+ return SpecificDecoder
289
+
290
+
291
+ def _ModifiedDecoder(wire_type, decode_value, modify_value):
292
+ """Like SimpleDecoder but additionally invokes modify_value on every value
293
+
294
+ before storing it. Usually modify_value is ZigZagDecode.
295
+ """
296
+
297
+ # Reusing _SimpleDecoder is slightly slower than copying a bunch of code, but
298
+ # not enough to make a significant difference.
299
+
300
+ def InnerDecode(buffer, pos):
301
+ result, new_pos = decode_value(buffer, pos)
302
+ return (modify_value(result), new_pos)
303
+
304
+ return _SimpleDecoder(wire_type, InnerDecode)
305
+
306
+
307
+ def _StructPackDecoder(wire_type, format):
308
+ """Return a constructor for a decoder for a fixed-width field.
309
+
310
+ Args:
311
+ wire_type: The field's wire type.
312
+ format: The format string to pass to struct.unpack().
313
+ """
314
+
315
+ value_size = struct.calcsize(format)
316
+ local_unpack = struct.unpack
317
+
318
+ # Reusing _SimpleDecoder is slightly slower than copying a bunch of code, but
319
+ # not enough to make a significant difference.
320
+
321
+ # Note that we expect someone up-stack to catch struct.error and convert
322
+ # it to _DecodeError -- this way we don't have to set up exception-
323
+ # handling blocks every time we parse one value.
324
+
325
+ def InnerDecode(buffer, pos):
326
+ new_pos = pos + value_size
327
+ result = local_unpack(format, buffer[pos:new_pos])[0]
328
+ return (result, new_pos)
329
+
330
+ return _SimpleDecoder(wire_type, InnerDecode)
331
+
332
+
333
+ def _FloatDecoder():
334
+ """Returns a decoder for a float field.
335
+
336
+ This code works around a bug in struct.unpack for non-finite 32-bit
337
+ floating-point values.
338
+ """
339
+
340
+ local_unpack = struct.unpack
341
+
342
+ def InnerDecode(buffer, pos):
343
+ """Decode serialized float to a float and new position.
344
+
345
+ Args:
346
+ buffer: memoryview of the serialized bytes
347
+ pos: int, position in the memory view to start at.
348
+
349
+ Returns:
350
+ Tuple[float, int] of the deserialized float value and new position
351
+ in the serialized data.
352
+ """
353
+ # We expect a 32-bit value in little-endian byte order. Bit 1 is the sign
354
+ # bit, bits 2-9 represent the exponent, and bits 10-32 are the significand.
355
+ new_pos = pos + 4
356
+ float_bytes = buffer[pos:new_pos].tobytes()
357
+
358
+ # If this value has all its exponent bits set, then it's non-finite.
359
+ # In Python 2.4, struct.unpack will convert it to a finite 64-bit value.
360
+ # To avoid that, we parse it specially.
361
+ if float_bytes[3:4] in b'\x7F\xFF' and float_bytes[2:3] >= b'\x80':
362
+ # If at least one significand bit is set...
363
+ if float_bytes[0:3] != b'\x00\x00\x80':
364
+ return (math.nan, new_pos)
365
+ # If sign bit is set...
366
+ if float_bytes[3:4] == b'\xFF':
367
+ return (-math.inf, new_pos)
368
+ return (math.inf, new_pos)
369
+
370
+ # Note that we expect someone up-stack to catch struct.error and convert
371
+ # it to _DecodeError -- this way we don't have to set up exception-
372
+ # handling blocks every time we parse one value.
373
+ result = local_unpack('<f', float_bytes)[0]
374
+ return (result, new_pos)
375
+
376
+ return _SimpleDecoder(wire_format.WIRETYPE_FIXED32, InnerDecode)
377
+
378
+
379
+ def _DoubleDecoder():
380
+ """Returns a decoder for a double field.
381
+
382
+ This code works around a bug in struct.unpack for not-a-number.
383
+ """
384
+
385
+ local_unpack = struct.unpack
386
+
387
+ def InnerDecode(buffer, pos):
388
+ """Decode serialized double to a double and new position.
389
+
390
+ Args:
391
+ buffer: memoryview of the serialized bytes.
392
+ pos: int, position in the memory view to start at.
393
+
394
+ Returns:
395
+ Tuple[float, int] of the decoded double value and new position
396
+ in the serialized data.
397
+ """
398
+ # We expect a 64-bit value in little-endian byte order. Bit 1 is the sign
399
+ # bit, bits 2-12 represent the exponent, and bits 13-64 are the significand.
400
+ new_pos = pos + 8
401
+ double_bytes = buffer[pos:new_pos].tobytes()
402
+
403
+ # If this value has all its exponent bits set and at least one significand
404
+ # bit set, it's not a number. In Python 2.4, struct.unpack will treat it
405
+ # as inf or -inf. To avoid that, we treat it specially.
406
+ if (
407
+ (double_bytes[7:8] in b'\x7F\xFF')
408
+ and (double_bytes[6:7] >= b'\xF0')
409
+ and (double_bytes[0:7] != b'\x00\x00\x00\x00\x00\x00\xF0')
410
+ ):
411
+ return (math.nan, new_pos)
412
+
413
+ # Note that we expect someone up-stack to catch struct.error and convert
414
+ # it to _DecodeError -- this way we don't have to set up exception-
415
+ # handling blocks every time we parse one value.
416
+ result = local_unpack('<d', double_bytes)[0]
417
+ return (result, new_pos)
418
+
419
+ return _SimpleDecoder(wire_format.WIRETYPE_FIXED64, InnerDecode)
420
+
421
+
422
+ def EnumDecoder(
423
+ field_number,
424
+ is_repeated,
425
+ is_packed,
426
+ key,
427
+ new_default,
428
+ clear_if_default=False,
429
+ ):
430
+ """Returns a decoder for enum field."""
431
+ enum_type = key.enum_type
432
+ if is_packed:
433
+ local_DecodeVarint = _DecodeVarint
434
+
435
+ def DecodePackedField(
436
+ buffer, pos, end, message, field_dict, current_depth=0
437
+ ):
438
+ """Decode serialized packed enum to its value and a new position.
439
+
440
+ Args:
441
+ buffer: memoryview of the serialized bytes.
442
+ pos: int, position in the memory view to start at.
443
+ end: int, end position of serialized data
444
+ message: Message object to store unknown fields in
445
+ field_dict: Map[Descriptor, Any] to store decoded values in.
446
+
447
+ Returns:
448
+ int, new position in serialized data.
449
+ """
450
+ del current_depth # unused
451
+ value = field_dict.get(key)
452
+ if value is None:
453
+ value = field_dict.setdefault(key, new_default(message))
454
+ endpoint, pos = local_DecodeVarint(buffer, pos)
455
+ endpoint += pos
456
+ if endpoint > end:
457
+ raise _DecodeError('Truncated message.')
458
+ while pos < endpoint:
459
+ value_start_pos = pos
460
+ element, pos = _DecodeSignedVarint32(buffer, pos)
461
+ # pylint: disable=protected-access
462
+ if element in enum_type.values_by_number:
463
+ value.append(element)
464
+ else:
465
+ if not message._unknown_fields:
466
+ message._unknown_fields = []
467
+ tag_bytes = encoder.TagBytes(
468
+ field_number, wire_format.WIRETYPE_VARINT
469
+ )
470
+
471
+ message._unknown_fields.append(
472
+ (tag_bytes, buffer[value_start_pos:pos].tobytes())
473
+ )
474
+ # pylint: enable=protected-access
475
+ if pos > endpoint:
476
+ if element in enum_type.values_by_number:
477
+ del value[-1] # Discard corrupt value.
478
+ else:
479
+ del message._unknown_fields[-1]
480
+ # pylint: enable=protected-access
481
+ raise _DecodeError('Packed element was truncated.')
482
+ return pos
483
+
484
+ return DecodePackedField
485
+ elif is_repeated:
486
+ tag_bytes = encoder.TagBytes(field_number, wire_format.WIRETYPE_VARINT)
487
+ tag_len = len(tag_bytes)
488
+
489
+ def DecodeRepeatedField(
490
+ buffer, pos, end, message, field_dict, current_depth=0
491
+ ):
492
+ """Decode serialized repeated enum to its value and a new position.
493
+
494
+ Args:
495
+ buffer: memoryview of the serialized bytes.
496
+ pos: int, position in the memory view to start at.
497
+ end: int, end position of serialized data
498
+ message: Message object to store unknown fields in
499
+ field_dict: Map[Descriptor, Any] to store decoded values in.
500
+
501
+ Returns:
502
+ int, new position in serialized data.
503
+ """
504
+ del current_depth # unused
505
+ value = field_dict.get(key)
506
+ if value is None:
507
+ value = field_dict.setdefault(key, new_default(message))
508
+ while 1:
509
+ element, new_pos = _DecodeSignedVarint32(buffer, pos)
510
+ # pylint: disable=protected-access
511
+ if element in enum_type.values_by_number:
512
+ value.append(element)
513
+ else:
514
+ if not message._unknown_fields:
515
+ message._unknown_fields = []
516
+ message._unknown_fields.append(
517
+ (tag_bytes, buffer[pos:new_pos].tobytes())
518
+ )
519
+ # pylint: enable=protected-access
520
+ # Predict that the next tag is another copy of the same repeated
521
+ # field.
522
+ pos = new_pos + tag_len
523
+ if buffer[new_pos:pos] != tag_bytes or new_pos >= end:
524
+ # Prediction failed. Return.
525
+ if new_pos > end:
526
+ raise _DecodeError('Truncated message.')
527
+ return new_pos
528
+
529
+ return DecodeRepeatedField
530
+ else:
531
+
532
+ def DecodeField(buffer, pos, end, message, field_dict, current_depth=0):
533
+ """Decode serialized repeated enum to its value and a new position.
534
+
535
+ Args:
536
+ buffer: memoryview of the serialized bytes.
537
+ pos: int, position in the memory view to start at.
538
+ end: int, end position of serialized data
539
+ message: Message object to store unknown fields in
540
+ field_dict: Map[Descriptor, Any] to store decoded values in.
541
+
542
+ Returns:
543
+ int, new position in serialized data.
544
+ """
545
+ del current_depth # unused
546
+ value_start_pos = pos
547
+ enum_value, pos = _DecodeSignedVarint32(buffer, pos)
548
+ if pos > end:
549
+ raise _DecodeError('Truncated message.')
550
+ if clear_if_default and IsDefaultScalarValue(enum_value):
551
+ field_dict.pop(key, None)
552
+ return pos
553
+ # pylint: disable=protected-access
554
+ if enum_value in enum_type.values_by_number:
555
+ field_dict[key] = enum_value
556
+ else:
557
+ if not message._unknown_fields:
558
+ message._unknown_fields = []
559
+ tag_bytes = encoder.TagBytes(field_number, wire_format.WIRETYPE_VARINT)
560
+ message._unknown_fields.append(
561
+ (tag_bytes, buffer[value_start_pos:pos].tobytes())
562
+ )
563
+ # pylint: enable=protected-access
564
+ return pos
565
+
566
+ return DecodeField
567
+
568
+
569
+ # --------------------------------------------------------------------
570
+
571
+ Int32Decoder = _SimpleDecoder(
572
+ wire_format.WIRETYPE_VARINT, _DecodeSignedVarint32
573
+ )
574
+
575
+ Int64Decoder = _SimpleDecoder(wire_format.WIRETYPE_VARINT, _DecodeSignedVarint)
576
+
577
+ UInt32Decoder = _SimpleDecoder(wire_format.WIRETYPE_VARINT, _DecodeVarint32)
578
+ UInt64Decoder = _SimpleDecoder(wire_format.WIRETYPE_VARINT, _DecodeVarint)
579
+
580
+ SInt32Decoder = _ModifiedDecoder(
581
+ wire_format.WIRETYPE_VARINT, _DecodeVarint32, wire_format.ZigZagDecode
582
+ )
583
+ SInt64Decoder = _ModifiedDecoder(
584
+ wire_format.WIRETYPE_VARINT, _DecodeVarint, wire_format.ZigZagDecode
585
+ )
586
+
587
+ # Note that Python conveniently guarantees that when using the '<' prefix on
588
+ # formats, they will also have the same size across all platforms (as opposed
589
+ # to without the prefix, where their sizes depend on the C compiler's basic
590
+ # type sizes).
591
+ Fixed32Decoder = _StructPackDecoder(wire_format.WIRETYPE_FIXED32, '<I')
592
+ Fixed64Decoder = _StructPackDecoder(wire_format.WIRETYPE_FIXED64, '<Q')
593
+ SFixed32Decoder = _StructPackDecoder(wire_format.WIRETYPE_FIXED32, '<i')
594
+ SFixed64Decoder = _StructPackDecoder(wire_format.WIRETYPE_FIXED64, '<q')
595
+ FloatDecoder = _FloatDecoder()
596
+ DoubleDecoder = _DoubleDecoder()
597
+
598
+ BoolDecoder = _ModifiedDecoder(wire_format.WIRETYPE_VARINT, _DecodeVarint, bool)
599
+
600
+
601
+ def StringDecoder(
602
+ field_number,
603
+ is_repeated,
604
+ is_packed,
605
+ key,
606
+ new_default,
607
+ clear_if_default=False,
608
+ ):
609
+ """Returns a decoder for a string field."""
610
+
611
+ local_DecodeVarint = _DecodeVarint
612
+
613
+ def _ConvertToUnicode(memview):
614
+ """Convert byte to unicode."""
615
+ byte_str = memview.tobytes()
616
+ try:
617
+ value = str(byte_str, 'utf-8')
618
+ except UnicodeDecodeError as e:
619
+ # add more information to the error message and re-raise it.
620
+ e.reason = '%s in field: %s' % (e, key.full_name)
621
+ raise
622
+
623
+ return value
624
+
625
+ assert not is_packed
626
+ if is_repeated:
627
+ tag_bytes = encoder.TagBytes(
628
+ field_number, wire_format.WIRETYPE_LENGTH_DELIMITED
629
+ )
630
+ tag_len = len(tag_bytes)
631
+
632
+ def DecodeRepeatedField(
633
+ buffer, pos, end, message, field_dict, current_depth=0
634
+ ):
635
+ del current_depth # unused
636
+ value = field_dict.get(key)
637
+ if value is None:
638
+ value = field_dict.setdefault(key, new_default(message))
639
+ while 1:
640
+ size, pos = local_DecodeVarint(buffer, pos)
641
+ new_pos = pos + size
642
+ if new_pos > end:
643
+ raise _DecodeError('Truncated string.')
644
+ value.append(_ConvertToUnicode(buffer[pos:new_pos]))
645
+ # Predict that the next tag is another copy of the same repeated field.
646
+ pos = new_pos + tag_len
647
+ if buffer[new_pos:pos] != tag_bytes or new_pos == end:
648
+ # Prediction failed. Return.
649
+ return new_pos
650
+
651
+ return DecodeRepeatedField
652
+ else:
653
+
654
+ def DecodeField(buffer, pos, end, message, field_dict, current_depth=0):
655
+ del current_depth # unused
656
+ size, pos = local_DecodeVarint(buffer, pos)
657
+ new_pos = pos + size
658
+ if new_pos > end:
659
+ raise _DecodeError('Truncated string.')
660
+ if clear_if_default and IsDefaultScalarValue(size):
661
+ field_dict.pop(key, None)
662
+ else:
663
+ field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
664
+ return new_pos
665
+
666
+ return DecodeField
667
+
668
+
669
+ def BytesDecoder(
670
+ field_number,
671
+ is_repeated,
672
+ is_packed,
673
+ key,
674
+ new_default,
675
+ clear_if_default=False,
676
+ ):
677
+ """Returns a decoder for a bytes field."""
678
+
679
+ local_DecodeVarint = _DecodeVarint
680
+
681
+ assert not is_packed
682
+ if is_repeated:
683
+ tag_bytes = encoder.TagBytes(
684
+ field_number, wire_format.WIRETYPE_LENGTH_DELIMITED
685
+ )
686
+ tag_len = len(tag_bytes)
687
+
688
+ def DecodeRepeatedField(
689
+ buffer, pos, end, message, field_dict, current_depth=0
690
+ ):
691
+ del current_depth # unused
692
+ value = field_dict.get(key)
693
+ if value is None:
694
+ value = field_dict.setdefault(key, new_default(message))
695
+ while 1:
696
+ size, pos = local_DecodeVarint(buffer, pos)
697
+ new_pos = pos + size
698
+ if new_pos > end:
699
+ raise _DecodeError('Truncated string.')
700
+ value.append(buffer[pos:new_pos].tobytes())
701
+ # Predict that the next tag is another copy of the same repeated field.
702
+ pos = new_pos + tag_len
703
+ if buffer[new_pos:pos] != tag_bytes or new_pos == end:
704
+ # Prediction failed. Return.
705
+ return new_pos
706
+
707
+ return DecodeRepeatedField
708
+ else:
709
+
710
+ def DecodeField(buffer, pos, end, message, field_dict, current_depth=0):
711
+ del current_depth # unused
712
+ size, pos = local_DecodeVarint(buffer, pos)
713
+ new_pos = pos + size
714
+ if new_pos > end:
715
+ raise _DecodeError('Truncated string.')
716
+ if clear_if_default and IsDefaultScalarValue(size):
717
+ field_dict.pop(key, None)
718
+ else:
719
+ field_dict[key] = buffer[pos:new_pos].tobytes()
720
+ return new_pos
721
+
722
+ return DecodeField
723
+
724
+
725
+ def GroupDecoder(field_number, is_repeated, is_packed, key, new_default):
726
+ """Returns a decoder for a group field."""
727
+
728
+ end_tag_bytes = encoder.TagBytes(field_number, wire_format.WIRETYPE_END_GROUP)
729
+ end_tag_len = len(end_tag_bytes)
730
+
731
+ assert not is_packed
732
+ if is_repeated:
733
+ tag_bytes = encoder.TagBytes(field_number, wire_format.WIRETYPE_START_GROUP)
734
+ tag_len = len(tag_bytes)
735
+
736
+ def DecodeRepeatedField(
737
+ buffer, pos, end, message, field_dict, current_depth=0
738
+ ):
739
+ value = field_dict.get(key)
740
+ if value is None:
741
+ value = field_dict.setdefault(key, new_default(message))
742
+ while 1:
743
+ value = field_dict.get(key)
744
+ if value is None:
745
+ value = field_dict.setdefault(key, new_default(message))
746
+ # Read sub-message.
747
+ current_depth += 1
748
+ if current_depth > _recursion_limit:
749
+ raise _DecodeError(
750
+ 'Error parsing message: too many levels of nesting.'
751
+ )
752
+ pos = value.add()._InternalParse(buffer, pos, end, current_depth)
753
+ current_depth -= 1
754
+ # Read end tag.
755
+ new_pos = pos + end_tag_len
756
+ if buffer[pos:new_pos] != end_tag_bytes or new_pos > end:
757
+ raise _DecodeError('Missing group end tag.')
758
+ # Predict that the next tag is another copy of the same repeated field.
759
+ pos = new_pos + tag_len
760
+ if buffer[new_pos:pos] != tag_bytes or new_pos == end:
761
+ # Prediction failed. Return.
762
+ return new_pos
763
+
764
+ return DecodeRepeatedField
765
+ else:
766
+
767
+ def DecodeField(buffer, pos, end, message, field_dict, current_depth=0):
768
+ value = field_dict.get(key)
769
+ if value is None:
770
+ value = field_dict.setdefault(key, new_default(message))
771
+ # Read sub-message.
772
+ current_depth += 1
773
+ if current_depth > _recursion_limit:
774
+ raise _DecodeError('Error parsing message: too many levels of nesting.')
775
+ pos = value._InternalParse(buffer, pos, end, current_depth)
776
+ current_depth -= 1
777
+ # Read end tag.
778
+ new_pos = pos + end_tag_len
779
+ if buffer[pos:new_pos] != end_tag_bytes or new_pos > end:
780
+ raise _DecodeError('Missing group end tag.')
781
+ return new_pos
782
+
783
+ return DecodeField
784
+
785
+
786
+ def MessageDecoder(field_number, is_repeated, is_packed, key, new_default):
787
+ """Returns a decoder for a message field."""
788
+
789
+ local_DecodeVarint = _DecodeVarint
790
+
791
+ assert not is_packed
792
+ if is_repeated:
793
+ tag_bytes = encoder.TagBytes(
794
+ field_number, wire_format.WIRETYPE_LENGTH_DELIMITED
795
+ )
796
+ tag_len = len(tag_bytes)
797
+
798
+ def DecodeRepeatedField(
799
+ buffer, pos, end, message, field_dict, current_depth=0
800
+ ):
801
+ value = field_dict.get(key)
802
+ if value is None:
803
+ value = field_dict.setdefault(key, new_default(message))
804
+ while 1:
805
+ # Read length.
806
+ size, pos = local_DecodeVarint(buffer, pos)
807
+ new_pos = pos + size
808
+ if new_pos > end:
809
+ raise _DecodeError('Truncated message.')
810
+ # Read sub-message.
811
+ current_depth += 1
812
+ if current_depth > _recursion_limit:
813
+ raise _DecodeError(
814
+ 'Error parsing message: too many levels of nesting.'
815
+ )
816
+ if (
817
+ value.add()._InternalParse(buffer, pos, new_pos, current_depth)
818
+ != new_pos
819
+ ):
820
+ # The only reason _InternalParse would return early is if it
821
+ # encountered an end-group tag.
822
+ raise _DecodeError('Unexpected end-group tag.')
823
+ current_depth -= 1
824
+ # Predict that the next tag is another copy of the same repeated field.
825
+ pos = new_pos + tag_len
826
+ if buffer[new_pos:pos] != tag_bytes or new_pos == end:
827
+ # Prediction failed. Return.
828
+ return new_pos
829
+
830
+ return DecodeRepeatedField
831
+ else:
832
+
833
+ def DecodeField(buffer, pos, end, message, field_dict, current_depth=0):
834
+ value = field_dict.get(key)
835
+ if value is None:
836
+ value = field_dict.setdefault(key, new_default(message))
837
+ # Read length.
838
+ size, pos = local_DecodeVarint(buffer, pos)
839
+ new_pos = pos + size
840
+ if new_pos > end:
841
+ raise _DecodeError('Truncated message.')
842
+ # Read sub-message.
843
+ current_depth += 1
844
+ if current_depth > _recursion_limit:
845
+ raise _DecodeError('Error parsing message: too many levels of nesting.')
846
+ if value._InternalParse(buffer, pos, new_pos, current_depth) != new_pos:
847
+ # The only reason _InternalParse would return early is if it encountered
848
+ # an end-group tag.
849
+ raise _DecodeError('Unexpected end-group tag.')
850
+ current_depth -= 1
851
+ return new_pos
852
+
853
+ return DecodeField
854
+
855
+
856
+ # --------------------------------------------------------------------
857
+
858
+ MESSAGE_SET_ITEM_TAG = encoder.TagBytes(1, wire_format.WIRETYPE_START_GROUP)
859
+
860
+
861
+ def MessageSetItemDecoder(descriptor):
862
+ """Returns a decoder for a MessageSet item.
863
+
864
+ The parameter is the message Descriptor.
865
+
866
+ The message set message looks like this:
867
+ message MessageSet {
868
+ repeated group Item = 1 {
869
+ required int32 type_id = 2;
870
+ required string message = 3;
871
+ }
872
+ }
873
+ """
874
+
875
+ type_id_tag_bytes = encoder.TagBytes(2, wire_format.WIRETYPE_VARINT)
876
+ message_tag_bytes = encoder.TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)
877
+ item_end_tag_bytes = encoder.TagBytes(1, wire_format.WIRETYPE_END_GROUP)
878
+
879
+ local_ReadTag = ReadTag
880
+ local_DecodeVarint = _DecodeVarint
881
+
882
+ def DecodeItem(buffer, pos, end, message, field_dict, current_depth=0):
883
+ """Decode serialized message set to its value and new position.
884
+
885
+ Args:
886
+ buffer: memoryview of the serialized bytes.
887
+ pos: int, position in the memory view to start at.
888
+ end: int, end position of serialized data
889
+ message: Message object to store unknown fields in
890
+ field_dict: Map[Descriptor, Any] to store decoded values in.
891
+
892
+ Returns:
893
+ int, new position in serialized data.
894
+ """
895
+ message_set_item_start = pos
896
+ type_id = -1
897
+ message_start = -1
898
+ message_end = -1
899
+
900
+ # Technically, type_id and message can appear in any order, so we need
901
+ # a little loop here.
902
+ while 1:
903
+ tag_bytes, pos = local_ReadTag(buffer, pos)
904
+ if tag_bytes == type_id_tag_bytes:
905
+ type_id, pos = local_DecodeVarint(buffer, pos)
906
+ elif tag_bytes == message_tag_bytes:
907
+ size, message_start = local_DecodeVarint(buffer, pos)
908
+ pos = message_end = message_start + size
909
+ elif tag_bytes == item_end_tag_bytes:
910
+ break
911
+ else:
912
+ field_number, wire_type = DecodeTag(tag_bytes)
913
+ _, pos = _DecodeUnknownField(buffer, pos, end, field_number, wire_type)
914
+ if pos == -1:
915
+ raise _DecodeError('Unexpected end-group tag.')
916
+
917
+ if pos > end:
918
+ raise _DecodeError('Truncated message.')
919
+
920
+ if type_id == -1:
921
+ raise _DecodeError('MessageSet item missing type_id.')
922
+ if message_start == -1:
923
+ raise _DecodeError('MessageSet item missing message.')
924
+
925
+ extension = message.Extensions._FindExtensionByNumber(type_id)
926
+ # pylint: disable=protected-access
927
+ if extension is not None:
928
+ value = field_dict.get(extension)
929
+ if value is None:
930
+ message_type = extension.message_type
931
+ if not hasattr(message_type, '_concrete_class'):
932
+ message_factory.GetMessageClass(message_type)
933
+ value = field_dict.setdefault(extension, message_type._concrete_class())
934
+ current_depth += 1
935
+ if current_depth > _recursion_limit:
936
+ raise _DecodeError('Error parsing message: too many levels of nesting.')
937
+ if (
938
+ value._InternalParse(
939
+ buffer, message_start, message_end, current_depth
940
+ )
941
+ != message_end
942
+ ):
943
+ # The only reason _InternalParse would return early is if it encountered
944
+ # an end-group tag.
945
+ raise _DecodeError('Unexpected end-group tag.')
946
+ current_depth -= 1
947
+ else:
948
+ if not message._unknown_fields:
949
+ message._unknown_fields = []
950
+ message._unknown_fields.append(
951
+ (MESSAGE_SET_ITEM_TAG, buffer[message_set_item_start:pos].tobytes())
952
+ )
953
+ # pylint: enable=protected-access
954
+
955
+ return pos
956
+
957
+ return DecodeItem
958
+
959
+
960
+ def UnknownMessageSetItemDecoder():
961
+ """Returns a decoder for a Unknown MessageSet item."""
962
+
963
+ type_id_tag_bytes = encoder.TagBytes(2, wire_format.WIRETYPE_VARINT)
964
+ message_tag_bytes = encoder.TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)
965
+ item_end_tag_bytes = encoder.TagBytes(1, wire_format.WIRETYPE_END_GROUP)
966
+
967
+ def DecodeUnknownItem(buffer):
968
+ pos = 0
969
+ end = len(buffer)
970
+ message_start = -1
971
+ message_end = -1
972
+ while 1:
973
+ tag_bytes, pos = ReadTag(buffer, pos)
974
+ if tag_bytes == type_id_tag_bytes:
975
+ type_id, pos = _DecodeVarint(buffer, pos)
976
+ elif tag_bytes == message_tag_bytes:
977
+ size, message_start = _DecodeVarint(buffer, pos)
978
+ pos = message_end = message_start + size
979
+ elif tag_bytes == item_end_tag_bytes:
980
+ break
981
+ else:
982
+ field_number, wire_type = DecodeTag(tag_bytes)
983
+ _, pos = _DecodeUnknownField(buffer, pos, end, field_number, wire_type)
984
+ if pos == -1:
985
+ raise _DecodeError('Unexpected end-group tag.')
986
+
987
+ if pos > end:
988
+ raise _DecodeError('Truncated message.')
989
+
990
+ if type_id == -1:
991
+ raise _DecodeError('MessageSet item missing type_id.')
992
+ if message_start == -1:
993
+ raise _DecodeError('MessageSet item missing message.')
994
+
995
+ return (type_id, buffer[message_start:message_end].tobytes())
996
+
997
+ return DecodeUnknownItem
998
+
999
+
1000
+ # --------------------------------------------------------------------
1001
+
1002
+
1003
+ def MapDecoder(field_descriptor, new_default, is_message_map):
1004
+ """Returns a decoder for a map field."""
1005
+
1006
+ key = field_descriptor
1007
+ tag_bytes = encoder.TagBytes(
1008
+ field_descriptor.number, wire_format.WIRETYPE_LENGTH_DELIMITED
1009
+ )
1010
+ tag_len = len(tag_bytes)
1011
+ local_DecodeVarint = _DecodeVarint
1012
+ # Can't read _concrete_class yet; might not be initialized.
1013
+ message_type = field_descriptor.message_type
1014
+
1015
+ def DecodeMap(buffer, pos, end, message, field_dict, current_depth=0):
1016
+ submsg = message_type._concrete_class()
1017
+ value = field_dict.get(key)
1018
+ if value is None:
1019
+ value = field_dict.setdefault(key, new_default(message))
1020
+ while 1:
1021
+ # Read length.
1022
+ size, pos = local_DecodeVarint(buffer, pos)
1023
+ new_pos = pos + size
1024
+ if new_pos > end:
1025
+ raise _DecodeError('Truncated message.')
1026
+ # Read sub-message.
1027
+ submsg.Clear()
1028
+ current_depth += 1
1029
+ if current_depth > _recursion_limit:
1030
+ raise _DecodeError('Error parsing message: too many levels of nesting.')
1031
+ if submsg._InternalParse(buffer, pos, new_pos, current_depth) != new_pos:
1032
+ # The only reason _InternalParse would return early is if it
1033
+ # encountered an end-group tag.
1034
+ raise _DecodeError('Unexpected end-group tag.')
1035
+ current_depth -= 1
1036
+
1037
+ if is_message_map:
1038
+ value[submsg.key].CopyFrom(submsg.value)
1039
+ else:
1040
+ value[submsg.key] = submsg.value
1041
+
1042
+ # Predict that the next tag is another copy of the same repeated field.
1043
+ pos = new_pos + tag_len
1044
+ if buffer[new_pos:pos] != tag_bytes or new_pos == end:
1045
+ # Prediction failed. Return.
1046
+ return new_pos
1047
+
1048
+ return DecodeMap
1049
+
1050
+
1051
+ def _DecodeFixed64(buffer, pos):
1052
+ """Decode a fixed64."""
1053
+ new_pos = pos + 8
1054
+ return (struct.unpack('<Q', buffer[pos:new_pos])[0], new_pos)
1055
+
1056
+
1057
+ def _DecodeFixed32(buffer, pos):
1058
+ """Decode a fixed32."""
1059
+
1060
+ new_pos = pos + 4
1061
+ return (struct.unpack('<I', buffer[pos:new_pos])[0], new_pos)
1062
+
1063
+
1064
+ DEFAULT_RECURSION_LIMIT = 100
1065
+ _recursion_limit = DEFAULT_RECURSION_LIMIT
1066
+
1067
+
1068
+ def SetRecursionLimit(new_limit):
1069
+ global _recursion_limit
1070
+ _recursion_limit = new_limit
1071
+
1072
+
1073
+ def _DecodeUnknownFieldSet(buffer, pos, end_pos=None, current_depth=0):
1074
+ """Decode UnknownFieldSet. Returns the UnknownFieldSet and new position."""
1075
+
1076
+ unknown_field_set = containers.UnknownFieldSet()
1077
+ while end_pos is None or pos < end_pos:
1078
+ tag_bytes, pos = ReadTag(buffer, pos)
1079
+ tag, _ = _DecodeVarint(tag_bytes, 0)
1080
+ field_number, wire_type = wire_format.UnpackTag(tag)
1081
+ if wire_type == wire_format.WIRETYPE_END_GROUP:
1082
+ break
1083
+ data, pos = _DecodeUnknownField(
1084
+ buffer, pos, end_pos, field_number, wire_type, current_depth
1085
+ )
1086
+ # pylint: disable=protected-access
1087
+ unknown_field_set._add(field_number, wire_type, data)
1088
+
1089
+ return (unknown_field_set, pos)
1090
+
1091
+
1092
+ def _DecodeUnknownField(
1093
+ buffer, pos, end_pos, field_number, wire_type, current_depth=0
1094
+ ):
1095
+ """Decode a unknown field. Returns the UnknownField and new position."""
1096
+
1097
+ if wire_type == wire_format.WIRETYPE_VARINT:
1098
+ data, pos = _DecodeVarint(buffer, pos)
1099
+ elif wire_type == wire_format.WIRETYPE_FIXED64:
1100
+ data, pos = _DecodeFixed64(buffer, pos)
1101
+ elif wire_type == wire_format.WIRETYPE_FIXED32:
1102
+ data, pos = _DecodeFixed32(buffer, pos)
1103
+ elif wire_type == wire_format.WIRETYPE_LENGTH_DELIMITED:
1104
+ size, pos = _DecodeVarint(buffer, pos)
1105
+ data = buffer[pos : pos + size].tobytes()
1106
+ pos += size
1107
+ elif wire_type == wire_format.WIRETYPE_START_GROUP:
1108
+ end_tag_bytes = encoder.TagBytes(
1109
+ field_number, wire_format.WIRETYPE_END_GROUP
1110
+ )
1111
+ current_depth += 1
1112
+ if current_depth >= _recursion_limit:
1113
+ raise _DecodeError('Error parsing message: too many levels of nesting.')
1114
+ data, pos = _DecodeUnknownFieldSet(buffer, pos, end_pos, current_depth)
1115
+ current_depth -= 1
1116
+ # Check end tag.
1117
+ if buffer[pos - len(end_tag_bytes) : pos] != end_tag_bytes:
1118
+ raise _DecodeError('Missing group end tag.')
1119
+ elif wire_type == wire_format.WIRETYPE_END_GROUP:
1120
+ return (0, -1)
1121
+ else:
1122
+ raise _DecodeError('Wrong wire type in tag.')
1123
+
1124
+ if pos > end_pos:
1125
+ raise _DecodeError('Truncated message.')
1126
+
1127
+ return (data, pos)
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/encoder.py ADDED
@@ -0,0 +1,931 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Code for encoding protocol message primitives.
8
+
9
+ Contains the logic for encoding every logical protocol field type
10
+ into one of the 5 physical wire types.
11
+
12
+ This code is designed to push the Python interpreter's performance to the
13
+ limits.
14
+
15
+ The basic idea is that at startup time, for every field (i.e. every
16
+ FieldDescriptor) we construct two functions: a "sizer" and an "encoder". The
17
+ sizer takes a value of this field's type and computes its byte size. The
18
+ encoder takes a writer function and a value. It encodes the value into byte
19
+ strings and invokes the writer function to write those strings. Typically the
20
+ writer function is the write() method of a BytesIO.
21
+
22
+ We try to do as much work as possible when constructing the writer and the
23
+ sizer rather than when calling them. In particular:
24
+ * We copy any needed global functions to local variables, so that we do not need
25
+ to do costly global table lookups at runtime.
26
+ * Similarly, we try to do any attribute lookups at startup time if possible.
27
+ * Every field's tag is encoded to bytes at startup, since it can't change at
28
+ runtime.
29
+ * Whatever component of the field size we can compute at startup, we do.
30
+ * We *avoid* sharing code if doing so would make the code slower and not sharing
31
+ does not burden us too much. For example, encoders for repeated fields do
32
+ not just call the encoders for singular fields in a loop because this would
33
+ add an extra function call overhead for every loop iteration; instead, we
34
+ manually inline the single-value encoder into the loop.
35
+ * If a Python function lacks a return statement, Python actually generates
36
+ instructions to pop the result of the last statement off the stack, push
37
+ None onto the stack, and then return that. If we really don't care what
38
+ value is returned, then we can save two instructions by returning the
39
+ result of the last statement. It looks funny but it helps.
40
+ * We assume that type and bounds checking has happened at a higher level.
41
+ """
42
+
43
+ __author__ = 'kenton@google.com (Kenton Varda)'
44
+
45
+ import struct
46
+
47
+ from google.protobuf.internal import wire_format
48
+
49
+ # This will overflow and thus become IEEE-754 "infinity". We would use
50
+ # "float('inf')" but it doesn't work on Windows pre-Python-2.6.
51
+ _POS_INF = 1e10000
52
+ _NEG_INF = -_POS_INF
53
+
54
+
55
+ def _VarintSize(value):
56
+ """Compute the size of a varint value."""
57
+ if value <= 0x7F:
58
+ return 1
59
+ if value <= 0x3FFF:
60
+ return 2
61
+ if value <= 0x1FFFFF:
62
+ return 3
63
+ if value <= 0xFFFFFFF:
64
+ return 4
65
+ if value <= 0x7FFFFFFFF:
66
+ return 5
67
+ if value <= 0x3FFFFFFFFFF:
68
+ return 6
69
+ if value <= 0x1FFFFFFFFFFFF:
70
+ return 7
71
+ if value <= 0xFFFFFFFFFFFFFF:
72
+ return 8
73
+ if value <= 0x7FFFFFFFFFFFFFFF:
74
+ return 9
75
+ return 10
76
+
77
+
78
+ def _SignedVarintSize(value):
79
+ """Compute the size of a signed varint value."""
80
+ if value < 0:
81
+ return 10
82
+ if value <= 0x7F:
83
+ return 1
84
+ if value <= 0x3FFF:
85
+ return 2
86
+ if value <= 0x1FFFFF:
87
+ return 3
88
+ if value <= 0xFFFFFFF:
89
+ return 4
90
+ if value <= 0x7FFFFFFFF:
91
+ return 5
92
+ if value <= 0x3FFFFFFFFFF:
93
+ return 6
94
+ if value <= 0x1FFFFFFFFFFFF:
95
+ return 7
96
+ if value <= 0xFFFFFFFFFFFFFF:
97
+ return 8
98
+ if value <= 0x7FFFFFFFFFFFFFFF:
99
+ return 9
100
+ return 10
101
+
102
+
103
+ def _TagSize(field_number):
104
+ """Returns the number of bytes required to serialize a tag with this field
105
+
106
+ number.
107
+ """
108
+ # Just pass in type 0, since the type won't affect the tag+type size.
109
+ return _VarintSize(wire_format.PackTag(field_number, 0))
110
+
111
+
112
+ # --------------------------------------------------------------------
113
+ # In this section we define some generic sizers. Each of these functions
114
+ # takes parameters specific to a particular field type, e.g. int32 or fixed64.
115
+ # It returns another function which in turn takes parameters specific to a
116
+ # particular field, e.g. the field number and whether it is repeated or packed.
117
+ # Look at the next section to see how these are used.
118
+
119
+
120
+ def _SimpleSizer(compute_value_size):
121
+ """A sizer which uses the function compute_value_size to compute the size of
122
+
123
+ each value. Typically compute_value_size is _VarintSize.
124
+ """
125
+
126
+ def SpecificSizer(field_number, is_repeated, is_packed):
127
+ tag_size = _TagSize(field_number)
128
+ if is_packed:
129
+ local_VarintSize = _VarintSize
130
+
131
+ def PackedFieldSize(value):
132
+ result = 0
133
+ for element in value:
134
+ result += compute_value_size(element)
135
+ return result + local_VarintSize(result) + tag_size
136
+
137
+ return PackedFieldSize
138
+ elif is_repeated:
139
+
140
+ def RepeatedFieldSize(value):
141
+ result = tag_size * len(value)
142
+ for element in value:
143
+ result += compute_value_size(element)
144
+ return result
145
+
146
+ return RepeatedFieldSize
147
+ else:
148
+
149
+ def FieldSize(value):
150
+ return tag_size + compute_value_size(value)
151
+
152
+ return FieldSize
153
+
154
+ return SpecificSizer
155
+
156
+
157
+ def _ModifiedSizer(compute_value_size, modify_value):
158
+ """Like SimpleSizer, but modify_value is invoked on each value before it is
159
+
160
+ passed to compute_value_size. modify_value is typically ZigZagEncode.
161
+ """
162
+
163
+ def SpecificSizer(field_number, is_repeated, is_packed):
164
+ tag_size = _TagSize(field_number)
165
+ if is_packed:
166
+ local_VarintSize = _VarintSize
167
+
168
+ def PackedFieldSize(value):
169
+ result = 0
170
+ for element in value:
171
+ result += compute_value_size(modify_value(element))
172
+ return result + local_VarintSize(result) + tag_size
173
+
174
+ return PackedFieldSize
175
+ elif is_repeated:
176
+
177
+ def RepeatedFieldSize(value):
178
+ result = tag_size * len(value)
179
+ for element in value:
180
+ result += compute_value_size(modify_value(element))
181
+ return result
182
+
183
+ return RepeatedFieldSize
184
+ else:
185
+
186
+ def FieldSize(value):
187
+ return tag_size + compute_value_size(modify_value(value))
188
+
189
+ return FieldSize
190
+
191
+ return SpecificSizer
192
+
193
+
194
+ def _FixedSizer(value_size):
195
+ """Like _SimpleSizer except for a fixed-size field.
196
+
197
+ The input is the size of one value.
198
+ """
199
+
200
+ def SpecificSizer(field_number, is_repeated, is_packed):
201
+ tag_size = _TagSize(field_number)
202
+ if is_packed:
203
+ local_VarintSize = _VarintSize
204
+
205
+ def PackedFieldSize(value):
206
+ result = len(value) * value_size
207
+ return result + local_VarintSize(result) + tag_size
208
+
209
+ return PackedFieldSize
210
+ elif is_repeated:
211
+ element_size = value_size + tag_size
212
+
213
+ def RepeatedFieldSize(value):
214
+ return len(value) * element_size
215
+
216
+ return RepeatedFieldSize
217
+ else:
218
+ field_size = value_size + tag_size
219
+
220
+ def FieldSize(value):
221
+ return field_size
222
+
223
+ return FieldSize
224
+
225
+ return SpecificSizer
226
+
227
+
228
+ # ====================================================================
229
+ # Here we declare a sizer constructor for each field type. Each "sizer
230
+ # constructor" is a function that takes (field_number, is_repeated, is_packed)
231
+ # as parameters and returns a sizer, which in turn takes a field value as
232
+ # a parameter and returns its encoded size.
233
+
234
+ Int32Sizer = Int64Sizer = EnumSizer = _SimpleSizer(_SignedVarintSize)
235
+
236
+ UInt32Sizer = UInt64Sizer = _SimpleSizer(_VarintSize)
237
+
238
+ SInt32Sizer = SInt64Sizer = _ModifiedSizer(
239
+ _SignedVarintSize, wire_format.ZigZagEncode
240
+ )
241
+
242
+ Fixed32Sizer = SFixed32Sizer = FloatSizer = _FixedSizer(4)
243
+ Fixed64Sizer = SFixed64Sizer = DoubleSizer = _FixedSizer(8)
244
+
245
+ BoolSizer = _FixedSizer(1)
246
+
247
+
248
+ def StringSizer(field_number, is_repeated, is_packed):
249
+ """Returns a sizer for a string field."""
250
+
251
+ tag_size = _TagSize(field_number)
252
+ local_VarintSize = _VarintSize
253
+ local_len = len
254
+ assert not is_packed
255
+ if is_repeated:
256
+
257
+ def RepeatedFieldSize(value):
258
+ result = tag_size * len(value)
259
+ for element in value:
260
+ l = local_len(element.encode('utf-8'))
261
+ result += local_VarintSize(l) + l
262
+ return result
263
+
264
+ return RepeatedFieldSize
265
+ else:
266
+
267
+ def FieldSize(value):
268
+ l = local_len(value.encode('utf-8'))
269
+ return tag_size + local_VarintSize(l) + l
270
+
271
+ return FieldSize
272
+
273
+
274
+ def BytesSizer(field_number, is_repeated, is_packed):
275
+ """Returns a sizer for a bytes field."""
276
+
277
+ tag_size = _TagSize(field_number)
278
+ local_VarintSize = _VarintSize
279
+ local_len = len
280
+ assert not is_packed
281
+ if is_repeated:
282
+
283
+ def RepeatedFieldSize(value):
284
+ result = tag_size * len(value)
285
+ for element in value:
286
+ l = local_len(element)
287
+ result += local_VarintSize(l) + l
288
+ return result
289
+
290
+ return RepeatedFieldSize
291
+ else:
292
+
293
+ def FieldSize(value):
294
+ l = local_len(value)
295
+ return tag_size + local_VarintSize(l) + l
296
+
297
+ return FieldSize
298
+
299
+
300
+ def GroupSizer(field_number, is_repeated, is_packed):
301
+ """Returns a sizer for a group field."""
302
+
303
+ tag_size = _TagSize(field_number) * 2
304
+ assert not is_packed
305
+ if is_repeated:
306
+
307
+ def RepeatedFieldSize(value):
308
+ result = tag_size * len(value)
309
+ for element in value:
310
+ result += element.ByteSize()
311
+ return result
312
+
313
+ return RepeatedFieldSize
314
+ else:
315
+
316
+ def FieldSize(value):
317
+ return tag_size + value.ByteSize()
318
+
319
+ return FieldSize
320
+
321
+
322
+ def MessageSizer(field_number, is_repeated, is_packed):
323
+ """Returns a sizer for a message field."""
324
+
325
+ tag_size = _TagSize(field_number)
326
+ local_VarintSize = _VarintSize
327
+ assert not is_packed
328
+ if is_repeated:
329
+
330
+ def RepeatedFieldSize(value):
331
+ result = tag_size * len(value)
332
+ for element in value:
333
+ l = element.ByteSize()
334
+ result += local_VarintSize(l) + l
335
+ return result
336
+
337
+ return RepeatedFieldSize
338
+ else:
339
+
340
+ def FieldSize(value):
341
+ l = value.ByteSize()
342
+ return tag_size + local_VarintSize(l) + l
343
+
344
+ return FieldSize
345
+
346
+
347
+ # --------------------------------------------------------------------
348
+ # MessageSet is special: it needs custom logic to compute its size properly.
349
+
350
+
351
+ def MessageSetItemSizer(field_number):
352
+ """Returns a sizer for extensions of MessageSet.
353
+
354
+ The message set message looks like this:
355
+ message MessageSet {
356
+ repeated group Item = 1 {
357
+ required int32 type_id = 2;
358
+ required string message = 3;
359
+ }
360
+ }
361
+ """
362
+ static_size = (
363
+ _TagSize(1) * 2 + _TagSize(2) + _VarintSize(field_number) + _TagSize(3)
364
+ )
365
+ local_VarintSize = _VarintSize
366
+
367
+ def FieldSize(value):
368
+ l = value.ByteSize()
369
+ return static_size + local_VarintSize(l) + l
370
+
371
+ return FieldSize
372
+
373
+
374
+ # --------------------------------------------------------------------
375
+ # Map is special: it needs custom logic to compute its size properly.
376
+
377
+
378
+ def MapSizer(field_descriptor, key_sizer, value_sizer):
379
+ """Returns a sizer for a map field."""
380
+
381
+ def FieldSize(map_value):
382
+ tag_size = _TagSize(field_descriptor.number)
383
+ local_VarintSize = _VarintSize
384
+
385
+ total = 0
386
+ for key in map_value:
387
+ val = map_value[key]
388
+ entry_size = key_sizer(key) + value_sizer(val)
389
+ total += tag_size + local_VarintSize(entry_size) + entry_size
390
+
391
+ return total
392
+
393
+ return FieldSize
394
+
395
+
396
+ # ====================================================================
397
+ # Encoders!
398
+
399
+
400
+ def _VarintEncoder():
401
+ """Return an encoder for a basic varint value (does not include tag)."""
402
+
403
+ local_int2byte = struct.Struct('>B').pack
404
+
405
+ def EncodeVarint(write, value, unused_deterministic=None):
406
+ bits = value & 0x7F
407
+ value >>= 7
408
+ while value:
409
+ write(local_int2byte(0x80 | bits))
410
+ bits = value & 0x7F
411
+ value >>= 7
412
+ return write(local_int2byte(bits))
413
+
414
+ return EncodeVarint
415
+
416
+
417
+ def _SignedVarintEncoder():
418
+ """Return an encoder for a basic signed varint value (does not include
419
+
420
+ tag).
421
+ """
422
+
423
+ local_int2byte = struct.Struct('>B').pack
424
+
425
+ def EncodeSignedVarint(write, value, unused_deterministic=None):
426
+ if value < 0:
427
+ value += 1 << 64
428
+ bits = value & 0x7F
429
+ value >>= 7
430
+ while value:
431
+ write(local_int2byte(0x80 | bits))
432
+ bits = value & 0x7F
433
+ value >>= 7
434
+ return write(local_int2byte(bits))
435
+
436
+ return EncodeSignedVarint
437
+
438
+
439
+ _EncodeVarint = _VarintEncoder()
440
+ _EncodeSignedVarint = _SignedVarintEncoder()
441
+
442
+
443
+ def _VarintBytes(value):
444
+ """Encode the given integer as a varint and return the bytes.
445
+
446
+ This is only called at startup time so it doesn't need to be fast.
447
+ """
448
+
449
+ pieces = []
450
+ _EncodeVarint(pieces.append, value, True)
451
+ return b''.join(pieces)
452
+
453
+
454
+ def TagBytes(field_number, wire_type):
455
+ """Encode the given tag and return the bytes. Only called at startup."""
456
+
457
+ return bytes(_VarintBytes(wire_format.PackTag(field_number, wire_type)))
458
+
459
+
460
+ # --------------------------------------------------------------------
461
+ # As with sizers (see above), we have a number of common encoder
462
+ # implementations.
463
+
464
+
465
+ def _SimpleEncoder(wire_type, encode_value, compute_value_size):
466
+ """Return a constructor for an encoder for fields of a particular type.
467
+
468
+ Args:
469
+ wire_type: The field's wire type, for encoding tags.
470
+ encode_value: A function which encodes an individual value, e.g.
471
+ _EncodeVarint().
472
+ compute_value_size: A function which computes the size of an individual
473
+ value, e.g. _VarintSize().
474
+ """
475
+
476
+ def SpecificEncoder(field_number, is_repeated, is_packed):
477
+ if is_packed:
478
+ tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
479
+ local_EncodeVarint = _EncodeVarint
480
+
481
+ def EncodePackedField(write, value, deterministic):
482
+ write(tag_bytes)
483
+ size = 0
484
+ for element in value:
485
+ size += compute_value_size(element)
486
+ local_EncodeVarint(write, size, deterministic)
487
+ for element in value:
488
+ encode_value(write, element, deterministic)
489
+
490
+ return EncodePackedField
491
+ elif is_repeated:
492
+ tag_bytes = TagBytes(field_number, wire_type)
493
+
494
+ def EncodeRepeatedField(write, value, deterministic):
495
+ for element in value:
496
+ write(tag_bytes)
497
+ encode_value(write, element, deterministic)
498
+
499
+ return EncodeRepeatedField
500
+ else:
501
+ tag_bytes = TagBytes(field_number, wire_type)
502
+
503
+ def EncodeField(write, value, deterministic):
504
+ write(tag_bytes)
505
+ return encode_value(write, value, deterministic)
506
+
507
+ return EncodeField
508
+
509
+ return SpecificEncoder
510
+
511
+
512
+ def _ModifiedEncoder(wire_type, encode_value, compute_value_size, modify_value):
513
+ """Like SimpleEncoder but additionally invokes modify_value on every value
514
+
515
+ before passing it to encode_value. Usually modify_value is ZigZagEncode.
516
+ """
517
+
518
+ def SpecificEncoder(field_number, is_repeated, is_packed):
519
+ if is_packed:
520
+ tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
521
+ local_EncodeVarint = _EncodeVarint
522
+
523
+ def EncodePackedField(write, value, deterministic):
524
+ write(tag_bytes)
525
+ size = 0
526
+ for element in value:
527
+ size += compute_value_size(modify_value(element))
528
+ local_EncodeVarint(write, size, deterministic)
529
+ for element in value:
530
+ encode_value(write, modify_value(element), deterministic)
531
+
532
+ return EncodePackedField
533
+ elif is_repeated:
534
+ tag_bytes = TagBytes(field_number, wire_type)
535
+
536
+ def EncodeRepeatedField(write, value, deterministic):
537
+ for element in value:
538
+ write(tag_bytes)
539
+ encode_value(write, modify_value(element), deterministic)
540
+
541
+ return EncodeRepeatedField
542
+ else:
543
+ tag_bytes = TagBytes(field_number, wire_type)
544
+
545
+ def EncodeField(write, value, deterministic):
546
+ write(tag_bytes)
547
+ return encode_value(write, modify_value(value), deterministic)
548
+
549
+ return EncodeField
550
+
551
+ return SpecificEncoder
552
+
553
+
554
+ def _StructPackEncoder(wire_type, format):
555
+ """Return a constructor for an encoder for a fixed-width field.
556
+
557
+ Args:
558
+ wire_type: The field's wire type, for encoding tags.
559
+ format: The format string to pass to struct.pack().
560
+ """
561
+
562
+ value_size = struct.calcsize(format)
563
+
564
+ def SpecificEncoder(field_number, is_repeated, is_packed):
565
+ local_struct_pack = struct.pack
566
+ if is_packed:
567
+ tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
568
+ local_EncodeVarint = _EncodeVarint
569
+
570
+ def EncodePackedField(write, value, deterministic):
571
+ write(tag_bytes)
572
+ local_EncodeVarint(write, len(value) * value_size, deterministic)
573
+ for element in value:
574
+ write(local_struct_pack(format, element))
575
+
576
+ return EncodePackedField
577
+ elif is_repeated:
578
+ tag_bytes = TagBytes(field_number, wire_type)
579
+
580
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
581
+ for element in value:
582
+ write(tag_bytes)
583
+ write(local_struct_pack(format, element))
584
+
585
+ return EncodeRepeatedField
586
+ else:
587
+ tag_bytes = TagBytes(field_number, wire_type)
588
+
589
+ def EncodeField(write, value, unused_deterministic=None):
590
+ write(tag_bytes)
591
+ return write(local_struct_pack(format, value))
592
+
593
+ return EncodeField
594
+
595
+ return SpecificEncoder
596
+
597
+
598
+ def _FloatingPointEncoder(wire_type, format):
599
+ """Return a constructor for an encoder for float fields.
600
+
601
+ This is like StructPackEncoder, but catches errors that may be due to
602
+ passing non-finite floating-point values to struct.pack, and makes a
603
+ second attempt to encode those values.
604
+
605
+ Args:
606
+ wire_type: The field's wire type, for encoding tags.
607
+ format: The format string to pass to struct.pack().
608
+ """
609
+
610
+ value_size = struct.calcsize(format)
611
+ if value_size == 4:
612
+
613
+ def EncodeNonFiniteOrRaise(write, value):
614
+ # Remember that the serialized form uses little-endian byte order.
615
+ if value == _POS_INF:
616
+ write(b'\x00\x00\x80\x7F')
617
+ elif value == _NEG_INF:
618
+ write(b'\x00\x00\x80\xFF')
619
+ elif value != value: # NaN
620
+ write(b'\x00\x00\xC0\x7F')
621
+ else:
622
+ raise
623
+
624
+ elif value_size == 8:
625
+
626
+ def EncodeNonFiniteOrRaise(write, value):
627
+ if value == _POS_INF:
628
+ write(b'\x00\x00\x00\x00\x00\x00\xF0\x7F')
629
+ elif value == _NEG_INF:
630
+ write(b'\x00\x00\x00\x00\x00\x00\xF0\xFF')
631
+ elif value != value: # NaN
632
+ write(b'\x00\x00\x00\x00\x00\x00\xF8\x7F')
633
+ else:
634
+ raise
635
+
636
+ else:
637
+ raise ValueError(
638
+ "Can't encode floating-point values that are "
639
+ '%d bytes long (only 4 or 8)' % value_size
640
+ )
641
+
642
+ def SpecificEncoder(field_number, is_repeated, is_packed):
643
+ local_struct_pack = struct.pack
644
+ if is_packed:
645
+ tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
646
+ local_EncodeVarint = _EncodeVarint
647
+
648
+ def EncodePackedField(write, value, deterministic):
649
+ write(tag_bytes)
650
+ local_EncodeVarint(write, len(value) * value_size, deterministic)
651
+ for element in value:
652
+ # This try/except block is going to be faster than any code that
653
+ # we could write to check whether element is finite.
654
+ try:
655
+ write(local_struct_pack(format, element))
656
+ except SystemError:
657
+ EncodeNonFiniteOrRaise(write, element)
658
+
659
+ return EncodePackedField
660
+ elif is_repeated:
661
+ tag_bytes = TagBytes(field_number, wire_type)
662
+
663
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
664
+ for element in value:
665
+ write(tag_bytes)
666
+ try:
667
+ write(local_struct_pack(format, element))
668
+ except SystemError:
669
+ EncodeNonFiniteOrRaise(write, element)
670
+
671
+ return EncodeRepeatedField
672
+ else:
673
+ tag_bytes = TagBytes(field_number, wire_type)
674
+
675
+ def EncodeField(write, value, unused_deterministic=None):
676
+ write(tag_bytes)
677
+ try:
678
+ write(local_struct_pack(format, value))
679
+ except SystemError:
680
+ EncodeNonFiniteOrRaise(write, value)
681
+
682
+ return EncodeField
683
+
684
+ return SpecificEncoder
685
+
686
+
687
+ # ====================================================================
688
+ # Here we declare an encoder constructor for each field type. These work
689
+ # very similarly to sizer constructors, described earlier.
690
+
691
+ Int32Encoder = Int64Encoder = EnumEncoder = _SimpleEncoder(
692
+ wire_format.WIRETYPE_VARINT, _EncodeSignedVarint, _SignedVarintSize
693
+ )
694
+
695
+ UInt32Encoder = UInt64Encoder = _SimpleEncoder(
696
+ wire_format.WIRETYPE_VARINT, _EncodeVarint, _VarintSize
697
+ )
698
+
699
+ SInt32Encoder = SInt64Encoder = _ModifiedEncoder(
700
+ wire_format.WIRETYPE_VARINT,
701
+ _EncodeVarint,
702
+ _VarintSize,
703
+ wire_format.ZigZagEncode,
704
+ )
705
+
706
+ # Note that Python conveniently guarantees that when using the '<' prefix on
707
+ # formats, they will also have the same size across all platforms (as opposed
708
+ # to without the prefix, where their sizes depend on the C compiler's basic
709
+ # type sizes).
710
+ Fixed32Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED32, '<I')
711
+ Fixed64Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED64, '<Q')
712
+ SFixed32Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED32, '<i')
713
+ SFixed64Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED64, '<q')
714
+ FloatEncoder = _FloatingPointEncoder(wire_format.WIRETYPE_FIXED32, '<f')
715
+ DoubleEncoder = _FloatingPointEncoder(wire_format.WIRETYPE_FIXED64, '<d')
716
+
717
+
718
+ def BoolEncoder(field_number, is_repeated, is_packed):
719
+ """Returns an encoder for a boolean field."""
720
+
721
+ false_byte = b'\x00'
722
+ true_byte = b'\x01'
723
+ if is_packed:
724
+ tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
725
+ local_EncodeVarint = _EncodeVarint
726
+
727
+ def EncodePackedField(write, value, deterministic):
728
+ write(tag_bytes)
729
+ local_EncodeVarint(write, len(value), deterministic)
730
+ for element in value:
731
+ if element:
732
+ write(true_byte)
733
+ else:
734
+ write(false_byte)
735
+
736
+ return EncodePackedField
737
+ elif is_repeated:
738
+ tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
739
+
740
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
741
+ for element in value:
742
+ write(tag_bytes)
743
+ if element:
744
+ write(true_byte)
745
+ else:
746
+ write(false_byte)
747
+
748
+ return EncodeRepeatedField
749
+ else:
750
+ tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
751
+
752
+ def EncodeField(write, value, unused_deterministic=None):
753
+ write(tag_bytes)
754
+ if value:
755
+ return write(true_byte)
756
+ return write(false_byte)
757
+
758
+ return EncodeField
759
+
760
+
761
+ def StringEncoder(field_number, is_repeated, is_packed):
762
+ """Returns an encoder for a string field."""
763
+
764
+ tag = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
765
+ local_EncodeVarint = _EncodeVarint
766
+ local_len = len
767
+ assert not is_packed
768
+ if is_repeated:
769
+
770
+ def EncodeRepeatedField(write, value, deterministic):
771
+ for element in value:
772
+ encoded = element.encode('utf-8')
773
+ write(tag)
774
+ local_EncodeVarint(write, local_len(encoded), deterministic)
775
+ write(encoded)
776
+
777
+ return EncodeRepeatedField
778
+ else:
779
+
780
+ def EncodeField(write, value, deterministic):
781
+ encoded = value.encode('utf-8')
782
+ write(tag)
783
+ local_EncodeVarint(write, local_len(encoded), deterministic)
784
+ return write(encoded)
785
+
786
+ return EncodeField
787
+
788
+
789
+ def BytesEncoder(field_number, is_repeated, is_packed):
790
+ """Returns an encoder for a bytes field."""
791
+
792
+ tag = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
793
+ local_EncodeVarint = _EncodeVarint
794
+ local_len = len
795
+ assert not is_packed
796
+ if is_repeated:
797
+
798
+ def EncodeRepeatedField(write, value, deterministic):
799
+ for element in value:
800
+ write(tag)
801
+ local_EncodeVarint(write, local_len(element), deterministic)
802
+ write(element)
803
+
804
+ return EncodeRepeatedField
805
+ else:
806
+
807
+ def EncodeField(write, value, deterministic):
808
+ write(tag)
809
+ local_EncodeVarint(write, local_len(value), deterministic)
810
+ return write(value)
811
+
812
+ return EncodeField
813
+
814
+
815
+ def GroupEncoder(field_number, is_repeated, is_packed):
816
+ """Returns an encoder for a group field."""
817
+
818
+ start_tag = TagBytes(field_number, wire_format.WIRETYPE_START_GROUP)
819
+ end_tag = TagBytes(field_number, wire_format.WIRETYPE_END_GROUP)
820
+ assert not is_packed
821
+ if is_repeated:
822
+
823
+ def EncodeRepeatedField(write, value, deterministic):
824
+ for element in value:
825
+ write(start_tag)
826
+ element._InternalSerialize(write, deterministic)
827
+ write(end_tag)
828
+
829
+ return EncodeRepeatedField
830
+ else:
831
+
832
+ def EncodeField(write, value, deterministic):
833
+ write(start_tag)
834
+ value._InternalSerialize(write, deterministic)
835
+ return write(end_tag)
836
+
837
+ return EncodeField
838
+
839
+
840
+ def MessageEncoder(field_number, is_repeated, is_packed):
841
+ """Returns an encoder for a message field."""
842
+
843
+ tag = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
844
+ local_EncodeVarint = _EncodeVarint
845
+ assert not is_packed
846
+ if is_repeated:
847
+
848
+ def EncodeRepeatedField(write, value, deterministic):
849
+ for element in value:
850
+ write(tag)
851
+ local_EncodeVarint(write, element.ByteSize(), deterministic)
852
+ element._InternalSerialize(write, deterministic)
853
+
854
+ return EncodeRepeatedField
855
+ else:
856
+
857
+ def EncodeField(write, value, deterministic):
858
+ write(tag)
859
+ local_EncodeVarint(write, value.ByteSize(), deterministic)
860
+ return value._InternalSerialize(write, deterministic)
861
+
862
+ return EncodeField
863
+
864
+
865
+ # --------------------------------------------------------------------
866
+ # As before, MessageSet is special.
867
+
868
+
869
+ def MessageSetItemEncoder(field_number):
870
+ """Encoder for extensions of MessageSet.
871
+
872
+ The message set message looks like this:
873
+ message MessageSet {
874
+ repeated group Item = 1 {
875
+ required int32 type_id = 2;
876
+ required string message = 3;
877
+ }
878
+ }
879
+ """
880
+ start_bytes = b''.join([
881
+ TagBytes(1, wire_format.WIRETYPE_START_GROUP),
882
+ TagBytes(2, wire_format.WIRETYPE_VARINT),
883
+ _VarintBytes(field_number),
884
+ TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED),
885
+ ])
886
+ end_bytes = TagBytes(1, wire_format.WIRETYPE_END_GROUP)
887
+ local_EncodeVarint = _EncodeVarint
888
+
889
+ def EncodeField(write, value, deterministic):
890
+ write(start_bytes)
891
+ local_EncodeVarint(write, value.ByteSize(), deterministic)
892
+ value._InternalSerialize(write, deterministic)
893
+ return write(end_bytes)
894
+
895
+ return EncodeField
896
+
897
+
898
+ # --------------------------------------------------------------------
899
+ # As before, Map is special.
900
+
901
+
902
+ def MapEncoder(
903
+ field_descriptor, key_encoder, value_encoder, key_sizer, value_sizer
904
+ ):
905
+ """Encoder for map fields.
906
+
907
+ Maps always have a wire format like this:
908
+ message MapEntry {
909
+ key_type key = 1;
910
+ value_type value = 2;
911
+ }
912
+ repeated MapEntry map = N;
913
+ """
914
+
915
+ tag_bytes = TagBytes(
916
+ field_descriptor.number, wire_format.WIRETYPE_LENGTH_DELIMITED
917
+ )
918
+ local_EncodeVarint = _EncodeVarint
919
+
920
+ def EncodeField(write, value, deterministic):
921
+ value_keys = sorted(value.keys()) if deterministic else value
922
+ for key in value_keys:
923
+ val = value[key]
924
+ entry_size = key_sizer(key) + value_sizer(val)
925
+
926
+ write(tag_bytes)
927
+ local_EncodeVarint(write, entry_size, deterministic)
928
+ key_encoder(write, key, deterministic)
929
+ value_encoder(write, val, deterministic)
930
+
931
+ return EncodeField
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/enum_type_wrapper.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """A simple wrapper around enum types to expose utility functions.
8
+
9
+ Instances are created as properties with the same name as the enum they wrap
10
+ on proto classes. For usage, see:
11
+ reflection_test.py
12
+ """
13
+
14
+ import sys
15
+ __author__ = 'rabsatt@google.com (Kevin Rabsatt)'
16
+
17
+
18
+ class EnumTypeWrapper(object):
19
+ """A utility for finding the names of enum values."""
20
+
21
+ DESCRIPTOR = None
22
+
23
+ # This is a type alias, which mypy typing stubs can type as
24
+ # a genericized parameter constrained to an int, allowing subclasses
25
+ # to be typed with more constraint in .pyi stubs
26
+ # Eg.
27
+ # def MyGeneratedEnum(Message):
28
+ # ValueType = NewType('ValueType', int)
29
+ # def Name(self, number: MyGeneratedEnum.ValueType) -> str
30
+ ValueType = int
31
+
32
+ def __init__(self, enum_type):
33
+ """Inits EnumTypeWrapper with an EnumDescriptor."""
34
+ self._enum_type = enum_type
35
+ self.DESCRIPTOR = enum_type # pylint: disable=invalid-name
36
+
37
+ def Name(self, number): # pylint: disable=invalid-name
38
+ """Returns a string containing the name of an enum value."""
39
+ try:
40
+ return self._enum_type.values_by_number[number].name
41
+ except KeyError:
42
+ pass # fall out to break exception chaining
43
+
44
+ if not isinstance(number, int):
45
+ raise TypeError(
46
+ 'Enum value for {} must be an int, but got {} {!r}.'.format(
47
+ self._enum_type.name, type(number), number
48
+ )
49
+ )
50
+ else:
51
+ # repr here to handle the odd case when you pass in a boolean.
52
+ raise ValueError(
53
+ 'Enum {} has no name defined for value {!r}'.format(
54
+ self._enum_type.name, number
55
+ )
56
+ )
57
+
58
+ def Value(self, name): # pylint: disable=invalid-name
59
+ """Returns the value corresponding to the given enum name."""
60
+ try:
61
+ return self._enum_type.values_by_name[name].number
62
+ except KeyError:
63
+ pass # fall out to break exception chaining
64
+ raise ValueError(
65
+ 'Enum {} has no value defined for name {!r}'.format(
66
+ self._enum_type.name, name
67
+ )
68
+ )
69
+
70
+ def keys(self):
71
+ """Return a list of the string names in the enum.
72
+
73
+ Returns:
74
+ A list of strs, in the order they were defined in the .proto file.
75
+ """
76
+
77
+ return [
78
+ value_descriptor.name for value_descriptor in self._enum_type.values
79
+ ]
80
+
81
+ def values(self):
82
+ """Return a list of the integer values in the enum.
83
+
84
+ Returns:
85
+ A list of ints, in the order they were defined in the .proto file.
86
+ """
87
+
88
+ return [
89
+ value_descriptor.number for value_descriptor in self._enum_type.values
90
+ ]
91
+
92
+ def items(self):
93
+ """Return a list of the (name, value) pairs of the enum.
94
+
95
+ Returns:
96
+ A list of (str, int) pairs, in the order they were defined
97
+ in the .proto file.
98
+ """
99
+ return [
100
+ (value_descriptor.name, value_descriptor.number)
101
+ for value_descriptor in self._enum_type.values
102
+ ]
103
+
104
+ def __getattr__(self, name):
105
+ """Returns the value corresponding to the given enum name."""
106
+ try:
107
+ return (
108
+ super(EnumTypeWrapper, self)
109
+ .__getattribute__('_enum_type')
110
+ .values_by_name[name]
111
+ .number
112
+ )
113
+ except KeyError:
114
+ pass # fall out to break exception chaining
115
+ raise AttributeError(
116
+ 'Enum {} has no value defined for name {!r}'.format(
117
+ self._enum_type.name, name
118
+ )
119
+ )
120
+
121
+ def __or__(self, other):
122
+ """Returns the union type of self and other."""
123
+ if sys.version_info >= (3, 10):
124
+ return type(self) | other
125
+ else:
126
+ raise NotImplementedError(
127
+ 'You may not use | on EnumTypes (or classes) below python 3.10'
128
+ )
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/extension_dict.py ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Contains _ExtensionDict class to represent extensions."""
8
+
9
+ from google.protobuf.descriptor import FieldDescriptor
10
+ from google.protobuf.internal import type_checkers
11
+
12
+
13
+ def _VerifyExtensionHandle(message, extension_handle):
14
+ """Verify that the given extension handle is valid."""
15
+
16
+ if not isinstance(extension_handle, FieldDescriptor):
17
+ raise KeyError(
18
+ 'HasExtension() expects an extension handle, got: %s' % extension_handle
19
+ )
20
+
21
+ if not extension_handle.is_extension:
22
+ raise KeyError('"%s" is not an extension.' % extension_handle.full_name)
23
+
24
+ if not extension_handle.containing_type:
25
+ raise KeyError(
26
+ '"%s" is missing a containing_type.' % extension_handle.full_name
27
+ )
28
+
29
+ if extension_handle.containing_type is not message.DESCRIPTOR:
30
+ raise KeyError(
31
+ 'Extension "%s" extends message type "%s", but this '
32
+ 'message is of type "%s".'
33
+ % (
34
+ extension_handle.full_name,
35
+ extension_handle.containing_type.full_name,
36
+ message.DESCRIPTOR.full_name,
37
+ )
38
+ )
39
+
40
+
41
+ # TODO: Unify error handling of "unknown extension" crap.
42
+ # TODO: Support iteritems()-style iteration over all
43
+ # extensions with the "has" bits turned on?
44
+ class _ExtensionDict(object):
45
+ """Dict-like container for Extension fields on proto instances.
46
+
47
+ Note that in all cases we expect extension handles to be
48
+ FieldDescriptors.
49
+ """
50
+
51
+ def __init__(self, extended_message):
52
+ """Args:
53
+
54
+ extended_message: Message instance for which we are the Extensions dict.
55
+ """
56
+ self._extended_message = extended_message
57
+
58
+ def __getitem__(self, extension_handle):
59
+ """Returns the current value of the given extension handle."""
60
+
61
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
62
+
63
+ result = self._extended_message._fields.get(extension_handle)
64
+ if result is not None:
65
+ return result
66
+
67
+ if extension_handle.is_repeated:
68
+ result = extension_handle._default_constructor(self._extended_message)
69
+ elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
70
+ message_type = extension_handle.message_type
71
+ if not hasattr(message_type, '_concrete_class'):
72
+ # pylint: disable=g-import-not-at-top
73
+ from google.protobuf import message_factory
74
+
75
+ message_factory.GetMessageClass(message_type)
76
+ if not hasattr(extension_handle.message_type, '_concrete_class'):
77
+ from google.protobuf import message_factory
78
+
79
+ message_factory.GetMessageClass(extension_handle.message_type)
80
+ result = extension_handle.message_type._concrete_class()
81
+ try:
82
+ result._SetListener(self._extended_message._listener_for_children)
83
+ except ReferenceError:
84
+ pass
85
+ else:
86
+ # Singular scalar -- just return the default without inserting into the
87
+ # dict.
88
+ return extension_handle.default_value
89
+
90
+ # Atomically check if another thread has preempted us and, if not, swap
91
+ # in the new object we just created. If someone has preempted us, we
92
+ # take that object and discard ours.
93
+ # WARNING: We are relying on setdefault() being atomic. This is true
94
+ # in CPython but we haven't investigated others. This warning appears
95
+ # in several other locations in this file.
96
+ if self._extended_message._frozen:
97
+ result._SetFrozen()
98
+ result = self._extended_message._fields.setdefault(extension_handle, result)
99
+
100
+ return result
101
+
102
+ def __eq__(self, other):
103
+ if not isinstance(other, self.__class__):
104
+ return False
105
+
106
+ my_fields = self._extended_message.ListFields()
107
+ other_fields = other._extended_message.ListFields()
108
+
109
+ # Get rid of non-extension fields.
110
+ my_fields = [field for field in my_fields if field.is_extension]
111
+ other_fields = [field for field in other_fields if field.is_extension]
112
+
113
+ return my_fields == other_fields
114
+
115
+ def __ne__(self, other):
116
+ return not self == other
117
+
118
+ def __len__(self):
119
+ fields = self._extended_message.ListFields()
120
+ # Get rid of non-extension fields.
121
+ extension_fields = [field for field in fields if field[0].is_extension]
122
+ return len(extension_fields)
123
+
124
+ def __hash__(self):
125
+ raise TypeError('unhashable object')
126
+
127
+ # Note that this is only meaningful for non-repeated, scalar extension
128
+ # fields. Note also that we may have to call _Modified() when we do
129
+ # successfully set a field this way, to set any necessary "has" bits in the
130
+ # ancestors of the extended message.
131
+ def __setitem__(self, extension_handle, value):
132
+ """If extension_handle specifies a non-repeated, scalar extension
133
+
134
+ field, sets the value of that field.
135
+ """
136
+
137
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
138
+
139
+ self._extended_message._AssureWritable()
140
+
141
+ if (
142
+ extension_handle.is_repeated
143
+ or extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE
144
+ ):
145
+ raise TypeError(
146
+ 'Cannot assign to extension "%s" because it is a repeated or '
147
+ 'composite type.'
148
+ % extension_handle.full_name
149
+ )
150
+
151
+ # It's slightly wasteful to lookup the type checker each time,
152
+ # but we expect this to be a vanishingly uncommon case anyway.
153
+ type_checker = type_checkers.GetTypeChecker(extension_handle)
154
+ # pylint: disable=protected-access
155
+ self._extended_message._fields[extension_handle] = type_checker.CheckValue(
156
+ value
157
+ )
158
+ self._extended_message._Modified()
159
+
160
+ def __delitem__(self, extension_handle):
161
+ self._extended_message.ClearExtension(extension_handle)
162
+
163
+ def _FindExtensionByName(self, name):
164
+ """Tries to find a known extension with the specified name.
165
+
166
+ Args:
167
+ name: Extension full name.
168
+
169
+ Returns:
170
+ Extension field descriptor.
171
+ """
172
+ descriptor = self._extended_message.DESCRIPTOR
173
+ extensions = descriptor.file.pool._extensions_by_name[descriptor]
174
+ return extensions.get(name, None)
175
+
176
+ def _FindExtensionByNumber(self, number):
177
+ """Tries to find a known extension with the field number.
178
+
179
+ Args:
180
+ number: Extension field number.
181
+
182
+ Returns:
183
+ Extension field descriptor.
184
+ """
185
+ descriptor = self._extended_message.DESCRIPTOR
186
+ extensions = descriptor.file.pool._extensions_by_number[descriptor]
187
+ return extensions.get(number, None)
188
+
189
+ def __iter__(self):
190
+ # Return a generator over the populated extension fields
191
+ return (
192
+ f[0] for f in self._extended_message.ListFields() if f[0].is_extension
193
+ )
194
+
195
+ def __contains__(self, extension_handle):
196
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
197
+
198
+ if extension_handle not in self._extended_message._fields:
199
+ return False
200
+
201
+ if extension_handle.is_repeated:
202
+ return bool(self._extended_message._fields.get(extension_handle))
203
+
204
+ if extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
205
+ value = self._extended_message._fields.get(extension_handle)
206
+ # pylint: disable=protected-access
207
+ return value is not None and value._is_present_in_parent
208
+
209
+ return True
Video-RSI/.venv/lib/python3.12/site-packages/google/protobuf/internal/field_mask.py ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+ """Contains FieldMask class."""
8
+
9
+ from google.protobuf.descriptor import FieldDescriptor
10
+
11
+
12
+ class FieldMask(object):
13
+ """Class for FieldMask message type."""
14
+
15
+ __slots__ = ()
16
+
17
+ def ToJsonString(self):
18
+ """Converts FieldMask to string according to ProtoJSON spec."""
19
+ camelcase_paths = []
20
+ for path in self.paths:
21
+ camelcase_paths.append(_SnakeCaseToCamelCase(path))
22
+ return ','.join(camelcase_paths)
23
+
24
+ def FromJsonString(self, value):
25
+ """Converts string to FieldMask according to ProtoJSON spec."""
26
+ if not isinstance(value, str):
27
+ raise ValueError('FieldMask JSON value not a string: {!r}'.format(value))
28
+ self.Clear()
29
+ if value:
30
+ for path in value.split(','):
31
+ self.paths.append(_CamelCaseToSnakeCase(path))
32
+
33
+ def IsValidForDescriptor(self, message_descriptor):
34
+ """Checks whether the FieldMask is valid for Message Descriptor."""
35
+ for path in self.paths:
36
+ if not _IsValidPath(message_descriptor, path):
37
+ return False
38
+ return True
39
+
40
+ def AllFieldsFromDescriptor(self, message_descriptor):
41
+ """Gets all direct fields of Message Descriptor to FieldMask."""
42
+ self.Clear()
43
+ for field in message_descriptor.fields:
44
+ self.paths.append(field.name)
45
+
46
+ def CanonicalFormFromMask(self, mask):
47
+ """Converts a FieldMask to the canonical form.
48
+
49
+ Removes paths that are covered by another path. For example,
50
+ "foo.bar" is covered by "foo" and will be removed if "foo"
51
+ is also in the FieldMask. Then sorts all paths in alphabetical order.
52
+
53
+ Args:
54
+ mask: The original FieldMask to be converted.
55
+ """
56
+ tree = _FieldMaskTree(mask)
57
+ tree.ToFieldMask(self)
58
+
59
+ def Union(self, mask1, mask2):
60
+ """Merges mask1 and mask2 into this FieldMask."""
61
+ _CheckFieldMaskMessage(mask1)
62
+ _CheckFieldMaskMessage(mask2)
63
+ tree = _FieldMaskTree(mask1)
64
+ tree.MergeFromFieldMask(mask2)
65
+ tree.ToFieldMask(self)
66
+
67
+ def Intersect(self, mask1, mask2):
68
+ """Intersects mask1 and mask2 into this FieldMask."""
69
+ _CheckFieldMaskMessage(mask1)
70
+ _CheckFieldMaskMessage(mask2)
71
+ tree = _FieldMaskTree(mask1)
72
+ intersection = _FieldMaskTree()
73
+ for path in mask2.paths:
74
+ tree.IntersectPath(path, intersection)
75
+ intersection.ToFieldMask(self)
76
+
77
+ def MergeMessage(
78
+ self,
79
+ source,
80
+ destination,
81
+ replace_message_field=False,
82
+ replace_repeated_field=False,
83
+ ):
84
+ """Merges fields specified in FieldMask from source to destination.
85
+
86
+ Args:
87
+ source: Source message.
88
+ destination: The destination message to be merged into.
89
+ replace_message_field: Replace message field if True. Merge message field
90
+ if False.
91
+ replace_repeated_field: Replace repeated field if True. Append elements of
92
+ repeated field if False.
93
+ """
94
+ tree = _FieldMaskTree(self)
95
+ tree.MergeMessage(
96
+ source, destination, replace_message_field, replace_repeated_field
97
+ )
98
+
99
+
100
+ def _IsValidPath(message_descriptor, path):
101
+ """Checks whether the path is valid for Message Descriptor."""
102
+ parts = path.split('.')
103
+ last = parts.pop()
104
+ for name in parts:
105
+ field = message_descriptor.fields_by_name.get(name)
106
+ if (
107
+ field is None
108
+ or field.is_repeated
109
+ or field.type != FieldDescriptor.TYPE_MESSAGE
110
+ ):
111
+ return False
112
+ message_descriptor = field.message_type
113
+ return last in message_descriptor.fields_by_name
114
+
115
+
116
+ def _CheckFieldMaskMessage(message):
117
+ """Raises ValueError if message is not a FieldMask."""
118
+ message_descriptor = message.DESCRIPTOR
119
+ if (
120
+ message_descriptor.name != 'FieldMask'
121
+ or message_descriptor.file.name != 'google/protobuf/field_mask.proto'
122
+ ):
123
+ raise ValueError(
124
+ 'Message {0} is not a FieldMask.'.format(message_descriptor.full_name)
125
+ )
126
+
127
+
128
+ def _SnakeCaseToCamelCase(path_name):
129
+ """Converts a path name from snake_case to camelCase."""
130
+ result = []
131
+ after_underscore = False
132
+ for c in path_name:
133
+ if c.isupper():
134
+ raise ValueError(
135
+ 'Fail to print FieldMask to Json string: Path name '
136
+ '{0} must not contain uppercase letters.'.format(path_name)
137
+ )
138
+ if after_underscore:
139
+ if c.islower():
140
+ result.append(c.upper())
141
+ after_underscore = False
142
+ else:
143
+ raise ValueError(
144
+ 'Fail to print FieldMask to Json string: The '
145
+ 'character after a "_" must be a lowercase letter '
146
+ 'in path name {0}.'.format(path_name)
147
+ )
148
+ elif c == '_':
149
+ after_underscore = True
150
+ else:
151
+ result += c
152
+
153
+ if after_underscore:
154
+ raise ValueError(
155
+ 'Fail to print FieldMask to Json string: Trailing "_" '
156
+ 'in path name {0}.'.format(path_name)
157
+ )
158
+ return ''.join(result)
159
+
160
+
161
+ def _CamelCaseToSnakeCase(path_name):
162
+ """Converts a field name from camelCase to snake_case."""
163
+ result = []
164
+ for c in path_name:
165
+ if c == '_':
166
+ raise ValueError(
167
+ 'Fail to parse FieldMask: Path name '
168
+ '{0} must not contain "_"s.'.format(path_name)
169
+ )
170
+ if c.isupper():
171
+ result += '_'
172
+ result += c.lower()
173
+ else:
174
+ result += c
175
+ return ''.join(result)
176
+
177
+
178
+ class _FieldMaskTree(object):
179
+ """Represents a FieldMask in a tree structure.
180
+
181
+ For example, given a FieldMask "foo.bar,foo.baz,bar.baz",
182
+ the FieldMaskTree will be:
183
+ [_root] -+- foo -+- bar
184
+ | |
185
+ | +- baz
186
+ |
187
+ +- bar --- baz
188
+ In the tree, each leaf node represents a field path.
189
+ """
190
+
191
+ __slots__ = ('_root',)
192
+
193
+ def __init__(self, field_mask=None):
194
+ """Initializes the tree by FieldMask."""
195
+ self._root = {}
196
+ if field_mask:
197
+ self.MergeFromFieldMask(field_mask)
198
+
199
+ def MergeFromFieldMask(self, field_mask):
200
+ """Merges a FieldMask to the tree."""
201
+ for path in field_mask.paths:
202
+ self.AddPath(path)
203
+
204
+ def AddPath(self, path):
205
+ """Adds a field path into the tree.
206
+
207
+ If the field path to add is a sub-path of an existing field path
208
+ in the tree (i.e., a leaf node), it means the tree already matches
209
+ the given path so nothing will be added to the tree. If the path
210
+ matches an existing non-leaf node in the tree, that non-leaf node
211
+ will be turned into a leaf node with all its children removed because
212
+ the path matches all the node's children. Otherwise, a new path will
213
+ be added.
214
+
215
+ Args:
216
+ path: The field path to add.
217
+ """
218
+ node = self._root
219
+ for name in path.split('.'):
220
+ if name not in node:
221
+ node[name] = {}
222
+ elif not node[name]:
223
+ # Pre-existing empty node implies we already have this entire tree.
224
+ return
225
+ node = node[name]
226
+ # Remove any sub-trees we might have had.
227
+ node.clear()
228
+
229
+ def ToFieldMask(self, field_mask):
230
+ """Converts the tree to a FieldMask."""
231
+ field_mask.Clear()
232
+ _AddFieldPaths(self._root, '', field_mask)
233
+
234
+ def IntersectPath(self, path, intersection):
235
+ """Calculates the intersection part of a field path with this tree.
236
+
237
+ Args:
238
+ path: The field path to calculates.
239
+ intersection: The out tree to record the intersection part.
240
+ """
241
+ node = self._root
242
+ for name in path.split('.'):
243
+ if name not in node:
244
+ return
245
+ elif not node[name]:
246
+ intersection.AddPath(path)
247
+ return
248
+ node = node[name]
249
+ intersection.AddLeafNodes(path, node)
250
+
251
+ def AddLeafNodes(self, prefix, node):
252
+ """Adds leaf nodes begin with prefix to this tree."""
253
+ if not node:
254
+ self.AddPath(prefix)
255
+ return
256
+ stack = [(prefix, node)]
257
+ while stack:
258
+ current_prefix, current_node = stack.pop()
259
+ if not current_node:
260
+ self.AddPath(current_prefix)
261
+ continue
262
+ for name in current_node:
263
+ child_path = current_prefix + '.' + name
264
+ stack.append((child_path, current_node[name]))
265
+
266
+ def MergeMessage(
267
+ self, source, destination, replace_message, replace_repeated
268
+ ):
269
+ """Merge all fields specified by this tree from source to destination."""
270
+ _MergeMessage(
271
+ self._root, source, destination, replace_message, replace_repeated
272
+ )
273
+
274
+
275
+ def _StrConvert(value):
276
+ """Converts value to str if it is not."""
277
+ # This file is imported by c extension and some methods like ClearField
278
+ # requires string for the field name. py2/py3 has different text
279
+ # type and may use unicode.
280
+ if not isinstance(value, str):
281
+ return value.encode('utf-8')
282
+ return value
283
+
284
+
285
+ def _MergeMessage(node, source, destination, replace_message, replace_repeated):
286
+ """Merge all fields specified by a sub-tree from source to destination."""
287
+ stack = [(node, source, destination)]
288
+ while stack:
289
+ current_node, current_source, current_destination = stack.pop()
290
+ source_descriptor = current_source.DESCRIPTOR
291
+ for name in current_node:
292
+ child = current_node[name]
293
+ field = source_descriptor.fields_by_name[name]
294
+ if field is None:
295
+ raise ValueError(
296
+ "Error: Can't find field {0} in message {1}.".format(
297
+ name, source_descriptor.full_name
298
+ )
299
+ )
300
+ if child:
301
+ # Sub-paths are only allowed for singular message fields.
302
+ if (
303
+ field.is_repeated
304
+ or field.cpp_type != FieldDescriptor.CPPTYPE_MESSAGE
305
+ ):
306
+ raise ValueError(
307
+ 'Error: Field {0} in message {1} is not a singular '
308
+ 'message field and cannot have sub-fields.'.format(
309
+ name, source_descriptor.full_name
310
+ )
311
+ )
312
+ if current_source.HasField(name):
313
+ stack.append((
314
+ child,
315
+ getattr(current_source, name),
316
+ getattr(current_destination, name),
317
+ ))
318
+ continue
319
+ if field.is_repeated:
320
+ if replace_repeated:
321
+ current_destination.ClearField(_StrConvert(name))
322
+ repeated_source = getattr(current_source, name)
323
+ repeated_destination = getattr(current_destination, name)
324
+ repeated_destination.MergeFrom(repeated_source)
325
+ else:
326
+ if field.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
327
+ if replace_message:
328
+ current_destination.ClearField(_StrConvert(name))
329
+ if current_source.HasField(name):
330
+ getattr(current_destination, name).MergeFrom(
331
+ getattr(current_source, name)
332
+ )
333
+ elif not field.has_presence or current_source.HasField(name):
334
+ setattr(current_destination, name, getattr(current_source, name))
335
+ else:
336
+ current_destination.ClearField(_StrConvert(name))
337
+
338
+
339
+ def _AddFieldPaths(node, prefix, field_mask):
340
+ """Adds the field paths descended from node to field_mask."""
341
+ stack = [(node, prefix)]
342
+ while stack:
343
+ current_node, current_prefix = stack.pop()
344
+ if not current_node and current_prefix:
345
+ field_mask.paths.append(current_prefix)
346
+ continue
347
+ for name in sorted(current_node, reverse=True):
348
+ if current_prefix:
349
+ child_path = current_prefix + '.' + name
350
+ else:
351
+ child_path = name
352
+ stack.append((current_node[name], child_path))