46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
# @FileName: format_username.py
|
||
# @Software:
|
||
# @Author: Leven Xiang
|
||
# @Mail: xiangle0109@outlook.com
|
||
# @Date: 2021/4/19 9:17
|
||
|
||
import re
|
||
|
||
|
||
def format2username(account):
|
||
"""
|
||
格式化账号,统一输出为用户名格式
|
||
:param account 用户账号可以是邮箱、DOMAIN\\username、username格式。
|
||
:return: username
|
||
"""
|
||
if account:
|
||
mail_compile = re.compile(r'(.*)@(.*)')
|
||
domain_compile = re.compile(r'(.*)\\(.*)')
|
||
|
||
if re.fullmatch(mail_compile, account):
|
||
return re.fullmatch(mail_compile, account).group(1)
|
||
elif re.fullmatch(domain_compile, account):
|
||
return re.fullmatch(domain_compile, account).group(2)
|
||
else:
|
||
return account.lower()
|
||
else:
|
||
raise NameError("输入的账号不能为空..")
|
||
|
||
|
||
def get_user_is_active(user_info):
|
||
try:
|
||
return True, user_info.get('active') or user_info.get('status')
|
||
except Exception as e:
|
||
return False, 'get_user_is_active: %s' % str(e)
|
||
|
||
except (KeyError, IndexError) as k_error:
|
||
return False, 'get_user_is_active: %s' % str(k_error)
|
||
|
||
|
||
if __name__ == '__main__':
|
||
user = 'jf.com\XiangLe'
|
||
username = format2username(user)
|
||
print(username)
|