param_validator 常用校验器的实现

目录

  • 一、前置说明
    • 1、总体目录
    • 2、相关回顾
    • 3、本节目标
  • 二、操作步骤
    • 1、项目目录
    • 2、代码实现
    • 3、测试代码
    • 4、日志输出
  • 三、后置说明
    • 1、要点小结
    • 2、下节准备

一、前置说明

1、总体目录

  • 《 pyparamvalidate 参数校验器,从编码到发布全过程》

2、相关回顾

  • param_validator 核心代码实现

3、本节目标

  • param_validator 常用校验器的实现

二、操作步骤

1、项目目录

  • atme : @me 用于存放临时的代码片断或其它内容。
  • pyparamvalidate : 新建一个与项目名称同名的package,为了方便发布至 pypi
  • core : 用于存放核心代码。
  • tests : 用于存放测试代码。
  • utils : 用于存放一些工具类或方法。

2、代码实现

pyparamvalidate/core/param_validator.py

import functools
import inspect
import os.pathclass ParameterValidationError(Exception):def __init__(self, func, parameter_name, parameter_value, param_rule_description=None, exception_msg=None):self.func_name = func.__name__self.parameter_name = parameter_nameself.parameter_value = parameter_valueself.param_rule_description = param_rule_descriptionself.exception_msg = exception_msgsuper().__init__(self.error_message())def error_message(self):return (f"Parameter '{self.parameter_name}' in function '{self.func_name}' is invalid. "f"\t{'Error: ' + self.exception_msg if self.exception_msg else ''}"f"\t{'Please refer to: ' + self.param_rule_description if self.param_rule_description else ''}")class ParameterValidator:def __init__(self, param_name, param_rule_des=None):""":param param_name: 参数名:param param_rule_des: 该参数的规则描述"""self.param_name = param_nameself.param_rule_description = param_rule_des# 用于收集校验器self.validators = []def __call__(self, func):@functools.wraps(func)def wrapper(*args, **kwargs):# 获取函数的参数和参数值bound_args = inspect.signature(func).bind(*args, **kwargs).arguments# 如果函数被装饰,且以关键字参数传值,则从 kwargs 中取参数值if self.param_name in kwargs:value = kwargs[self.param_name]# # 如果函数被装饰,且以位置参数传值,则从 bound_args 中取参数值elif self.param_name in bound_args:value = bound_args.get(self.param_name)# 如果函数没有被装饰,则直接执行返回结果else:return func(*args, **kwargs)# 使用验证器进行验证for validator, exception_msg in self.validators:# 如果没验证通过,则抛出异常if not validator(value):raise ParameterValidationError(func, self.param_name, value,self.param_rule_description, exception_msg)# 所有参数校验通过,则执行函数返回结果return func(*args, **kwargs)return wrapperdef add_validator(self, validator_function, exception_msg=None):self.validators.append((validator_function, exception_msg))return selfdef is_string(self, exception_msg=None):return self.add_validator(lambda value: isinstance(value, str), exception_msg)def is_int(self, exception_msg=None):return self.add_validator(lambda value: isinstance(value, int), exception_msg)def is_positive(self, exception_msg=None):return self.add_validator(lambda value: value > 0, exception_msg)def is_float(self, exception_msg=None):return self.add_validator(lambda value: isinstance(value, float), exception_msg)def is_list(self, exception_msg=None):return self.add_validator(lambda value: isinstance(value, list), exception_msg)def is_dict(self, exception_msg=None):return self.add_validator(lambda value: isinstance(value, dict), exception_msg)def is_set(self, exception_msg=None):return self.add_validator(lambda value: isinstance(value, set), exception_msg)def is_tuple(self, exception_msg=None):return self.add_validator(lambda value: isinstance(value, tuple), exception_msg)def is_not_none(self, exception_msg=None):return self.add_validator(lambda value: value is not None, exception_msg)def is_not_empty(self, exception_msg=None):return self.add_validator(lambda value: bool(value), exception_msg)def is_allowed_value(self, allowed_values, exception_msg=None):return self.add_validator(lambda value: value in allowed_values, exception_msg)def max_length(self, max_length, exception_msg=None):return self.add_validator(lambda value: len(value) <= max_length, exception_msg)def min_length(self, min_length, exception_msg=None):return self.add_validator(lambda value: len(value) >= min_length, exception_msg)def is_substring(self, super_string, exception_msg=None):return self.add_validator(lambda value: value in super_string, exception_msg)def is_subset(self, superset, exception_msg=None):return self.add_validator(lambda value: value.issubset(superset), exception_msg)def is_sublist(self, super_list, exception_msg=None):return self.add_validator(lambda value: set(value).issubset(set(super_list)), exception_msg)def contains_substring(self, substring, exception_msg=None):return self.add_validator(lambda value: substring in value, exception_msg)def contains_subset(self, subset, exception_msg=None):return self.add_validator(lambda value: subset.issubset(value), exception_msg)def contains_sublist(self, sublist, exception_msg=None):return self.add_validator(lambda value: set(sublist).issubset(set(value)), exception_msg)def is_file_suffix(self, file_suffix, exception_msg=None):return self.add_validator(lambda value: value.endswith(file_suffix), exception_msg)def is_file(self, exception_msg=None):return self.add_validator(lambda value: os.path.isfile(value), exception_msg)def is_dir(self, exception_msg=None):return self.add_validator(lambda value: os.path.isdir(value), exception_msg)def is_method(self, exception_msg=None):def method_check(value):return callable(value)return self.add_validator(method_check, exception_msg)def custom_validator(self, validator_function, exception_msg=None):return self.add_validator(validator_function, exception_msg)

3、测试代码

pyparamvalidate/tests/test_param_validator.py

import osimport pytestfrom pyparamvalidate.core.param_validator import ParameterValidator, ParameterValidationErrordef test_is_string_validator_passing_01():"""不描述参数规则"""@ParameterValidator("param").is_string()def example_function(param):print(param)return paramassert example_function(param="test") == "test"with pytest.raises(ParameterValidationError) as exc_info:example_function(param=123)print(exc_info.value)assert "invalid" in str(exc_info.value)def test_is_string_validator_passing_02():"""在校验器中描述参数规则"""@ParameterValidator("param").is_string("Value must be a string")def example_function(param):print(param)return paramassert example_function(param="test") == "test"with pytest.raises(ParameterValidationError) as exc_info:example_function(param=123)print(exc_info.value)assert "Value must be a string" in str(exc_info.value)def test_is_string_validator_passing_03():"""在 ParameterValidator 实例化时描述参数规则"""@ParameterValidator("param", param_rule_des="Value must be a string").is_string()def example_function(param):print(param)return paramassert example_function(param="test") == "test"with pytest.raises(ParameterValidationError) as exc_info:example_function(param=123)print(exc_info.value)assert "Value must be a string" in str(exc_info.value)def test_is_int_validator():@ParameterValidator("param").is_int("Value must be an integer")def example_function(param):return paramassert example_function(param=123) == 123with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must be an integer" in str(exc_info.value)def test_is_positive_validator():@ParameterValidator("param").is_positive("Value must be positive")def example_function(param):return paramassert example_function(param=5) == 5with pytest.raises(ParameterValidationError) as exc_info:example_function(param=-3)assert "Value must be positive" in str(exc_info.value)def test_is_float_validator():@ParameterValidator("param").is_float("Value must be a float")def example_function(param):return paramassert example_function(param=3.14) == 3.14with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must be a float" in str(exc_info.value)def test_is_list_validator():@ParameterValidator("param").is_list("Value must be a list")def example_function(param):return paramassert example_function(param=[1, 2, 3]) == [1, 2, 3]with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must be a list" in str(exc_info.value)def test_is_dict_validator():@ParameterValidator("param").is_dict("Value must be a dictionary")def example_function(param):return paramassert example_function(param={"key": "value"}) == {"key": "value"}with pytest.raises(ParameterValidationError) as exc_info:example_function(param=[1, 2, 3])assert "Value must be a dictionary" in str(exc_info.value)def test_is_set_validator():@ParameterValidator("param").is_set("Value must be a set")def example_function(param):return paramassert example_function(param={1, 2, 3}) == {1, 2, 3}with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must be a set" in str(exc_info.value)def test_is_tuple_validator():@ParameterValidator("param").is_tuple("Value must be a tuple")def example_function(param):return paramassert example_function(param=(1, 2, 3)) == (1, 2, 3)with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must be a tuple" in str(exc_info.value)def test_is_not_none_validator():@ParameterValidator("param").is_not_none("Value must not be None")def example_function(param):return paramassert example_function(param="test") == "test"with pytest.raises(ParameterValidationError) as exc_info:example_function(param=None)assert "Value must not be None" in str(exc_info.value)def test_is_not_empty_validator():@ParameterValidator("param").is_not_empty("Value must not be empty")def example_function(param):return paramassert example_function(param="test") == "test"with pytest.raises(ParameterValidationError) as exc_info:example_function(param="")assert "Value must not be empty" in str(exc_info.value)def test_max_length_validator():@ParameterValidator("param").max_length(5, "Value must have max length of 5")def example_function(param):return paramassert example_function(param="test") == "test"with pytest.raises(ParameterValidationError) as exc_info:example_function(param="toolongtext")assert "Value must have max length of 5" in str(exc_info.value)def test_min_length_validator():@ParameterValidator("param").min_length(5, "Value must have min length of 5")def example_function(param):return paramassert example_function(param="toolongtext") == "toolongtext"with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must have min length of 5" in str(exc_info.value)def test_is_substring_validator():@ParameterValidator("param").is_substring("superstring", "Value must be a substring")def example_function(param):return paramassert example_function(param="string") == "string"with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must be a substring" in str(exc_info.value)def test_is_subset_validator():@ParameterValidator("param").is_subset({1, 2, 3}, "Value must be a subset")def example_function(param):return paramassert example_function(param={1, 2}) == {1, 2}with pytest.raises(ParameterValidationError) as exc_info:example_function(param={4, 5})assert "Value must be a subset" in str(exc_info.value)def test_is_sublist_validator():@ParameterValidator("param").is_sublist([1, 2, 3], "Value must be a sub-list")def example_function(param):return paramassert example_function(param=[1, 2]) == [1, 2]with pytest.raises(ParameterValidationError) as exc_info:example_function(param=[1, 2, 3, 4, 5])assert "Value must be a sub-list" in str(exc_info.value)def test_contains_substring_validator():@ParameterValidator("param").contains_substring("substring", "Value must contain substring")def example_function(param):return paramassert example_function(param="This is a substring") == "This is a substring"with pytest.raises(ParameterValidationError) as exc_info:example_function(param="test")assert "Value must contain substring" in str(exc_info.value)def test_contains_subset_validator():@ParameterValidator("param").contains_subset({1, 2, 3}, "Value must contain a subset")def example_function(param):return paramassert example_function(param={1, 2, 3, 4, 5}) == {1, 2, 3, 4, 5}with pytest.raises(ParameterValidationError) as exc_info:example_function(param={4, 5})assert "Value must contain a subset" in str(exc_info.value)def test_contains_sublist_validator():@ParameterValidator("param").contains_sublist([1, 2, 3], "Value must contain a sub-list")def example_function(param):return paramassert example_function(param=[1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]with pytest.raises(ParameterValidationError) as exc_info:example_function(param=[4, 5])assert "Value must contain a sub-list" in str(exc_info.value)def test_is_file_suffix_validator():@ParameterValidator("param").is_file_suffix(".txt", "Value must have .txt suffix")def example_function(param):return paramassert example_function(param="example.txt") == "example.txt"with pytest.raises(ParameterValidationError) as exc_info:example_function(param="example.jpg")assert "Value must have .txt suffix" in str(exc_info.value)def test_is_file_validator():@ParameterValidator("param").is_file("Value must be a valid file path")def example_function(param):return paramassert example_function(param=__file__) == __file__with pytest.raises(ParameterValidationError) as exc_info:example_function(param="/nonexistent/file.txt")assert "Value must be a valid file path" in str(exc_info.value)def test_is_dir_validator():@ParameterValidator("param").is_dir("Value must be a valid directory path")def example_function(param):return paramassert example_function(param=os.path.dirname(__file__)) == os.path.dirname(__file__)with pytest.raises(ParameterValidationError) as exc_info:example_function(param="/nonexistent/directory")assert "Value must be a valid directory path" in str(exc_info.value)def test_is_method_validator():def method():...@ParameterValidator("param").is_method("Value must be a callable method")def example_function(param):return paramassert example_function(param=method)with pytest.raises(ParameterValidationError) as exc_info:example_function(param="not a method")assert "Value must be a callable method" in str(exc_info.value)def test_custom_validator():def custom_check(value):return value % 2 == 0@ParameterValidator("param").custom_validator(custom_check, "Value must be an even number")def example_function(param):return paramassert example_function(param=4) == 4with pytest.raises(ParameterValidationError) as exc_info:example_function(param=5)assert "Value must be an even number" in str(exc_info.value)def test_multiple_custom_validators():def custom_check_1(value):return value % 2 == 0def custom_check_2(value):return value > 0@ParameterValidator("param").custom_validator(custom_check_1, "Value must be an even number").custom_validator(custom_check_2, "Value must be a positive number")def example_function(param):return paramassert example_function(param=4) == 4with pytest.raises(ParameterValidationError) as exc_info:example_function(param=5)assert "Value must be an even number" in str(exc_info.value)with pytest.raises(ParameterValidationError) as exc_info:example_function(param=-2)assert "Value must be a positive number" in str(exc_info.value)def test_complex_validator():@ParameterValidator("name").is_string("Name must be a string").is_not_empty("Name cannot be empty")@ParameterValidator("age").is_int("Age must be an integer").is_positive("Age must be a positive number")@ParameterValidator("gender").is_allowed_value(["male", "female"], "Gender must be either 'male' or 'female'")@ParameterValidator("description").is_string("Description must be a string").is_not_empty("Description cannot be empty")def example_function(name, age, gender='male', **kwargs):description = kwargs.get("description")return name, age, gender, description# 正向测试用例result = example_function(name="John", age=25, gender="male", description="A person")assert result == ("John", 25, "male", "A person")# 反向测试用例:测试 name 不是字符串的情况with pytest.raises(ParameterValidationError) as exc_info:example_function(name=123, age=25, gender="male", description="A person")assert "Name must be a string" in str(exc_info.value)# 反向测试用例:测试 age 不是正整数的情况with pytest.raises(ParameterValidationError) as exc_info:example_function(name="John", age="25", gender="male", description="A person")assert "Age must be an integer" in str(exc_info.value)# 反向测试用例:测试 gender 不是预定义值的情况with pytest.raises(ParameterValidationError) as exc_info:example_function(name="John", age=25, gender="other", description="A person")assert "Gender must be either 'male' or 'female'" in str(exc_info.value)# 反向测试用例:测试 description 不是字符串的情况with pytest.raises(ParameterValidationError) as exc_info:example_function(name="John", age=25, gender="male", description=123)assert "Description must be a string" in str(exc_info.value)# 反向测试用例:测试 description 是空字符串的情况with pytest.raises(ParameterValidationError) as exc_info:example_function(name="John", age=25, gender="male", description="")assert "Description cannot be empty" in str(exc_info.value)

4、日志输出

执行 test 的日志如下,验证通过:

============================= test session starts =============================
collecting ... collected 27 itemstest_param_validator.py::test_is_string_validator_passing_01 PASSED      [  3%]test
Parameter 'param' in function 'example_function' is invalid. 		test_param_validator.py::test_is_string_validator_passing_02 PASSED      [  7%]test
Parameter 'param' in function 'example_function' is invalid. 	Error: Value must be a string	test_param_validator.py::test_is_string_validator_passing_03 PASSED      [ 11%]test
Parameter 'param' in function 'example_function' is invalid. 		Please refer to: Value must be a stringtest_param_validator.py::test_is_int_validator PASSED                    [ 14%]
test_param_validator.py::test_is_positive_validator PASSED               [ 18%]
test_param_validator.py::test_is_float_validator PASSED                  [ 22%]
test_param_validator.py::test_is_list_validator PASSED                   [ 25%]
test_param_validator.py::test_is_dict_validator PASSED                   [ 29%]
test_param_validator.py::test_is_set_validator PASSED                    [ 33%]
test_param_validator.py::test_is_tuple_validator PASSED                  [ 37%]
test_param_validator.py::test_is_not_none_validator PASSED               [ 40%]
test_param_validator.py::test_is_not_empty_validator PASSED              [ 44%]
test_param_validator.py::test_max_length_validator PASSED                [ 48%]
test_param_validator.py::test_min_length_validator PASSED                [ 51%]
test_param_validator.py::test_is_substring_validator PASSED              [ 55%]
test_param_validator.py::test_is_subset_validator PASSED                 [ 59%]
test_param_validator.py::test_is_sublist_validator PASSED                [ 62%]
test_param_validator.py::test_contains_substring_validator PASSED        [ 66%]
test_param_validator.py::test_contains_subset_validator PASSED           [ 70%]
test_param_validator.py::test_contains_sublist_validator PASSED          [ 74%]
test_param_validator.py::test_is_file_suffix_validator PASSED            [ 77%]
test_param_validator.py::test_is_file_validator PASSED                   [ 81%]
test_param_validator.py::test_is_dir_validator PASSED                    [ 85%]
test_param_validator.py::test_is_method_validator PASSED                 [ 88%]
test_param_validator.py::test_custom_validator PASSED                    [ 92%]
test_param_validator.py::test_multiple_custom_validators PASSED          [ 96%]
test_param_validator.py::test_complex_validator PASSED                   [100%]============================= 27 passed in 0.05s ==============================

三、后置说明

1、要点小结

  • is_string:检查参数是否为字符串。
  • is_int:检查参数是否为整数。
  • is_positive:检查参数是否为正数。
  • is_float:检查参数是否为浮点数。
  • is_list:检查参数是否为列表。
  • is_dict:检查参数是否为字典。
  • is_set:检查参数是否为集合。
  • is_tuple:检查参数是否为元组。
  • is_not_none:检查参数是否不为None。
  • is_not_empty:检查参数是否不为空(对于字符串、列表、字典、集合等)。
  • is_allowed_value:检查参数是否在指定的允许值范围内。
  • max_length:检查参数的长度是否不超过指定的最大值。
  • min_length:检查参数的长度是否不小于指定的最小值。
  • is_substring:检查参数是否为指定字符串的子串。
  • is_subset:检查参数是否为指定集合的子集。
  • is_sublist:检查参数是否为指定列表的子列表。
  • contains_substring:检查参数是否包含指定字符串。
  • contains_subset:检查参数是否包含指定集合。
  • contains_sublist:检查参数是否包含指定列表。
  • is_file:检查参数是否为有效的文件。
  • is_dir:检查参数是否为有效的目录。
  • is_file_suffix:检查参数是否以指定文件后缀结尾。
  • is_method:检查参数是否为可调用的方法(函数)。

除了以上内置验证器外,还可以使用 custom_validator 方法添加自定义验证器,请参考 test_multiple_custom_validators 测试用例。

2、下节准备

  • 添加 is_similar_dict 校验器 : 如果key值相同,value类型相同,则判定为True,支持比对嵌套字典

点击返回主目录

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/598949.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【数据采集与预处理】数据接入工具Kafka

目录 一、Kafka简介 &#xff08;一&#xff09;消息队列 &#xff08;二&#xff09;什么是Kafka 二、Kafka架构 三、Kafka工作流程分析 &#xff08;一&#xff09;Kafka核心组成 &#xff08;二&#xff09;写入流程 &#xff08;三&#xff09;Zookeeper 存储结构 …

竞赛保研 基于机器视觉的银行卡识别系统 - opencv python

1 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 基于深度学习的银行卡识别算法设计 该项目较为新颖&#xff0c;适合作为竞赛课题方向&#xff0c;学长非常推荐&#xff01; &#x1f9ff; 更多资料, 项目分享&#xff1a; https://gitee.com/dancheng…

Mybatis动态SQL注解开发操作数据库

通过Mybatis的动态注解开发&#xff0c;只需要在映射文件中使用注解来配置映射关系&#xff0c;从而无需编写XML映射文件。常用的注解有Select&#xff0c;Update&#xff0c;Insert&#xff0c;Delete等&#xff0c;它们分别用于配置查询&#xff0c;更新&#xff0c;插入和删…

Linux系统安全

作为一种开放源代码的操作系统&#xff0c;linux服务器以其安全、高效和稳定的显著优势而得以广泛应用。 账号安全控制 用户账号是计算机使用者的身份凭证或标识&#xff0c;每个要访问系统资源的人&#xff0c;必须凭借其用户账号 才能进入计算机.在Linux系统中&#xff0c;提…

MIGO向成本中心发料,从成本中心收货

向成本中心发料&#xff0c;首先在MM03查看物料是否有库存&#xff0c;物料的计价标准和产成品的计价标准价是否同一种&#xff0c;S价或者V价 首先&#xff0c;“会计1”视图&#xff0c;查看物料库存 “成本2”视图查看标准成本发布 1、MIGO发货&#xff0c;选&#xff1a;A…

Solid Converter 10.1(PDF转换器)软件安装包下载及安装教程

Solid Converter 10.1下载链接&#xff1a;https://docs.qq.com/doc/DUkdMbXRpZ255dXFT 1、选中下载好的安装包右键解压到【Solid Converter 10.1.11102.4312】文件夹。 2、选中"solidconverter"右键以管理员身份运行 3、选择”自定义安装”&#xff0c;勾选”我已阅…

MySql 1170-BLOB/TEXT 错误

MySql 1170-BLOB/TEXT column idused in key specification without a key length 原因&#xff1a;由于将主键id设置为 text类型&#xff0c;所以导致主键 的长度&#xff0c;没有设置。 解决方案&#xff1a;方案1&#xff1a;将主键id设置为varchar 类型的,设置对应的长度…

如何通过Python将各种数据写入到Excel工作表

在数据处理和报告生成等工作中&#xff0c;Excel表格是一种常见且广泛使用的工具。然而&#xff0c;手动将大量数据输入到Excel表格中既费时又容易出错。为了提高效率并减少错误&#xff0c;使用Python编程语言来自动化数据写入Excel表格是一个明智的选择。Python作为一种简单易…

揭秘人工智能:探索智慧未来

&#x1f308;个人主页&#xff1a;聆风吟 &#x1f525;系列专栏&#xff1a;数据结构、网络奇遇记 &#x1f516;少年有梦不应止于心动&#xff0c;更要付诸行动。 文章目录 &#x1f4cb;前言一. 什么是人工智能?二. 人工智能的关键技术2.1 机器学习2.2 深度学习2.1 计算机…

《系统架构设计师教程(第2版)》第3章-信息系统基础知识-05-专家系统(ES)

文章目录 1. 先了解人工智能2.1 人工智能的特点2.2 人工智能的主要分支2. ES概述2.1 概述2.2 和一般系统的区别1)第一遍说了5点(理解为主)2)第二遍说的3点(主要记这个)3. ES的特点4. ES的组成4.1 知识库4.2 综合数据库4.3 推理机4.4 知识获取模块4.5 解释程序4.6 人一机接…

linux泡妞大法之Nginx网站服务

技能目标 学会 Nginx 网站服务的基本构建 了解 Nginx 访问控制实现的方法 掌握 Nginx 部署虚拟主机的方法 学会 LNMP 架构部署及应用的方法 在各种网站服务器软件中&#xff0c;除了 Apache HTTP Server 外&#xff0c;还有一款轻量级…

授权策略(authorize方法)

authorize方法&#xff08;授权策略的使用示例&#xff09; $this->authorize(destroy, $status) 要实现这个功能&#xff0c;你需要执行以下步骤&#xff1a; 1、创建一个授权策略&#xff1a; 在Laravel中&#xff0c;授权策略是用于定义用户对特定操作的权限的类。你可…

我是一片骂声中成长起来的专家,RocketMQ消息中间件实战派上下册!!

曾几何&#xff0c;我的技术真的很烂&#xff0c;烂到技术主管每次都是点名要Review我的业务代码。 曾几何&#xff0c;我对技术沉淀没有一点自我意识&#xff0c;总是觉得临时抱一下佛脚就可以了。 曾几何&#xff0c;我也觉得技术无用&#xff0c;看看那些业务领导&#xf…

每日一道算法题day-two(备战蓝桥杯)

今天带来的题目是&#xff1a; 填充 有一个长度为 n的 0101 串&#xff0c;其中有一些位置标记为 ?&#xff0c;这些位置上可以任意填充 0 或者 1&#xff0c;请问如何填充这些位置使得这个 0101 串中出现互不重叠的 00 和 11 子串最多&#xff0c;输出子串个数。 输入格式…

【Kubernetes】Kubernetes ConfigMap 实战指南

ConfigMap 是 Kubernetes 中一种用于存储配置信息的资源对象,它允许您将配置与应用程序解耦,轻松管理和更新配置。在这个实战指南中,我们将涵盖创建、更新、删除 ConfigMap,并探讨其原理、优点、不足。最后,我们将通过一个实际案例演示如何在 Node.js 应用程序中使用 Conf…

Spring框架-Spring Bean管理

文章目录 Spring Bean管理Spring Bean配置方式&#xff1a;使用XML配置方式&#xff1a;User.javaapplicationContext.xmlUserTest.java 使用注解配置方式&#xff1a;ComponentServiceRepositoryConfigurationScopeValueQualifierPrimary Bean的作用域和生命周期&#xff1a;B…

2023年广东省网络安全A模块(笔记详解)

模块A 基础设施设置与安全加固 一、项目和任务描述&#xff1a; 假定你是某企业的网络安全工程师&#xff0c;对于企业的服务器系统&#xff0c;根据任务要求确保各服务正常运行&#xff0c;并通过综合运用登录和密码策略、流量完整性保护策略、事件监控策略、防火墙策略等多…

企业数据资源入表,对数商企业有什么变化?释放了什么信号?

不是必须的&#xff0c;二者没有必然联系。 数据资产入表的专业术语是数据资产会计核算。在《企业数据资源相关会计处理暂行规定》出台之前&#xff0c;很多企业的数据产品研究和开发阶段所产生的支出大都是费用化&#xff0c;直接计入损益表&#xff0c;但企业有一部分数据产…

Linux习题4

解析&#xff1a; 用二进制表示 rwx&#xff0c;r 代表可读&#xff0c;w 代表可写&#xff0c;x 代表可执行。如果可读&#xff0c;权限二进制为 100&#xff0c;十进制是4&#xff1b;如果可写&#xff0c;权限二进制为 010&#xff0c;十进制是2&#xff1b; 如果可执行&a…

如何在Linux上部署1Panel面板并远程访问内网Web端管理界面

文章目录 前言1. Linux 安装1Panel2. 安装cpolar内网穿透3. 配置1Panel公网访问地址4. 公网远程访问1Panel管理界面5. 固定1Panel公网地址 前言 1Panel 是一个现代化、开源的 Linux 服务器运维管理面板。高效管理,通过 Web 端轻松管理 Linux 服务器&#xff0c;包括主机监控、…