-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstdlib_printers.py
61 lines (47 loc) · 2.17 KB
/
stdlib_printers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
###
# Copyright 2022-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
"""Proxy for the gdb.libstdcxx.v6.printers submodule.
This module exists so GDB pretty printers defined in the gdbmongo package can refer to
gdbmongo.stdlib_printers.XX types without caring around which version of the MongoDB toolchain the
libstdc++ GDB pretty printers were loaded from. The intended usage in GDB pretty printers resembles
the following Python snippet:
.. code-block:: python
# The `from gdbmongo.stdlib_printers import ...` syntax cannot be used because it would attempt
# to reference an attribute before the gdb.libstdcxx.v6 module has been registered in
# sys.modules.
import gdbmongo.stdlib_printers
class MyPrinter:
def __init__(self, val: gdb.Value, /) -> None:
self.val = val
self.pipeline = val["_pipeline"]
def to_string(self) -> str:
# The class is aliased here as a local variable for some brevity.
StdVectorPrinter = gdbmongo.stdlib_printers.StdVectorPrinter
iterator = StdVectorPrinter("std::vector", self.pipeline).children()
for (index, (_, stage)) in enumerate(iterator):
...
"""
import importlib
import types
import typing
import gdbmongo.stdlib_printers_loader
def _resolve_printers_submodule() -> types.ModuleType:
"""Import the gdb.libstdcxx.v6.printers submodule."""
return importlib.import_module(".printers", package=gdbmongo.stdlib_printers_loader.MODULE_NAME)
def __getattr__(name: str) -> typing.Any:
return getattr(_resolve_printers_submodule(), name)
def __dir__() -> typing.List[str]:
return dir(_resolve_printers_submodule())