coderouter 0.1.0__py3-none-any.whl

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.
coderouter/__init__.py ADDED
@@ -0,0 +1,9 @@
1
+ """
2
+ CodeRouter - A simple routing library
3
+ """
4
+
5
+ __version__ = "0.1.0"
6
+
7
+ from .router import Router, Route
8
+
9
+ __all__ = ["Router", "Route"]
coderouter/router.py ADDED
@@ -0,0 +1,30 @@
1
+ """
2
+ Simple routing implementation
3
+ """
4
+
5
+ class Route:
6
+ def __init__(self, path, handler, methods=None):
7
+ self.path = path
8
+ self.handler = handler
9
+ self.methods = methods or ["GET"]
10
+
11
+ class Router:
12
+ def __init__(self):
13
+ self.routes = []
14
+
15
+ def add_route(self, path, handler, methods=None):
16
+ route = Route(path, handler, methods)
17
+ self.routes.append(route)
18
+ return route
19
+
20
+ def match(self, path, method="GET"):
21
+ for route in self.routes:
22
+ if route.path == path and method in route.methods:
23
+ return route
24
+ return None
25
+
26
+ def handle(self, path, method="GET", *args, **kwargs):
27
+ route = self.match(path, method)
28
+ if route:
29
+ return route.handler(*args, **kwargs)
30
+ return None
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: coderouter
3
+ Version: 0.1.0
4
+ Summary: A simple routing library
5
+ Home-page: https://github.com/lawrencechen/coderouter
6
+ Author: Lawrence Chen
7
+ Author-email:
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.7
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Requires-Python: >=3.7
18
+ Description-Content-Type: text/markdown
19
+ Dynamic: author
20
+ Dynamic: classifier
21
+ Dynamic: description
22
+ Dynamic: description-content-type
23
+ Dynamic: home-page
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # CodeRouter
28
+
29
+ A simple routing library for Python applications.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install coderouter
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```python
40
+ from coderouter import Router
41
+
42
+ router = Router()
43
+
44
+ def home_handler():
45
+ return "Welcome home!"
46
+
47
+ def about_handler():
48
+ return "About page"
49
+
50
+ router.add_route("/", home_handler)
51
+ router.add_route("/about", about_handler, methods=["GET", "POST"])
52
+
53
+ # Handle requests
54
+ result = router.handle("/") # Returns "Welcome home!"
55
+ result = router.handle("/about", "POST") # Returns "About page"
56
+ ```
57
+
58
+ ## License
59
+
60
+ MIT
@@ -0,0 +1,6 @@
1
+ coderouter/__init__.py,sha256=K3wAwt0Sjx9zjpScsLS1FkGHFyKx8nkYaVYkIR_N3G4,134
2
+ coderouter/router.py,sha256=3Ss_9LMpJV_9YPeRWKC666-Q8xFpPpgc7k_k8qAuI-4,811
3
+ coderouter-0.1.0.dist-info/METADATA,sha256=WsxPPVI7RNbd6d0BeGQDBSPqu_nZG2dA4I4p_QGh_YQ,1379
4
+ coderouter-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ coderouter-0.1.0.dist-info/top_level.txt,sha256=FTxYPfy7FV7M5SNsdHnIU3vKaNfvfZpNFlbXVw2JRwU,11
6
+ coderouter-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ coderouter