Skip to content

Commit b028bbe

Browse files
Project init
0 parents  commit b028bbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+512
-0
lines changed

Chamak.egg-info/PKG-INFO

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Metadata-Version: 2.1
2+
Name: Chamak
3+
Version: 0.0.6
4+
Summary: A python implementation of laravel framework for machine learning, AI, datascience and data intensive work.
5+
Home-page: https://github.com/bedus-creation/LaraPy
6+
Author: Bedram Tamang
7+
Author-email: [email protected]
8+
License: UNKNOWN
9+
Description: # LaraPy
10+
A python implementation of laravel framework for machine learning, AI, datascience and data intensive work.
11+
12+
### Features
13+
* **MVC** Framework
14+
* **Routing**
15+
* **jinja 2** templating engine.
16+
17+
# Installation
18+
Download project directly from github repository. Clone it and remove the origin (Optional).
19+
```
20+
git clone [email protected]:bedus-creation/LaraPy.git project_name
21+
cd project_name
22+
git remote remove origin
23+
```
24+
25+
### Serve app
26+
```
27+
python serve
28+
```
29+
### Testing
30+
```
31+
python -m pytest
32+
33+
# With out Network
34+
python -m pytest -m "not network"
35+
```
36+
37+
Platform: UNKNOWN
38+
Classifier: Programming Language :: Python :: 3
39+
Classifier: License :: OSI Approved :: MIT License
40+
Classifier: Operating System :: OS Independent
41+
Requires-Python: >=3.6
42+
Description-Content-Type: text/markdown

Chamak.egg-info/SOURCES.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
setup.cfg
2+
setup.py
3+
Chamak/__init__.py
4+
Chamak.egg-info/PKG-INFO
5+
Chamak.egg-info/SOURCES.txt
6+
Chamak.egg-info/dependency_links.txt
7+
Chamak.egg-info/top_level.txt
8+
Chamak/Foundation/FileReponse.py
9+
Chamak/Foundation/Request.py
10+
Chamak/Foundation/Response.py
11+
Chamak/Foundation/Router.py
12+
Chamak/Foundation/__init__.py
13+
Chamak/Foundation/app.py
14+
Chamak/Foundation/bootstrap.py
15+
Chamak/view/__init__.py
16+
Chamak/view/view.py

Chamak.egg-info/dependency_links.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Chamak.egg-info/top_level.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chamak

Chamak/Container/Container.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Container:
2+
def __init__(self):
3+
pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Migration:
2+
pass

Chamak/Database/Migrations/Schema.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Schema:
2+
3+
@staticmethod
4+
def create(self):
5+
pass
6+
7+
@staticmethod
8+
def dropIfExists():
9+
pass

Chamak/Database/Model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Model:
2+
pass

Chamak/Foundation/FileReponse.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from webob import Request, Response
2+
import mimetypes
3+
4+
class FileReponse:
5+
6+
@staticmethod
7+
def is_static(filename):
8+
return FileReponse().get_mimetype(filename) != None
9+
10+
def get_mimetype(self, filename):
11+
type, encoding = mimetypes.guess_type(filename)
12+
return type
13+
14+
def make_response(self, filename):
15+
res = Response(content_type=self.get_mimetype(filename))
16+
res.body = open(filename, 'rb').read()
17+
return res

Chamak/Foundation/Request.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from Chamak.Foundation.app import Application
2+
3+
4+
class Request:
5+
@staticmethod
6+
def uri():
7+
return Application.get('env')['PATH_INFO'].strip('/')
8+
9+
@staticmethod
10+
def method():
11+
return Application.get('env')['REQUEST_METHOD']

Chamak/Foundation/Response.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Response:
2+
def __init__(self, start_response):
3+
self.response = start_response
4+
5+
def sendResponse(self, data, status):
6+
data = bytes(data, 'utf-16')
7+
response_headers = [
8+
('Content-type', 'text/html'),
9+
('Content-Length', str(len(data)))
10+
]
11+
self.response(status, response_headers)
12+
return iter([data])

Chamak/Foundation/Router.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import importlib
2+
from Chamak.Foundation.app import Application
3+
from werkzeug.exceptions import HTTPException
4+
from Chamak.Foundation.FileReponse import FileReponse
5+
6+
7+
class Router:
8+
routes = {
9+
'GET': {},
10+
'POST': {}
11+
}
12+
13+
@staticmethod
14+
def get(uri, controller):
15+
Router.routes['GET'][uri.strip('/')] = controller
16+
17+
@staticmethod
18+
def post(uri, controller):
19+
Router.routes['POST'][uri.strip('/')] = controller
20+
21+
@staticmethod
22+
def load(file):
23+
importlib.import_module(file)
24+
return Router()
25+
26+
def direct(self, uri, requestType):
27+
if FileReponse.is_static(uri):
28+
return FileReponse().make_response("public/"+uri)
29+
30+
if uri in Router.routes[requestType].keys():
31+
data = Router.routes[requestType][uri].split('@')
32+
return self.callAction(data[0], data[1])
33+
raise HTTPException('Routes not defined yet.')
34+
35+
def callAction(self, controllerClass, action):
36+
controller = 'app.Http.Controllers.' + controllerClass
37+
module = importlib.import_module(controller)
38+
class_ = getattr(module, controllerClass)
39+
return getattr(class_(), action)()

Chamak/Foundation/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "Foundation"
Binary file not shown.
Binary file not shown.
Binary file not shown.
658 Bytes
Binary file not shown.

Chamak/Foundation/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Application:
2+
registry = {}
3+
4+
@staticmethod
5+
def bind(key, value):
6+
Application.registry[key] = value
7+
8+
@staticmethod
9+
def get(key):
10+
if key in Application.registry.keys():
11+
return Application.registry[key]
12+
raise Exception('Key is not binded in container')

Chamak/Foundation/bootstrap.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from Chamak.Foundation.app import Application
2+
import importlib
3+
from config.app import config
4+
from config.database import database
5+
from Chamak.Foundation.Router import Router
6+
from Chamak.Foundation.Request import Request
7+
from Chamak.Foundation.Response import Response
8+
9+
10+
class Bootstrap:
11+
def __init__(self, env, response):
12+
self.env = env
13+
self.response = response
14+
self.boot()
15+
16+
def boot(self):
17+
Application.bind('env', self.env)
18+
Application.bind('config', config)
19+
Application.bind('response', Response(self.response))
20+
21+
@staticmethod
22+
def run():
23+
return Router.load('routes.web').direct(Request.uri(), Request.method())

Chamak/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "Chamak"
148 Bytes
Binary file not shown.

Chamak/view/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "View"

Chamak/view/view.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from jinja2 import Environment, FileSystemLoader, select_autoescape
2+
from Chamak.Foundation.app import Application
3+
4+
5+
class View:
6+
def __init__(self):
7+
file_loader = FileSystemLoader('resources/views')
8+
self.env = Environment(loader=file_loader,
9+
autoescape=select_autoescape(enabled_extensions=('html', 'htm', 'xml'),
10+
disabled_extensions=(), default_for_string=True, default=False))
11+
12+
def view(self, name, data=None):
13+
template = self.env.get_template(name + '.html')
14+
data = template.render(data=data)
15+
return Application.get('response').sendResponse(data, '200')

Licence

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Bedram Tamang
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.

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rm -f -r dist/*
2+
python setup.py sdist bdist_wheel
3+
twine upload dist/*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from webob import Request, Response
2+
import mimetypes
3+
4+
class FileReponse:
5+
6+
@staticmethod
7+
def is_static(filename):
8+
return FileReponse().get_mimetype(filename) != None
9+
10+
def get_mimetype(self, filename):
11+
type, encoding = mimetypes.guess_type(filename)
12+
return type
13+
14+
def make_response(self, filename):
15+
res = Response(content_type=self.get_mimetype(filename))
16+
res.body = open(filename, 'rb').read()
17+
return res
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from Chamak.Foundation.app import Application
2+
3+
4+
class Request:
5+
@staticmethod
6+
def uri():
7+
return Application.get('env')['PATH_INFO'].strip('/')
8+
9+
@staticmethod
10+
def method():
11+
return Application.get('env')['REQUEST_METHOD']
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Response:
2+
def __init__(self, start_response):
3+
self.response = start_response
4+
5+
def sendResponse(self, data, status):
6+
data = bytes(data, 'utf-16')
7+
response_headers = [
8+
('Content-type', 'text/html'),
9+
('Content-Length', str(len(data)))
10+
]
11+
self.response(status, response_headers)
12+
return iter([data])

build/lib/Chamak/Foundation/Router.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import importlib
2+
from Chamak.Foundation.app import Application
3+
from werkzeug.exceptions import HTTPException
4+
from Chamak.Foundation.FileReponse import FileReponse
5+
6+
7+
class Router:
8+
routes = {
9+
'GET': {},
10+
'POST': {}
11+
}
12+
13+
@staticmethod
14+
def get(uri, controller):
15+
Router.routes['GET'][uri.strip('/')] = controller
16+
17+
@staticmethod
18+
def post(uri, controller):
19+
Router.routes['POST'][uri.strip('/')] = controller
20+
21+
@staticmethod
22+
def load(file):
23+
importlib.import_module(file)
24+
return Router()
25+
26+
def direct(self, uri, requestType):
27+
if FileReponse.is_static(uri):
28+
return FileReponse().make_response("public/"+uri)
29+
30+
if uri in Router.routes[requestType].keys():
31+
data = Router.routes[requestType][uri].split('@')
32+
return self.callAction(data[0], data[1])
33+
raise HTTPException('Routes not defined yet.')
34+
35+
def callAction(self, controllerClass, action):
36+
controller = 'app.Http.Controllers.' + controllerClass
37+
module = importlib.import_module(controller)
38+
class_ = getattr(module, controllerClass)
39+
return getattr(class_(), action)()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "Foundation"

build/lib/Chamak/Foundation/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Application:
2+
registry = {}
3+
4+
@staticmethod
5+
def bind(key, value):
6+
Application.registry[key] = value
7+
8+
@staticmethod
9+
def get(key):
10+
if key in Application.registry.keys():
11+
return Application.registry[key]
12+
raise Exception('Key is not binded in container')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from Chamak.Foundation.app import Application
2+
import importlib
3+
from config.app import config
4+
from config.database import database
5+
from Chamak.Foundation.Router import Router
6+
from Chamak.Foundation.Request import Request
7+
from Chamak.Foundation.Response import Response
8+
9+
10+
class Bootstrap:
11+
def __init__(self, env, response):
12+
self.env = env
13+
self.response = response
14+
self.boot()
15+
16+
def boot(self):
17+
Application.bind('env', self.env)
18+
Application.bind('config', config)
19+
Application.bind('response', Response(self.response))
20+
21+
@staticmethod
22+
def run():
23+
return Router.load('routes.web').direct(Request.uri(), Request.method())

build/lib/Chamak/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "Chamak"

build/lib/Chamak/view/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "View"

build/lib/Chamak/view/view.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from jinja2 import Environment, FileSystemLoader, select_autoescape
2+
from Chamak.Foundation.app import Application
3+
4+
5+
class View:
6+
def __init__(self):
7+
file_loader = FileSystemLoader('resources/views')
8+
self.env = Environment(loader=file_loader,
9+
autoescape=select_autoescape(enabled_extensions=('html', 'htm', 'xml'),
10+
disabled_extensions=(), default_for_string=True, default=False))
11+
12+
def view(self, name, data=None):
13+
template = self.env.get_template(name + '.html')
14+
data = template.render(data=data)
15+
return Application.get('response').sendResponse(data, '200')

dist/Chamak-0.0.6-py3-none-any.whl

4.89 KB
Binary file not shown.

dist/Chamak-0.0.6.tar.gz

2.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)