Skip to content

Commit 0138cff

Browse files
committed
chore: merge from main
2 parents 9e76a4f + 67641f1 commit 0138cff

File tree

77 files changed

+6459
-128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+6459
-128
lines changed

__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from smartinspect import SmartInspect # noqa
2+
from smartinspect_handler.smartinspect_handler import SmartInspectHandler # noqa
3+
from connections.builders import ConnectionStringBuilder # noqa

common/clock.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Clock:
66
@staticmethod
77
def now() -> int:
8-
current_time_millis = time.time() * 1000
9-
local_timezone_offset_millis = datetime.now(timezone.utc).astimezone().utcoffset().total_seconds() * 1000
10-
current_time_micros = int((current_time_millis + local_timezone_offset_millis) * 1000)
8+
current_time_micros = time.time_ns() / 1e3
9+
local_timezone_offset_micros = datetime.now(timezone.utc).astimezone().utcoffset().total_seconds() * 1e6
10+
current_time_micros = int(current_time_micros + local_timezone_offset_micros)
1111
return current_time_micros

common/clock_resolution.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

common/color/color.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@ class Color(Enum):
2020
# additional colors can be added, syntax is <<colorname>> = RGBAColor(r, g, b)
2121

2222
def get_red(self):
23-
return self.value.red
23+
return self.value.get_red()
2424

2525
def get_green(self):
26-
return self.value.green
26+
return self.value.get_green()
2727

2828
def get_blue(self):
29-
return self.value.blue
29+
return self.value.get_blue()
3030

3131
def get_alpha(self):
32-
return self.value.alpha
33-
34-
35-
36-
32+
return self.value.get_alpha()

common/color/rgbacolor.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ def __init__(self, r: int, g: int, b: int, a: int = 0x00):
44
value = (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | (b & 255) << 0
55
self.__value = value
66

7-
@property
8-
def red(self):
7+
def get_red(self):
98
return self.__value >> 16 & 255
109

11-
@property
12-
def green(self):
10+
def get_green(self):
1311
return self.__value >> 8 & 255
1412

15-
@property
16-
def blue(self):
13+
def get_blue(self):
1714
return self.__value >> 0 & 255
1815

19-
@property
20-
def alpha(self):
16+
def get_alpha(self):
2117
return self.__value >> 24 & 255
2218

2319
@staticmethod

common/context/binary_context.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,54 @@
55

66

77
class BinaryContext(ViewerContext):
8+
"""
9+
This is the base class for all viewer contexts, which deal with
10+
binary data. A viewer context is the library-side representation
11+
of a viewer in the Console.
12+
13+
.. note::
14+
This class is not guaranteed to be threadsafe.
15+
"""
16+
817
def __init__(self, viewer_id: ViewerId):
18+
"""
19+
Initializes a BinaryContext instance.
20+
21+
:param viewer_id: The viewer ID to use.
22+
"""
923
super().__init__(viewer_id)
1024
self.__data: BytesIO = BytesIO()
1125

1226
@property
13-
def viewer_data(self):
27+
def viewer_data(self) -> bytes:
28+
"""
29+
Overridden. Returns the actual binary data which will be
30+
displayed in the viewer specified by the ViewerId.
31+
32+
:rtype: binary
33+
"""
1434
return self.__data.getvalue()
1535

1636
def reset_data(self):
37+
"""
38+
Resets the internal data stream.
39+
40+
.. note::
41+
This method is intended to reset the internal data stream
42+
if custom handling of data is needed by derived classes.
43+
"""
44+
1745
self.__data.seek(0)
1846
self.__data.truncate()
1947

2048
def load_from_file(self, filename: str):
49+
"""
50+
Loads the binary data from a file.
51+
52+
:param filename: The name of the file to load the binary data from.
53+
:raises ValueError: The filename string is empty.
54+
"""
55+
2156
if filename == "":
2257
raise ValueError("filename not provided")
2358
else:
@@ -27,6 +62,17 @@ def load_from_file(self, filename: str):
2762
self.__data.write(content)
2863

2964
def append_bytes(self, bytestring: (bytes, bytearray), offset: int = 0, length: int = 0):
65+
"""
66+
Overloaded. Appends a buffer. Lets you specify the offset in
67+
the buffer and the amount of bytes to append.
68+
69+
:param bytestring: The buffer to append.
70+
:param offset: The offset at which to begin appending.
71+
:param length: The number of bytes to append.
72+
73+
:raises TypeError: if type requirements are not met by the arguments
74+
"""
75+
3076
if not isinstance(bytestring, bytes) and \
3177
not isinstance(bytestring, bytes):
3278
raise TypeError("bytestring must be bytes sequence")
@@ -41,6 +87,10 @@ def append_bytes(self, bytestring: (bytes, bytearray), offset: int = 0, length:
4187
self.__data.write(bytestring[offset: offset + length])
4288

4389
def close(self) -> None:
90+
"""
91+
Overridden. Releases any resources.
92+
"""
93+
4494
if not self.__data.closed:
4595
try:
4696
self.__data.close()
@@ -49,5 +99,11 @@ def close(self) -> None:
4999
# we are not expecting an exception
50100

51101
def load_from_stream(self, stream):
102+
"""
103+
Loads the binary data from a stream.
104+
105+
:param stream: The stream to load the binary data from.
106+
"""
107+
52108
self.reset_data()
53109
self.__data.write(stream)

common/context/binary_viewer_context.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33

44

55
class BinaryViewerContext(BinaryContext):
6+
"""Represents the binary viewer in the Console which can display binary
7+
data in a read-only hex editor.
68
9+
.. note::
10+
11+
The binary viewer in the Console interprets the data of a Log Entry as binary data
12+
and displays it in a read-only hex editor.
13+
14+
You can use the BinaryViewerContext class for creating custom log
15+
methods around for sending custom binary data.
16+
17+
.. note::
18+
19+
This class is not guaranteed to be threadsafe.
20+
"""
721
def __init__(self):
22+
"""
23+
Initializes a BinaryViewerContext instance.
24+
"""
825
super().__init__(ViewerId.BINARY)

common/context/data_viewer_context.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,24 @@
33

44

55
class DataViewerContext(TextContext):
6+
"""
7+
Represents the data viewer in the Console which can display simple
8+
and unformatted text.
9+
10+
.. note::
11+
The data viewer in the Console interprets the data of a Log Entry as text and displays it in a read-only text
12+
field.
13+
14+
You can use the DataViewerContext class for creating custom log
15+
methods around LogCustomContext for
16+
sending custom text data.
17+
18+
.. note::
19+
This class is not guaranteed to be threadsafe.
20+
"""
21+
622
def __init__(self):
23+
"""
24+
Initializes a DataViewerContext instance.
25+
"""
726
super().__init__(ViewerId.DATA)

common/context/inspector_viewer_context.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,50 @@
33

44

55
class InspectorViewerContext(ValueListViewerContext):
6+
"""
7+
Represents the inspector viewer in the Console which displays
8+
key/value pairs in an object inspector control.
9+
10+
The inspector viewer in the Console interprets the
11+
`data of a Log Entry <LogEntry.data>` as a key/value list with
12+
group support like object inspectors from popular IDEs. This class
13+
takes care of the necessary formatting and escaping required by the
14+
corresponding inspector viewer in the Console.
15+
16+
You can use the InspectorViewerContext class for creating custom
17+
log methods around Session.log_custom_context
18+
for sending custom data organized as grouped key/value pairs.
19+
20+
.. note::
21+
This class is not guaranteed to be threadsafe.
22+
"""
23+
624
def __init__(self):
25+
"""
26+
Initializes an InspectorViewerContext instance.
27+
"""
728
super().__init__(ViewerId.INSPECTOR)
829

930
def start_group(self, group: str):
31+
"""
32+
Starts a new group.
33+
34+
:param group: The name of the group to use.
35+
"""
1036
if isinstance(group, str):
1137
self.append_text("[")
1238
self.append_text(self.escape_item(group))
1339
self.append_text("]\r\n")
1440

1541
def escape_item(self, item: str) -> str:
42+
"""
43+
Overridden. Escapes a key or a value.
44+
45+
This method ensures that the escaped key or value does not contain any newline characters,
46+
such as the carriage return or linefeed characters.
47+
Furthermore, it escapes the '\\', '=', '[' and ']' characters.
48+
49+
:param item: The key or value to escape.
50+
:returns: The escaped key or value.
51+
"""
1652
return self.escape_line(item, "\\=[]")

common/context/list_viewer_context.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,47 @@
33

44

55
class ListViewerContext(TextContext):
6+
"""
7+
Represents the list viewer in the Console which can display simple lists of text data.
8+
9+
The list viewer in the Console interprets the data of a Log Entry as a list. Every line in the text data
10+
is interpreted as one item of the list. This class takes care of the necessary formatting and escaping required
11+
by the corresponding list viewer in the Console.
12+
13+
You can use the ListViewerContext class for creating custom log methods around LogCustomContext for sending
14+
custom data organized as simple lists.
15+
16+
.. note::
17+
This class is not guaranteed to be threadsafe.
18+
"""
19+
620
def __init__(self, viewer_id: ViewerId = ViewerId.LIST) -> None:
21+
"""
22+
Initializes a ListViewerContext instance using a viewer ID.
23+
24+
This constructor is intended for derived classes, such as the ValueListViewerContext class,
25+
which extend the capabilities of this class and use a different viewer ID.
26+
27+
:param viewer_id: The viewer ID to use.
28+
"""
729
super().__init__(viewer_id)
830

931
@staticmethod
1032
def escape_line(line: str = "", escape_chars: str = "") -> str:
33+
34+
"""
35+
Escapes a line.
36+
37+
This method ensures that the escaped line does not
38+
contain characters listed in the escape_chars parameter plus
39+
any newline characters, such as the carriage return or
40+
linefeed characters.
41+
42+
:param line: The line to escape.
43+
:param escape_chars: A string of characters which should be escaped in addition to the newline characters.
44+
Can be empty.
45+
:returns: The escaped line.
46+
"""
1147
if (
1248
not isinstance(line, str) or
1349
not isinstance(escape_chars, str)

0 commit comments

Comments
 (0)