def calc_handler(request): try: r = request_handler.RequestHandler(request) cost = r.declared_price * t.get_rate(r.date, r.cargo_type) cost = cost.quantize(decimal.Decimal('1'), rounding=decimal.ROUND_UP) except request_handler.RequestError as e: response = {'error': e.__str__()} logger.Logger().log(request=e.request, response=response) except tariff.TariffError as e: response = {'error': e.__str__()} logger.Logger().log(request=r.params, response=response) else: response = {'price': cost.__str__()} logger.Logger().log(request=r.params, response=response) return request.Response(json=response)
def processRequest(self, req_obj, handler): command = req_obj["command"] # Preparing a JSON object, obj, to be used by RequestHandler functions with different parameters based on the command obj = {"username": req_obj["parameters"]["username"]} if command == "AUTH" or command == "NWUA": obj["password"] = req_obj["parameters"]["password"] obj["filename"] = self.__user_file elif command == "LIST": obj["list"] = self.__list elif command == "CHAT": obj["chat_name"] = req_obj["parameters"]["chat_name"] obj["list"] = self.__list elif command == "JOIN": obj["chat_name"] = req_obj["parameters"]["chat_name"] obj["list"] = self.__list elif command == "BANN": obj["chat_name"] = req_obj["parameters"]["chat_name"] obj["banned_user"] = req_obj["parameters"]["banned_user"] obj["filename"] = self.__user_file obj["list"] = self.__list elif command == "KICK": obj["chat_name"] = req_obj["parameters"]["chat_name"] obj["kicked_user"] = req_obj["parameters"]["kicked_user"] obj["filename"] = self.__user_file obj["list"] = self.__list elif command == "MSSG": obj["payload"] = req_obj["payload"] reqh_obj = reqh.RequestHandler(obj) # Returns response string return reqh_obj.run_command(command, handler, client_map)
def __init__(self, port=DEFAULT_PORT): self.port = port self.parser = parser.RequestParser() self.handler = handler.RequestHandler()
from flask import Flask, render_template, request, jsonify, redirect, url_for, flash, session, send_file, send_from_directory from wtforms import Form, BooleanField, TextField, PasswordField, validators from passlib.hash import sha256_crypt from pymysql import escape_string as thwart import sqlite3 from sqlalchemy import create_engine from websocket import create_connection from werkzeug.utils import secure_filename import pycld2 from flask_mail import Mail, Message from dbconnect import connection import request_handler rh = request_handler.RequestHandler() app = Flask(__name__) euser = os.environ["EMAILUSER"] epass = os.environ["EMAILPASSWORD"] mail_settings = { "MAIL_SERVER": 'smtp.gmail.com', "MAIL_PORT": 465, "MAIL_USER_TLS": False, "MAIL_USE_SSL": True, "MAIL_USERNAME": euser, "MAIL_PASSWORD": epass }
def incompatibleVersion(self): reqh_obj = reqh.RequestHandler() # Returns response string return reqh_obj.run_command("VRSN", "", "")
def rh(): return request_handler.RequestHandler()