# encoding=utf-8 import os import hashlib import copy import web import xconfig import xutils from xutils import ConfigParser, textutil, dbutil, fsutil from xconfig import Storage dbutil.register_table("user", "用户信息表") config = xconfig # 用户配置 _users = None INVALID_NAMES = fsutil.load_set_config("./config/user/invalid_names.list") def is_valid_username(name): """有效的用户名为字母+数字""" if name in INVALID_NAMES: return False return name.isalnum() def _get_users(force_reload=False): """获取用户,内部接口""" global _users # 有并发风险 if _users is not None and not force_reload:
import xconfig import xtemplate import xtables import xutils import xauth import threading from collections import deque from threading import Thread, Timer, current_thread from xutils import Storage, Queue, tojson, MyStdout, cacheutil, u, dbutil, fsutil __version__ = "1.0" __author__ = "xupingmao ([email protected])" __copyright__ = "(C) 2016-2020 xupingmao. GNU GPL 3." __contributors__ = [] dbutil.register_table("schedule", "任务调度表 <schedule:id>") def wrapped_handler(pattern, handler_clz): # Py2 自定义类不是type类型 if not inspect.isclass(handler_clz): return handler_clz def wrap(result): if isinstance(result, (list, dict)): web.header("Content-Type", "application/json") return tojson(result) return result class WrappedHandler: """ 默认的handler装饰器 1. 装饰器相对于继承来说,性能略差一些,但是更加安全,父类的方法不会被子类所覆盖
import six import web.db as db import os import xconfig import xtables import xutils import xauth import xmanager import copy import threading from collections import Counter from xutils import readfile, savetofile, sqlite3, Storage from xutils import dateutil, cacheutil, Timer, dbutil, textutil, fsutil from xutils import attrget dbutil.register_table("note_full", "笔记完整信息 <note_full:note_id>") dbutil.register_table("note_index", "笔记索引,不包含内容 <note_index:note_id>") dbutil.register_table("note_tiny", "用户维度的笔记索引 <note_tiny:user:note_id>") dbutil.register_table("notebook", "笔记分组") dbutil.register_table("token", "用于分享的令牌") dbutil.register_table("note_history", "笔记的历史版本") dbutil.register_table("note_comment", "笔记的评论") dbutil.register_table("comment_index", "用户维度的评论索引") dbutil.register_table("search_history", "搜索历史") dbutil.register_table("note_edit_log", "笔记编辑日志") dbutil.register_table("note_visit_log", "笔记访问日志") dbutil.register_table("note_public", "公共笔记索引") dbutil.register_table("note_tags", "笔记标签 <note_tags:user:note_id>") DB_PATH = xconfig.DB_PATH MAX_EDIT_LOG = 500
插件的生命周期 - 插件的注册:debug模式下实时注册,非debug模式:初始化注册+按需注册 - 插件的卸载:退出应用 - 插件的刷新:刷新系统的时候重新加载 - 插件的删除:删除插件文件 插件日志: - 日志关系:每个用户保留一个插件访问记录,记录最近访问的时间,访问的总次数 - 日志的创建:访问的时候创建 - 日志的更新:访问的时候更新 - 日志的删除:暂无 """ dbutil.register_table("plugin_visit_log", "插件访问日志") class PluginContext(Storage): def __init__(self): self.title = "" self.name = "" self.url = "" self.description = "" self.fname = "" self.fpath = "" self.category = "" self.required_role = "" self.atime = "" self.editable = True self.edit_link = ""
# encoding=utf-8 # @modified 2020/09/05 15:13:15 import web import time import hashlib import xutils import xauth import xtemplate from xutils import dateutil, cacheutil, dbutil RETRY_LIMIT = 3 dbutil.register_table("record", "记录表") def get_real_ip(): x_forwarded_for = web.ctx.env.get("HTTP_X_FORWARDED_FOR") if x_forwarded_for != None: return x_forwarded_for.split(",")[0] return web.ctx.env.get("REMOTE_ADDR") def save_login_info(name, value): message = "%s-%s" % (get_real_ip(), value) if name != "": dbutil.insert( "record:login", dict(type="login", key=name, value=message, ctime=xutils.format_datetime(),
# -*- coding:utf-8 -*- # @author xupingmao <*****@*****.**> # @since 2019/06/12 22:59:33 # @modified 2020/11/22 13:19:21 import xutils import xconfig import xmanager import xtables from xutils import dbutil, cacheutil, textutil, Storage, functions from xtemplate import T dbutil.register_table("message", "短文本") dbutil.register_table("msg_search_history", "备忘搜索历史") dbutil.register_table("msg_key", "备忘搜索关键字") dbutil.register_table("msg_history", "备忘历史") dbutil.register_table("user_stat", "用户数据统计") class MessageDO(Storage): id = "主键" tag = "标签" user = "******" def __init__(self): pass def create_message(**kw): tag = kw['tag'] if tag == 'key': key = "msg_key:%s:%s" % (kw['user'], dbutil.timeseq())