pyobjc-framework-ExceptionHandling 10.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ """
2
+ Python mapping for the ExceptionHandling framework.
3
+
4
+ This module does not contain docstrings for the wrapped code, check Apple's
5
+ documentation for details on how to use these functions and classes.
6
+ """
7
+
8
+
9
+ def _setup():
10
+ import sys
11
+
12
+ import Foundation
13
+ import objc
14
+ from . import _metadata
15
+
16
+ dir_func, getattr_func = objc.createFrameworkDirAndGetattr(
17
+ name="ExceptionHandling",
18
+ frameworkIdentifier="com.apple.ExceptionHandling",
19
+ frameworkPath=objc.pathForFramework(
20
+ "/System/Library/Frameworks/ExceptionHandling.framework"
21
+ ),
22
+ globals_dict=globals(),
23
+ inline_list=None,
24
+ parents=(Foundation,),
25
+ metadict=_metadata.__dict__,
26
+ )
27
+
28
+ globals()["__dir__"] = dir_func
29
+ globals()["__getattr__"] = getattr_func
30
+
31
+ del sys.modules["ExceptionHandling._metadata"]
32
+
33
+
34
+ globals().pop("_setup")()
@@ -0,0 +1,84 @@
1
+ # This file is generated by objective.metadata
2
+ #
3
+ # Last update: Sat May 18 09:28:47 2024
4
+ #
5
+ # flake8: noqa
6
+
7
+ import objc, sys
8
+ from typing import NewType
9
+
10
+ if sys.maxsize > 2**32:
11
+
12
+ def sel32or64(a, b):
13
+ return b
14
+
15
+ else:
16
+
17
+ def sel32or64(a, b):
18
+ return a
19
+
20
+
21
+ if objc.arch == "arm64":
22
+
23
+ def selAorI(a, b):
24
+ return a
25
+
26
+ else:
27
+
28
+ def selAorI(a, b):
29
+ return b
30
+
31
+
32
+ misc = {}
33
+ constants = """$NSStackTraceKey$NSUncaughtRuntimeErrorException$NSUncaughtSystemExceptionException$"""
34
+ enums = """$NSHandleOtherExceptionMask@512$NSHandleTopLevelExceptionMask@128$NSHandleUncaughtExceptionMask@2$NSHandleUncaughtRuntimeErrorMask@32$NSHandleUncaughtSystemExceptionMask@8$NSHangOnOtherExceptionMask@16$NSHangOnTopLevelExceptionMask@8$NSHangOnUncaughtExceptionMask@1$NSHangOnUncaughtRuntimeErrorMask@4$NSHangOnUncaughtSystemExceptionMask@2$NSLogOtherExceptionMask@256$NSLogTopLevelExceptionMask@64$NSLogUncaughtExceptionMask@1$NSLogUncaughtRuntimeErrorMask@16$NSLogUncaughtSystemExceptionMask@4$"""
35
+ misc.update({})
36
+ misc.update({})
37
+ misc.update({})
38
+ functions = {"NSExceptionHandlerResume": (b"v",)}
39
+ r = objc.registerMetaDataForSelector
40
+ objc._updatingMetadata(True)
41
+ try:
42
+ r(
43
+ b"NSObject",
44
+ b"exceptionHandler:shouldHandleException:mask:",
45
+ {
46
+ "retval": {"type": "Z"},
47
+ "arguments": {2: {"type": b"@"}, 3: {"type": b"@"}, 4: {"type": b"Q"}},
48
+ },
49
+ )
50
+ r(
51
+ b"NSObject",
52
+ b"exceptionHandler:shouldLogException:mask:",
53
+ {
54
+ "retval": {"type": "Z"},
55
+ "arguments": {2: {"type": b"@"}, 3: {"type": b"@"}, 4: {"type": b"Q"}},
56
+ },
57
+ )
58
+ finally:
59
+ objc._updatingMetadata(False)
60
+ protocols = {
61
+ "NSExceptionHandlerDelegate": objc.informal_protocol(
62
+ "NSExceptionHandlerDelegate",
63
+ [
64
+ objc.selector(
65
+ None,
66
+ b"exceptionHandler:shouldLogException:mask:",
67
+ b"Z@:@@Q",
68
+ isRequired=False,
69
+ ),
70
+ objc.selector(
71
+ None,
72
+ b"exceptionHandler:shouldHandleException:mask:",
73
+ b"Z@:@@Q",
74
+ isRequired=False,
75
+ ),
76
+ ],
77
+ )
78
+ }
79
+ expressions = {
80
+ "NSHangOnEveryExceptionMask": "(NSHangOnUncaughtExceptionMask|NSHangOnUncaughtSystemExceptionMask|NSHangOnUncaughtRuntimeErrorMask|NSHangOnTopLevelExceptionMask|NSHangOnOtherExceptionMask)",
81
+ "NSLogAndHandleEveryExceptionMask": "(NSLogUncaughtExceptionMask|NSLogUncaughtSystemExceptionMask|NSLogUncaughtRuntimeErrorMask|NSHandleUncaughtExceptionMask|NSHandleUncaughtSystemExceptionMask|NSHandleUncaughtRuntimeErrorMask|NSLogTopLevelExceptionMask|NSHandleTopLevelExceptionMask|NSLogOtherExceptionMask|NSHandleOtherExceptionMask)",
82
+ }
83
+
84
+ # END OF FILE
@@ -0,0 +1,222 @@
1
+ """
2
+ Low level debugging helper for PyObjC.
3
+
4
+ Allows you to log Python and ObjC (via atos) stack traces for NSExceptions
5
+ raised.
6
+
7
+ General guidelines for use:
8
+
9
+ - It's typically only useful when you log EVERY exception, because Foundation
10
+ and AppKit will swallow most of them. This means that you should never
11
+ use this module in a release build.
12
+
13
+ - Typical use involves only calling installExceptionHandler or
14
+ installVerboseExceptionHandler. It may be removed at any time by calling
15
+ removeDebuggingHandler.
16
+ """
17
+
18
+ import os
19
+ import sys
20
+ import traceback
21
+
22
+ import objc
23
+ from ExceptionHandling import (
24
+ NSExceptionHandler,
25
+ NSLogAndHandleEveryExceptionMask,
26
+ NSLogUncaughtExceptionMask,
27
+ NSStackTraceKey,
28
+ )
29
+ from Foundation import NSLog, NSObject
30
+
31
+ DEFAULTMASK = NSLogUncaughtExceptionMask
32
+ EVERYTHINGMASK = NSLogAndHandleEveryExceptionMask
33
+
34
+
35
+ __all__ = [
36
+ "LOGSTACKTRACE",
37
+ "DEFAULTVERBOSITY",
38
+ "DEFAULTMASK",
39
+ "EVERYTHINGMASK",
40
+ "installExceptionHandler",
41
+ "installVerboseExceptionHandler",
42
+ "installPythonExceptionHandler",
43
+ "removeExceptionHandler",
44
+ "handlerInstalled",
45
+ ]
46
+
47
+
48
+ def isPythonException(exception):
49
+ if hasattr(exception, "_pyobjc_info_"):
50
+ return False
51
+
52
+ if not hasattr(exception, "userInfo"):
53
+ return True
54
+
55
+ return (exception.userInfo() or {}).get("__pyobjc_exc_type__") is not None
56
+
57
+
58
+ def nsLogPythonException(exception):
59
+ userInfo = exception.userInfo()
60
+ NSLog(
61
+ "%@",
62
+ "*** Python exception discarded!\n"
63
+ + "".join(
64
+ traceback.format_exception(
65
+ userInfo["__pyobjc_exc_type__"],
66
+ userInfo["__pyobjc_exc_value__"],
67
+ userInfo["__pyobjc_exc_traceback__"],
68
+ )
69
+ ),
70
+ )
71
+ # we logged it, so don't log it for us
72
+ return False
73
+
74
+
75
+ _atos_command = None
76
+
77
+
78
+ def _run_atos(stack):
79
+ global _atos_command
80
+ if _atos_command is None:
81
+ if os.path.exists("/usr/bin/atos"):
82
+ _atos_command = "/usr/bin/atos"
83
+
84
+ if os.uname()[2].startswith("13."):
85
+ # The atos command on OSX 10.9 gives a usage
86
+ # warning that's suppressed with the "-d" option.
87
+ _atos_command += " -d"
88
+
89
+ elif os.path.exists("/usr/bin/xcrun"):
90
+ _atos_command = "/usr/bin/xcrun atos"
91
+
92
+ else:
93
+ return None
94
+
95
+ return os.popen(f"{_atos_command} -p {os.getpid()} {stack}")
96
+
97
+
98
+ def nsLogObjCException(exception):
99
+ stacktrace = None
100
+
101
+ try:
102
+ stacktrace = exception.callStackSymbols()
103
+
104
+ except AttributeError:
105
+ pass
106
+
107
+ if stacktrace is None:
108
+ stack = exception.callStackReturnAddresses()
109
+ if stack:
110
+ pipe = _run_atos(" ".join(hex(v) for v in stack))
111
+ if pipe is None:
112
+ return True
113
+
114
+ stacktrace = pipe.readlines()
115
+ stacktrace.reverse()
116
+ pipe.close()
117
+
118
+ if stacktrace is None:
119
+ userInfo = exception.userInfo()
120
+ stack = userInfo.get(NSStackTraceKey)
121
+ if not stack:
122
+ return True
123
+
124
+ pipe = _run_atos(stack)
125
+ if pipe is None:
126
+ return True
127
+
128
+ stacktrace = pipe.readlines()
129
+ stacktrace.reverse()
130
+ pipe.close()
131
+
132
+ NSLog(
133
+ "%@",
134
+ "*** ObjC exception '%s' (reason: '%s') discarded\n"
135
+ % (exception.name(), exception.reason())
136
+ + "Stack trace (most recent call last):\n"
137
+ + "".join([(" " + line) for line in stacktrace]),
138
+ )
139
+ return False
140
+
141
+
142
+ LOGSTACKTRACE = 1 << 0
143
+ DEFAULTVERBOSITY = 0
144
+
145
+
146
+ class PyObjCDebuggingDelegate(NSObject):
147
+ verbosity = objc.ivar("verbosity", b"i")
148
+
149
+ def initWithVerbosity_(self, verbosity):
150
+ self = self.init()
151
+ self.verbosity = verbosity
152
+ return self
153
+
154
+ @objc.typedSelector(b"c@:@@I")
155
+ def exceptionHandler_shouldLogException_mask_(self, sender, exception, aMask):
156
+ try:
157
+ if isPythonException(exception):
158
+ if self.verbosity & LOGSTACKTRACE:
159
+ nsLogObjCException(exception)
160
+ return nsLogPythonException(exception)
161
+ elif self.verbosity & LOGSTACKTRACE:
162
+ return nsLogObjCException(exception)
163
+ else:
164
+ return False
165
+ except: # noqa: B001, E722
166
+ print(
167
+ "*** Exception occurred during exception handler ***", file=sys.stderr
168
+ )
169
+ traceback.print_exc(sys.stderr)
170
+ return True
171
+
172
+ @objc.typedSelector(b"c@:@@I")
173
+ def exceptionHandler_shouldHandleException_mask_(self, sender, exception, aMask):
174
+ return False
175
+
176
+
177
+ def installExceptionHandler(verbosity=DEFAULTVERBOSITY, mask=DEFAULTMASK):
178
+ """
179
+ Install the exception handling delegate that will log every exception
180
+ matching the given mask with the given verbosity.
181
+ """
182
+ # we need to retain this, cause the handler doesn't
183
+ global _exceptionHandlerDelegate
184
+ delegate = PyObjCDebuggingDelegate.alloc().initWithVerbosity_(verbosity)
185
+ NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_(mask)
186
+ NSExceptionHandler.defaultExceptionHandler().setDelegate_(delegate)
187
+ _exceptionHandlerDelegate = delegate
188
+
189
+
190
+ def installPythonExceptionHandler():
191
+ """
192
+ Install a verbose exception handling delegate that logs every exception
193
+ raised.
194
+
195
+ Will log only Python stack traces, if available.
196
+ """
197
+ installExceptionHandler(verbosity=DEFAULTVERBOSITY, mask=EVERYTHINGMASK)
198
+
199
+
200
+ def installVerboseExceptionHandler():
201
+ """
202
+ Install a verbose exception handling delegate that logs every exception
203
+ raised.
204
+
205
+ Will log both Python and ObjC stack traces, if available.
206
+ """
207
+ installExceptionHandler(verbosity=LOGSTACKTRACE, mask=EVERYTHINGMASK)
208
+
209
+
210
+ def removeExceptionHandler():
211
+ """
212
+ Remove the current exception handler delegate
213
+ """
214
+ NSExceptionHandler.defaultExceptionHandler().setDelegate_(None)
215
+ NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_(0)
216
+
217
+
218
+ def handlerInstalled():
219
+ """
220
+ Is an exception handler delegate currently installed?
221
+ """
222
+ return NSExceptionHandler.defaultExceptionHandler().delegate() is not None
@@ -0,0 +1,10 @@
1
+ (This is the MIT license, note that libffi-src is a separate product with its own license)
2
+
3
+ Copyright 2002, 2003 - Bill Bumgarner, Ronald Oussoren, Steve Majewski, Lele Gaifax, et.al.
4
+ Copyright 2003-2024 - Ronald Oussoren
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyobjc-framework-ExceptionHandling
3
+ Version: 10.3.2
4
+ Summary: Wrappers for the framework ExceptionHandling on macOS
5
+ Home-page: https://github.com/ronaldoussoren/pyobjc
6
+ Author: Ronald Oussoren
7
+ Author-email: pyobjc-dev@lists.sourceforge.net
8
+ License: MIT License
9
+ Keywords: PyObjC,ExceptionHandling
10
+ Platform: MacOS X
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Environment :: Console
13
+ Classifier: Environment :: MacOS X :: Cocoa
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Operating System :: MacOS :: MacOS X
18
+ Classifier: Programming Language :: Python
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Programming Language :: Python :: Implementation :: CPython
28
+ Classifier: Programming Language :: Objective C
29
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
+ Classifier: Topic :: Software Development :: User Interfaces
31
+ Requires-Python: >=3.8
32
+ Description-Content-Type: text/x-rst; charset=UTF-8
33
+ License-File: LICENSE.txt
34
+ Requires-Dist: pyobjc-core>=10.3.2
35
+ Requires-Dist: pyobjc-framework-Cocoa>=10.3.2
36
+ Project-URL: Documentation, https://pyobjc.readthedocs.io/en/latest/
37
+ Project-URL: Issue tracker, https://github.com/ronaldoussoren/pyobjc/issues
38
+ Project-URL: Repository, https://github.com/ronaldoussoren/pyobjc
39
+
40
+
41
+ Wrappers for the "ExceptionHandling" framework on macOS. The ExceptionHandling
42
+ framework provides facilities for monitoring and debugging exceptional
43
+ conditions in Cocoa programs.
44
+
45
+ PyObjC also provides low-level debugging utilities beyond the core
46
+ ExceptionHandling framework in the module ``PyObjCTools.Debugging``.
47
+
48
+ These wrappers don't include documentation, please check Apple's documentation
49
+ for information on how to use this framework and PyObjC's documentation
50
+ for general tips and tricks regarding the translation between Python
51
+ and (Objective-)C frameworks
52
+
53
+
54
+ Project links
55
+ -------------
56
+
57
+ * `Documentation <https://pyobjc.readthedocs.io/en/latest/>`_
58
+
59
+ * `Issue Tracker <https://github.com/ronaldoussoren/pyobjc/issues>`_
60
+
61
+ * `Repository <https://github.com/ronaldoussoren/pyobjc/>`_
62
+
@@ -0,0 +1,8 @@
1
+ ExceptionHandling/__init__.py,sha256=8CWyoEPdIYpP6d3HgdqPSN8SkwJ3xVRhkb435iHJdPs,880
2
+ ExceptionHandling/_metadata.py,sha256=IsCzCyj877M_h2pvGZTSHwYEKzesdoT0XF7UWkd2l_s,2770
3
+ PyObjCTools/Debugging.py,sha256=H05RL2YGsGMhl-czhn_wbCIuogetBHRr2-t0jXkSwoY,6164
4
+ pyobjc_framework_ExceptionHandling-10.3.2.dist-info/LICENSE.txt,sha256=VBYOCJp5HziM90a14Txl68gt3y2rIJpcoZAoVkfX4Ho,1249
5
+ pyobjc_framework_ExceptionHandling-10.3.2.dist-info/METADATA,sha256=tAfukXwDBGs55OSWbM1zGuVW5OWoMEHPb2ij7u8zjRQ,2550
6
+ pyobjc_framework_ExceptionHandling-10.3.2.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
7
+ pyobjc_framework_ExceptionHandling-10.3.2.dist-info/top_level.txt,sha256=9dZWP3ne-rbt6Zo7CxEHR5dISz4ZAn4PknLp-VV8bXs,30
8
+ pyobjc_framework_ExceptionHandling-10.3.2.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1,2 @@
1
+ ExceptionHandling
2
+ PyObjCTools