sbsv 0.0.1__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.
sbsv-0.0.1/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ build
2
+ dist
3
+ *.egg-info
sbsv-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Seungheon Han
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
sbsv-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.1
2
+ Name: sbsv
3
+ Version: 0.0.1
4
+ Summary: SBSV: Square Brackets Separated Values
5
+ Project-URL: Homepage, https://github.com/hsh814/sbsv
6
+ Project-URL: Issues, https://github.com/hsh814/sbsv/issues
7
+ Author-email: Seungheon Han <shhan814@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+
15
+ # SBSV: square bracket separated values
16
+
17
+ ## Install
18
+
19
+ ```shell
20
+ python3 -m pip install svsb
21
+ ```
22
+
23
+ ## Use
24
+ You can read this log-like data:
25
+ ```sbsv
26
+ [meta-data] [id 1] [format string]
27
+ [meta-data] [id 2] [format token]
28
+ [data] [string] [id 1] [actual some long string...]
29
+ [data] [token] [id 2] [actual [some] [multiple] [tokens]]
30
+ [stat] [rows 2]
31
+ ```
32
+
33
+ ```python
34
+ import sbsv
35
+
36
+ parser = sbsv.parser()
37
+ parser.add_schema("[meta-data] [id: int] [format: str]")
38
+ parser.add_schema("[data] [string] [id: int] [actual: str]")
39
+ parser.add_schema("[data] [token] [id: int] [actual: list[str]]")
40
+ parser.add_schema("[stat] [rows: int]")
41
+ with open("testfile.svsb", "r") as f:
42
+ result = parser.load(f)
43
+ ```
44
+
45
+ Result would looks like:
46
+ ```
47
+ {
48
+ "meta-data": [{"id": 1, "format": "string"}, {"id": 2, "format": "string"}],
49
+ "data": {
50
+ "string": [{"id": 1, "actual": "some long string..."}],
51
+ "token": [{"id": 2, "actual": ["some", "multiple", "tokens"]}]
52
+ },
53
+ "stat": [{"rows": 2}]
54
+ }
55
+ ```
56
+
57
+ ## Details
58
+ ### Basic schema
59
+ Schema is consisted with schema name, variable name and type annotation.
60
+ ```
61
+ [schema-name] [var-name: type]
62
+ ```
63
+ You can use [A-Za-z0-9\-_] for names.
64
+
65
+ ### Sub schema
66
+ ```
67
+ [my-schema] [sub-schema] [some: int] [other: str] [data: bool]
68
+ ```
69
+ You can add any sub schema.
70
+ But if you add sub schema, you cannot add new schema with same schema name without sub schema.
71
+ ```
72
+ [my-schema] [no: int] [sub: str] [schema: str]
73
+ # this will cause error
74
+ ```
75
+
76
+ ### Ignore
77
+ ```
78
+ [2024-03-04 13:22:56] [DEBUG] [necessary] [from] [this part]
79
+ ```
80
+ Regular log file may contain unnecessary data. You can specify parser to ignore `[2024-03-04 13:22:56] [DEBUG]` part.
81
+
82
+ ```python
83
+ parser.add_schema("[$ignore] [$ignore] [necessary] [from] [this: str]")
84
+ ```
85
+
86
+ ### Primitive types
87
+ Primitive types are `str`, `int`, `float`, `bool`, `null`.
88
+
89
+ ### Complex types
90
+ You can use `list`.
91
+
sbsv-0.0.1/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # SBSV: square bracket separated values
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ python3 -m pip install svsb
7
+ ```
8
+
9
+ ## Use
10
+ You can read this log-like data:
11
+ ```sbsv
12
+ [meta-data] [id 1] [format string]
13
+ [meta-data] [id 2] [format token]
14
+ [data] [string] [id 1] [actual some long string...]
15
+ [data] [token] [id 2] [actual [some] [multiple] [tokens]]
16
+ [stat] [rows 2]
17
+ ```
18
+
19
+ ```python
20
+ import sbsv
21
+
22
+ parser = sbsv.parser()
23
+ parser.add_schema("[meta-data] [id: int] [format: str]")
24
+ parser.add_schema("[data] [string] [id: int] [actual: str]")
25
+ parser.add_schema("[data] [token] [id: int] [actual: list[str]]")
26
+ parser.add_schema("[stat] [rows: int]")
27
+ with open("testfile.svsb", "r") as f:
28
+ result = parser.load(f)
29
+ ```
30
+
31
+ Result would looks like:
32
+ ```
33
+ {
34
+ "meta-data": [{"id": 1, "format": "string"}, {"id": 2, "format": "string"}],
35
+ "data": {
36
+ "string": [{"id": 1, "actual": "some long string..."}],
37
+ "token": [{"id": 2, "actual": ["some", "multiple", "tokens"]}]
38
+ },
39
+ "stat": [{"rows": 2}]
40
+ }
41
+ ```
42
+
43
+ ## Details
44
+ ### Basic schema
45
+ Schema is consisted with schema name, variable name and type annotation.
46
+ ```
47
+ [schema-name] [var-name: type]
48
+ ```
49
+ You can use [A-Za-z0-9\-_] for names.
50
+
51
+ ### Sub schema
52
+ ```
53
+ [my-schema] [sub-schema] [some: int] [other: str] [data: bool]
54
+ ```
55
+ You can add any sub schema.
56
+ But if you add sub schema, you cannot add new schema with same schema name without sub schema.
57
+ ```
58
+ [my-schema] [no: int] [sub: str] [schema: str]
59
+ # this will cause error
60
+ ```
61
+
62
+ ### Ignore
63
+ ```
64
+ [2024-03-04 13:22:56] [DEBUG] [necessary] [from] [this part]
65
+ ```
66
+ Regular log file may contain unnecessary data. You can specify parser to ignore `[2024-03-04 13:22:56] [DEBUG]` part.
67
+
68
+ ```python
69
+ parser.add_schema("[$ignore] [$ignore] [necessary] [from] [this: str]")
70
+ ```
71
+
72
+ ### Primitive types
73
+ Primitive types are `str`, `int`, `float`, `bool`, `null`.
74
+
75
+ ### Complex types
76
+ You can use `list`.
77
+
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "sbsv"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name="Seungheon Han", email="shhan814@gmail.com" },
10
+ ]
11
+ description = "SBSV: Square Brackets Separated Values"
12
+ readme = "README.md"
13
+ requires-python = ">=3.6"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/hsh814/sbsv"
22
+ Issues = "https://github.com/hsh814/sbsv/issues"
@@ -0,0 +1 @@
1
+ __version__='0.0.1'
@@ -0,0 +1,50 @@
1
+ from typing import List, Dict, Tuple, Set, TextIO
2
+
3
+
4
+ class parser:
5
+ data: dict
6
+ schema: dict
7
+ def __init__(self, data: List[List[tuple]]):
8
+ self.data = dict()
9
+ self.schema = dict()
10
+ def add_schema(self, schema: str):
11
+ # 1. tokenize
12
+ tokens = self.parser_level_1(schema)
13
+ # 2. parse
14
+ for token in tokens:
15
+ key, value = self.parser_default(token)
16
+ self.schema[tokens[0]] = value
17
+ def load(self, fp: TextIO):
18
+ return self.loads(fp.read())
19
+ def loads(self, s: str):
20
+ for line in s.split('\n'):
21
+ line = line.strip()
22
+ def parser_default(self, token: str) -> Tuple[str, str]:
23
+ tokens = token.split(maxsplit=1)
24
+ if len(tokens) == 1:
25
+ return tokens[0], ""
26
+ return tokens[0], tokens[1]
27
+ def parser_level_1(self, line: str) -> List[str]:
28
+ result = list()
29
+ level = 0
30
+ current = ""
31
+ for c in range(len(line)):
32
+ char = line[c]
33
+ if char == '[':
34
+ level += 1
35
+ if level == 1:
36
+ if len(current.strip()) > 0:
37
+ result.append(current.strip())
38
+ current = ""
39
+ continue
40
+ elif char == ']':
41
+ level -= 1
42
+ if level == 0:
43
+ result.append(current.strip())
44
+ current = ""
45
+ continue
46
+ if level > 0:
47
+ current += char
48
+ if len(current.strip()) > 0:
49
+ result.append(current.strip())
50
+ return result