yamlscript 0.1.0__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: yamlscript
3
- Version: 0.1.0
3
+ Version: 0.1.3
4
4
  Summary: Program in YAML
5
5
  Home-page: https://github.com/ingydotnet/yamlscript
6
6
  Author: Ingy döt Net
@@ -51,15 +51,25 @@ Us the `yamlscript` module in your Python program like this:
51
51
  ```python
52
52
  import yamlscript
53
53
 
54
- ys = yamlscript.YAMLScript(options_dict)
55
-
54
+ ys_file = open('file.ys')
56
55
  ys_code = open('file.ys').read()
57
56
 
58
- ys.run(ys_code)
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
- clojure_code = ys.compile(ys_code)
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.30'
5
+ yamlscript_version = '0.1.33'
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
- compile_ys_to_clj = libys.compile_ys_to_clj
36
- compile_ys_to_clj.restype = ctypes.c_char_p
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 compile(self, ys_str):
51
- ys_input = ys_str.rstrip().replace("\n", "\\n")
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
- data_value = json.loads(data_json)
73
-
74
- # free_buffer(data_buffer)
75
-
76
- return data_value
53
+ return json.loads(data_json)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: yamlscript
3
- Version: 0.1.0
3
+ Version: 0.1.3
4
4
  Summary: Program in YAML
5
5
  Home-page: https://github.com/ingydotnet/yamlscript
6
6
  Author: Ingy döt Net
@@ -1,5 +1,4 @@
1
- version = '0.1.0'
2
- yamlscript_version = '0.1.30'
1
+ version = '0.1.3'
3
2
 
4
3
  from setuptools import setup
5
4
  import pathlib
@@ -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