def get_Ostate(self,s): """ 字母 =》'A' 数字 =》'N' 中文 =》'C' 特殊字符不变 :param s: :return: """ A=self.get_num('A') N=self.get_num("N") C=self.get_num("C") state=[] s=str(s) if len(s)==0: #空字符串取0 state.append([0]) return state s=str(s).encode("utf-8","ignore").decode('utf8','ignore') for i in s: if i.encode("utf-8").isalpha(): state.append([A]) elif i.isdigit(): state.append([N]) elif is_chinese(i): state.append([C]) else: state.append([self.get_num(i)]) return state
def preprocess(read): sentences = [] no = set() for c in read: if not utils.is_chinese(c) and c not in dian: no.add(c) # print(no) content = replace_article(read,no) return re.split('|'.join(dian),content)
def register(username, password, imsi): ''' # 注册限制暂不支持 # f sdks.get(sdkType) and settings.REGISTERLIMIT : # if imsi and not register_imei(imsi): # raise RegisterError(_YYTEXT(u'您今天已注册三个账户,请明天再试。')) ''' if settings.ISUSECLOSESERVERTIME: closetime = time.strptime(settings.CLOSEREGTIME, '%Y-%m-%d %H:%M:%S') curtime = time.localtime() if curtime > closetime: raise RegisterError(_YYTEXT(u'服务器维护中,请稍后再试')) if is_chinese(username): raise RegisterError(_YYTEXT(u'帐号不支持中文,请重新输入')) if len(username) < 6: raise RegisterError(_YYTEXT(u'该帐号位数不足6位,请重新输入')) if password != 'dummy' and len(password) < 6: raise RegisterError(_YYTEXT(u'密码位数不足6位,请重新输入')) if username.startswith("IOS"): raise RegisterError(_YYTEXT(u'帐号不合法,请重新输入')) if imsi in g_block_devices: raise RegisterError(_YYTEXT(u'该设备已被禁止注册,如有疑问请联系客服')) username = username if UsernameIndexing.exists(username): raise RegisterError(_YYTEXT(u'该帐号已被注册,请重新输入')) hashed = utils.make_password(password) try: UsernameIndexing.register(0, username) # 先占位 user = User.create(username=username, password=hashed, imsi=imsi) user.save() UsernameIndexing.pool.execute('HSET', UsernameIndexing.key, username, user.userID) # 更新 except DuplicateIndexException: raise RegisterError(_YYTEXT(u'该帐号已被注册,请重新输入')) except EntityExistsException: UsernameIndexing.unregister(username) raise RegisterError(_YYTEXT(u'该帐号已被注册,请重新输入')) except Exception as e: UsernameIndexing.unregister(username) logger.exception('register') raise e return user
def preprocess(read): sentences = [] no = set() for c in read: if not utils.is_chinese(c) and c not in dian + [' ']: no.add(c) # print(no) content = replace_article(read, no) content = re.split('|'.join(dian), content) result = [] for sen in content: sen = sen.split(' ') temp = [] for c in sen: if c != '': temp.append(c) sen = ' '.join(temp) if sen != '': # print(sen) result.append(sen) return result
def test_all_chars_under_255_must_pass(char_num): char = chr(char_num) assert not utils.is_chinese(char)
def test_chinese_chars(chinese_char): assert utils.is_chinese(chinese_char)
def test_german_chars(german_char): assert not utils.is_chinese(german_char)
def test_french_chars(french_char): assert not utils.is_chinese(french_char)
def test_spanish_chars(spanish_char): assert not utils.is_chinese(spanish_char)