def __init__(self, instance_filename): instance = json.loads(fileutil.read_file(instance_filename)) self.pid = instance["pid"] self.address = str(instance["address"]) self.client = None if not pid_exists(self.pid): raise Exception("Instance pid is invalid")
def load_file(self, path): json_str = fileutil.read_file(path) if json_str is not None and json_str: json_obj = jsontranslator.json_to_object(json_str) else: raise JsonParseError("File content was empty .") self._data = json_obj
def compile_resource_dict(resdir): resdict = {} for dirpath, dirnames, filenames in os.walk(resdir): for filename in filenames: filepath = os.path.join(dirpath, filename) respath = os.path.relpath(filepath, resdir) sys.stdout.write("Compiling resource: %r\n" % respath) resdict[respath] = read_file(filepath) return resdict
#coding:utf-8 import getMem2 import fileutil from flask import Flask, request, render_template, redirect, session app = Flask(__name__) fileutil.read_file() app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' @app.route('/') def index(): if 'username' in session: return redirect('/list') return render_template('login.html') @app.route('/loginaction') def login(): user = request.args.get('user') pwd = request.args.get('pwd') erro_msg = '' if user and pwd: if user == 'admin' and pwd == 'pwd': session['username'] = '******' return redirect('/list') else: erro_msg = 'wrong user or password!' else: erro_msg = 'need user and pwd'
def __init__(self, instance_filename): instance = json.loads(fileutil.read_file(instance_filename)) self.pid = instance["pid"] self.address = str(instance["address"]) self.client = None
def read_settings(filename): return json.loads(fileutil.read_file(filename))