mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
style: 统一代码风格和格式 docs: 完善函数和方法的文档字符串 refactor(base_model): 移除冗余的表名和表参数生成方法 refactor(constant): 更新返回码注释格式 refactor(router_class): 添加路由处理器的详细文档 refactor(database): 完善数据库连接函数的文档 refactor(security): 添加认证类和方法的详细文档 refactor(validator): 更新验证器函数的文档格式 refactor(serialize): 优化序列化工具类的文档 refactor(response): 完善响应类的文档字符串 refactor(dependencies): 添加依赖函数的详细文档 refactor(initialize): 完善初始化脚本的文档 refactor(plugin): 添加生命周期和中间件注册的文档 refactor(service): 完善服务层方法的文档 refactor(controller): 添加控制器方法的详细文档 refactor(crud): 完善CRUD操作的文档字符串 refactor(schema): 简化模型类并移除冗余字段 refactor(param): 更新查询参数类的注释格式 refactor(template): 优化代码生成模板的格式 refactor(console): 添加控制台输出功能的实现 refactor(util): 完善工具函数的文档字符串
73 lines
1.5 KiB
Python
73 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import re
|
|
|
|
def search_string(pattern: str, text: str) -> re.Match[str] | None:
|
|
"""
|
|
全字段正则匹配
|
|
|
|
参数:
|
|
- pattern (str): 正则表达式模式。
|
|
- text (str): 待匹配的文本。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not pattern or not text:
|
|
return None
|
|
|
|
result = re.search(pattern, text)
|
|
return result
|
|
|
|
|
|
def match_string(pattern: str, text: str) -> re.Match[str] | None:
|
|
"""
|
|
从字段开头正则匹配
|
|
|
|
参数:
|
|
- pattern (str): 正则表达式模式。
|
|
- text (str): 待匹配的文本。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not pattern or not text:
|
|
return None
|
|
|
|
result = re.match(pattern, text)
|
|
return result
|
|
|
|
|
|
def is_phone(number: str) -> re.Match[str] | None:
|
|
"""
|
|
检查手机号码格式
|
|
|
|
参数:
|
|
- number (str): 待检查的手机号码。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not number:
|
|
return None
|
|
|
|
phone_pattern = r'^1[3-9]\d{9}$'
|
|
return match_string(phone_pattern, number)
|
|
|
|
|
|
def is_git_url(url: str) -> re.Match[str] | None:
|
|
"""
|
|
检查 git URL 格式
|
|
|
|
参数:
|
|
- url (str): 待检查的 URL。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not url:
|
|
return None
|
|
|
|
git_pattern = r'^(?!(git\+ssh|ssh)://|git@)(?P<scheme>git|https?|file)://(?P<host>[^/]*)(?P<path>(?:/[^/]*)*/)(?P<repo>[^/]+?)(?:\.git)?$'
|
|
return match_string(git_pattern, url)
|