bethkit 1.0.0__py3-none-win_amd64.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.
bethkit/__init__.py ADDED
@@ -0,0 +1,102 @@
1
+ """
2
+ Copyright (c) Modding Forge
3
+
4
+ bethkit — Python bindings for the bethkit Bethesda plugin and archive toolkit.
5
+
6
+ Place ``bethkit_ffi.dll`` (Windows), ``libbethkit_ffi.so`` (Linux), or
7
+ ``libbethkit_ffi.dylib`` (macOS) next to this package, or set the
8
+ ``BETHKIT_LIB`` environment variable to the full path of the library before
9
+ importing.
10
+
11
+ Quick example::
12
+
13
+ from bethkit import Plugin, Game
14
+
15
+ with Plugin.open(Path("Ordinator - Perks of Skyrim.esp"), Game.SKYRIM_SE) as p:
16
+ for master in p.masters:
17
+ print(master)
18
+ for group in p:
19
+ for child in group:
20
+ if hasattr(child, "form_id"):
21
+ print(f"0x{child.form_id:08X}", child.editor_id)
22
+ """
23
+ from __future__ import annotations
24
+
25
+ from ._error import (
26
+ BethkitClosedError,
27
+ BethkitError,
28
+ BethkitLibraryNotFoundError,
29
+ BethkitNativeError,
30
+ BethkitNotFoundError,
31
+ BethkitOwnershipError,
32
+ )
33
+ from .archive import Archive, ArchiveEntry, Ba2Dx10Writer, Ba2GnrlWriter, BsaWriter
34
+ from .enums import (
35
+ Ba2Version,
36
+ BsaVersion,
37
+ FieldValueKind,
38
+ Game,
39
+ PluginKind,
40
+ StringFileKind,
41
+ )
42
+ from .load_order import GlobalFormId, LoadOrder
43
+ from .plugin import (
44
+ CacheHit,
45
+ Group,
46
+ Plugin,
47
+ PluginCache,
48
+ PluginWriter,
49
+ Record,
50
+ SubRecord,
51
+ WritableGroup,
52
+ WritableRecord,
53
+ )
54
+ from .schema import EnumVal, FlagsVal, NamedField, RecordView, SchemaRegistry, TypedFormId
55
+ from .strings import LocalizationSet, StringTable
56
+
57
+ __all__ = [
58
+ # Exceptions
59
+ "BethkitError",
60
+ "BethkitLibraryNotFoundError",
61
+ "BethkitNativeError",
62
+ "BethkitClosedError",
63
+ "BethkitOwnershipError",
64
+ "BethkitNotFoundError",
65
+ # Enums
66
+ "Game",
67
+ "PluginKind",
68
+ "StringFileKind",
69
+ "BsaVersion",
70
+ "Ba2Version",
71
+ "FieldValueKind",
72
+ # Plugin reading
73
+ "Plugin",
74
+ "Group",
75
+ "Record",
76
+ "SubRecord",
77
+ # Archives
78
+ "Archive",
79
+ "ArchiveEntry",
80
+ "BsaWriter",
81
+ "Ba2GnrlWriter",
82
+ "Ba2Dx10Writer",
83
+ # Schema
84
+ "SchemaRegistry",
85
+ "RecordView",
86
+ "NamedField",
87
+ "TypedFormId",
88
+ "EnumVal",
89
+ "FlagsVal",
90
+ # Load order & cache
91
+ "LoadOrder",
92
+ "GlobalFormId",
93
+ "PluginCache",
94
+ "CacheHit",
95
+ # Strings
96
+ "StringTable",
97
+ "LocalizationSet",
98
+ # Writing
99
+ "PluginWriter",
100
+ "WritableGroup",
101
+ "WritableRecord",
102
+ ]
bethkit/_error.py ADDED
@@ -0,0 +1,85 @@
1
+ """
2
+ Copyright (c) Modding Forge
3
+ """
4
+ from __future__ import annotations
5
+
6
+
7
+ class BethkitError(Exception):
8
+ """
9
+ Base exception for all bethkit errors.
10
+
11
+ All exceptions raised by bethkit.py are subclasses of this class,
12
+ so callers can catch everything with a single ``except BethkitError``.
13
+ """
14
+
15
+
16
+ class BethkitLibraryNotFoundError(BethkitError):
17
+ """
18
+ Raised when the native bethkit shared library cannot be loaded.
19
+
20
+ Check that ``bethkit_ffi.dll`` / ``libbethkit_ffi.so`` /
21
+ ``libbethkit_ffi.dylib`` is placed next to the package directory or
22
+ that the ``BETHKIT_LIB`` environment variable points to the file.
23
+ """
24
+
25
+
26
+ class BethkitNativeError(BethkitError):
27
+ """
28
+ Raised when a native FFI call returns an error code.
29
+
30
+ The error message is the text returned by ``bethkit_last_error()``
31
+ immediately after the failing call, copied before any subsequent
32
+ FFI call can overwrite the thread-local error buffer.
33
+
34
+ Attributes:
35
+ message (str): Human-readable error text from the native library.
36
+ """
37
+
38
+ message: str
39
+ """Human-readable error text from the native library."""
40
+
41
+ def __init__(self, message: str) -> None:
42
+ """
43
+ Args:
44
+ message (str): Error text returned by the native library.
45
+ """
46
+
47
+ super().__init__(message)
48
+ self.message = message
49
+
50
+ def __repr__(self) -> str:
51
+ """
52
+ Returns:
53
+ str: Developer-friendly representation including the message.
54
+ """
55
+
56
+ return f"BethkitNativeError({self.message!r})"
57
+
58
+
59
+ class BethkitClosedError(BethkitError):
60
+ """
61
+ Raised when a method is called on an already-closed native handle.
62
+
63
+ Once :meth:`close` has been called (or the context manager has
64
+ exited), the wrapper object is invalid and must not be used.
65
+ """
66
+
67
+
68
+ class BethkitOwnershipError(BethkitError):
69
+ """
70
+ Raised when ownership of a handle is transferred more than once.
71
+
72
+ After a handle has been moved into a container (e.g.
73
+ :meth:`~bethkit.PluginCache.add`), the original wrapper is consumed
74
+ and must not be used again.
75
+ """
76
+
77
+
78
+ class BethkitNotFoundError(BethkitNativeError):
79
+ """
80
+ Raised by ``*_required`` convenience methods when a lookup fails.
81
+
82
+ Normal lookup methods return ``None`` on not-found; this exception
83
+ is raised only by the strict ``*_required`` variants that must
84
+ succeed or fail loudly.
85
+ """
@@ -0,0 +1,44 @@
1
+ """
2
+ Copyright (c) Modding Forge
3
+
4
+ Internal FFI package — loads the native library and declares ctypes types.
5
+
6
+ Not part of the public API; import from ``bethkit`` directly.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ from ._loader import (
11
+ copy_and_free_str,
12
+ enc,
13
+ last_error,
14
+ load_lib,
15
+ raise_last_error,
16
+ senc,
17
+ )
18
+ from ._types import (
19
+ BethkitEnumVal,
20
+ BethkitFieldValue,
21
+ BethkitFieldValuePayload,
22
+ BethkitFlagsVal,
23
+ BethkitGlobalFormId,
24
+ BethkitNamedField,
25
+ BethkitSlice,
26
+ BethkitTypedFormId,
27
+ )
28
+
29
+ __all__ = [
30
+ "copy_and_free_str",
31
+ "enc",
32
+ "last_error",
33
+ "load_lib",
34
+ "raise_last_error",
35
+ "senc",
36
+ "BethkitEnumVal",
37
+ "BethkitFieldValue",
38
+ "BethkitFieldValuePayload",
39
+ "BethkitFlagsVal",
40
+ "BethkitGlobalFormId",
41
+ "BethkitNamedField",
42
+ "BethkitSlice",
43
+ "BethkitTypedFormId",
44
+ ]