def test_merging_5_things(self): sample_dict1 = {"dict1": 1} sample_dict2 = {"dict2": 2} sample_dict2_copy = sample_dict2 sample_dict3 = {"dict3": 3} sample_dict3_copy = sample_dict3 sample_dict4 = {"dict4": 4} sample_dict4_copy = sample_dict4 sample_dict5 = {"dict5": 5} sample_dict5_copy = sample_dict5 result = extend(sample_dict1, sample_dict2, sample_dict3, sample_dict4, sample_dict5) correct_result = { "dict1": 1, "dict2": 2, "dict3": 3, "dict4": 4, "dict5": 5 } self.assertDictEqual(sample_dict2, sample_dict2_copy) self.assertDictEqual(sample_dict3, sample_dict3_copy) self.assertDictEqual(sample_dict4, sample_dict4_copy) self.assertDictEqual(sample_dict5, sample_dict5_copy) self.assertDictEqual(sample_dict1, result) self.assertDictEqual(result, correct_result)
def test_merge_preserving_originals(self): sample_dict1 = {} sample_dict2 = { "apple": 0, "banana": { "weight": 52, "price": 100 }, "cherry": 97 } sample_dict2_copy = sample_dict2 sample_dict3 = {"banana": {"price": 200}, "durian": 100} sample_dict3_copy = sample_dict3 result = extend(sample_dict1, sample_dict2, sample_dict3) correct_result = { "apple": 0, "banana": { "price": 200 }, "durian": 100, "cherry": 97 } self.assertDictEqual(sample_dict1, result) self.assertDictEqual(result, correct_result) self.assertDictEqual(sample_dict2, sample_dict2_copy) self.assertDictEqual(sample_dict3, sample_dict3_copy)
def test_true_extend(self): sample_dict1 = { "apple": 0, "banana": { "weight": 52, "price": 100 }, "cherry": 97 } sample_dict2 = {"banana": {"price": 200}, "durian": 100} sample_dict2_copy = sample_dict2 result = extend(True, sample_dict1, sample_dict2) correct_result = { "apple": 0, "banana": { "weight": 52, "price": 200 }, "cherry": 97, "durian": 100 } self.assertDictEqual(sample_dict1, result) self.assertDictEqual(sample_dict2, sample_dict2_copy) self.assertDictEqual(result, correct_result)
def test_merge_on_deep_layer(self): sample_dict1 = {"layer1": {"layer2": {"layer3": {"last_layer": 1}}}} sample_dict2 = {"layer1": {"layer2": {"layer_3": {"last_layer": 2}}}} sample_dict2_copy = sample_dict2 result = extend(sample_dict1, sample_dict2) correct_result = {"layer1": {"layer2": {"layer_3": {"last_layer": 2}}}} self.assertDictEqual(sample_dict1, result) self.assertDictEqual(sample_dict2, sample_dict2_copy) self.assertDictEqual(result, correct_result)
def test_2_dicts(self): sample_dict1 = {"foo": 1} sample_dict2 = {"bar": 2} sample_dict2_copy = sample_dict2 result = extend(sample_dict1, sample_dict2) correct_result = {"foo": 1, "bar": 2} self.assertDictEqual(result, correct_result) self.assertDictEqual(sample_dict2_copy, sample_dict2) self.assertDictEqual(sample_dict1, result)
def test_true_merge_reg_dict_with_dict_with_list(self): sample_dict1 = {"foo": 1} sample_dict2 = {"bar": ["list"]} sample_dict2_copy = {"bar": ["list"]} correct_result = {"foo": 1, "bar": ["list"]} result = extend(True, sample_dict1, sample_dict2) self.assertDictEqual(sample_dict1, result) self.assertDictEqual(result, correct_result) self.assertDictEqual(sample_dict2, sample_dict2_copy)
def test_true_merge_deep_dicts(self): sample_dict1 = { "layer1": { "layer2": { "layer3": { "layer4": { "layer5": { "layer6": 1 } } } } } } sample_dict2 = { "layer1": { "layer2": { "layer_other_3": { "layer4": { "layer5": { "layer6": 1 } } } } } } sample_dict2_copy = sample_dict2 result = extend(True, sample_dict1, sample_dict2) correct_result = { 'layer1': { 'layer2': { 'layer_other_3': { 'layer4': { 'layer5': { 'layer6': 1 } } }, 'layer3': { 'layer4': { 'layer5': { 'layer6': 1 } } } } } } self.assertDictEqual(sample_dict1, result) self.assertDictEqual(result, correct_result) self.assertDictEqual(sample_dict2, sample_dict2_copy)
def test_true_merge_with_lists_blank_first(self): dict_1 = {"apple": [{"price": 100, "weight": 200}, "extra", "extra"]} dict_2 = {"apple": [{"price": 200}, "two", "three"]} result = extend(True, {}, dict_1, dict_2) correct_result = { "apple": [{ "price": 200, "weight": 200 }, "two", "three"] } self.assertDictEqual(result, correct_result)
def copy_images(path): print('##-COPY IMAGES FOR TRAINING') sides = os.listdir(path) new_path = path + '/t_images' if not os.path.isdir(new_path): os.mkdir(new_path) if 'model' in sides: sides.remove('model') if 't_images' in sides: sides.remove('t_images') if 'locationInfo.txt' in sides: sides.remove('locationInfo.txt') if 'Origin.jpg' in sides: sides.remove('Origin.jpg') for side in sides: side_path = path + '/' + side classes = os.listdir(side_path) print("Copy image classes: ", classes, "in", side) for element in classes: dir_path = side_path + '/' + element eleN_path = new_path + '/' + element config.makeDir(eleN_path) extend.extend(eleN_path, dir_path) '''
def test_merge_dict_in_list_with_overlap(self): sample_dict1 = [{"foo": 1, "bling": 1}, "extra1", ["extra2"]] sample_dict2 = [{"foo": 2, "bar": 2}] sample_dict2_copy = sample_dict2 result = extend(sample_dict1, sample_dict2) correct_result = [{ "foo": 2, "bar": 2, "bling": 1 }, "extra1", ["extra2"]] self.assertListEqual(sample_dict1, result) self.assertListEqual(sample_dict2, sample_dict2_copy) self.assertListEqual(result, correct_result)
def test_one_merging_list_with_primitive_data_types(self): sample_dict1 = {"foo": 1, "bar": 1} sample_dict2 = {"bar": [1, "2", 3.0, True, None], "foobar": 1} sample_dict2_copy = sample_dict2 result = extend(sample_dict1, sample_dict2) correct_result = { "foo": 1, "bar": [1, "2", 3.0, True, None], "foobar": 1 } self.assertDictEqual(sample_dict1, result) self.assertDictEqual(sample_dict2, sample_dict2_copy) self.assertDictEqual(result, correct_result)
def test_merge_dict_with_Nones(self): # copied from jquery unittest options = {"number1": 1, "x_string": "x", "string": "new_string"} null_dict = {"number1": None} correct_result = { "number1": None, "x_string": "x", "string": "new_string" } result = extend(options, null_dict) self.assertDictEqual(options, result) self.assertEqual(null_dict["number1"], None) self.assertDictEqual(result, correct_result)
def test_true_merge_with_lists_no_overlapping_dicts(self): sample_dict1 = { "outer": [{ "foo": 1, "bar": 1 }, "extra1", "extra2", ["extra3"]] } sample_dict2 = {"outer": ["more_extra", {"foo": 2, "bar": 2}]} result = { "outer": ["more_extra", { "foo": 2, "bar": 2 }, "extra2", ["extra3"]] } self.assertDictEqual(extend(True, sample_dict1, sample_dict2), result)
def test_recursive_dicts(self): sample_dict1 = {"foobar": 1} sample_dict2 = {"layer1": {"layer2": {"layer3": {"last_layer": 0}}}} sample_dict2_copy = sample_dict2 result = extend(sample_dict1, sample_dict2) correct_result = { "foobar": 1, "layer1": { "layer2": { "layer3": { "last_layer": 0 } } } } self.assertDictEqual(sample_dict1, result) self.assertDictEqual(sample_dict2, sample_dict2_copy) self.assertDictEqual(result, correct_result)
def test_None_is_2nd_arg(self): sample_dict1 = { "number1": 5, "number2": 7, "string1": "peter", "string2": "pan" } sample_dict2 = {"number2": 1, "string2": "x", "new_string": "xxx"} sample_dict2_copy = {"number2": 1, "string2": "x", "new_string": "xxx"} correct_result = { "number1": 5, "number2": 1, "string1": "peter", "string2": "x", "new_string": "xxx" } result = extend(sample_dict1, None, sample_dict2) self.assertDictEqual(sample_dict1, result) self.assertDictEqual(result, correct_result) self.assertDictEqual(sample_dict2, sample_dict2_copy)
def test_true_merge_with_overlap(self): sample_dict1 = { "layer1": { "layer2": { "layer3": 1 }, "layer2_extra1": 1 }, "layer1_extra1": 1 } sample_dict2 = { "layer1": { "layer2": { "layer3": 2 }, "layer2_extra2": 2 }, "layer1_extra2": 2 } sample_dict2_copy = sample_dict2 result = extend(True, sample_dict1, sample_dict2) correct_result = { "layer1": { "layer2": { "layer3": 2 }, "layer2_extra2": 2, "layer2_extra1": 1 }, "layer1_extra1": 1, "layer1_extra2": 2 } self.assertDictEqual(sample_dict1, result) self.assertDictEqual(result, correct_result) self.assertDictEqual(sample_dict2, sample_dict2_copy)
super(HighlightStyle, self).__init__() self.tint_color = 'red' class ClickHandler(object): def __init__(self): self.action = self.click_handler self.click_color = 'blue' def click_handler(self, sender): self.tint_color = self.click_color view = ui.View() button = extend(ui.Button(), HighlightStyle(), ClickHandler()) button.title = 'Styled button' view.add_subview(button) view.present() button.frame = view.bounds.inset(300, 100) #============================== import types import ui # Extend the instance given as the first argument with the methods and properties of the instances given as the second and subsequent arguments
module = blockdiag def __init__(self, options): self.options = options def parse_diagram(self, string): return self.module.parser.parse_string(string) def run(self, string): self.create_fontmap() return self.build_diagram(self.parse_diagram(string)) class CommandMixin(object): def blockdiag(self, string): return self.app.run(string) class DiagShell(CommandMixin): def __init__(self, app): self.app = app app = DummyApplication(DummyOption()) import extend app = extend.extend(app) shell = DiagShell(app) shell.blockdiag(u"diagram { a -> b;}")
def test_1_list(self): sample_list = ["value", 1, 2.0, False, None] sample_list_copy = ["value", 1, 2.0, False, None] self.assertListEqual(extend(sample_list), sample_list_copy)
from UserTag import get_lsi, LSI from topic import get_topic_words_in_str from extend import extend outfile1 = open('first_topics.txt', 'w') outfile2 = open('second_topics.txt', 'w') topics_str = get_lsi(10) topics_dcit = [] for topic in topics_str: topics_dcit.append(get_topic_words_in_str(topic)) for t in topics_dcit: outfile1.writelines('------------------topic--------\n') for w in t: t[w] = extend(w) outfile1.write(w.encode('utf8')+':') for tw in t[w]: outfile1.write(tw.encode('utf8')+' ') outfile1.writelines('---\n') outfile1.writelines('---\n') new_topic = [] new_topic_dict = [] for t in topics_dcit: outfile2.writelines('------------------topic--------\n') new_topic_str = LSI(t.values(), 1)[0] for nw in get_topic_words_in_str(new_topic_str).keys(): outfile2.write(nw.encode('utf8')+' ') outfile2.writelines('---\n')
def verify_sigaddr(task_name, verify_addr, verify_option, extend_option, bt_option): """ param:task_name: param:verify_addr:待验证邮箱地址 param:verify_option param:extend_opeion: param:bt_option: """ count = 0 flag = True model_qq = r'\d{5,11}@qq.com' # 匹配QQ邮箱:5到11位的数字作为邮箱名 model_163_126 = r'[a-zA-Z][a-zA-Z0-9\_]{4,16}[a-zA-Z0-9]@1(63|26).com' # 匹配163,126邮箱:6到18位,以字母开头,以字母或数字结尾,可由字母数字下划线组成 model_yeah = r'[a-zA-Z][a-zA-Z0-9\_]{4,16}[a-zA-Z0-9]@yeah.net' # yeah.net,规则与163相同 model_sina = r'[a-z0-9][a-z0-9\_]{2,14}[a-z0-9]@sina.com' # 匹配新浪邮箱:4到16位,字母小写或数字或下划线,下划线不能在结尾 model_sohu = r'[a-zA-Z][a-zA-Z0-9\_]{5,15}@sohu.com' # 匹配搜狐邮箱:6到16位,字母开头,字母数字下划线 model_189 = r'\d{11}@189.cn' # 用电话号码命名 model_edu = r'[a-zA-Z0-9]\w*@\w+.edu.cn' # 高校邮箱 # list_all=['*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**'] verifyList = {} list = [] print (verify_option) # 根据验证选项确定用什么邮箱进行验证?? if verify_option.find('0') >= 0: list.append('*****@*****.**') verifyList['126'] = 1 if verify_option.find('1') >= 0: list.append('*****@*****.**') verifyList['163'] = 1 if verify_option.find('2') >= 0: list.append('*****@*****.**') verifyList['qq'] = 1 if verify_option.find('3') >= 0: list.append('*****@*****.**') verifyList['sina'] = 1 if verify_option.find('4') >= 0: list.append('*****@*****.**') verifyList['sohu'] = 1 if verify_option.find('5') >= 0: list.append('*****@*****.**') verifyList['189'] = 1 if verify_option.find('6') >= 0: list.append('*****@*****.**') verifyList['yeah'] = 1 print (list) new_list = [] # 收到新邮件的邮箱 for from_addr in list: temp = from_addr[from_addr.find('@') + 1: from_addr.find('.')] if from_addr == '*****@*****.**': password = '******' # 授权码的问题 smtp_server = 'smtp.qq.com' imap_server = 'imap.qq.com' # pop3_server='pop.qq.com' password_imap = 'zoxreyhbujdnbacc' elif from_addr == '*****@*****.**': password = '******' smtp_server = 'smtp.163.com' imap_server = 'imap.163.com' # pop3_server='pop.163.com' password_imap = 'RaoYuXin1234' elif from_addr == '*****@*****.**': password = '******' smtp_server = 'smtp.126.com' imap_server = 'imap.126.com' # pop3_server='pop.126.com' password_imap = 'jizhongyi111' elif from_addr == '*****@*****.**': password = '******' smtp_server = 'smtp.yeah.net' imap_server = 'imap.yeah.net' # pop3_server='pop.yeah.net' password_imap = 'RaoYuXin1234' elif from_addr == '*****@*****.**': password = '******' smtp_server = 'smtp.sohu.com' imap_server = 'imap.sohu.com' # pop3_server='pop3.sohu.com' password_imap = 'yaoyuxin1234' elif from_addr == '*****@*****.**': password = '******' smtp_server = 'smtp.sina.com' imap_server = 'imap.sina.com' # pop3_server='pop.sina.com' password_imap = 'yaoyuxin1234' elif from_addr == '*****@*****.**': password = '******' smtp_server = 'smtp.189.cn' imap_server = 'imap.189.cn' # pop3_server='pop.189.cn' password_imap = 'raoyuxin1234' try: msg = MIMEText('hello,send by Python..', 'plain', 'utf-8') msg['From'] = _format_addr('您的好友<%s>' % from_addr) msg['To'] = _format_addr('管理员<%s>' % verify_addr) msg['Subject'] = Header('来自朋友的问候。。。。', 'utf-8').encode() server = smtplib.SMTP(smtp_server, 25) # server.set_debuglevel(1)#打印通信进程 server.starttls() # 登录发信邮箱 server.login(from_addr, password) try: server.sendmail(from_addr, [verify_addr], msg.as_string()) except smtplib.SMTPDataError: alter_list(list, from_addr) continue # server.sendmail(from_addr,[verify_addr],msg.as_string()) server.quit() print(from_addr, '已投递') time.sleep(1) try: # 通过LoginMail函数借助IMAP服务读取邮件数量判断是否有新邮件 is_new = LoginMail(imap_server, from_addr, password_imap) # 当is_new==1时,说明有新邮件,遂检查是否是退信 except Exception as e: print(e) continue print(is_new) if is_new == 1: # 如果存在新邮件,则取回检查是否是退信 new_list.append(from_addr) except smtplib.SMTPRecipientsRefused: # 邮箱异常处理 print(from_addr, '验证其无效') verifyList[temp] = '2' flag = False except smtplib.SMTPServerDisconnected: # 挂了一个邮箱 print(from_addr, '连接失败,换一个邮箱进行验证') verifyList[temp] = -1 alter_list(list, from_addr) #print(list) continue except smtplib.SMTPSenderRefused: alter_list(list, from_addr) # print(new_list) for new_mail in new_list: try: if new_mail == '*****@*****.**': password = '******' # 授权码的问题 pop3_server = 'pop.qq.com' elif new_mail == '*****@*****.**': password = '******' pop3_server = 'pop.163.com' elif new_mail == '*****@*****.**': password = '******' pop3_server = 'pop.126.com' elif new_mail == '*****@*****.**': password = '******' pop3_server = 'pop.yeah.net' elif new_mail == '*****@*****.**': password = '******' pop3_server = 'pop3.sohu.com' elif new_mail == '*****@*****.**': password = '******' pop3_server = 'pop.sina.com' elif new_mail == '*****@*****.**': password = '******' pop3_server = 'pop.189.cn' # 通过邮箱POP服务取回邮箱中最新的邮件 server = poplib.POP3_SSL(pop3_server) server.user(new_mail) server.pass_(password) # print('Message:%s. Size:%s'%server.stat()) resp, mails, octects = server.list() # print(mails) index = len(mails) resp, lines, octects = server.retr(index) # msg_cotent=b'\r\n'.join(lines).decode('utf-8') try: msg_cotent = b'\r\n'.join(lines).decode('GBK') # 获得整个邮件的原始文本 except UnicodeDecodeError: msg_cotent = b'\r\n'.join(lines).decode('utf-8') # msg_cotent=b'\r\n'.join(lines).decode('GBK')#获得整个邮件的原始文本 msg = Parser().parsestr(msg_cotent) # 把邮件解析为message对象 is_backmail = print_info(msg) # print(is_backmail) print_info在输出的同时对邮件解析,判断是否是退信 # 检查是否是退信邮件 if is_backmail == 1: print(new_mail, '验证其无效\n') verifyList[temp] ="3" count = count + 1 server.quit() except Exception as e: print(e) print(new_mail) continue # print('共有',count,'个邮箱通过交叉验证证明',verify_addr,'无效') if extend_option == '1': try: temp_dict = extend.extend(task_name) extend.exaddr_verify(temp_dict) except Exception as e: print (e) if bt_option == '1': try: robot.mutilTrack(task_name) except Exception as e: print(e) print(verifyList) temp = [] for i in verifyList.keys(): temp.append(i+':'+ str(verifyList[i])) print (temp) db = MySQLdb.connect(user="******", passwd="", host="localhost", db="email") cursor = db.cursor() if flag == False: sql = 'update verify_email set status= "1",result="0",detail="%s" where email="%s";' % (str(temp), verify_addr) cursor.execute(sql) db.commit() elif flag == True and count > len(list)/2: sql = 'update verify_email set status= "1",result="0",detail="%s" where email="%s";' % (str(temp), verify_addr) cursor.execute(sql) db.commit() else: sql = 'update verify_email set status= "1",result="1",detail="%s" where email="%s";' % (str(temp), verify_addr) cursor.execute(sql) db.commit() return True
class DummyApplication(Application): module = blockdiag def __init__(self, options): self.options = options def parse_diagram(self, string): return self.module.parser.parse_string(string) def run(self, string): self.create_fontmap() return self.build_diagram(self.parse_diagram(string)) class CommandMixin(object): def blockdiag(self, string): return self.app.run(string) class DiagShell(CommandMixin): def __init__(self, app): self.app = app app = DummyApplication(DummyOption()) import extend app = extend.extend(app) shell = DiagShell(app) shell.blockdiag(u"diagram { a -> b;}")
from UserTag import get_lsi, LSI from topic import get_topic_words_in_str from extend import extend outfile1 = open('first_topics.txt', 'w') outfile2 = open('second_topics.txt', 'w') topics_str = get_lsi(10) topics_dcit = [] for topic in topics_str: topics_dcit.append(get_topic_words_in_str(topic)) for t in topics_dcit: outfile1.writelines('------------------topic--------\n') for w in t: t[w] = extend(w) outfile1.write(w.encode('utf8') + ':') for tw in t[w]: outfile1.write(tw.encode('utf8') + ' ') outfile1.writelines('---\n') outfile1.writelines('---\n') new_topic = [] new_topic_dict = [] for t in topics_dcit: outfile2.writelines('------------------topic--------\n') new_topic_str = LSI(t.values(), 1)[0] for nw in get_topic_words_in_str(new_topic_str).keys(): outfile2.write(nw.encode('utf8') + ' ') outfile2.writelines('---\n')
def test_blank_list(self): self.assertListEqual(extend([]), [])
def test_blank_dict(self): self.assertDictEqual(extend(), {})
def test_1_dict(self): sample_dict1 = {"test": 1} sample_dict1_copy = {"test": 1} self.assertDictEqual(extend(sample_dict1), sample_dict1_copy)