- 新增图像生成接口,支持试用、积分和自定义API Key模式 - 实现生成图片结果异步上传至MinIO存储,带重试机制 - 优化积分预扣除和异常退还逻辑,保障用户积分准确 - 添加获取生成历史记录接口,支持时间范围和分页 - 提供本地字典配置接口,支持模型、比例、提示模板和尺寸 - 实现图片批量上传接口,支持S3兼容对象存储 feat(admin): 增加管理员角色管理与权限分配接口 - 实现角色列表查询、角色创建、更新及删除功能 - 增加权限列表查询接口 - 实现用户角色分配接口,便于统一管理用户权限 - 增加系统字典增删查改接口,支持分类过滤和排序 - 权限控制全面覆盖管理接口,保证安全访问 feat(auth): 完善用户登录注册及权限相关接口与页面 - 实现手机号验证码发送及校验功能,保障注册安全 - 支持手机号注册、登录及退出接口,集成日志记录 - 增加修改密码功能,验证原密码后更新 - 提供动态导航菜单接口,基于权限展示不同菜单 - 实现管理界面路由及日志、角色、字典管理页面访问权限控制 - 添加系统日志查询接口,支持关键词和等级筛选 feat(app): 初始化Flask应用并配置蓝图与数据库 - 创建应用程序工厂,加载配置,初始化数据库和Redis客户端 - 注册认证、API及管理员蓝图,整合路由 - 根路由渲染主页模板 - 应用上下文中自动创建数据库表,保证运行环境准备完毕 feat(database): 提供数据库创建与迁移支持脚本 - 新增数据库创建脚本,支持自动检测是否已存在 - 添加数据库表初始化脚本,支持创建和删除所有表 - 实现RBAC权限初始化,包含基础权限和角色创建 - 新增字段手动修复脚本,添加用户API Key和积分字段 - 强制迁移脚本支持清理连接和修复表结构,初始化默认数据及角色分配 feat(config): 新增系统配置参数 - 配置数据库、Redis、Session和MinIO相关参数 - 添加AI接口地址及试用Key配置 - 集成阿里云短信服务配置及开发模式相关参数 feat(extensions): 初始化数据库、Redis和MinIO客户端 - 创建全局SQLAlchemy数据库实例和Redis客户端 - 配置基于boto3的MinIO兼容S3客户端 chore(logs): 添加示例系统日志文件 - 记录用户请求、验证码发送成功与失败的日志信息
259 lines
6.8 KiB
C
259 lines
6.8 KiB
C
/* This is a set of functions used by test_extension_interface.py to test the
|
|
* Greenlet C API.
|
|
*/
|
|
|
|
#include "../greenlet.h"
|
|
|
|
#ifndef Py_RETURN_NONE
|
|
# define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
|
|
#endif
|
|
|
|
#define TEST_MODULE_NAME "_test_extension"
|
|
|
|
// CAUTION: MSVC is stupidly picky:
|
|
//
|
|
// "The compiler ignores, without warning, any __declspec keywords
|
|
// placed after * or & and in front of the variable identifier in a
|
|
// declaration."
|
|
// (https://docs.microsoft.com/en-us/cpp/cpp/declspec?view=msvc-160)
|
|
//
|
|
// So pointer return types must be handled differently (because of the
|
|
// trailing *), or you get inscrutable compiler warnings like "error
|
|
// C2059: syntax error: ''"
|
|
//
|
|
// In C23, there is a standard syntax for attributes, and
|
|
// GCC defines an attribute to use with this: [[gnu:noinline]].
|
|
// In the future, this is expected to become standard.
|
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
/* We used to check for GCC 4+ or 3.4+, but those compilers are
|
|
laughably out of date. Just assume they support it. */
|
|
# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
|
|
#elif defined(_MSC_VER)
|
|
/* We used to check for && (_MSC_VER >= 1300) but that's also out of date. */
|
|
# define UNUSED(x) UNUSED_ ## x
|
|
#endif
|
|
|
|
static PyObject*
|
|
test_switch(PyObject* UNUSED(self), PyObject* greenlet)
|
|
{
|
|
PyObject* result = NULL;
|
|
|
|
if (greenlet == NULL || !PyGreenlet_Check(greenlet)) {
|
|
PyErr_BadArgument();
|
|
return NULL;
|
|
}
|
|
|
|
result = PyGreenlet_Switch((PyGreenlet*)greenlet, NULL, NULL);
|
|
if (result == NULL) {
|
|
if (!PyErr_Occurred()) {
|
|
PyErr_SetString(PyExc_AssertionError,
|
|
"greenlet.switch() failed for some reason.");
|
|
}
|
|
return NULL;
|
|
}
|
|
Py_INCREF(result);
|
|
return result;
|
|
}
|
|
|
|
static PyObject*
|
|
test_switch_kwargs(PyObject* UNUSED(self), PyObject* args, PyObject* kwargs)
|
|
{
|
|
PyGreenlet* g = NULL;
|
|
PyObject* result = NULL;
|
|
|
|
PyArg_ParseTuple(args, "O!", &PyGreenlet_Type, &g);
|
|
|
|
if (g == NULL || !PyGreenlet_Check(g)) {
|
|
PyErr_BadArgument();
|
|
return NULL;
|
|
}
|
|
|
|
result = PyGreenlet_Switch(g, NULL, kwargs);
|
|
if (result == NULL) {
|
|
if (!PyErr_Occurred()) {
|
|
PyErr_SetString(PyExc_AssertionError,
|
|
"greenlet.switch() failed for some reason.");
|
|
}
|
|
return NULL;
|
|
}
|
|
Py_XINCREF(result);
|
|
return result;
|
|
}
|
|
|
|
static PyObject*
|
|
test_getcurrent(PyObject* UNUSED(self))
|
|
{
|
|
PyGreenlet* g = PyGreenlet_GetCurrent();
|
|
if (g == NULL || !PyGreenlet_Check(g) || !PyGreenlet_ACTIVE(g)) {
|
|
PyErr_SetString(PyExc_AssertionError,
|
|
"getcurrent() returned an invalid greenlet");
|
|
Py_XDECREF(g);
|
|
return NULL;
|
|
}
|
|
Py_DECREF(g);
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
static PyObject*
|
|
test_setparent(PyObject* UNUSED(self), PyObject* arg)
|
|
{
|
|
PyGreenlet* current;
|
|
PyGreenlet* greenlet = NULL;
|
|
|
|
if (arg == NULL || !PyGreenlet_Check(arg)) {
|
|
PyErr_BadArgument();
|
|
return NULL;
|
|
}
|
|
if ((current = PyGreenlet_GetCurrent()) == NULL) {
|
|
return NULL;
|
|
}
|
|
greenlet = (PyGreenlet*)arg;
|
|
if (PyGreenlet_SetParent(greenlet, current)) {
|
|
Py_DECREF(current);
|
|
return NULL;
|
|
}
|
|
Py_DECREF(current);
|
|
if (PyGreenlet_Switch(greenlet, NULL, NULL) == NULL) {
|
|
return NULL;
|
|
}
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
static PyObject*
|
|
test_new_greenlet(PyObject* UNUSED(self), PyObject* callable)
|
|
{
|
|
PyObject* result = NULL;
|
|
PyGreenlet* greenlet = PyGreenlet_New(callable, NULL);
|
|
|
|
if (!greenlet) {
|
|
return NULL;
|
|
}
|
|
|
|
result = PyGreenlet_Switch(greenlet, NULL, NULL);
|
|
Py_CLEAR(greenlet);
|
|
if (result == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
Py_INCREF(result);
|
|
return result;
|
|
}
|
|
|
|
static PyObject*
|
|
test_raise_dead_greenlet(PyObject* UNUSED(self))
|
|
{
|
|
PyErr_SetString(PyExc_GreenletExit, "test GreenletExit exception.");
|
|
return NULL;
|
|
}
|
|
|
|
static PyObject*
|
|
test_raise_greenlet_error(PyObject* UNUSED(self))
|
|
{
|
|
PyErr_SetString(PyExc_GreenletError, "test greenlet.error exception");
|
|
return NULL;
|
|
}
|
|
|
|
static PyObject*
|
|
test_throw(PyObject* UNUSED(self), PyGreenlet* g)
|
|
{
|
|
const char msg[] = "take that sucka!";
|
|
PyObject* msg_obj = Py_BuildValue("s", msg);
|
|
PyGreenlet_Throw(g, PyExc_ValueError, msg_obj, NULL);
|
|
Py_DECREF(msg_obj);
|
|
if (PyErr_Occurred()) {
|
|
return NULL;
|
|
}
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
static PyObject*
|
|
test_throw_exact(PyObject* UNUSED(self), PyObject* args)
|
|
{
|
|
PyGreenlet* g = NULL;
|
|
PyObject* typ = NULL;
|
|
PyObject* val = NULL;
|
|
PyObject* tb = NULL;
|
|
|
|
if (!PyArg_ParseTuple(args, "OOOO:throw", &g, &typ, &val, &tb)) {
|
|
return NULL;
|
|
}
|
|
|
|
PyGreenlet_Throw(g, typ, val, tb);
|
|
if (PyErr_Occurred()) {
|
|
return NULL;
|
|
}
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
static PyMethodDef test_methods[] = {
|
|
{"test_switch",
|
|
(PyCFunction)test_switch,
|
|
METH_O,
|
|
"Switch to the provided greenlet sending provided arguments, and \n"
|
|
"return the results."},
|
|
{"test_switch_kwargs",
|
|
(PyCFunction)test_switch_kwargs,
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
"Switch to the provided greenlet sending the provided keyword args."},
|
|
{"test_getcurrent",
|
|
(PyCFunction)test_getcurrent,
|
|
METH_NOARGS,
|
|
"Test PyGreenlet_GetCurrent()"},
|
|
{"test_setparent",
|
|
(PyCFunction)test_setparent,
|
|
METH_O,
|
|
"Se the parent of the provided greenlet and switch to it."},
|
|
{"test_new_greenlet",
|
|
(PyCFunction)test_new_greenlet,
|
|
METH_O,
|
|
"Test PyGreenlet_New()"},
|
|
{"test_raise_dead_greenlet",
|
|
(PyCFunction)test_raise_dead_greenlet,
|
|
METH_NOARGS,
|
|
"Just raise greenlet.GreenletExit"},
|
|
{"test_raise_greenlet_error",
|
|
(PyCFunction)test_raise_greenlet_error,
|
|
METH_NOARGS,
|
|
"Just raise greenlet.error"},
|
|
{"test_throw",
|
|
(PyCFunction)test_throw,
|
|
METH_O,
|
|
"Throw a ValueError at the provided greenlet"},
|
|
{"test_throw_exact",
|
|
(PyCFunction)test_throw_exact,
|
|
METH_VARARGS,
|
|
"Throw exactly the arguments given at the provided greenlet"},
|
|
{NULL, NULL, 0, NULL}
|
|
};
|
|
|
|
|
|
#define INITERROR return NULL
|
|
|
|
static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT,
|
|
TEST_MODULE_NAME,
|
|
NULL,
|
|
0,
|
|
test_methods,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL};
|
|
|
|
PyMODINIT_FUNC
|
|
PyInit__test_extension(void)
|
|
{
|
|
PyObject* module = NULL;
|
|
module = PyModule_Create(&moduledef);
|
|
|
|
if (module == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
PyGreenlet_Import();
|
|
#ifdef Py_GIL_DISABLED
|
|
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
|
|
#endif
|
|
return module;
|
|
}
|