| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/usr/bin/env /usr/bin/python3
- # -*- coding:utf-8 -*-
- import random
- import string
- from typing import Dict, List, Set, Union
- def contains_all(some_dict: Union[Dict, List, Set], keys: List[str]):
- """
- 判断`config`中是否存在`keys`中的任意一个
- Args:
- some_dict:
- keys:
- Returns:
- """
- for key in keys:
- if not some_dict.__contains__(key):
- return False
- return True
- def exist(some_collection: Union[Dict, List, Set], keys: List[str]):
- """
- 判断`config`中是否存在`keys`中的任意一个
- Args:
- some_collection:
- keys:
- Returns:
- """
- for key in keys:
- if some_collection.__contains__(key):
- return True
- return False
- def generate_random_string(length):
- """
- 生成给定长度的随机字符串
- Args:
- length: 指定长度
- Returns: 生成的随机字符串
- """
- letters_and_digits = string.ascii_letters + string.digits
- return ''.join(random.choice(letters_and_digits) for i in range(length))
|