zig-zon 0.3.0__tar.gz → 0.3.2__tar.gz
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.
- {zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8 → zig-zon-0.3.2}/LICENSE +1 -1
- {zig-zon-0.3.0 → zig-zon-0.3.2}/PKG-INFO +5 -4
- {zig-zon-0.3.0 → zig-zon-0.3.2}/build.zig +4 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/build.zig.zon +1 -1
- {zig-zon-0.3.0 → zig-zon-0.3.2}/setup.zig.json +1 -1
- {zig-zon-0.3.0 → zig-zon-0.3.2}/src/zig_zon.zig +226 -160
- {zig-zon-0.3.0 → zig-zon-0.3.2}/pkg-info.zon +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/setup.py +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/src/zig_zon.pyi +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2/zig-pkg/zig_python_sdist-0.0.8}/LICENSE +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/README.md +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/build.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/build.zig.zon +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/pkg-info.zon +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/CPython.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/Compression.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/LowerDashString.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/SDistStep.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/VenvInstallTest.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/extract_link_info.py +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/pip_runner.py +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/pkg_info.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/python-translatec.h +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/python.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/python_allocator.zig +0 -0
- {zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/setup_json.zig +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zig-zon
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: a native cpython extension to parse zig object notation strings
|
|
5
5
|
Author-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
6
6
|
Maintainer-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
@@ -27,12 +27,13 @@ It therefore needs to download the `ziglang` python package.
|
|
|
27
27
|
Depending on your OS, you may need the python development headers
|
|
28
28
|
(e.g. `python3-dev`) installed.
|
|
29
29
|
|
|
30
|
-
##
|
|
31
|
-
|
|
32
|
-
install from source on <https://pypi.org/project/zig-zon>:
|
|
30
|
+
## Installation
|
|
33
31
|
|
|
34
32
|
```bash
|
|
33
|
+
# from PyPi: https://pypi.org/project/zig-zon
|
|
35
34
|
pip install zig-zon
|
|
35
|
+
# directly from the Codeberg Release:
|
|
36
|
+
pip install https://codeberg.org/dasimmet/python-zig-zon/releases/download/0.3.2/zig_zon-0.3.2.tar.gz
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
## Parsing
|
|
@@ -6,6 +6,8 @@ const zon = @import("build.zig.zon");
|
|
|
6
6
|
pub fn build(b: *Build) void {
|
|
7
7
|
const target = b.standardTargetOptions(.{});
|
|
8
8
|
const optimize = b.standardOptimizeOption(.{});
|
|
9
|
+
const limited_api_opt = b.option([]const u8, "py-limited-api", "") orelse "cp38";
|
|
10
|
+
const limited_api = if (limited_api_opt.len == 0) null else limited_api_opt;
|
|
9
11
|
|
|
10
12
|
// this target and section of our build is used at pip install time
|
|
11
13
|
const ext_install_step = b.step("bdist-wheel", "build python extension module");
|
|
@@ -18,6 +20,7 @@ pub fn build(b: *Build) void {
|
|
|
18
20
|
.name = "zig-zon",
|
|
19
21
|
.version = zon.version,
|
|
20
22
|
.description = b.path("README.md"),
|
|
23
|
+
.py_limited_api = limited_api,
|
|
21
24
|
.build = .{
|
|
22
25
|
.args = &.{
|
|
23
26
|
ext_install_step.name,
|
|
@@ -60,6 +63,7 @@ pub fn build(b: *Build) void {
|
|
|
60
63
|
.target = target,
|
|
61
64
|
.version = zon.version,
|
|
62
65
|
.optimize = .ReleaseSmall,
|
|
66
|
+
.py_limited_api = limited_api,
|
|
63
67
|
});
|
|
64
68
|
const lib = b.addLibrary(.{
|
|
65
69
|
.name = "zig_zon",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"zig_zon","version":{"major":0,"minor":3,"patch":
|
|
1
|
+
{"name":"zig_zon","version":{"major":0,"minor":3,"patch":2},"zig_version":{"major":0,"minor":16,"patch":0},"build":{"args":["--fork=zig-pkg/zig_python_sdist-0.0.8","bdist-wheel","-Doptimize=ReleaseSmall"],"requires":[],"packages":[],"copy_patterns":[{"pattern":"zig-out/lib/*","package_dir":false}]},"py_limited_api":"cp38","has_ext_modules":true}
|
|
@@ -8,7 +8,6 @@ const Serializer = std.zon.Serializer;
|
|
|
8
8
|
const cpython = @import("cpython");
|
|
9
9
|
const c = cpython.c;
|
|
10
10
|
const PyObject = c.PyObject;
|
|
11
|
-
|
|
12
11
|
pub var zigmodule: c.PyModuleDef = .{
|
|
13
12
|
.m_name = "zig_zon",
|
|
14
13
|
.m_methods = @constCast(&[_]c.PyMethodDef{
|
|
@@ -34,7 +33,7 @@ pub var zigmodule: c.PyModuleDef = .{
|
|
|
34
33
|
}),
|
|
35
34
|
};
|
|
36
35
|
|
|
37
|
-
pub export fn PyInit_zig_zon() [*c]
|
|
36
|
+
pub export fn PyInit_zig_zon() [*c]PyObject {
|
|
38
37
|
const mod = c.PyModule_Create(&zigmodule);
|
|
39
38
|
if (mod == null) return null;
|
|
40
39
|
|
|
@@ -46,22 +45,91 @@ pub export fn PyInit_zig_zon() [*c]c.PyObject {
|
|
|
46
45
|
return mod;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
const PyStr = struct {
|
|
49
|
+
bytes: *PyObject,
|
|
50
|
+
slice: [:0]const u8,
|
|
51
|
+
|
|
52
|
+
pub fn init(unicode_obj: *PyObject) ?PyStr {
|
|
53
|
+
const bytes = c.PyUnicode_AsUTF8String(unicode_obj) orelse return null;
|
|
54
|
+
var len: c.Py_ssize_t = 0;
|
|
55
|
+
var ptr: [*c]u8 = undefined;
|
|
56
|
+
if (c.PyBytes_AsStringAndSize(bytes, &ptr, &len) < 0) {
|
|
57
|
+
c.Py_DecRef(bytes);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return PyStr{
|
|
61
|
+
.bytes = bytes,
|
|
62
|
+
.slice = ptr[0..@intCast(len) :0],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
pub fn deinit(self: PyStr) void {
|
|
67
|
+
c.Py_DecRef(self.bytes);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
inline fn PyObject_CallNoArgs(func: *PyObject) ?*PyObject {
|
|
72
|
+
return c.PyObject_CallObject(func, null);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
inline fn PyObject_CallOneArg(func: *PyObject, arg: *PyObject) ?*PyObject {
|
|
76
|
+
return c.PyObject_CallFunctionObjArgs(func, arg, @as(?*anyopaque, null));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
inline fn PyType_GetName(op: *c.PyObject) ?*PyObject {
|
|
80
|
+
const typ: *PyObject = @ptrCast(@alignCast(c.Py_TYPE(op) orelse return null));
|
|
81
|
+
return c.PyObject_GetAttrString(typ, "__name__");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn getBuiltinType(name: [*:0]const u8) ?*PyObject {
|
|
85
|
+
const builtins = c.PyImport_ImportModule("builtins") orelse return null;
|
|
86
|
+
defer c.Py_DecRef(builtins);
|
|
87
|
+
return c.PyObject_GetAttrString(builtins, name);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var PyDict_Type: *PyObject = undefined;
|
|
91
|
+
var PyList_Type: *PyObject = undefined;
|
|
92
|
+
var PyLong_Type: *PyObject = undefined;
|
|
93
|
+
var PyFloat_Type: *PyObject = undefined;
|
|
94
|
+
var PyUnicode_Type: *PyObject = undefined;
|
|
95
|
+
var PyBytes_Type: *PyObject = undefined;
|
|
96
|
+
var PyByteArray_Type: *PyObject = undefined;
|
|
97
|
+
var PySet_Type: *PyObject = undefined;
|
|
98
|
+
var PyFrozenSet_Type: *PyObject = undefined;
|
|
99
|
+
var PyTrue_Obj: *PyObject = undefined;
|
|
100
|
+
var PyFalse_Obj: *PyObject = undefined;
|
|
101
|
+
var Struct_Type: *PyObject = undefined;
|
|
102
|
+
var Tuple_Type: *PyObject = undefined;
|
|
103
|
+
var Integer_Type: *PyObject = undefined;
|
|
104
|
+
var Hex_Type: *PyObject = undefined;
|
|
105
|
+
var Float_Type: *PyObject = undefined;
|
|
106
|
+
var String_Type: *PyObject = undefined;
|
|
107
|
+
var ByteString_Type: *PyObject = undefined;
|
|
108
|
+
var Enum_Type: *PyObject = undefined;
|
|
109
|
+
var BareEnum_Type: *PyObject = undefined;
|
|
110
|
+
var QuotedEnum_Type: *PyObject = undefined;
|
|
111
|
+
|
|
112
|
+
inline fn PyBool_Check(obj: *c.PyObject) bool {
|
|
113
|
+
return obj == PyTrue_Obj or obj == PyFalse_Obj;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
inline fn PyFloat_Check(obj: *c.PyObject) bool {
|
|
117
|
+
return c.PyObject_IsInstance(obj, PyFloat_Type) == 1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
inline fn PyByteArray_Check(obj: *c.PyObject) bool {
|
|
121
|
+
return c.PyObject_IsInstance(obj, PyByteArray_Type) == 1;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
inline fn PyAnySet_Check(obj: *c.PyObject) bool {
|
|
125
|
+
return c.PyObject_IsInstance(obj, PySet_Type) == 1 or c.PyObject_IsInstance(obj, PyFrozenSet_Type) == 1;
|
|
126
|
+
}
|
|
59
127
|
|
|
60
128
|
fn createSubclass(
|
|
61
|
-
base: *c
|
|
129
|
+
base: [*c]PyObject,
|
|
62
130
|
name: [*:0]const u8,
|
|
63
131
|
doc: [*:0]const u8,
|
|
64
|
-
) ?*
|
|
132
|
+
) ?*PyObject {
|
|
65
133
|
const slots = [_]c.PyType_Slot{
|
|
66
134
|
.{ .slot = c.Py_tp_base, .pfunc = @ptrCast(base) },
|
|
67
135
|
.{ .slot = c.Py_tp_doc, .pfunc = @ptrCast(@constCast(doc)) },
|
|
@@ -78,28 +146,41 @@ fn createSubclass(
|
|
|
78
146
|
}
|
|
79
147
|
|
|
80
148
|
fn initCustomTypes(mod: [*c]c.PyObject) bool {
|
|
81
|
-
|
|
149
|
+
PyDict_Type = getBuiltinType("dict") orelse return false;
|
|
150
|
+
PyList_Type = getBuiltinType("list") orelse return false;
|
|
151
|
+
PyLong_Type = getBuiltinType("int") orelse return false;
|
|
152
|
+
PyFloat_Type = getBuiltinType("float") orelse return false;
|
|
153
|
+
PyUnicode_Type = getBuiltinType("str") orelse return false;
|
|
154
|
+
PyBytes_Type = getBuiltinType("bytes") orelse return false;
|
|
155
|
+
PyByteArray_Type = getBuiltinType("bytearray") orelse return false;
|
|
156
|
+
PySet_Type = getBuiltinType("set") orelse return false;
|
|
157
|
+
PyFrozenSet_Type = getBuiltinType("frozenset") orelse return false;
|
|
158
|
+
|
|
159
|
+
PyTrue_Obj = c.PyBool_FromLong(1) orelse return false;
|
|
160
|
+
PyFalse_Obj = c.PyBool_FromLong(0) orelse return false;
|
|
161
|
+
|
|
162
|
+
Struct_Type = createSubclass(PyDict_Type, "zig_zon.Struct", "a zon struct wrapping dict") orelse return false;
|
|
82
163
|
assert(0 <= c.PyObject_SetAttrString(mod, "Struct", Struct_Type));
|
|
83
164
|
|
|
84
|
-
Tuple_Type = createSubclass(
|
|
165
|
+
Tuple_Type = createSubclass(PyList_Type, "zig_zon.Tuple", "a zon tuple wrapping list") orelse return false;
|
|
85
166
|
assert(0 <= c.PyObject_SetAttrString(mod, "Tuple", Tuple_Type));
|
|
86
167
|
|
|
87
|
-
Integer_Type = createSubclass(
|
|
168
|
+
Integer_Type = createSubclass(PyLong_Type, "zig_zon.Integer", "a zon integer wrapping int") orelse return false;
|
|
88
169
|
assert(0 <= c.PyObject_SetAttrString(mod, "Integer", Integer_Type));
|
|
89
170
|
|
|
90
|
-
Hex_Type = createSubclass(
|
|
171
|
+
Hex_Type = createSubclass(PyLong_Type, "zig_zon.Hex", "a zon hex wrapping int") orelse return false;
|
|
91
172
|
assert(0 <= c.PyObject_SetAttrString(mod, "Hex", Hex_Type));
|
|
92
173
|
|
|
93
|
-
Float_Type = createSubclass(
|
|
174
|
+
Float_Type = createSubclass(PyFloat_Type, "zig_zon.Float", "a zon float wrapping float") orelse return false;
|
|
94
175
|
assert(0 <= c.PyObject_SetAttrString(mod, "Float", Float_Type));
|
|
95
176
|
|
|
96
|
-
String_Type = createSubclass(
|
|
177
|
+
String_Type = createSubclass(PyUnicode_Type, "zig_zon.String", "a zon string wrapping str") orelse return false;
|
|
97
178
|
assert(0 <= c.PyObject_SetAttrString(mod, "String", String_Type));
|
|
98
179
|
|
|
99
|
-
ByteString_Type = createSubclass(
|
|
180
|
+
ByteString_Type = createSubclass(PyBytes_Type, "zig_zon.ByteString", "a zon bytestring wrapping bytes") orelse return false;
|
|
100
181
|
assert(0 <= c.PyObject_SetAttrString(mod, "ByteString", ByteString_Type));
|
|
101
182
|
|
|
102
|
-
Enum_Type = createSubclass(
|
|
183
|
+
Enum_Type = createSubclass(PyUnicode_Type, "zig_zon.Enum", "a zon enum wrapping str") orelse return false;
|
|
103
184
|
assert(0 <= c.PyObject_SetAttrString(mod, "Enum", Enum_Type));
|
|
104
185
|
|
|
105
186
|
BareEnum_Type = createSubclass(Enum_Type, "zig_zon.BareEnum", "a zon bare enum wrapping Enum") orelse return false;
|
|
@@ -126,51 +207,46 @@ const ParseOptions = struct {
|
|
|
126
207
|
bytes: BytesMode = .@"error",
|
|
127
208
|
};
|
|
128
209
|
|
|
129
|
-
fn parseBytesMode(mode_obj: *
|
|
130
|
-
|
|
210
|
+
fn parseBytesMode(mode_obj: *PyObject, mode: *BytesMode) bool {
|
|
211
|
+
const s = PyStr.init(mode_obj) orelse {
|
|
131
212
|
c.PyErr_SetString(c.PyExc_TypeError, "bytes must be a string");
|
|
132
213
|
return false;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (ptr == null) return false;
|
|
137
|
-
const s = ptr[0..@intCast(len)];
|
|
138
|
-
if (std.mem.eql(u8, s, "error")) {
|
|
214
|
+
};
|
|
215
|
+
defer s.deinit();
|
|
216
|
+
if (std.mem.eql(u8, s.slice, "error")) {
|
|
139
217
|
mode.* = .@"error";
|
|
140
|
-
} else if (std.mem.eql(u8, s, "auto")) {
|
|
218
|
+
} else if (std.mem.eql(u8, s.slice, "auto")) {
|
|
141
219
|
mode.* = .auto;
|
|
142
|
-
} else if (std.mem.eql(u8, s, "always")) {
|
|
220
|
+
} else if (std.mem.eql(u8, s.slice, "always")) {
|
|
143
221
|
mode.* = .always;
|
|
144
222
|
} else {
|
|
145
|
-
_ = c.PyErr_Format(c.PyExc_ValueError, "invalid bytes mode '%s' (expected 'error', 'auto', or 'always')", ptr);
|
|
223
|
+
_ = c.PyErr_Format(c.PyExc_ValueError, "invalid bytes mode '%s' (expected 'error', 'auto', or 'always')", s.slice.ptr);
|
|
146
224
|
return false;
|
|
147
225
|
}
|
|
148
226
|
return true;
|
|
149
227
|
}
|
|
150
228
|
|
|
151
229
|
fn parseParseKwargs(
|
|
152
|
-
kw: *
|
|
230
|
+
kw: *PyObject,
|
|
153
231
|
has_positional_mode: bool,
|
|
154
232
|
options: *ParseOptions,
|
|
155
233
|
) bool {
|
|
156
234
|
var pos: c.Py_ssize_t = 0;
|
|
157
|
-
var key: ?*
|
|
158
|
-
var val: ?*
|
|
235
|
+
var key: ?*PyObject = null;
|
|
236
|
+
var val: ?*PyObject = null;
|
|
159
237
|
while (c.PyDict_Next(kw, &pos, &key, &val) != 0) {
|
|
160
238
|
if (c.PyUnicode_Check(key.?) == 0) continue;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (kptr == null) return false;
|
|
164
|
-
const kname = kptr[0..@intCast(klen)];
|
|
239
|
+
const kstr = PyStr.init(key.?) orelse return false;
|
|
240
|
+
defer kstr.deinit();
|
|
165
241
|
|
|
166
|
-
if (std.mem.eql(u8,
|
|
242
|
+
if (std.mem.eql(u8, kstr.slice, "bytes")) {
|
|
167
243
|
if (has_positional_mode) {
|
|
168
244
|
c.PyErr_SetString(c.PyExc_TypeError, "parse() got multiple values for argument 'bytes'");
|
|
169
245
|
return false;
|
|
170
246
|
}
|
|
171
247
|
if (!parseBytesMode(val.?, &options.bytes)) return false;
|
|
172
248
|
} else {
|
|
173
|
-
_ = c.PyErr_Format(c.PyExc_TypeError, "got an unexpected keyword argument '%s'",
|
|
249
|
+
_ = c.PyErr_Format(c.PyExc_TypeError, "got an unexpected keyword argument '%s'", kstr.slice.ptr);
|
|
174
250
|
return false;
|
|
175
251
|
}
|
|
176
252
|
}
|
|
@@ -185,14 +261,12 @@ pub fn parse(self: [*]PyObject, args: [*]PyObject, kwargs: ?[*]PyObject) callcon
|
|
|
185
261
|
return null;
|
|
186
262
|
}
|
|
187
263
|
const zon_obj = c.PyTuple_GetItem(args, 0);
|
|
188
|
-
|
|
264
|
+
const zon_str = PyStr.init(zon_obj) orelse {
|
|
189
265
|
c.PyErr_SetString(c.PyExc_TypeError, "zon must be a string");
|
|
190
266
|
return null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
if (zon_ptr == null) return null;
|
|
195
|
-
const zon_slice: [:0]const u8 = zon_ptr[0..@intCast(zon_len) :0];
|
|
267
|
+
};
|
|
268
|
+
defer zon_str.deinit();
|
|
269
|
+
const zon_slice: [:0]const u8 = zon_str.slice;
|
|
196
270
|
|
|
197
271
|
var options: ParseOptions = .{};
|
|
198
272
|
if (arg_count == 2) {
|
|
@@ -251,7 +325,7 @@ pub fn parse(self: [*]PyObject, args: [*]PyObject, kwargs: ?[*]PyObject) callcon
|
|
|
251
325
|
};
|
|
252
326
|
}
|
|
253
327
|
|
|
254
|
-
inline fn PyNone() [*c]
|
|
328
|
+
inline fn PyNone() [*c]PyObject {
|
|
255
329
|
return c.Py_BuildValue("");
|
|
256
330
|
}
|
|
257
331
|
|
|
@@ -265,7 +339,7 @@ const ZonError = error{
|
|
|
265
339
|
WriteFailed,
|
|
266
340
|
} || IdentifierError || NumberLiteralError;
|
|
267
341
|
|
|
268
|
-
fn parseZonAst(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: ParseOptions) ZonError!*
|
|
342
|
+
fn parseZonAst(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: ParseOptions) ZonError!*PyObject {
|
|
269
343
|
const node_tag = tree.nodeTag(node);
|
|
270
344
|
switch (node_tag) {
|
|
271
345
|
.struct_init_comma,
|
|
@@ -298,12 +372,12 @@ fn parseZonAst(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: Parse
|
|
|
298
372
|
);
|
|
299
373
|
const base_str = c.PyUnicode_FromStringAndSize(enum_parsed_name.ptr, @intCast(enum_parsed_name.len)) orelse return error.InvalidLiteral;
|
|
300
374
|
defer c.Py_DecRef(base_str);
|
|
301
|
-
return
|
|
375
|
+
return PyObject_CallOneArg(QuotedEnum_Type, base_str) orelse error.InvalidLiteral;
|
|
302
376
|
}
|
|
303
377
|
|
|
304
378
|
const base_str = c.PyUnicode_FromStringAndSize(enum_name.ptr, @intCast(enum_name.len)) orelse return error.InvalidLiteral;
|
|
305
379
|
defer c.Py_DecRef(base_str);
|
|
306
|
-
return
|
|
380
|
+
return PyObject_CallOneArg(BareEnum_Type, base_str) orelse error.InvalidLiteral;
|
|
307
381
|
},
|
|
308
382
|
.string_literal, .multiline_string_literal => {
|
|
309
383
|
var buf = std.ArrayListUnmanaged(u8).empty;
|
|
@@ -319,23 +393,23 @@ fn parseZonAst(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: Parse
|
|
|
319
393
|
.always => {
|
|
320
394
|
const base_bytes = c.PyBytes_FromStringAndSize(buf.items.ptr, @intCast(buf.items.len)) orelse return error.PyErr;
|
|
321
395
|
defer c.Py_DecRef(base_bytes);
|
|
322
|
-
return
|
|
396
|
+
return PyObject_CallOneArg(ByteString_Type, base_bytes) orelse error.PyErr;
|
|
323
397
|
},
|
|
324
398
|
.auto => {
|
|
325
399
|
if (std.unicode.utf8ValidateSlice(buf.items)) {
|
|
326
400
|
const base_str = c.PyUnicode_FromStringAndSize(buf.items.ptr, @intCast(buf.items.len)) orelse return error.PyErr;
|
|
327
401
|
defer c.Py_DecRef(base_str);
|
|
328
|
-
return
|
|
402
|
+
return PyObject_CallOneArg(String_Type, base_str) orelse error.PyErr;
|
|
329
403
|
} else {
|
|
330
404
|
const base_bytes = c.PyBytes_FromStringAndSize(buf.items.ptr, @intCast(buf.items.len)) orelse return error.PyErr;
|
|
331
405
|
defer c.Py_DecRef(base_bytes);
|
|
332
|
-
return
|
|
406
|
+
return PyObject_CallOneArg(ByteString_Type, base_bytes) orelse error.PyErr;
|
|
333
407
|
}
|
|
334
408
|
},
|
|
335
409
|
.@"error" => {
|
|
336
410
|
const base_str = c.PyUnicode_DecodeUTF8(buf.items.ptr, @intCast(buf.items.len), "strict") orelse return error.PyErr;
|
|
337
411
|
defer c.Py_DecRef(base_str);
|
|
338
|
-
return
|
|
412
|
+
return PyObject_CallOneArg(String_Type, base_str) orelse error.PyErr;
|
|
339
413
|
},
|
|
340
414
|
}
|
|
341
415
|
},
|
|
@@ -377,7 +451,7 @@ const NumberLiteralError = error{
|
|
|
377
451
|
NumberLiteralFail,
|
|
378
452
|
};
|
|
379
453
|
|
|
380
|
-
fn parseNumberLiteral(arena: Allocator, tree: Ast, node: Ast.Node.Index, negated: bool) NumberLiteralError!*
|
|
454
|
+
fn parseNumberLiteral(arena: Allocator, tree: Ast, node: Ast.Node.Index, negated: bool) NumberLiteralError!*PyObject {
|
|
381
455
|
_ = arena;
|
|
382
456
|
const num_token = tree.lastToken(node);
|
|
383
457
|
const token_bytes = tree.tokenSlice(num_token);
|
|
@@ -386,7 +460,7 @@ fn parseNumberLiteral(arena: Allocator, tree: Ast, node: Ast.Node.Index, negated
|
|
|
386
460
|
.int => |n| {
|
|
387
461
|
const factor: i64 = if (negated) -1 else 1;
|
|
388
462
|
const neglim = 9223372036854775807; // 2**63 - 1
|
|
389
|
-
const base_int: *
|
|
463
|
+
const base_int: *PyObject = if (n <= neglim)
|
|
390
464
|
c.PyLong_FromSsize_t(factor * @as(i64, @intCast(n))) orelse return error.NumberLiteralFail
|
|
391
465
|
else blk: {
|
|
392
466
|
if (factor == -1) return error.BigIntNotImplemented;
|
|
@@ -396,7 +470,7 @@ fn parseNumberLiteral(arena: Allocator, tree: Ast, node: Ast.Node.Index, negated
|
|
|
396
470
|
|
|
397
471
|
const is_hex = std.mem.startsWith(u8, token_bytes, "0x") or std.mem.startsWith(u8, token_bytes, "0X");
|
|
398
472
|
const cls = if (is_hex) Hex_Type else Integer_Type;
|
|
399
|
-
return
|
|
473
|
+
return PyObject_CallOneArg(cls, base_int) orelse error.NumberLiteralFail;
|
|
400
474
|
},
|
|
401
475
|
.big_int => return error.BigIntNotImplemented,
|
|
402
476
|
.float => |n| {
|
|
@@ -409,7 +483,7 @@ fn parseNumberLiteral(arena: Allocator, tree: Ast, node: Ast.Node.Index, negated
|
|
|
409
483
|
|
|
410
484
|
const base_float = c.PyFloat_FromDouble(factor * float) orelse return error.NumberLiteralFail;
|
|
411
485
|
defer c.Py_DecRef(base_float);
|
|
412
|
-
return
|
|
486
|
+
return PyObject_CallOneArg(Float_Type, base_float) orelse error.NumberLiteralFail;
|
|
413
487
|
},
|
|
414
488
|
.failure => |err| {
|
|
415
489
|
std.log.err("number literal: {} bytes: {s}", .{ err, token_bytes });
|
|
@@ -418,11 +492,11 @@ fn parseNumberLiteral(arena: Allocator, tree: Ast, node: Ast.Node.Index, negated
|
|
|
418
492
|
}
|
|
419
493
|
}
|
|
420
494
|
|
|
421
|
-
fn parseZonStruct(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: ParseOptions) ZonError!*
|
|
495
|
+
fn parseZonStruct(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: ParseOptions) ZonError!*PyObject {
|
|
422
496
|
var buf: [2]Ast.Node.Index = undefined;
|
|
423
497
|
const struct_init = tree.fullStructInit(&buf, node) orelse return error.StructExpected;
|
|
424
498
|
|
|
425
|
-
const ret =
|
|
499
|
+
const ret = PyObject_CallNoArgs(Struct_Type) orelse return error.StructExpected;
|
|
426
500
|
errdefer c.Py_DecRef(ret);
|
|
427
501
|
|
|
428
502
|
for (struct_init.ast.fields) |field_init| {
|
|
@@ -436,7 +510,7 @@ fn parseZonStruct(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: Pa
|
|
|
436
510
|
return ret;
|
|
437
511
|
}
|
|
438
512
|
|
|
439
|
-
fn parseZonArray(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: ParseOptions) !*
|
|
513
|
+
fn parseZonArray(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: ParseOptions) !*PyObject {
|
|
440
514
|
// ret.* = c.Py_BuildValue("l", @as(u64, 1));
|
|
441
515
|
var buf: [2]Ast.Node.Index = undefined;
|
|
442
516
|
const array_init = tree.fullArrayInit(&buf, node) orelse {
|
|
@@ -445,7 +519,7 @@ fn parseZonArray(arena: Allocator, tree: Ast, node: Ast.Node.Index, options: Par
|
|
|
445
519
|
return error.ZonArrayInitFailed;
|
|
446
520
|
};
|
|
447
521
|
|
|
448
|
-
const ret =
|
|
522
|
+
const ret = PyObject_CallNoArgs(Tuple_Type) orelse return error.ZonArrayInitFailed;
|
|
449
523
|
errdefer c.Py_DecRef(ret);
|
|
450
524
|
|
|
451
525
|
for (array_init.ast.elements) |elem_node| {
|
|
@@ -509,12 +583,18 @@ const IntegerMode = enum {
|
|
|
509
583
|
const StringifyOptions = struct {
|
|
510
584
|
integer_mode: IntegerMode = .auto,
|
|
511
585
|
dict_as_tuples: bool = false,
|
|
512
|
-
encoding: [
|
|
586
|
+
encoding: [64:0]u8 = initEncoding("utf-8"),
|
|
513
587
|
whitespace: bool = true,
|
|
588
|
+
|
|
589
|
+
fn initEncoding(comptime default: []const u8) [64:0]u8 {
|
|
590
|
+
var buf: [64:0]u8 = [_:0]u8{0} ** 64;
|
|
591
|
+
@memcpy(buf[0..default.len], default);
|
|
592
|
+
return buf;
|
|
593
|
+
}
|
|
514
594
|
};
|
|
515
595
|
|
|
516
596
|
inline fn isNone(obj: *c.PyObject) bool {
|
|
517
|
-
return obj == @as(*
|
|
597
|
+
return obj == @as(*PyObject, @ptrCast(&c._Py_NoneStruct));
|
|
518
598
|
}
|
|
519
599
|
|
|
520
600
|
fn isNamedTuple(obj: *c.PyObject) bool {
|
|
@@ -524,7 +604,7 @@ fn isNamedTuple(obj: *c.PyObject) bool {
|
|
|
524
604
|
|
|
525
605
|
fn serializeObject(
|
|
526
606
|
serializer: *Serializer,
|
|
527
|
-
obj: *
|
|
607
|
+
obj: *PyObject,
|
|
528
608
|
options: StringifyOptions,
|
|
529
609
|
) !void {
|
|
530
610
|
if (c.Py_EnterRecursiveCall(" while serializing to ZON") != 0) return error.PyErr;
|
|
@@ -535,7 +615,7 @@ fn serializeObject(
|
|
|
535
615
|
return;
|
|
536
616
|
}
|
|
537
617
|
|
|
538
|
-
if (
|
|
618
|
+
if (PyBool_Check(obj)) {
|
|
539
619
|
if (c.PyObject_IsTrue(obj) != 0) {
|
|
540
620
|
try serializer.writer.writeAll("true");
|
|
541
621
|
} else {
|
|
@@ -564,22 +644,20 @@ fn serializeObject(
|
|
|
564
644
|
if (use_hex) {
|
|
565
645
|
const hex_str_obj = c.PyNumber_ToBase(obj, 16) orelse return error.PyErr;
|
|
566
646
|
defer c.Py_DecRef(hex_str_obj);
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
try serializer.writer.writeAll(ptr[0..@intCast(len)]);
|
|
647
|
+
const s = PyStr.init(hex_str_obj) orelse return error.PyErr;
|
|
648
|
+
defer s.deinit();
|
|
649
|
+
try serializer.writer.writeAll(s.slice);
|
|
571
650
|
} else {
|
|
572
651
|
const str_obj = c.PyObject_Str(obj) orelse return error.PyErr;
|
|
573
652
|
defer c.Py_DecRef(str_obj);
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
try serializer.writer.writeAll(ptr[0..@intCast(len)]);
|
|
653
|
+
const s = PyStr.init(str_obj) orelse return error.PyErr;
|
|
654
|
+
defer s.deinit();
|
|
655
|
+
try serializer.writer.writeAll(s.slice);
|
|
578
656
|
}
|
|
579
657
|
return;
|
|
580
658
|
}
|
|
581
659
|
|
|
582
|
-
if (
|
|
660
|
+
if (PyFloat_Check(obj)) {
|
|
583
661
|
const d = c.PyFloat_AsDouble(obj);
|
|
584
662
|
if (std.math.isNan(d)) {
|
|
585
663
|
try serializer.writer.writeAll("nan");
|
|
@@ -603,56 +681,46 @@ fn serializeObject(
|
|
|
603
681
|
}
|
|
604
682
|
|
|
605
683
|
if (c.PyObject_IsInstance(obj, BareEnum_Type) == 1) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
if (ptr == null) return error.PyErr;
|
|
609
|
-
const s = ptr[0..@intCast(len)];
|
|
684
|
+
const s = PyStr.init(obj) orelse return error.PyErr;
|
|
685
|
+
defer s.deinit();
|
|
610
686
|
try serializer.writer.writeByte('.');
|
|
611
|
-
try serializer.writer.writeAll(s);
|
|
687
|
+
try serializer.writer.writeAll(s.slice);
|
|
612
688
|
return;
|
|
613
689
|
}
|
|
614
690
|
|
|
615
691
|
if (c.PyObject_IsInstance(obj, QuotedEnum_Type) == 1) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (ptr == null) return error.PyErr;
|
|
619
|
-
const s = ptr[0..@intCast(len)];
|
|
692
|
+
const s = PyStr.init(obj) orelse return error.PyErr;
|
|
693
|
+
defer s.deinit();
|
|
620
694
|
try serializer.writer.writeAll(".@\"");
|
|
621
|
-
try serializer.writer.print("{f}", .{std.zig.fmtString(s)});
|
|
695
|
+
try serializer.writer.print("{f}", .{std.zig.fmtString(s.slice)});
|
|
622
696
|
try serializer.writer.writeByte('"');
|
|
623
697
|
return;
|
|
624
698
|
}
|
|
625
699
|
|
|
626
700
|
if (c.PyObject_IsInstance(obj, Enum_Type) == 1) {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
const s = ptr[0..@intCast(len)];
|
|
631
|
-
try serializer.ident(s);
|
|
701
|
+
const s = PyStr.init(obj) orelse return error.PyErr;
|
|
702
|
+
defer s.deinit();
|
|
703
|
+
try serializer.ident(s.slice);
|
|
632
704
|
return;
|
|
633
705
|
}
|
|
634
706
|
|
|
635
707
|
if (c.PyUnicode_Check(obj) != 0) {
|
|
636
|
-
const enc = std.mem.sliceTo(options.encoding, 0);
|
|
708
|
+
const enc = std.mem.sliceTo(&options.encoding, 0);
|
|
637
709
|
const is_utf8 = std.mem.eql(u8, enc, "utf-8") or
|
|
638
710
|
std.mem.eql(u8, enc, "utf_8") or
|
|
639
711
|
std.mem.eql(u8, enc, "UTF-8");
|
|
640
712
|
if (is_utf8) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const s = ptr[0..@intCast(len)];
|
|
645
|
-
try serializer.string(s);
|
|
713
|
+
const s = PyStr.init(obj) orelse return error.PyErr;
|
|
714
|
+
defer s.deinit();
|
|
715
|
+
try serializer.string(s.slice);
|
|
646
716
|
} else {
|
|
647
|
-
const encoded = c.PyUnicode_AsEncodedString(obj, options.encoding, "strict") orelse return error.PyErr;
|
|
717
|
+
const encoded = c.PyUnicode_AsEncodedString(obj, &options.encoding, "strict") orelse return error.PyErr;
|
|
648
718
|
defer c.Py_DecRef(encoded);
|
|
649
|
-
const decoded = c.PyUnicode_FromEncodedObject(encoded, options.encoding, "strict") orelse return error.PyErr;
|
|
719
|
+
const decoded = c.PyUnicode_FromEncodedObject(encoded, &options.encoding, "strict") orelse return error.PyErr;
|
|
650
720
|
defer c.Py_DecRef(decoded);
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
const s = ptr[0..@intCast(len)];
|
|
655
|
-
try serializer.string(s);
|
|
721
|
+
const s = PyStr.init(decoded) orelse return error.PyErr;
|
|
722
|
+
defer s.deinit();
|
|
723
|
+
try serializer.string(s.slice);
|
|
656
724
|
}
|
|
657
725
|
return;
|
|
658
726
|
}
|
|
@@ -666,14 +734,12 @@ fn serializeObject(
|
|
|
666
734
|
return;
|
|
667
735
|
}
|
|
668
736
|
|
|
669
|
-
if (c.PyBytes_Check(obj) != 0 or
|
|
670
|
-
const text = c.PyUnicode_FromEncodedObject(obj, options.encoding, "strict") orelse return error.PyErr;
|
|
737
|
+
if (c.PyBytes_Check(obj) != 0 or PyByteArray_Check(obj)) {
|
|
738
|
+
const text = c.PyUnicode_FromEncodedObject(obj, &options.encoding, "strict") orelse return error.PyErr;
|
|
671
739
|
defer c.Py_DecRef(text);
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const s = ptr[0..@intCast(len)];
|
|
676
|
-
try serializer.string(s);
|
|
740
|
+
const s = PyStr.init(text) orelse return error.PyErr;
|
|
741
|
+
defer s.deinit();
|
|
742
|
+
try serializer.string(s.slice);
|
|
677
743
|
return;
|
|
678
744
|
}
|
|
679
745
|
|
|
@@ -686,12 +752,10 @@ fn serializeObject(
|
|
|
686
752
|
});
|
|
687
753
|
for (0..@intCast(count)) |i| {
|
|
688
754
|
const fname_obj = c.PyTuple_GetItem(fields, @intCast(i));
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
if (kptr == null) return error.PyErr;
|
|
692
|
-
const kname = kptr[0..@intCast(klen)];
|
|
755
|
+
const fname = PyStr.init(fname_obj) orelse return error.PyErr;
|
|
756
|
+
defer fname.deinit();
|
|
693
757
|
const fval_obj = c.PyTuple_GetItem(obj, @intCast(i));
|
|
694
|
-
try struct_container.fieldPrefix(
|
|
758
|
+
try struct_container.fieldPrefix(fname.slice);
|
|
695
759
|
try serializeObject(serializer, fval_obj, options);
|
|
696
760
|
}
|
|
697
761
|
try struct_container.end();
|
|
@@ -705,8 +769,8 @@ fn serializeObject(
|
|
|
705
769
|
.whitespace_style = .{ .fields = @intCast(dict_len) },
|
|
706
770
|
});
|
|
707
771
|
var pos: c.Py_ssize_t = 0;
|
|
708
|
-
var key: ?*
|
|
709
|
-
var val: ?*
|
|
772
|
+
var key: ?*PyObject = null;
|
|
773
|
+
var val: ?*PyObject = null;
|
|
710
774
|
while (c.PyDict_Next(obj, &pos, &key, &val) != 0) {
|
|
711
775
|
try outer.fieldPrefix();
|
|
712
776
|
var inner = try serializer.beginTuple(.{
|
|
@@ -724,18 +788,16 @@ fn serializeObject(
|
|
|
724
788
|
.whitespace_style = .{ .fields = @intCast(dict_len) },
|
|
725
789
|
});
|
|
726
790
|
var pos: c.Py_ssize_t = 0;
|
|
727
|
-
var key: ?*
|
|
728
|
-
var val: ?*
|
|
791
|
+
var key: ?*PyObject = null;
|
|
792
|
+
var val: ?*PyObject = null;
|
|
729
793
|
while (c.PyDict_Next(obj, &pos, &key, &val) != 0) {
|
|
730
794
|
if (c.PyUnicode_Check(key.?) == 0) {
|
|
731
795
|
c.PyErr_SetString(c.PyExc_TypeError, "dict keys must be strings when serialized as a struct; use dict_as_tuples=True");
|
|
732
796
|
return error.PyErr;
|
|
733
797
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
const kname = kptr[0..@intCast(klen)];
|
|
738
|
-
try struct_container.fieldPrefix(kname);
|
|
798
|
+
const kstr = PyStr.init(key.?) orelse return error.PyErr;
|
|
799
|
+
defer kstr.deinit();
|
|
800
|
+
try struct_container.fieldPrefix(kstr.slice);
|
|
739
801
|
try serializeObject(serializer, val.?, options);
|
|
740
802
|
}
|
|
741
803
|
try struct_container.end();
|
|
@@ -758,7 +820,7 @@ fn serializeObject(
|
|
|
758
820
|
return;
|
|
759
821
|
}
|
|
760
822
|
|
|
761
|
-
if (
|
|
823
|
+
if (PyAnySet_Check(obj)) {
|
|
762
824
|
const count = c.PySet_Size(obj);
|
|
763
825
|
var container = try serializer.beginTuple(.{
|
|
764
826
|
.whitespace_style = .{ .fields = @intCast(count) },
|
|
@@ -775,67 +837,71 @@ fn serializeObject(
|
|
|
775
837
|
return;
|
|
776
838
|
}
|
|
777
839
|
|
|
778
|
-
|
|
840
|
+
if (PyType_GetName(obj)) |type_name| {
|
|
841
|
+
defer c.Py_DecRef(type_name);
|
|
842
|
+
_ = c.PyErr_Format(c.PyExc_TypeError, "Object of type '%U' is not ZON serializable", type_name);
|
|
843
|
+
} else {
|
|
844
|
+
c.PyErr_SetString(c.PyExc_TypeError, "Object is not ZON serializable");
|
|
845
|
+
}
|
|
779
846
|
return error.PyErr;
|
|
780
847
|
}
|
|
781
848
|
|
|
782
849
|
fn parseStringifyKwargs(
|
|
783
|
-
kw: *
|
|
850
|
+
kw: *PyObject,
|
|
784
851
|
options: *StringifyOptions,
|
|
785
852
|
) bool {
|
|
786
853
|
var pos: c.Py_ssize_t = 0;
|
|
787
|
-
var key: ?*
|
|
788
|
-
var val: ?*
|
|
854
|
+
var key: ?*PyObject = null;
|
|
855
|
+
var val: ?*PyObject = null;
|
|
789
856
|
while (c.PyDict_Next(kw, &pos, &key, &val) != 0) {
|
|
790
857
|
if (c.PyUnicode_Check(key.?) == 0) continue;
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
if (kptr == null) return false;
|
|
794
|
-
const kname = kptr[0..@intCast(klen)];
|
|
858
|
+
const kstr = PyStr.init(key.?) orelse return false;
|
|
859
|
+
defer kstr.deinit();
|
|
795
860
|
|
|
796
|
-
if (std.mem.eql(u8,
|
|
797
|
-
|
|
861
|
+
if (std.mem.eql(u8, kstr.slice, "integer_mode")) {
|
|
862
|
+
const vstr = PyStr.init(val.?) orelse {
|
|
798
863
|
c.PyErr_SetString(c.PyExc_TypeError, "integer_mode must be a string");
|
|
799
864
|
return false;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (vptr == null) return false;
|
|
804
|
-
const vs = vptr[0..@intCast(vlen)];
|
|
805
|
-
if (std.mem.eql(u8, vs, "auto")) {
|
|
865
|
+
};
|
|
866
|
+
defer vstr.deinit();
|
|
867
|
+
if (std.mem.eql(u8, vstr.slice, "auto")) {
|
|
806
868
|
options.integer_mode = .auto;
|
|
807
|
-
} else if (std.mem.eql(u8,
|
|
869
|
+
} else if (std.mem.eql(u8, vstr.slice, "int")) {
|
|
808
870
|
options.integer_mode = .int;
|
|
809
|
-
} else if (std.mem.eql(u8,
|
|
871
|
+
} else if (std.mem.eql(u8, vstr.slice, "hex")) {
|
|
810
872
|
options.integer_mode = .hex;
|
|
811
|
-
} else if (std.mem.eql(u8,
|
|
873
|
+
} else if (std.mem.eql(u8, vstr.slice, "fallback_int")) {
|
|
812
874
|
options.integer_mode = .fallback_int;
|
|
813
|
-
} else if (std.mem.eql(u8,
|
|
875
|
+
} else if (std.mem.eql(u8, vstr.slice, "fallback_hex")) {
|
|
814
876
|
options.integer_mode = .fallback_hex;
|
|
815
|
-
} else if (std.mem.eql(u8,
|
|
877
|
+
} else if (std.mem.eql(u8, vstr.slice, "error")) {
|
|
816
878
|
options.integer_mode = .@"error";
|
|
817
879
|
} else {
|
|
818
|
-
_ = c.PyErr_Format(c.PyExc_ValueError, "invalid integer_mode '%s' (expected 'auto', 'int', 'hex', 'fallback_int', 'fallback_hex', or 'error')",
|
|
880
|
+
_ = c.PyErr_Format(c.PyExc_ValueError, "invalid integer_mode '%s' (expected 'auto', 'int', 'hex', 'fallback_int', 'fallback_hex', or 'error')", vstr.slice.ptr);
|
|
819
881
|
return false;
|
|
820
882
|
}
|
|
821
|
-
} else if (std.mem.eql(u8,
|
|
883
|
+
} else if (std.mem.eql(u8, kstr.slice, "dict_as_tuples")) {
|
|
822
884
|
const is_true = c.PyObject_IsTrue(val.?);
|
|
823
885
|
if (is_true < 0) return false;
|
|
824
886
|
options.dict_as_tuples = is_true != 0;
|
|
825
|
-
} else if (std.mem.eql(u8,
|
|
826
|
-
|
|
887
|
+
} else if (std.mem.eql(u8, kstr.slice, "encoding")) {
|
|
888
|
+
const estr = PyStr.init(val.?) orelse {
|
|
827
889
|
c.PyErr_SetString(c.PyExc_TypeError, "encoding must be a string");
|
|
828
890
|
return false;
|
|
891
|
+
};
|
|
892
|
+
defer estr.deinit();
|
|
893
|
+
if (estr.slice.len >= options.encoding.len) {
|
|
894
|
+
c.PyErr_SetString(c.PyExc_ValueError, "encoding name too long");
|
|
895
|
+
return false;
|
|
829
896
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
} else if (std.mem.eql(u8, kname, "whitespace")) {
|
|
897
|
+
@memset(&options.encoding, 0);
|
|
898
|
+
@memcpy(options.encoding[0..estr.slice.len], estr.slice);
|
|
899
|
+
} else if (std.mem.eql(u8, kstr.slice, "whitespace")) {
|
|
834
900
|
const is_true = c.PyObject_IsTrue(val.?);
|
|
835
901
|
if (is_true < 0) return false;
|
|
836
902
|
options.whitespace = is_true != 0;
|
|
837
903
|
} else {
|
|
838
|
-
_ = c.PyErr_Format(c.PyExc_TypeError, "got an unexpected keyword argument '%s'",
|
|
904
|
+
_ = c.PyErr_Format(c.PyExc_TypeError, "got an unexpected keyword argument '%s'", kstr.slice.ptr);
|
|
839
905
|
return false;
|
|
840
906
|
}
|
|
841
907
|
}
|
|
@@ -843,9 +909,9 @@ fn parseStringifyKwargs(
|
|
|
843
909
|
}
|
|
844
910
|
|
|
845
911
|
fn serializeToPyStr(
|
|
846
|
-
val_obj: *
|
|
912
|
+
val_obj: *PyObject,
|
|
847
913
|
options: StringifyOptions,
|
|
848
|
-
) [*c]
|
|
914
|
+
) [*c]PyObject {
|
|
849
915
|
var arena_instance = std.heap.ArenaAllocator.init(cpython.py_allocator);
|
|
850
916
|
defer arena_instance.deinit();
|
|
851
917
|
const arena = arena_instance.allocator();
|
|
@@ -902,7 +968,7 @@ pub fn py_dump(self: [*]PyObject, args: [*]PyObject, kwargs: ?[*]PyObject) callc
|
|
|
902
968
|
return null;
|
|
903
969
|
}
|
|
904
970
|
const val_obj = c.PyTuple_GetItem(args, 0);
|
|
905
|
-
const file_obj: *
|
|
971
|
+
const file_obj: *PyObject = c.PyTuple_GetItem(args, 1);
|
|
906
972
|
|
|
907
973
|
var options: StringifyOptions = .{};
|
|
908
974
|
if (kwargs) |kw| {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/LowerDashString.zig
RENAMED
|
File without changes
|
|
File without changes
|
{zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/VenvInstallTest.zig
RENAMED
|
File without changes
|
{zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/extract_link_info.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/python-translatec.h
RENAMED
|
File without changes
|
|
File without changes
|
{zig-zon-0.3.0 → zig-zon-0.3.2}/zig-pkg/zig_python_sdist-0.0.8/src/build/python_allocator.zig
RENAMED
|
File without changes
|
|
File without changes
|