yamlscript 0.1.0__tar.gz → 0.1.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.
- {yamlscript-0.1.0/lib/yamlscript.egg-info → yamlscript-0.1.2}/PKG-INFO +1 -1
- {yamlscript-0.1.0 → yamlscript-0.1.2}/ReadMe.md +14 -4
- yamlscript-0.1.2/lib/yamlscript/__init__.py +20 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/lib/yamlscript/loader.py +6 -29
- {yamlscript-0.1.0 → yamlscript-0.1.2/lib/yamlscript.egg-info}/PKG-INFO +1 -1
- {yamlscript-0.1.0 → yamlscript-0.1.2}/setup.py +1 -2
- yamlscript-0.1.0/lib/yamlscript/__init__.py +0 -31
- {yamlscript-0.1.0 → yamlscript-0.1.2}/.long_description.md +0 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/MANIFEST.in +0 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/lib/yamlscript.egg-info/SOURCES.txt +0 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/lib/yamlscript.egg-info/dependency_links.txt +0 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/lib/yamlscript.egg-info/requires.txt +0 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/lib/yamlscript.egg-info/top_level.txt +0 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/setup.cfg +0 -0
- {yamlscript-0.1.0 → yamlscript-0.1.2}/test/test.py +0 -0
|
@@ -51,15 +51,25 @@ Us the `yamlscript` module in your Python program like this:
|
|
|
51
51
|
```python
|
|
52
52
|
import yamlscript
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
ys_file = open('file.ys')
|
|
56
55
|
ys_code = open('file.ys').read()
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
# Class method
|
|
58
|
+
data = yamlscript.load(ys_file)
|
|
59
|
+
data = yamlscript.load(ys_code)
|
|
59
60
|
|
|
61
|
+
# Instance method
|
|
62
|
+
ys = yamlscript.YAMLScript()
|
|
63
|
+
data = ys.load(ys_file)
|
|
60
64
|
data = ys.load(ys_code)
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
# Error handling
|
|
67
|
+
try:
|
|
68
|
+
yamlscript.load("a: b: c")
|
|
69
|
+
except Exception as e:
|
|
70
|
+
print(e)
|
|
71
|
+
print(ys.error['cause'])
|
|
72
|
+
print(ys.error['trace'])
|
|
63
73
|
```
|
|
64
74
|
|
|
65
75
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import io
|
|
2
|
+
from . import loader
|
|
3
|
+
|
|
4
|
+
class YAMLScript():
|
|
5
|
+
def load(self, input):
|
|
6
|
+
if isinstance(input, str):
|
|
7
|
+
return self._load_string(input)
|
|
8
|
+
elif isinstance(input, io.IOBase):
|
|
9
|
+
return self._load_string(input.read())
|
|
10
|
+
|
|
11
|
+
def _load_string(self, input):
|
|
12
|
+
self.error = None
|
|
13
|
+
resp = loader.Loader().load(input)
|
|
14
|
+
error = self.error = resp.get('error')
|
|
15
|
+
if error:
|
|
16
|
+
raise Exception(error['cause'])
|
|
17
|
+
return resp['data']
|
|
18
|
+
|
|
19
|
+
def load(input):
|
|
20
|
+
return YAMLScript().load(input)
|
|
@@ -2,7 +2,7 @@ import os, sys
|
|
|
2
2
|
import ctypes
|
|
3
3
|
import json
|
|
4
4
|
|
|
5
|
-
yamlscript_version = '0.1.
|
|
5
|
+
yamlscript_version = '0.1.32'
|
|
6
6
|
|
|
7
7
|
so = 'dylib' if sys.platform == 'darwin' else 'so'
|
|
8
8
|
libys_name = 'libyamlscript.' + so + '.' + yamlscript_version
|
|
@@ -32,11 +32,8 @@ libys.graal_create_isolate(
|
|
|
32
32
|
ctypes.byref(isolatethread),
|
|
33
33
|
)
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
eval_ys_to_json = libys.eval_ys_to_json
|
|
39
|
-
eval_ys_to_json.restype = ctypes.c_char_p
|
|
35
|
+
load_ys_to_json = libys.load_ys_to_json
|
|
36
|
+
load_ys_to_json.restype = ctypes.c_char_p
|
|
40
37
|
|
|
41
38
|
# User API class:
|
|
42
39
|
class Loader():
|
|
@@ -47,30 +44,10 @@ class Loader():
|
|
|
47
44
|
Load the returned JSON into a Python value and return that.
|
|
48
45
|
"""
|
|
49
46
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
data_json = compile_ys_to_clj(
|
|
54
|
-
isolatethread,
|
|
55
|
-
ctypes.c_char_p(bytes(ys_input, "utf8")),
|
|
56
|
-
).decode()
|
|
57
|
-
|
|
58
|
-
data_value = json.loads(data_json)
|
|
59
|
-
|
|
60
|
-
# free_buffer(data_buffer)
|
|
61
|
-
|
|
62
|
-
return data_value.get("clojure")
|
|
63
|
-
|
|
64
|
-
def load(self, ys_str):
|
|
65
|
-
ys_input = ys_str.rstrip().replace("\n", "\\n")
|
|
66
|
-
|
|
67
|
-
data_json = eval_ys_to_json(
|
|
47
|
+
def load(self, ys_input):
|
|
48
|
+
data_json = load_ys_to_json(
|
|
68
49
|
isolatethread,
|
|
69
50
|
ctypes.c_char_p(bytes(ys_input, "utf8")),
|
|
70
51
|
).decode()
|
|
71
52
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# free_buffer(data_buffer)
|
|
75
|
-
|
|
76
|
-
return data_value
|
|
53
|
+
return json.loads(data_json)
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import io
|
|
2
|
-
from . import loader
|
|
3
|
-
|
|
4
|
-
class YAMLScript():
|
|
5
|
-
def compile(self, input):
|
|
6
|
-
if isinstance(input, str):
|
|
7
|
-
return self._compile_string(input)
|
|
8
|
-
elif isinstance(input, io.IOBase):
|
|
9
|
-
return self._compile_string(input.read())
|
|
10
|
-
|
|
11
|
-
def load(self, input):
|
|
12
|
-
if isinstance(input, str):
|
|
13
|
-
return self._load_string(input)
|
|
14
|
-
elif isinstance(input, io.IOBase):
|
|
15
|
-
return self._load_string(input.read())
|
|
16
|
-
|
|
17
|
-
def _compile_string(self, input):
|
|
18
|
-
return loader.Loader().compile(input)
|
|
19
|
-
|
|
20
|
-
def _load_string(self, input):
|
|
21
|
-
return loader.Loader().load(input)
|
|
22
|
-
|
|
23
|
-
def compile(input):
|
|
24
|
-
return YAMLScript().compile(input)
|
|
25
|
-
|
|
26
|
-
def load(input):
|
|
27
|
-
return YAMLScript().load(input)
|
|
28
|
-
|
|
29
|
-
def run(input):
|
|
30
|
-
YAMLScript().load(input)
|
|
31
|
-
return None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|