pycronado 0.0.0__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.
- pycronado-0.0.0/PKG-INFO +13 -0
- pycronado-0.0.0/pyproject.toml +23 -0
- pycronado-0.0.0/setup.cfg +4 -0
- pycronado-0.0.0/src/pycronado/core.py +69 -0
- pycronado-0.0.0/src/pycronado/util.py +13 -0
- pycronado-0.0.0/src/pycronado.egg-info/PKG-INFO +13 -0
- pycronado-0.0.0/src/pycronado.egg-info/SOURCES.txt +9 -0
- pycronado-0.0.0/src/pycronado.egg-info/dependency_links.txt +1 -0
- pycronado-0.0.0/src/pycronado.egg-info/requires.txt +1 -0
- pycronado-0.0.0/src/pycronado.egg-info/top_level.txt +1 -0
- pycronado-0.0.0/tests/test_smoke.py +11 -0
pycronado-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pycronado
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Set of trivial tools for building microservices with Tornado
|
|
5
|
+
Author-email: inaimathi <leo.zovic@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/inaimathi/pycronado
|
|
7
|
+
Project-URL: Issues, https://github.com/inaimathi/pycronado/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: tornado
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pycronado"
|
|
7
|
+
version = "0.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="inaimathi", email="leo.zovic@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Set of trivial tools for building microservices with Tornado"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = ["tornado"]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/inaimathi/pycronado"
|
|
23
|
+
Issues = "https://github.com/inaimathi/pycronado/issues"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
import tornado
|
|
5
|
+
|
|
6
|
+
from .util import getLogger
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PublicJSONHandler(tornado.web.RequestHandler):
|
|
10
|
+
def prepare(self):
|
|
11
|
+
self._logger = None
|
|
12
|
+
self._data = None
|
|
13
|
+
self.set_header("Access-Control-Allow-Origin", "*")
|
|
14
|
+
self.set_header("Access-Control-Allow-Headers", "*")
|
|
15
|
+
self.set_header("Access-Control-Allow-Methods", "*")
|
|
16
|
+
|
|
17
|
+
def logger(self):
|
|
18
|
+
if self._logger is None:
|
|
19
|
+
self._logger = getLogger(f"handler:{self.request.uri}")
|
|
20
|
+
return self._logger
|
|
21
|
+
|
|
22
|
+
def set_default_headers(self):
|
|
23
|
+
self.set_header("Content-Type", "application/json")
|
|
24
|
+
|
|
25
|
+
def param(self, param_name, default=None):
|
|
26
|
+
if self._data is None:
|
|
27
|
+
try:
|
|
28
|
+
self._data = json.loads(self.request.body)
|
|
29
|
+
except json.JSONDecodeError:
|
|
30
|
+
self._data = {}
|
|
31
|
+
return self._data.get(param_name, self.get_argument(param_name, default))
|
|
32
|
+
|
|
33
|
+
def json(self, data, status=None):
|
|
34
|
+
if status is not None:
|
|
35
|
+
self.set_status(status)
|
|
36
|
+
return self.write(json.dumps(data))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Default404Handler(PublicJSONHandler):
|
|
40
|
+
def prepare(self):
|
|
41
|
+
self.json({"status": "error", "message": "not found"}, status=404)
|
|
42
|
+
self.finish()
|
|
43
|
+
return self.request.connection.close()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def getApp(
|
|
47
|
+
name, routes, static_path=None, static_url_prefix=None, default_handler_class=None
|
|
48
|
+
):
|
|
49
|
+
if default_handler_class is None:
|
|
50
|
+
default_handler_class = Default404Handler
|
|
51
|
+
app = tornado.web.Application(
|
|
52
|
+
routes,
|
|
53
|
+
default_handler_class=default_handler_class,
|
|
54
|
+
debug=True,
|
|
55
|
+
static_path=static_path,
|
|
56
|
+
static_url_prefix=static_url_prefix,
|
|
57
|
+
)
|
|
58
|
+
app.logger = getLogger(name)
|
|
59
|
+
return app
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
async def start(app, port):
|
|
63
|
+
app.logger.info(f"Listening on {port}")
|
|
64
|
+
app.listen(int(port))
|
|
65
|
+
await asyncio.Event().wait()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def run(app, port):
|
|
69
|
+
asyncio.run(start(app, port))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def getLogger(name, level=logging.DEBUG):
|
|
5
|
+
logger = logging.getLogger(name)
|
|
6
|
+
logger.setLevel(level)
|
|
7
|
+
formatter = logging.Formatter(
|
|
8
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
9
|
+
)
|
|
10
|
+
console_handler = logging.StreamHandler()
|
|
11
|
+
console_handler.setFormatter(formatter)
|
|
12
|
+
logger.addHandler(console_handler)
|
|
13
|
+
return logger
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pycronado
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Set of trivial tools for building microservices with Tornado
|
|
5
|
+
Author-email: inaimathi <leo.zovic@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/inaimathi/pycronado
|
|
7
|
+
Project-URL: Issues, https://github.com/inaimathi/pycronado/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: tornado
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
src/pycronado/core.py
|
|
3
|
+
src/pycronado/util.py
|
|
4
|
+
src/pycronado.egg-info/PKG-INFO
|
|
5
|
+
src/pycronado.egg-info/SOURCES.txt
|
|
6
|
+
src/pycronado.egg-info/dependency_links.txt
|
|
7
|
+
src/pycronado.egg-info/requires.txt
|
|
8
|
+
src/pycronado.egg-info/top_level.txt
|
|
9
|
+
tests/test_smoke.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tornado
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pycronado
|