验证字符集范围参数 Args: charset_range: 字符集范围参数 Returns: bool: 参数是否有效 Raises: DDDDOCRError: 当参数无效时
(charset_range: Union[int, str, List[str]])
| 138 | |
| 139 | |
| 140 | def validate_charset_range(charset_range: Union[int, str, List[str]]) -> bool: |
| 141 | """ |
| 142 | 验证字符集范围参数 |
| 143 | |
| 144 | Args: |
| 145 | charset_range: 字符集范围参数 |
| 146 | |
| 147 | Returns: |
| 148 | bool: 参数是否有效 |
| 149 | |
| 150 | Raises: |
| 151 | DDDDOCRError: 当参数无效时 |
| 152 | """ |
| 153 | if charset_range is None: |
| 154 | return True |
| 155 | |
| 156 | if isinstance(charset_range, int): |
| 157 | if charset_range < 0: |
| 158 | raise DDDDOCRError("字符集范围索引必须为非负整数") |
| 159 | elif isinstance(charset_range, str): |
| 160 | if len(charset_range) == 0: |
| 161 | raise DDDDOCRError("字符集范围字符串不能为空") |
| 162 | elif isinstance(charset_range, list): |
| 163 | if len(charset_range) == 0: |
| 164 | raise DDDDOCRError("字符集范围列表不能为空") |
| 165 | for char in charset_range: |
| 166 | if not isinstance(char, str): |
| 167 | raise DDDDOCRError("字符集范围列表中的元素必须为字符串") |
| 168 | else: |
| 169 | raise DDDDOCRError(f"不支持的字符集范围类型: {type(charset_range)}") |
| 170 | |
| 171 | return True |
no test coverage detected
searching dependent graphs…