# user_dic={' xiaohong ': ' 123 ', ' Xiaobai ': ' 123 ', ' Xiaohei ': ' 123 '} # With open (' Idpd.txt ', ' W ', encoding= ' utf-8 ') as F: # f.write (str (user_dic))# with open (' Idpd.txt ', ' R ', encoding= ' Utf-8 ') as F2:# read=f2.read ()# print (read)# user_dic= Eval (read)# writes the User_dic dictionary to the file and imports the file dictionary
#idpd_path=r ' F:\Pycharmprojects\0615\idpd.txt '#idpd_dic={' id ': false, ' password ': false}#def Login (func):#def login (*args,**kwargs):#if idpd_dic[' id '] and idpd_dic[' password ']:#Res=func (*args,**kwargs)#return res#With open (Idpd_path, ' R ', encoding= ' utf-8 ') as F:#Login_dic=eval (F.read ())
Make Cache#From urllib.request import Urlopen#Import OS#cashe_path=r ' F:\Pycharmprojects\0615\makecache.txt '#def make_cashe (func):#def wrapper (*args,**kwargs):#if Os.path.getsize (cashe_path):#print (' \033[45m====> with Cache \033[0m ')#With open (Cashe_path, ' RB ',) as F:#Res=f.read ()#Else:#Res=func (*args,**kwargs)#with open (Cashe_path, ' WB ') as F:a#F.write (RES)#return res#return wrapper#@make_cashe#def get (URL):#return Urlopen (URL). Read ()
#declare an empty dictionary at the beginning of the file, and then add an adorner to each function to do the automatic addition to the dictionary#fun_dic={}#def Outer (key):#def outer (func):#def wrapper (*args,**kwargs):#Fun_dic[key]=func#return wrapper#return outer# #@Outer (' F1 ')#def f1 ():#print (' from F1 ')#@Outer (' F2 ')#def f2 ():#print (' from F2 ')#@Outer (' F3 ')#def f3 ():#print (' fromt f3 ')#F1 ()#F2 ()#f3 ()#print (fun_dic)
#i=input (' ID: ')#password=input (' Password: ')#if I in Login_dic and password in login_dic:#print (' login successfully ')#idpd_dic[' id ']=true#idpd_dic[' password ']=true#Res=func (*args,**kwargs)#return res#Else:#Print (' login error ')#Return Login#after the authentication is successful, it is no longer necessary to run other certificates
#declare an empty dictionary at the beginning of the file, and then add an adorner to each function to do the automatic addition to the dictionary#fun_dic={}#def Outer (key):#def outer (func):#def wrapper (*args,**kwargs):#Fun_dic[key]=func#return wrapper#return outer# #@Outer (' F1 ')#def f1 ():#print (' from F1 ')#@Outer (' F2 ')#def f2 ():#print (' from F2 ')#@Outer (' F3 ')#def f3 ():#print (' fromt f3 ')#F1 ()#F2 ()#f3 ()#print (fun_dic)
Python Decorator Job