def load_all_modules(self, no_libs_check): """ Loads all the Modules from the modules folder """ _all_modules = list(iter_modules(modules.__path__)) for _module in _all_modules: module_object = Module(_module[1]) try: if no_libs_check or self.check_dependencies(module_object): module_object.load_manager_class() self.loaded_modules.append(module_object) except ImportError as e: SimpleTUI.msg_dialog("Missing packages", "There was an error while importing a package for the\n" + module_object.platform_name + " module: \n\n" + str(e) + "\n\n" + "This module won't be loaded.", SimpleTUI.DIALOG_ERROR)
def add(self, name: str, class_path: str): """Instantiates a worker, instantiates a messenger, and bundles both to a module. The module will be added to the modules dictionary. Args: name: The name of the module. class_path: The path to the Python class. Returns: True if module has been added, False if not. Raises: ValueError: If module file not exists. """ if not self.module_exists(class_path): raise ValueError(f'Module "{class_path}" not found') messenger = MQTTMessenger(self._manager, name) worker = self.get_worker_instance(name, class_path) self._modules[name] = Module(messenger, worker) self.logger.debug(f'Loaded module "{name}"')
import base64 import json from Crypto.PublicKey import RSA from flask import request, make_response from common.constants import BankCertificates, CertificateOwner, CertificateType from common.messages import Messages, ErrorMessages from core.module import Module from models.bank_session import BankSession from models.vpb_card import VPBBank, DoesNotExist from services.cipher import decrypt_rsa from services.converter import json as custom_json from services.keys import get_key module = Module('api', __name__, url_prefix='/api') @module.get_post('/authorization') def authorization(): data = request.form.to_dict() session_id = data.get('session_id') kuis = get_key(CertificateOwner.VPB_BANK, CertificateType.BANK)['public_key'] b64_kuis = base64.b64encode(kuis) authdata = data.get('authdata') if authdata == Messages.AUTH_REQUEST: pi = data.get('pi') pi = json.loads(pi)
from core.module import Module sample = Module('sample_module', __name__).set_prefix(False).set_route() from .routes import web
from flask import render_template, flash, request, url_for, make_response from werkzeug.utils import redirect from common.constants import CertificateOwner, CertificateType from core.module import Module from models.cart import Cart from models.product import Product, DoesNotExist from services import identity from services.keys import get_key module = Module('shop', __name__, url_prefix='/shop') @module.get('/') def shop(): products = Product.objects.all() return render_template('sites/shop/index.html', products=products) @module.post('/add-to-cart/<string:product_id>&<int:quantity>') def add_to_cart(product_id, quantity): cart = Cart.get_current() cart.add_product(product_id, quantity) response = make_response() response.set_cookie('cart', cart.jsonified_data) flash("Add succeeded!", 'success') return response @module.post('/remove-from-cart/<string:product_id>') def remove_from_cart(product_id):
from flask import render_template, url_for, request import requests from core.module import Module from models.product import Product module = Module('product', __name__, url_prefix='/product') @module.get('/<string:product_id>') def detail(product_id): product = Product.objects.get(pk=product_id) return render_template('sites/shop/product_detail.html', product=product)
from flask import render_template, request, url_for from flask_mail import Message from werkzeug.utils import redirect from core.module import Module from models.vcb_card import VCBBank from vietcombank_app.forms import RegisterForm module = Module('home', __name__) @module.get_post('/') def index(): if request.method == 'POST': data = request.form card_id = data.get('card-id') password = data.get('password') card = VCBBank.authenticate(card_id, password) if card: return render_template('profile.html', card=card) return render_template('index.html') @module.get_post('/register') def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): data = (request.form).to_dict() data.pop('csrf_token', None)
from flask import request, session from core.module import Module module = Module('profile', __name__, url_prefix='/profile') @module.get('/') def info(): print() return 'User Info'