viur-scriptor-api 0.0.1__tar.gz → 0.0.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.
Files changed (21) hide show
  1. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/PKG-INFO +1 -1
  2. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/pyproject.toml +4 -3
  3. viur_scriptor_api-0.0.2/viur/scriptor/network.py +172 -0
  4. viur_scriptor_api-0.0.1/test.py +0 -8
  5. viur_scriptor_api-0.0.1/viur/scriptor/network.py +0 -135
  6. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/.gitignore +0 -0
  7. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/LICENSE +0 -0
  8. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/Pipfile +0 -0
  9. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/Pipfile.lock +0 -0
  10. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/README.md +0 -0
  11. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/__init__.py +0 -0
  12. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/csvwriter.py +0 -0
  13. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/dialog.py +0 -0
  14. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/logger.py +0 -0
  15. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/module.py +0 -0
  16. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/progressbar.py +0 -0
  17. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/readers.py +0 -0
  18. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/renderer.py +0 -0
  19. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/utils.py +0 -0
  20. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/viur.py +0 -0
  21. {viur_scriptor_api-0.0.1 → viur_scriptor_api-0.0.2}/viur/scriptor/writer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: viur-scriptor-api
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: This is the internal Scriptor library that the viur-scriptor utilizes. The API includes components for networking as well as parts related to the Scriptor's files.
5
5
  Project-URL: Homepage, https://github.com/viur-framework/viur-scriptor-api
6
6
  Project-URL: Bug Tracker, https://github.com/viur-framework/viur-scriptor-api/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "viur-scriptor-api"
7
- version = "0.0.1"
7
+ version = "0.0.2"
8
8
  authors = [
9
9
  { name="Cian", email="co@mausbrand.de" },
10
10
  ]
@@ -34,7 +34,8 @@ exclude = [
34
34
  "/docs",
35
35
  "/tests",
36
36
  ]
37
-
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["viur"]
38
39
  [project.urls]
39
40
  "Homepage" = "https://github.com/viur-framework/viur-scriptor-api"
40
- "Bug Tracker" = "https://github.com/viur-framework/viur-scriptor-api/issues"
41
+ "Bug Tracker" = "https://github.com/viur-framework/viur-scriptor-api/issues"
@@ -0,0 +1,172 @@
1
+ import json
2
+
3
+ from urllib.parse import urlencode as _urlencode
4
+ from .utils import is_pyodide_context
5
+ from abc import abstractmethod
6
+
7
+ if is_pyodide_context():
8
+ from js import console, fetch, FormData
9
+ from pyodide.ffi import to_js
10
+ from config import BASE_URL
11
+ else:
12
+ import requests
13
+ from requests.sessions import cookiejar_from_dict
14
+
15
+ from .logger import Logging as logging
16
+ import traceback
17
+
18
+
19
+ class Request:
20
+ COOKIES = {}
21
+
22
+ def __init__(self, method: str, url: str, credentials: bool = False, headers: dict = None,
23
+ data: dict = None) -> None:
24
+ self._status = None
25
+ self._result = None
26
+
27
+ self._method = method.upper()
28
+ self._data = None
29
+ self._credentials = credentials
30
+
31
+ if data:
32
+ if method == "GET":
33
+ url += "?" + _urlencode(data)
34
+ else:
35
+ if is_pyodide_context():
36
+ self._data = FormData.new()
37
+ for k, v in data.items():
38
+ for val in self.to_form_value(k,v):
39
+ self._data.append(val[0], val[1])
40
+
41
+ else:
42
+ self._data = data
43
+
44
+ self._headers = headers
45
+ self._url = url
46
+ self._response = None
47
+
48
+ def flat(self, val):
49
+ res = []
50
+ for v in val:
51
+ if isinstance(v, list):
52
+ res.extend(self.flat(v))
53
+ else:
54
+ res.append(v)
55
+ return res
56
+
57
+ def to_form_value(self, bone_name, val):
58
+ def to_form_value_intern(bone_name_intern, val_intern):
59
+ res = []
60
+ if isinstance(val_intern, list):
61
+ if any([isinstance(entry, dict) for entry in val_intern]):
62
+ for idx, entry in enumerate(val_intern):
63
+ res += to_form_value_intern(bone_name + "." + str(idx), entry)
64
+ else:
65
+ for v in val_intern:
66
+ res.append(to_form_value_intern(bone_name, v))
67
+
68
+ elif isinstance(val_intern, dict):
69
+ for k, v in val_intern.items():
70
+ if bone_name_intern:
71
+ res.append(to_form_value_intern(f"{bone_name_intern}.{k}", v))
72
+ else:
73
+ res.append(to_form_value_intern(k, v))
74
+ else:
75
+ if val_intern is None:
76
+ val_intern = ""
77
+ if bone_name_intern:
78
+ res.append((bone_name, val_intern))
79
+
80
+ return res
81
+
82
+ return self.flat(to_form_value_intern(bone_name, val))
83
+
84
+ async def perform(self):
85
+ if is_pyodide_context():
86
+ options = {"method": self._method}
87
+
88
+ if self._headers:
89
+ options.update({"headers": to_js(self._headers)})
90
+
91
+ if self._data:
92
+ options.update({"body": to_js(self._data)})
93
+
94
+ if self._credentials:
95
+ options.update({"credentials": 'include'})
96
+
97
+ self._response = await fetch(self._url, **options)
98
+ self._status = self._response.status
99
+ else:
100
+ kwargs = {"headers": self._headers}
101
+ if self._method == "POST":
102
+ kwargs.update({"data": self._data})
103
+
104
+ try:
105
+ if self._credentials:
106
+ kwargs.update({"cookies": self.COOKIES})
107
+ except AttributeError:
108
+ Logging.error("You need to set an cookie.")
109
+
110
+ self._response = requests.request(self._method, self._url, **kwargs)
111
+ self._status = self._response.status_code
112
+
113
+ async def json(self):
114
+ if not self._response:
115
+ return None
116
+
117
+ if is_pyodide_context():
118
+ _text = await self._response.text()
119
+ try:
120
+ ret = json.loads(_text)
121
+ except:
122
+ # Logging.error(traceback.format_exc())
123
+ ret = _text
124
+ return ret
125
+
126
+ return self._response.json()
127
+
128
+ async def text(self):
129
+ if is_pyodide_context():
130
+ return await self._response.text()
131
+
132
+ return self._response.text
133
+
134
+ async def blob(self):
135
+ if is_pyodide_context():
136
+ return await self._response.blob()
137
+
138
+ return self._response.content
139
+
140
+ @staticmethod
141
+ async def get(*args, **kwargs):
142
+ _request = Request("GET", *args, **kwargs)
143
+ await _request.perform()
144
+ return _request
145
+
146
+ @staticmethod
147
+ async def post(*args, **kwargs):
148
+ _request = Request("POST", *args, **kwargs)
149
+ await _request.perform()
150
+
151
+ return _request
152
+
153
+ @staticmethod
154
+ async def put(*args, **kwargs):
155
+ _request = Request("PUT", *args, **kwargs)
156
+ await _request.perform()
157
+
158
+ return _request
159
+
160
+ @staticmethod
161
+ async def delete(*args, **kwargs):
162
+ _request = Request("DELETE", *args, **kwargs)
163
+ await _request.perform()
164
+
165
+ return _request
166
+
167
+ @staticmethod
168
+ async def patch(*args, **kwargs):
169
+ _request = Request("PATCH", *args, **kwargs)
170
+ await _request.perform()
171
+
172
+ return _request
@@ -1,8 +0,0 @@
1
- from viur.scriptor.dialog import table
2
- import asyncio
3
-
4
- async def main():
5
- x = await table(header=["Name", "Vorname"], rows=[["1", "2"], ['3', '4']], select=True, multiple=True)
6
- print(x)
7
-
8
- asyncio.run(main())
@@ -1,135 +0,0 @@
1
- import json
2
-
3
- from urllib.parse import urlencode as _urlencode
4
- from .utils import is_pyodide_context
5
- from abc import abstractmethod
6
-
7
- if is_pyodide_context():
8
- from js import console, fetch, FormData
9
- from pyodide.ffi import to_js
10
- from config import BASE_URL
11
- else:
12
- import requests
13
- from requests.sessions import cookiejar_from_dict
14
-
15
- from .logger import Logging
16
-
17
- import traceback
18
-
19
-
20
- class Request:
21
- COOKIES = {}
22
-
23
- def __init__(self, method: str, url: str, credentials: bool = False, headers: dict = None, data: dict = None) -> None:
24
- self._status = None
25
- self._result = None
26
-
27
- self._method = method.upper()
28
- self._data = None
29
- self._credentials = credentials
30
-
31
- if data:
32
- if method == "GET":
33
- url += "?" + _urlencode(data)
34
- else:
35
- if is_pyodide_context():
36
- self._data = FormData.new()
37
- for k, v in data.items():
38
- self._data.append(k, v)
39
- else:
40
- self._data = data
41
-
42
- self._headers = headers
43
- self._url = url
44
- self._response = None
45
-
46
- async def perform(self):
47
- if is_pyodide_context():
48
- options = {"method": self._method}
49
-
50
- if self._headers:
51
- options.update({"headers": to_js(self._headers)})
52
-
53
- if self._data:
54
- options.update({"body": to_js(self._data)})
55
-
56
- if self._credentials:
57
- options.update({"credentials": 'include'})
58
-
59
- self._response = await fetch(self._url, **options)
60
- self._status = self._response.status
61
- else:
62
- kwargs = {"headers":self._headers}
63
- if self._method == "POST":
64
- kwargs.update({"data": self._data})
65
-
66
- try:
67
- if self._credentials:
68
- kwargs.update({"cookies": self.COOKIES})
69
- except AttributeError:
70
- Logging.error("You need to set an cookie.")
71
-
72
- self._response = requests.request(self._method, self._url, **kwargs)
73
- self._status = self._response.status_code
74
-
75
- async def json(self):
76
- if not self._response:
77
- return None
78
-
79
- if is_pyodide_context():
80
- _text = await self._response.text()
81
- try:
82
- ret = json.loads(_text)
83
- except:
84
- #Logging.error(traceback.format_exc())
85
- ret = _text
86
- return ret
87
-
88
- return self._response.json()
89
-
90
- async def text(self):
91
- if is_pyodide_context():
92
- return await self._response.text()
93
-
94
- return self._response.text
95
-
96
- async def blob(self):
97
- if is_pyodide_context():
98
- return await self._response.blob()
99
-
100
- return self._response.content
101
-
102
- @staticmethod
103
- async def get(*args, **kwargs):
104
- _request = Request("GET", *args, **kwargs)
105
- await _request.perform()
106
- return _request
107
-
108
-
109
- @staticmethod
110
- async def post(*args, **kwargs):
111
- _request = Request("POST", *args, **kwargs)
112
- await _request.perform()
113
-
114
- return _request
115
-
116
- @staticmethod
117
- async def put(*args, **kwargs):
118
- _request = Request("PUT", *args, **kwargs)
119
- await _request.perform()
120
-
121
- return _request
122
-
123
- @staticmethod
124
- async def delete(*args, **kwargs):
125
- _request = Request("DELETE", *args, **kwargs)
126
- await _request.perform()
127
-
128
- return _request
129
-
130
- @staticmethod
131
- async def patch(*args, **kwargs):
132
- _request = Request("PATCH", *args, **kwargs)
133
- await _request.perform()
134
-
135
- return _request