Spaces:
Paused
Paused
| # -*- coding: utf-8 -*- | |
| robe_version="1;;" | |
| ##import sys;import os;sys.path.append(os.environ["cpy"]+r"\Mjmoji");from mw import * ; | |
| ##import mlwebOrWeb as ml | |
| ## wardrobe | |
| import sys,os,re | |
| import shutil | |
| import inspect | |
| import time | |
| import traceback | |
| import pprint | |
| import functools | |
| if "Byte": | |
| from io import StringIO, BytesIO | |
| lf= "\n";lff=lf*2;sp=" ";lf2="\n";tab="\t"; | |
| def fpreturn(*_): return _[0] | |
| def fpre(*_): return _ | |
| pr=print | |
| tfolder="r:/temp" | |
| if not os.path.exists(tfolder): tfolder=os.environ["tmp"] | |
| if "cpa" in os.environ: | |
| cpy=os.path.abspath(__file__+"\\..\\..") | |
| cpw=os.path.abspath(__file__+"\\..") | |
| T45=os.environ["USERNAME"] | |
| cpa=os.environ["cpa"] | |
| ZVCherryPicker=cpy+"\\qt\\ZVCherryPicker.pyw" | |
| HeartNote=cpy+"\\qt\\HeartNote.pyw" | |
| else: | |
| cpa=None | |
| class p310:# require version | |
| def __getstate__(zl):return #pickle | |
| membile={} | |
| def membile(fp,membile=membile): | |
| membilefp=membile.setdefault(fp,{}) | |
| def f(*w,**W): | |
| if(p:=membilefp.get((w,str(W)))):return p | |
| p=fp(*w,**W) | |
| membilefp[(w,str(W))]=p | |
| return p | |
| f.membile=membilefp | |
| return f | |
| def rint(w): | |
| if not typeint(w): | |
| assert 0,"not rint" | |
| return int(w) | |
| def typeint(w): | |
| try: | |
| int(w) | |
| return True | |
| except:False | |
| def typefn(fn,remove=0): | |
| if (re.search(r'["*/:<>?\\|]',(fn))):return | |
| if (".." in fn):return | |
| if len(fn)>255:return | |
| try: | |
| open(fn,"ab") | |
| ## if remove: os.remove(fn) | |
| return 1 | |
| except:False | |
| def fpf(fn,fb="",tail=""): | |
| if not typefn(fn): | |
| if not fb: | |
| f,e=lfn.splitext(fn) | |
| fb=f[:200]+e | |
| fn=fb | |
| if tail: wfdb(fn+"_", putp(1,tail)) | |
| return fn | |
| def putp(fl,te):#,*w,**W): | |
| import pickle | |
| put=pickle.dumps | |
| ## print(te) | |
| if fl==1: te= put(te) | |
| if fl==2: te= pickle.loads(te) | |
| return te | |
| def exrange(li,step=2): | |
| if len(li)/step < 0: return | |
| for x in range(0,len(li)//step): | |
| yield li[x*step:x*step+step] | |
| def pr2(*a,**k): pass; | |
| oriAB=lambda x: (print(x[:122],lf*2,x[-122:])) | |
| ppf=pprint.pformat | |
| def orib(lii, ix=-1,bound=4): | |
| "print(li[:4],li[-4:])" | |
| if(ix==-1): | |
| lambda x: (print(x[:4],lf*2,x[-4:])) | |
| else: | |
| lio=[lii[ix+n] for n in list(range(-bound,bound)) if(ix+n>0 and ix+n<len(lii)) ] | |
| for v in lio: | |
| if(v==lii[ix]):lio[lio.index(v)]="__"+v | |
| ## lio[ix]="__"+lio[ix] | |
| #lio[ix]+=lf | |
| print(lfjw(lio)) | |
| def printline(*a,**k):#X/ref | |
| f=inspect.currentframe() | |
| if(sys.version=='3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)]'): | |
| no=inspect.currentframe(1) | |
| elif(sys.hexversion>=0x030401F0):#'3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)]'): | |
| "c7 3.7.7 64bit -> 3.8.6" | |
| fb=f | |
| for _ in range(4): | |
| print(fb.f_lineno,fb.f_code.co_filename, fb.f_code.co_name) | |
| fb=fb.f_back | |
| if not fb: | |
| break | |
| ## print(" L-"+str(no),*a,**k) | |
| def prfl(li):#prFirstLast | |
| print(li[0],lf,li[-1]); | |
| def pren(v): | |
| print(list(enumerate(v))) | |
| #mrk1------------file | |
| def wfdb(filename,te):#writeFileDirectInBinaryMode | |
| f = open(filename,"wb") | |
| f.write(te) | |
| def wfdt(filename,te):#text | |
| return wfd(filename).t(te) | |
| def wfdt8L(filename,te):#textUni NewLine Unix Format | |
| f = open(filename,"wU",encoding="utf-8") | |
| f.write(te) | |
| def wfd8(fn,te): | |
| wfd(fn).w(te,code="utf8",copy=0) | |
| def afdt(filename,te):#textUni | |
| f = open(filename,"a+",encoding="utf-8") | |
| f.write(te) | |
| write8dd=afdt | |
| afdtu=afdt | |
| def rfdb(fn): | |
| f = open(fn,"rb") | |
| te = f.read() | |
| return te | |
| def rfdt(fn):return wfd(fn).r() | |
| def rfdl(fn): | |
| f = open(fn,"r") | |
| te = f.readlines() | |
| return te | |
| def rfdv0(fn,codeList=("cp932","utf-16","utf-8","eucjp"),lines=True): | |
| for c in codeList: | |
| f = open(fn,"r",encoding=c) | |
| try: | |
| te = f.readlines() if(lines)else f.read() | |
| break | |
| except UnicodeDecodeError as XP: | |
| continue; | |
| except UnicodeError as XP: | |
| continue; | |
| return te | |
| def rfdlv(fn): return rfdv0(fn) | |
| def rfdtv(fn): return rfdv0(fn,lines=False) | |
| def rfdtu(fn): | |
| f = open(fn,"r",encoding="utf-8") | |
| te = f.read() | |
| return te | |
| def vcs(bte,cs=("utf8","cp932","utf16","eucjp")): | |
| for c in cs: | |
| try: return bte.decode(c) | |
| except: continue | |
| class wfd():#clWfd | |
| tab="\t" | |
| def __init__(zl,fn,region=(),ir=None,lf="\n"): | |
| zl.fn=fn | |
| zl.code="utf8" | |
| zl.lf=lf | |
| zl.ir=ir# | |
| zl.by=None | |
| def readtime(zl,mod=0): | |
| zl.ts=(lfn.getatime(zl.fn)+mod, mtime(zl.fn)+mod) | |
| return zl | |
| ## def restoretime(zl): | |
| def rfdv(zl):return zl.r(cs=("cp932","utf-16","utf-8","eucjp","mbcs"))#noMbcs) | |
| ## def mem(zl): zl.by=zl.rb(); return zl; | |
| def rb(zl): return open(zl.fn,"rb").read() | |
| def r(zl,cs=("utf8","cp932","utf16","eucjp"),lines=False,m=0,te=""): | |
| if te: e1=te | |
| else: | |
| with open(zl.fn,"rb") as f: | |
| e1 = f.read() | |
| for c in cs: | |
| try: | |
| t1=e1.decode(c) | |
| if("\r\n" in t1): | |
| #if(t1.count("\r")!=t1.count("\n")):return 0 | |
| zl.lf="\r\n" | |
| elif("\n" in t1):zl.lf="\n" | |
| elif("\r" in t1):zl.lf="\r" | |
| else:#oneline | |
| pass | |
| if lines: te=t1.splitlines() | |
| else: te=t1 | |
| #te=te.replace(zl.lf, "\n") | |
| zl.code=c | |
| break | |
| except (UnicodeDecodeError, UnicodeError) as e: | |
| zl.lastException=e | |
| continue; | |
| else: | |
| return 0 | |
| if(zl.ir) and 0: | |
| te=zl.lte=findall(zl.ir,te) | |
| if m: #chk modified | |
| import hashlib | |
| zl.mtime=mtime(zl.fn) | |
| zl.sha=hashlib.sha256(te.encode()).digest() | |
| return te | |
| def csvr(zl,*aw,lf=None,tab=None,**kw): | |
| return list(csv.reader(StringIO(zl.r()), delimiter=tab or zl.tab)) | |
| def w8(zl,te): return zl.w(te,code="utf8") | |
| def w16(zl,te): return zl.w(te,code="utf_16_LE") | |
| def wjis(zl,te): return zl.write8re(zl.fn,te,"cp932") | |
| def write8re(zl,fn,te,code="",lines=False,copy=True,lf=1,nbase=0,ts=0): | |
| if not code: code=zl.code | |
| dir = lfnd(fn) | |
| if dir: inidi(dir) | |
| if(ifexist(fn) and copy): | |
| dnRestore=f"{tfolder}/restore" | |
| inidi(dnRestore) | |
| zl.fnRestore=nxNumFull(dnRestore,"%s"+lfn.split(fn)[1],nZfill=2) if nbase else jofn(dnRestore,cfile(fn)+" "+tp()) | |
| shutil.copy2(fn,zl.fnRestore) | |
| ## emove__ | |
| rmbat(zl.fnRestore) | |
| ## if(type(te)!=str):return 0 | |
| if 1: | |
| Lf=(zl.lf if lf==1 else lf) | |
| t1=jw(Lf,te) if lines else te | |
| #no t1=zl.CallBackCaller() if zl.ir else t1 | |
| e1=t1 | |
| if isinstance(e1, str): e1=e1.encode(code) | |
| try: | |
| with open(fn, 'wb') as fo: | |
| fo.write(e1) | |
| except Exception as e: | |
| #restore() | |
| ## zl.LastError=e | |
| open(r"r:\fail reason.txt","w").write(str(e)) | |
| open(r"r:\fail "+tp()+".txt", "wb").write(e1) | |
| #with open(nxNumFull(r"r:","%s"+os.path.split(fn)[1],nZfill=2), 'wb') as fo: | |
| return 0 | |
| if ts==1: os.utime(zl.fn, zl.ts) | |
| ## finally: | |
| if 0: | |
| ## t2=rfdtv(fn) | |
| fo=wfd(fn) | |
| t2=fo.r(cs=("utf8","utf16","eucjp","cp932")) | |
| print(fo.code,t2) | |
| ## print(fnRestore,t2) | |
| #diff() | |
| return 1 | |
| ## def write8re(zl,fn,te,*aw,**kw):print("w;",fn,len(te), lf, dif32(zl.r(),te)) | |
| def w(zl,te,*a,**k):return zl.write8re(zl.fn, te, *a, **k) | |
| def t(zl,te,*a,**k): | |
| rmbat(zl.fn,rembat="wf t.bat") | |
| return zl.write8re(zl.fn, te,copy=False *a, **k) | |
| def CallBackCaller(zl): | |
| te=zl.r((zl.code,)) | |
| rnte="" | |
| l=0 | |
| for n,ran in enumerate(zl.lte):#range list.appended(ire.search) | |
| rnte+=te[l:ran[0]] | |
| rnte+=zl.cb(n) | |
| l=ran[1] | |
| rnte+=te[l:] | |
| return rnte | |
| def ornkf(byte,cs=("utf8","cp932","utf16","eucjp"),lines=False): | |
| return | |
| for c in csf: | |
| try: | |
| t1=e1.decode(c) | |
| if("\r\n" in t1): | |
| if(t1.count("\r")!=t1.count("\n")):return 0 | |
| zl.lf="\r\n" | |
| elif("\n" in t1):zl.lf="\n" | |
| elif("\r" in t1):zl.lf="\r" | |
| else:#oneline | |
| pass | |
| if lines: te=t1.splitlines() | |
| else: te=t1.replace(zl.lf, "\n") | |
| zl.code=c | |
| break | |
| except UnicodeDecodeError as XP: | |
| continue; | |
| except UnicodeError as XP: | |
| continue; | |
| else: | |
| return 0 | |
| ## with open(zl.fn, "rb", encoding=zl.code): | |
| return te | |
| #----mrk1----------- | |
| def line(): | |
| return inspect.currentframe().f_back.f_lineno | |
| def cmpd(te,tf):#cmpDokomade.Use for comic rename | |
| for n in range(999): | |
| if te[n] != tf[n]: | |
| return n | |
| def cmpfs(li): | |
| "os.path.commonprefix(list)" | |
| ip=min(compd(li[0],f) for f in li) | |
| return ip | |
| def wfy(li,ws=5):# windowfy function, window size | |
| for n,f in enumerate(li): | |
| yield li[n:n+5] | |
| ##def orin(te=" input"): | |
| ## print(te) | |
| ## input() | |
| def owari(): | |
| print("\nowari:"); | |
| input("owari:") | |
| from argparse import ArgumentParser | |
| def arx(a=None):#Exe | |
| parser = ArgumentParser(description="command_error") | |
| parser.add_argument("-f",type=str) | |
| parser.add_argument("-re",type=str) | |
| parser.add_argument("fil",nargs="*") | |
| arps=parser.parse_args(a) | |
| return arps | |
| def a2a(li): | |
| return jw(" ",('"{}"'.format(f) for f in li)) | |
| def chdir(x=0): | |
| os.chdir(lfnd(sys.argv[x])) | |
| class pushd: | |
| def __init__(sl,dir): | |
| if 1: inidi(dir) | |
| sl.dL=os.getcwd() | |
| os.chdir(dir) | |
| def __enter__(sl): | |
| return 1 | |
| def __exit__(sl, _type, value, traceback): | |
| os.chdir(sl.dL) | |
| "contextmanager" | |
| ##@contextmanager | |
| ##def __pushd(dir): | |
| ## try: yield chdir(pop:=dir) | |
| ## finally: chdir(pop) | |
| def chdirc(fil=0,idx=1):# mv to z droped file | |
| if not fil:fil=sys.argv[1:] | |
| if isinstance(fil,(hhww)): fil=fil.fil | |
| if not fil: | |
| pr("please drop off the file");input("chdirc()"); | |
| else: | |
| os.chdir(lfnd(fil[0])) | |
| return fil | |
| def chdirm():# mv to z file own is in | |
| chdirc(args=sys.argv,idx=0) | |
| def cdn(args = sys.argv):#ChDirNakereba 引数があればそのディレクトリに。なければスクリプトの | |
| if(len(args) == 1): | |
| lena=0; | |
| else: | |
| lena=1; | |
| argf= args[lena] | |
| d=re.match(r"(.+(?:\\|/))",argf).group(1) | |
| os.chdir(d) | |
| # a=input(argf) | |
| return args[1:]; | |
| #r:\p\fi.mkv | |
| #r:\p | |
| #r:\p #fi | |
| #fi. | |
| #fi.mkv | |
| #.mkv | |
| #mkv | |
| def cdir(fn):return lfnd(fn) | |
| def cdiy(argf):#+yen | |
| return argf[:argf.rfind('\\')+1]#fail .-1+1=0 ."" | |
| def cfile(fn):return lfnb(lfn.splitext(fn)[0]) | |
| def cdotc(fn):return lfnb(fn) | |
| def catsuff(fn,suf):#foo.mkv, mp4 >> foo.mp4 | |
| tail=fn.rfind('.') | |
| if(tail==-1):tail=None | |
| fnre=fn[:tail]+"."+suf | |
| if(fnre==fn): | |
| return "onaji" | |
| return fnre | |
| replaceSuffix=catsuff | |
| def catpref(fn,prefix): | |
| "/foo.mkv, f2 >> /f2foo.mkv" | |
| yenpos=fn.rfind('\\') | |
| if(yenpos==-1): | |
| fnre=prefix+fn | |
| else: | |
| fnre=fn[:yenpos]+'\\'+prefix+fn[yenpos+1:] | |
| return fnre | |
| def CatPS(fn,p,s): | |
| return catsuff(catpref(fn,p),s) | |
| # | |
| if "jwdir": | |
| def lgest(lis): | |
| l=lis[0] | |
| for l2 in lis: | |
| if l2>l: l=l2 | |
| return l | |
| def notanybad(lis): | |
| for f in lis: | |
| if not f: return False | |
| return True | |
| #from jwdir import * | |
| jwdir=getattr(os.path,b'\x6A\x6F\x69\x6E'.decode()) | |
| jofn=jwdir | |
| def jw(te,list): | |
| assert isinstance(te,(str,bytes)) | |
| #assert 1==len(typ:=set(type(f) for f in [te,*list])), ["type not unique ",typ] | |
| assert hasattr(list,"__iter__") | |
| return getattr(te,b'\x6A\x6F\x69\x6E'.decode())(list) | |
| lfjw=functools.partial(jw, lf) | |
| _lfn="LibFileName"#="lfn" | |
| lfn=os.path | |
| lfnd=lfn.dirname | |
| lfndir=lfn.dirname | |
| lfnb=lfn.basename | |
| mtime=lfn.getmtime | |
| ctime=lfn.getctime | |
| n12=__builtins__[b'\x65\x6E\x75\x6D\x65\x72\x61\x74\x65'.decode()] | |
| def fpn1(lis): | |
| if isinstance(lis,(dict)): return getattr(lis,b'\x69\x74\x65\x6D\x73'.decode())() | |
| return n12(lis) | |
| sleep=getattr(time,b'\x73\x6C\x65\x65\x70'.decode()) | |
| def shuttown(stdin,*w): | |
| assert hasattr(stdin, b'\x63\x6C\x6F\x73\x65'.decode()) | |
| return getattr(stdin,b'\x63\x6C\x6F\x73\x65'.decode())(*w) | |
| def dq(te):#double quote | |
| if(te[0] != '"' or te[-1] != '"'): | |
| return '"'+te+'"'; | |
| def prit(*w): | |
| te=jw(" ", [str(f) for f in w])+lf; | |
| print("---") | |
| print(te, end=""); | |
| if w[:1]==(1,):input("*") | |
| sys.exit(); | |
| prexit=prit | |
| def inidi(pdir): | |
| if os.path.exists(pdir): return 1 | |
| else:os.makedirs(pdir); return 0 | |
| def inidir(*dirlist): | |
| with pushd("."): | |
| for f in dirlist: | |
| assert type(f)==str, "inidir;" | |
| #f=os.path.abspath(f) | |
| if not f: | |
| os.chdir("..") | |
| continue | |
| p=os.path.split(f) | |
| if(p[0]):#"c:\dir\" | |
| if not lfn.exists(p[0]):os.makedirs(p[0]) | |
| assert lfn.isdir(p[0]) | |
| os.chdir(p[0]) | |
| if(p[1]):#"c:\file" > ("c:\", "file") | |
| if not os.path.exists(f):wfdb(f,b"") | |
| def isdir(fn): | |
| if os.path.isdir(fn): return fn; | |
| if os.path.isfile(fn): return 0; | |
| if os.path.islink(fn): return 0; | |
| def isBound(length,index): | |
| if(length<0): | |
| index=abs(index+1) | |
| return bool(length>index) | |
| def boundary(x,b): | |
| if b[0]>x:x=b[0]; | |
| if b[1]<=x:x=b[1]-1 | |
| return x | |
| def ifexist(fn):#return True | |
| return lfn.exists(fn) | |
| def AbImage1(fs,grouping=False):#連番を表示しない。冗長になるのを防ぐ | |
| lioView=[] | |
| DiNameTm=puni() | |
| for fn in fs: | |
| NameTm=re.sub(r"\d","5",fn) | |
| DiNameTm.up(NameTm,fn) | |
| # | |
| ireTailNm=re.compile(r"(\d+)") | |
| def fTailNm(fn):#return rearest number | |
| fn=re.sub(r"(mp4|mp3)","",fn) | |
| mo=ireTailNm.findall(fn) | |
| if mo: | |
| Nm=int(mo[-1]) | |
| return Nm | |
| return 0 | |
| if grouping: | |
| d2=list((k,sorted(v,key=lambda e: -fTailNm(e))) for k,v in DiNameTm.items()) | |
| l1=[[" "+f[0]]+f[1:grouping] for k,f in d2] | |
| lioView=[f1 for f2 in l1 for f1 in f2] | |
| else: | |
| lioView=[max(v,key=fTailNm) for k,v in DiNameTm.items()] | |
| return lioView | |
| def orror(*a,**k): | |
| te=jw(" ",(str(f)for f in a)) + lf; | |
| afdt("orror00.txt",te) | |
| def orro2(*a,**k): | |
| te=""; | |
| for f in a: | |
| ty=type(f); | |
| if(ty==int): | |
| ti=str(f); | |
| te= te+ti | |
| else: | |
| te+=f; | |
| te+=" "; | |
| te+=lf; | |
| afdt("orror00.txt",te) | |
| def orro3(fn,te0=None,sp=" "): | |
| if(te0!=None): | |
| wfd(fn).w(te0,copy=False) | |
| def f(*a,**k): | |
| te=jw(sp,[str(t) for t in a]); | |
| afdt(fn,te+lf) | |
| return te | |
| return f; | |
| def move2(src,dist, rec=0): | |
| if dist==src: return | |
| distdir=lfn.dirname(dist) | |
| if distdir and not(ifexist(distdir)): os.makedirs(distdir) | |
| if rec: afdt("r:\\temp\\rename.txt",dist+tab+src+lf); | |
| os.rename(src,dist); | |
| ##def move2(src,dist): move2(dist,src,0) | |
| def rmbat(fns,rembat="rmbat.bat",tmd=tfolder):#jis only | |
| rembat=tmd+"/"+rembat | |
| if not ifexist(rembat): afdt(rembat, 'chcp 65001\r\n') | |
| for fn in fns if type(fns)!=str else [fns]: afdt(rembat,'del "{fn}"\r\n'.format(fn=lfn.abspath(fn))) | |
| orRemove=rmbat | |
| def remove(fn,add=1): | |
| if not ifexist(fn):return | |
| if add: afdt(r"r:\temp\rename.txt",":rm"+"\t"+fn+lf); | |
| os.chmod(fn,0o770) | |
| if lfn.isdir(fn): | |
| shutil.rmtree(fn) | |
| elif lfn.isfile(fn): | |
| os.remove(fn) | |
| return 1 | |
| def remo(fn): return remove(fn,add=0) | |
| _perf_counter0=time.perf_counter() | |
| def perf_counter(): | |
| return time.perf_counter()-_perf_counter0 | |
| def timepref(w=5,n=2):# zero width, after z decimal point | |
| return time.strftime("%Y%m%d-%H%M%S")+"-{t:0{w}d}".format(w=w,t=time.perf_counter_ns()//(1000000000//10**n)) | |
| from datetime import datetime, timedelta, timezone | |
| JST = timezone(timedelta(hours=+9), 'JST') | |
| ##def today(): | |
| _now=0 | |
| def tp(te="%Y%m%d-%H%M%S",n=2, JST=JST ):#%f | |
| global _now | |
| while 1: | |
| ((t:=datetime.now(JST))) | |
| now=t.strftime(te) | |
| if n:now+="-{}".format(f"{t.microsecond:06}"[:n]) | |
| if _now!=now:break | |
| _now=now | |
| return now | |
| def emove(src,timebase=True): | |
| src=os.path.abspath(src) | |
| c=os.path.splitdrive(src)[0]+os.path.sep #c: | |
| emo=jofn(c, "emove______") | |
| if not(os.path.exists(emo)): os.makedirs(emo) | |
| _id=tp()# if timebase | |
| #base="{} {}".format(os.path.basename(src), _id) | |
| base=_id | |
| dst=jofn(c, "emove______", base) | |
| afdt(jofn(emo,"wrld.txt"),src+"\t"+base+lf); | |
| os.rename(src,dst) | |
| return dst | |
| def emrestore(fn="C"): | |
| if len(fn)==1: | |
| emo=jofn(fn[0]+":/", "emove______") | |
| else:emo=fn | |
| li=rcsr(jofn(emo,"wrld.txt")) | |
| return li | |
| return (li[-400:]) | |
| #emove(r"r:\02zv.txt") | |
| def fripfn(*w): | |
| ff=w[0]+"fripfn" | |
| os.rename(w[0],ff) | |
| os.rename(w[1],w[0]) | |
| os.rename(ff,w[1]) | |
| #2remove | |
| def orsplit1(te,Threshold=1): | |
| return [j for j in te.splitlines() if len(j)>=Threshold and j[0]!="#"] | |
| def orsplit(te,delimiter): | |
| t2=te.split(lf) | |
| t3=[j.split(delimiter) for j in t2 if len(j) > 0] | |
| return t3 | |
| def orsplit2(te,delimiter,threshold=5,strip=fpreturn): | |
| "VzComment" | |
| t2=te.split("\n") | |
| l1list=[[strip(f) for f in j.split(delimiter)] for j in t2 if len(j)>=threshold and j[0]!="#"] | |
| return l1list | |
| def colonsplit(te): return orsplit2(te,":",strip= str.strip) | |
| def colonsplitf(fn): return orsplit2(wfd(fn).r(),"\t:",strip= str.strip) | |
| ##def orsplit3(te,delimiter): | |
| ## "VzCommentCsv" | |
| ## t2=te.split(lf) | |
| ## l2list=[j.split(delimiter) for j in t2 if j[0]!="#"] | |
| ## return l2list | |
| def orsub(map0,te): | |
| pat=jw("|",map(lambda e:re.escape(e),map0)); | |
| ## pr(pat); | |
| irfinal=re.compile(pat) | |
| def f6(mo): | |
| mg= mo.group(0);#[0]; | |
| if (mg in map0): | |
| mg=map0[mg]; | |
| else: | |
| assert 0,("orsub"); | |
| return mg; | |
| t2=irfinal.sub(f6,te); | |
| return t2; | |
| def orsubne(map0,te):#NonEscape | |
| pat=jw("|",map0); | |
| ## pr(pat); | |
| irfinal=re.compile(pat) | |
| ## mapi={orsub({r"\[":"[",r"\]":"]",r"^":"","$":""},k):v for k,v in map0.items()} | |
| def f6(mo): | |
| mg= mo.group(0);#[0]; | |
| li=[v for k,v in map0.items() if re.match(k,mg)] | |
| if li:pass | |
| else: | |
| assert 0,("orsub") | |
| return mg; | |
| t2=irfinal.sub(f6,te); | |
| return t2; | |
| # | |
| def findall(ire,te,rebuild=0): | |
| ire=re.compile(*ire) if not isinstance(ire,re.Pattern) else ire | |
| ran=(0,0)#range | |
| while 1: | |
| mo=ire.search(te,ran[1]) | |
| if(mo): | |
| ## print(mo,mo.groups()) | |
| if rebuild: | |
| yield (ran[1],mo.span()[0]), 0 | |
| yield mo.span(), mo | |
| else: yield mo | |
| ran=mo.span() | |
| else:break | |
| if rebuild: yield (ran[1], len(te)), 0 | |
| #2regex | |
| ##prexit(findall(re.compile(r"(\d*) (?=<d>\d*)a"),"1 2a")) | |
| ##prexit(findall(re.compile(r"(\d)(?P<d2>2)?"),"123 1 12")) | |
| ##prexit(list(findall((r"('.+?')",),"1'2'3 '1' 12",rebuild=1))) | |
| def dif1(prefix,pat="#mrk1"): | |
| ir1=compilev(pat) | |
| mo=ir1.findall(rfdtu(sys.argv[0])) | |
| for n,v in enumerate(mo): | |
| write8("r:\\"+prefix+"%d%d"%(n,len(v))+".txt",v) | |
| def dif2(t1,t2): | |
| from difflib import HtmlDiff | |
| df = HtmlDiff() | |
| return df.make_file(t1,t2) | |
| def charjunk(c): | |
| return c==" \t" | |
| def dif3(t1,t2): | |
| import difflib as dif | |
| print=orro3(r"r:\tstDiff.txt") | |
| print("ndiff\n",lfjw(list(dif.ndiff(t1,t2)))) | |
| dcd=dif.Differ().compare(t1,t2) | |
| print("compare",list(dcd)) | |
| unif=list(dif.unified_diff(t1,t2)) | |
| print("unified",lfjw(unif)) | |
| #wel print("ndiff",list(dif.ndiff(t1,t2,charjunk=charjunk))) | |
| con=dif.context_diff(t1,t2) | |
| print("context",lfjw(con)) | |
| ir1=dif.SequenceMatcher(None,t1,t2) | |
| print("opcodes ",ir1.ratio(),list(ir1.get_opcodes())) | |
| return jw(lf,unif) | |
| # | |
| def dif3tst(): | |
| import difflib as dif | |
| t1="am..==d" | |
| t2="pm..i==" | |
| l1=list(t1); l2=list(t2) | |
| ir1=dif.SequenceMatcher(None,t1,t2) | |
| mo=ir1.get_matching_blocks() | |
| print(ir1.ratio())#equal==1.0 | |
| print(lf,t1,lf,t2,lf, list(mo)) | |
| print(list(ir1.get_opcodes())) | |
| sys.exit() | |
| def dif4(*T): | |
| import difflib as dif | |
| return lfjw(list(dif.unified_diff(*[t.splitlines() for t in T]))[2:]) | |
| def dif32(*T): return dif3(*[t.splitlines() for t in T]) | |
| def dif5(t1,t2, splitlines=str.splitlines): | |
| import difflib as dif | |
| f=(dif.SequenceMatcher(None,*[splitlines(t) for t in (t1,t2)])) | |
| return f.get_opcodes() | |
| def difri(T,splitlines=fpreturn): | |
| import difflib as dif | |
| return (dif.SequenceMatcher(None,*[splitlines(t) for t in T])) | |
| qfem=""" | |
| ; ;; | |
| : ;c | |
| \\ ;y | |
| / ;l | |
| " ;d | |
| ? ;q | |
| < ;k | |
| > ;r | |
| | ;s | |
| * ;a | |
| """# | |
| q_fileEscapeMap={k:v for k,v in [k.split(" ") for k in qfem.split(lf) if k]} | |
| ##q_fileEscapeMap={";":";;",":":";c","\\":";y","/":";l",'"':";d","?":";q"} | |
| def esfn(fn):#EscapeFileName;x/2 | |
| return orsub(q_fileEscapeMap,fn ); | |
| def exfn(fn):#extract | |
| return orsub(puni(q_fileEscapeMap).tenchi(),fn); | |
| time.perf_counter() | |
| ##def clock | |
| def orbench(p):#BenchMark(Proc)K@milisecond | |
| t = time.perf_counter() | |
| tsai = time.perf_counter() - t | |
| t = time.perf_counter() | |
| rn=p() | |
| t = time.perf_counter() -t -tsai; | |
| return t,rn; | |
| def cbbench(f): | |
| ## @functools.wraps(f) | |
| def cb(*a,**k): | |
| timeL=time.perf_counter() | |
| rn2=f(*a,**k) | |
| rn1=time.perf_counter()-timeL | |
| return rn1,rn2 | |
| return cb | |
| def timefor(cb,lis,to,start="start",logfile=""): | |
| def pr(te): return afdt(logfile or tfolder+"/log for time", te+lf) | |
| if start: pr(start) | |
| ti2pre=tia0=ti0=time.perf_counter() | |
| x9=len(lis) | |
| for x1,fn in enumerate(lis): | |
| et=cb(x1, fn, pr) | |
| ## if 1: | |
| ti2=time.perf_counter() | |
| eli=(ti2-ti0) | |
| x1p=x1+1 | |
| ti9=eli/(x1p) * x9 | |
| mean=eli/(x1p) | |
| one=ti2 - ti2pre | |
| ti2pre=ti2 | |
| remain=ti9-eli | |
| if (ti2-tia0) > to[0]: | |
| te=et+f"({one:.1f}), {x1p}/{x9} , {eli:.1f} / {ti9:.1f}, {remain=:.1f}" | |
| print(te) | |
| pr(te) | |
| tia0=ti2 | |
| if to[1] and eli > to[1]:return | |
| if et=="return": return et | |
| #--------- | |
| def rnz(te,li,opt=re.S|re.I): | |
| for s,d in li:#src dist; | |
| ## pr(s,"__",d); | |
| ir=re.compile(s,opt);#DOTALL|IGNORE ##|re.X=VERBOSE | |
| te=ir.sub(d,te); | |
| return te | |
| def sas(reg,te,bug=False,**ww): | |
| teli=[te] | |
| #reg=([(re.compile(f[0]),f[1]) for f in f2] for f2 in reg) | |
| reg=([re.compile(f,re.S) for f in f2] for f2 in reg) | |
| for ix,(ri,rx) in enumerate(reg): | |
| li2=[] | |
| for ta in teli: | |
| #li2.extend([f for f in ri[0].sub(lambda e:ri[0].sub(ri[1],e), ta) if f]) | |
| li2.extend([f for f in ri.findall(ta) if f]) | |
| teli=li2 | |
| if bug: afdt(r"r:\fwfw-search.txt","mrk{}\n".format(ix)+ppf(teli)) | |
| return teli | |
| def traverse(reg,te,bug=False,**ww): | |
| fn=reg; #fn.teli=[te] | |
| def fp1(fn,pare,F,after): | |
| if after:return | |
| fn.teli=[] | |
| for ta in pare.teli if pare else [te]: | |
| rin,rx1,rx2=fn.pat | |
| li=compilex(rin).findall(ta) | |
| for t1 in li: | |
| for rex in rx1: | |
| if rex.search(t1):continue | |
| fn.teli.append(t1) | |
| from mlwebOrWeb import webrap | |
| ## print(fn, f"{fn.flget=}") | |
| if fn.flget: #fn.teli=[ webrap().gtoff(f,"utf-8") for f in fn.teli] | |
| li=[] | |
| for n1,f in enumerate(fn.teli): | |
| print(f"download {n1+1} / {len(fn.teli)}") | |
| li.append(webrap().gtoff(f,"utf-8")) | |
| fn.teli=li | |
| def mimi(fn):return fn.mimi | |
| lamrec(fp1,fn, mimi,F=0,pare=None) | |
| return | |
| if 0: | |
| ##class reg(re): | |
| def compile(me,*w): | |
| try: | |
| return re.compile(*w) | |
| except re.error as e:e | |
| def sub(me,*w): | |
| try: | |
| return me.sub(*w) | |
| except re.error as e: | |
| e | |
| compilev=lambda e:re.compile(e,re.S|re.I|re.X|re.M) | |
| compilevs=lambda e:re.compile(e.replace(" ","\\s*"),re.S|re.I) | |
| compilex=lambda e:re.compile(e.replace(" ","\\s*"),re.S|re.I|re.X) | |
| compiled=lambda e:re.compile(e,re.S|re.I) | |
| compilefn=lambda e:re.compile(e,re.I) | |
| irealpha=re.compile(r"[_\.a-zA-Z0-9]") | |
| def adcompile(fp): | |
| if isinstance(fp,str): return compilevs(fp).search | |
| if isinstance(fp,re.Pattern): return fp.search | |
| return fp | |
| # #----------- | |
| def tae(p):#TryAndError例外で終了させずに表示する | |
| try: | |
| p() | |
| except Exception as e: | |
| orro4(e,lf,e.args,lf,type(e)); | |
| return(e) | |
| def t1t(p): return ttt(p,times=1) | |
| def ttt(p,times=10,interval=4):# try ten times | |
| for n in range(times): | |
| try: | |
| return p() | |
| except Exception as e: | |
| if n+1 >= times: return e | |
| time.sleep(interval) | |
| continue | |
| import th | |
| cbTryLock=th.Lock() | |
| def cbTry(f,ercb=None,lo=0,ww=(),pr=0): | |
| ## flq=1 if hasattr(f, "__self__") and isinstance(f.__self__, orq) else 0 | |
| ## la=lambda e: a[1:] | |
| counter=0 | |
| def cb(*a,**k): | |
| try: | |
| #return f(**k) if a[flq:] is (False,) else f(*a,**k) | |
| ## print("cb;", a,f,cb) | |
| #return f(**k) if not a[flq:] or a[flq] is False else f(*a,**k) | |
| if ww: | |
| wwa=ww[0] | |
| www=ww[1] if ww[1:] else {} | |
| if lo==1:lg("cb", f.__qualname__, a,k,ww) | |
| return f(*wwa,**k,**www) if not a or a[0] is False else f(*wwa, *a,**k,**www)#pass | |
| if lo==1:lg("cb", f.__qualname__, a,k) | |
| return f(**k) if not a or a[0] is False else f(*a,**k) #pass | |
| ##except: except2(0,find="p",edit="npp") | |
| except Exception as e: # exit is not exception | |
| #except: | |
| et=0 | |
| cb.counter+=1 | |
| if cb.counter>10:return | |
| if ercb: et=cbTry(ercb)(e) | |
| if et:return | |
| if pr: print(except2(0,find="")) | |
| else: | |
| ## with cbTryLock:#? | |
| except2(0,find="p",edit="note") | |
| ## e2=except2() | |
| ## Mini(te) | |
| cb.counter-=1 | |
| cb.counter=0 | |
| return cb | |
| def edipt(te="",find="p",edit=0,fntbl=()): | |
| if edit:return edipt_edit(te,find,edit,fntbl) | |
| e2=te or traceback.format_exc() | |
| e2=e2.replace("Traceback (most recent call last):","-"*9) | |
| if find: | |
| if find=="p": | |
| ## mo=compiled((r'(?<= File ")(.*?)", line (\d+), in (.+?)\n(.*?)')).findall(e2) | |
| mo=compiled((r'(?<= File ")([^\n]+?)", line (\d+)(?:, in )?([^\n]*?)\n((?! File).*?(?=\n))?')).findall(e2) | |
| mo=[[fppmobile(f) for f in f2] for f2 in mo if not any(((compilex(r"/python|\\Python\\|importlib").search(f2[0])), ("#pass" in f2[-1]) )) ] | |
| return (fppmobile(omiterror(e2)),mo) | |
| if find=="node": | |
| mo=compiled(r'at ([\w\.]* )?\(?(C:.*?):(\d+):(\d+)').findall(e2) | |
| mo=[[fppmobile(f) for f in f2] for f2 in mo if not any(((compilex(r"/python|\\Python\\|importlib").search(f2[0])), ("//pass" in f2[-1]) )) ] | |
| mo=[[w[f] for f in (1,2,0,3)] for w in mo] | |
| return (fppmobile(omiterror(e2)),mo) | |
| if 0: | |
| mo=re.findall(r'"<string>", line (\d+)(), in <module>\n(.*)',e2) | |
| return mo | |
| return fppmobile(omiterror(e2)) | |
| except2=edipt | |
| def edipt_edit(te,find,edit=0,fntbl=()): | |
| e2=edipt(te,find=find) | |
| t1=e2[0].splitlines().pop() | |
| if "dialog rejected;" in t1: return | |
| if "SystemExit" in t1: return | |
| from qNote1 import iniap, Mini, clhk | |
| from dialog_ import orDialog | |
| app=iniap() | |
| mono=orDialog() | |
| if not e2[1]: return Mini(e2) | |
| if find=="p": | |
| mo=[clhk(f, teh=(f"({cfile(f[0])}), {f[1]}, {f[2]}, \n{f[3]}")) for f in e2[1]] | |
| if find=="node": | |
| mo=[clhk(f, teh=(f"({cfile(f[0])}), {f[1]}, {f[2]}")) for f in e2[1]] | |
| if (mf:=re.search("AssertionError: (.*)", e2[0])): mo=[clhk("*", teh=mf.group(1))]+mo | |
| whw=[mo+[e2[0]]] | |
| mono.xch(whw) | |
| if not mono.fiFiles:return | |
| fn,*_=mono.pickupli() | |
| if type(fn)==str:return e2 | |
| (fn,pos,mod,te)=fn | |
| if fn in fntbl: fn=fntbl[fn] | |
| ## print(fn,fntbl) | |
| #npp(fn,f"-n{pos}") | |
| orPOA([HeartNote, fn, "-pos",pos,"0"]) | |
| return e2 | |
| def omiterror(e2): | |
| return rnz(e2,( | |
| ("NameError: name",""), | |
| )) | |
| def mpvstring(e2): | |
| #t1=e2.splitlines().pop() | |
| e2=re.sub(r'Traceback .+?\n','',e2) | |
| e2=re.sub(r' File "C:\\cpy\\qt\\(?:clas\\)?(.+?)(?:\.pyw?)", line (\d+),',r'"\1",\2',e2) | |
| if "mpv property does not exist" in te: | |
| if(mo:=re.search(r"'(mpv property does not exist)',.*?b('.*?'),",te)): te=str(mo.groups()) | |
| else: te="mpv not exist" | |
| ## te=rnz(te,( | |
| ## (r"'(mpv property does not exist)',.*?b('.*?'),",r"\1 \2"), | |
| ## (r"\d+",""), | |
| ## )) | |
| def orpopen(mp3): | |
| import subprocess as p | |
| return p.Popen([mp3],shell=True); | |
| def orPOA(cmd,shell=True): | |
| import subprocess as p | |
| return p.Popen(cmd,shell=shell); | |
| def popen1(cmd,shell=True): | |
| import subprocess as p | |
| return p.Popen(cmd,shell=shell).wait() | |
| ##orPOA(r'start cmd /c "r:\c f.bat"') | |
| def wiff(w): | |
| orPOA([mdir("wiff"),*w]) | |
| def npp(*w): | |
| if not w: return mdir("npp") | |
| orPOA([mdir("npp"),*w]) | |
| def nppw(lis,fn=tfolder+"/log"): | |
| wfd(fn).t(lis) | |
| npp(fn) | |
| class puni(dict): | |
| ## def update(zl,k,v): dict.update(zl,[(k,v)]) | |
| def ez(zl,k):#di.get() | |
| return zl[k] if(k in zl) else 0; | |
| def ud(zl,k,v): | |
| zl.update([(k,v)]); | |
| def up(zl,k,L):#update append | |
| if(k in zl): | |
| zl[k].append(L); | |
| else: | |
| zl.update([(k,[L])]); | |
| def uni(zl,k,L):#update append uni | |
| if(k in zl and L not in zl[k]): | |
| zl[k].append(L); | |
| else: | |
| zl.update([(k,[L])]); | |
| def setclr(zl,li,la): | |
| for nc,f in enumerate(li): | |
| k=la(f) | |
| zl.up(k,f) | |
| return zl | |
| def updateIncliment(zl,k): | |
| zl.ul(k,1) | |
| def ul(zl,k,L):#update vz Length | |
| if(k in zl): | |
| zl[k]+=L; | |
| else: | |
| zl[k]=L | |
| def us(zl,k):#文字ごとの生起確率 | |
| for c in k: | |
| zl.ui(c); | |
| return zl; | |
| ## def counter(zl,w): | |
| def Clip(zl,count,regexpattern="."): | |
| "Clip key less than count" | |
| ire=re.compile(regexpattern) | |
| return puni([(k,v) for k,v in zl.items() if(v>count)and(ire.match(k))]) | |
| def LetterFrequency(zl,te,llen=2): | |
| for k in range(len(te)-llen+1): | |
| zl.ui(te[k:k+llen]) | |
| return zl; | |
| def sortedlist(zl):#oredered list by value; | |
| return [[k,v] for k, v in sorted(zl.items(), key=lambda x:x[1])] | |
| def ok(zl):#oredered list by key; | |
| return [[k,v] for k, v in sorted(zl.items(), key=lambda x:x[0])] | |
| def ovk(zl,valuekey):#sort by appended list | |
| pass | |
| def tenchi(zl): | |
| li={v:k for k,v in zl.items()} | |
| ## li=map(lambda x: x,li); | |
| return li; | |
| d=puni() | |
| for k,v in zl.items(): | |
| d[v]=k; | |
| return d;#X/2 | |
| def rms(zl,la): | |
| pops={k:v for k,v in zl.items() if la(k,v)} | |
| _=[zl.pop(k) for k in pops] | |
| return zl,pops | |
| #listDict | |
| def lipop(zl,k,cb): | |
| for k,v in zl.items(): | |
| for n,v1 in enumerate(v): | |
| if(cb(v1)):return k,n | |
| def lipop1(zl,f,te): | |
| #{f,[[open,],[file,],[copy,],]};findcopy():lipop(f,"copy") | |
| return zl.lipop(f,lambda e: e[0]==te) | |
| ## def compres(zl,w0,fp=fpreturn,uni=0): | |
| ## for f in w0: | |
| ## zl.compresin(f,fp) | |
| ## return zl | |
| def compres(zl,f,fp=fpreturn,uni=0,te=""):#配列の長さは同じにする | |
| z2=zl | |
| if 1: | |
| z2=zl | |
| for w in f[:-1]: | |
| w=fp(w) | |
| if w not in z2: z2[w]=puni() | |
| z2=z2[w] | |
| assert isinstance(z2,puni), "not list len"#,f | |
| if te: | |
| assert f[-1] not in z2, "not list len. 123 12"#,f | |
| z2[f[-1]]=te | |
| else: | |
| z2.ul(f[-1],1) | |
| return z2[f[-1]] | |
| def flat(zl): | |
| li=[((x,),v) for x,v in zl.items()] | |
| for p,v in li: | |
| if isinstance(v,puni): | |
| li.extend(((*p,p2),v2) for p2,v2 in v.items()) | |
| else: | |
| yield (*p,v) | |
| class pini(puni): | |
| def __init__(zl,d={},fn="pini00.ini"): | |
| dict.__init__(zl,d); | |
| zl.fn=lfn.abspath(fn); | |
| if lfn.isfile(fn): | |
| f=rfdv0(fn,["utf-8"]) | |
| for j in f: | |
| a=j.split("\t"); | |
| ## try: | |
| ## nm=float(a[1]) | |
| ## except: | |
| ## pass; | |
| if(len(a)== 2): | |
| ## exete='zl["%s"]=' % a[0]#.replace("\\","\\\\"); | |
| exete='zl[%s]=' % a[0]#.replace("\\","\\\\"); | |
| et2= exete+a[1]; | |
| exec(et2); | |
| else: | |
| notTheFormat | |
| def save(zl): | |
| te=""; | |
| #print(os.getcwd()) | |
| for f,v in fpn1(zl): | |
| ti= repr(f) +"\t" +repr(v)+"\n"; | |
| te+=ti; | |
| wfd8(zl.fn,te);#Exceptions during cleanup are always ignored; see the object.__del__() documentation: | |
| # | |
| def ordiMdirs():# Dictionary of Directory | |
| global diMdirs | |
| diMdirs=globals().get("diMdirs") or dict([j.split("\t")[:2] for j in wfd(os.environ["cpa"]+r"\data\dirs-{}.txt".format(T45)).r(lines=True) if j[:2]]) | |
| return diMdirs | |
| def mdir(f): return ordiMdirs()[f] | |
| class _: | |
| def __init__(zl,fn,unquote=1): | |
| zl.fn=fn | |
| zl.unquote=unquote | |
| w="" | |
| def split(zl): | |
| zl.w={f:(v[0]) for f,*v in orsplit(wfd(zl.fn).r(),"\t") if v} | |
| def __call__(zl,at): | |
| if not zl.w: zl.split() | |
| return zl.w[at] | |
| def __getattr__(zl,at): | |
| return zl(at) | |
| if cpa: mdir=_(os.environ["cpa"]+r"\data\dirs-{}.txt".format(T45)) | |
| class _(_): | |
| def split(zl): | |
| from urllib.parse import unquote | |
| if not zl.unquote: unquote=fpreturn | |
| zl.w={f:unquote(v[-1]) for f,*v in orsplit2(wfd(zl.fn).r(),"\t")} | |
| abenatsumi=_(lfn.abspath(__file__+"/../"+"abenatsumi.txt")) | |
| # | |
| def fFlat(li,lirn): | |
| if(type(li)==list): | |
| for j in li: | |
| L1=fFlat(j,lirn) | |
| else: | |
| L1=li | |
| lirn.append(L1) | |
| return lirn | |
| class List(list): | |
| def rx(zl,te): | |
| ir1=re.compile(te) | |
| zl.res=[] | |
| for i,j in enumerate(zl): | |
| mo=ir1.search(j) | |
| if mo: | |
| zl.res.append(j) | |
| return zl.res | |
| def rxenu(zl,te): | |
| ir1=re.compile(te) | |
| zl.res=[] | |
| for i,j in enumerate(zl): | |
| mo=ir1.search(j) | |
| if mo: | |
| zl.res.append((i,j)) | |
| return zl.res | |
| def __lt__(zl,f): return zl.append(f) | |
| def __lshift__(zl,li): return zl.extend(li) | |
| #def __getitem__(zl,f): | |
| def getx(zl,f,v): | |
| return zl.index(f) if f in zl else v | |
| def u(zl,f,v): | |
| zl[zl.index(f)]=v | |
| ## def up(zl,v): | |
| orList=List | |
| class ListHash(List):#from collections import OrderedDict | |
| def put(zl,k,v):#up | |
| 1 | |
| class orLiset(set):#unique list | |
| pass | |
| def cmp(zl,ot): | |
| zl.cmp[x](zl[y],ot) | |
| ## if(role=="cmp"):split(sel) | |
| def get(zl,x,y,role="edit"): | |
| return zl[y][x] | |
| class LastOperation(List): | |
| def __init__(zl,li=(),threshold=30,wriIni=False,k="",uniq=True): | |
| zl.threshold=threshold | |
| zl.see=-1 | |
| zl.uniq=uniq | |
| if(wriIni):#dict.setdefault() | |
| if(k in wriIni): | |
| li=wriIni[k] | |
| list.__init__(zl,li) | |
| wriIni[k]=zl | |
| else: | |
| list.__init__(zl,li) | |
| def rm(zl,te): | |
| if zl.uniq and (te in zl): | |
| zl.pop(zl.index(te)) | |
| def ap(zl,te): | |
| if zl.uniq and (te in zl): | |
| zl._ap(zl.pop(zl.index(te))) | |
| else: | |
| if(len(zl)>=zl.threshold):zl.pop() | |
| zl._ap(te) | |
| zl.see=0 | |
| def aprx(zl,te):#Word completion | |
| if zl.uniq and (zl.get(te)): | |
| zl._ap(zl.pop(zl.res[0][0])) | |
| else: | |
| if(len(zl)>=zl.threshold):zl.pop() | |
| zl._ap(te) | |
| zl.see=0 | |
| ## def _ap(zl,element): | |
| ## zl.insert(0,element) | |
| _ap=lambda zl,x:zl.insert(0,x) | |
| def get(zl,te): | |
| r=zl.rxenu(te) | |
| return r[0] | |
| def up(zl): | |
| if(len(zl)-1>zl.see): | |
| zl.see+=1 | |
| return zl[zl.see] | |
| def down(zl): | |
| if(zl.see>0): | |
| zl.see-=1 | |
| return zl[zl.see] | |
| clHistry=LastOperation | |
| ##class cycle(): | |
| class orLog(LastOperation): | |
| def __call__(zl,*w): | |
| if(len(zl)>=zl.threshold):zl.pop(0) | |
| zl.append((w[0],w[1:])) | |
| return zl | |
| def __repr__(zl): | |
| if not zl: return "[]" | |
| rn=[f[1] for f in zl.find(zl[-1][0])]#findByLastKey | |
| return str(rn) | |
| def find(zl,pat): | |
| ir1=re.compile(str(pat)) | |
| rn= [f for f in zl if ir1.search(str(f[0]))] | |
| return rn | |
| imorLog=orLog(threshold=32100) | |
| ##logi=lambda *x:imorLog.ap(x[0],x[1:]) | |
| lg=logi=imorLog | |
| lgf=logifind=lambda x="":imorLog.find(x) | |
| lgfv=lgf2=lambda x="":[f[1] for f in imorLog.find(x)]# value | |
| lglf=lambda x:jw(lf,[jw(" ",[str(f) for f in l]) for l in lgfv(x)]) | |
| ##jw(lf,[l for l in lgfv(x)]) | |
| lgc=lambda: imorLog.clear() | |
| def msri(proc,lp):#mashiroInner | |
| fil = sys.argv | |
| if(len(fil) == 1): | |
| pr("please drop off the file");input();exit() | |
| for fi in fil[1:]: | |
| proc(fi,lp); | |
| mashiro=msri; | |
| gif=r"(jpg|jpeg|png|gif|tiff|jfif|webp)$" | |
| ignoreFiles=(r"R:\TEMP",r"R:\Clip1.txt.txt",r"R:\OnClipChange1.txt",r"R:\Recycled",r'R:\System Volume Information') | |
| def listdir(r=None,iref="",walk=False,flat=False,isdir=False): | |
| "f in listdir() if not(f in ignoreFiles)" | |
| assert ifexist(r or "."),r | |
| if type(iref)==str:iref=re.compile(iref,re.I).search | |
| li=[(jwdir(r,f) if flat else f) for f in (os.listdir(r) if not walk else walky(r)) if ((os.path.abspath(jofn(r or "",f)) not in ignoreFiles) and (iref(f)))] | |
| if isdir: li=[f for f in li if isdir(jwdir(r,f) if r else f)] | |
| return li | |
| def walky(r): | |
| for p, ds ,fs in os.walk(r): | |
| for fn in ds+fs: | |
| yield jofn(p,fn) | |
| def unfoldfiles(ars,ap=False): | |
| for fn in ars: | |
| if os.path.isfile(fn): | |
| fn | |
| else: | |
| lifn=walky(fn) | |
| for fn in lifn: | |
| fn | |
| def orWalk(d,proc,lp):#CallBackWalk | |
| waw = os.walk(ddf[0]) | |
| for r, ds ,fs in waw: | |
| mod=ddf[2].search(r) | |
| if mod :#除外子孫のフォルダをさらに(被除外リスト)出力からも除外 | |
| lidex.append(r); | |
| else: | |
| ldir=[] | |
| for fc in fs: | |
| ldir.append(fc) | |
| orcb(ldir,r,ddf) | |
| def rnWalk(d,inc,exc): | |
| irInc=[re.compile(f,re.I) for f in inc] | |
| irExc=[re.compile(f,re.I) for f in exc] | |
| lii=[] | |
| for r, ds ,fs in os.walk(d): | |
| dsfs=ds+fs | |
| for fn in dsfs: | |
| for ire in irInc: | |
| mod=ire.search(fn) | |
| if mod : | |
| lii.append((r,fn)); | |
| break | |
| for k,(r,fn) in enumerate(lii): | |
| for ire in irExc: | |
| mod=ire.search(fn) | |
| if mod : | |
| lii.pop(k); | |
| break | |
| return lii | |
| def ywalk(dn=None,dr=0,pop=-1): | |
| ds=[dn or os.getcwd()] | |
| while 1: | |
| cd=ds.pop(pop) | |
| ag=os.listdir(cd) | |
| if dr: ag=ag[::dr] | |
| for f in ag: yield cd,ag,jofn(cd,f) | |
| else:# not break return | |
| ds+=[fp for f in ag if os.path.isdir(fp:=jofn(cd,f))] | |
| if not ds : break | |
| continue | |
| break | |
| while 0: | |
| sn=hhww(dn=listdir(r"c:\v\t",iref=isdir)[0]) | |
| dnd=os.path.dirname(sn.dn) | |
| if(dnd in [r"c:\v"]): break | |
| for cd,fs,fp in ywalk(dnd): | |
| pass | |
| li=(list(listdir(dnd,iref=isdir))) | |
| ix=li.index(os.path.basename(sn.dn)) | |
| ##prexit([f for f in ywalk(r"c:\v\t")]) | |
| def nxDir(fn,ceil,fs=0,dr=1): | |
| for n in range(9): | |
| dn=lfnd(fn) | |
| if dn in ceil: | |
| return | |
| fs=listdir(dn,flat=1) | |
| if fn == fs[-dr]:# -1 | 0 # last sister | |
| fn=dn | |
| else: | |
| if not dr: fs.reverse() | |
| for nxf in fs[fs.index(fn)+1:]: | |
| fn=jofn(dn, fs[fs.index(fn)+1]) | |
| if os.path.isfile(fn): | |
| yield fn | |
| else: | |
| for cd, ag, fnw in ywalk(fn,dr=0 if dr else -1): | |
| yield fnw | |
| def nxfortst(*a): | |
| for n,f in enumerate(nxDir(*a,dr=1)): | |
| print(n,f) | |
| ##prexit("nxfor:",nxfortst(r"C:\v\T\eva7\cover\..jpeg",(r"C:\v",))) | |
| def merge(li,fl="f"): | |
| l4=orList() | |
| for f1,f2 in li: | |
| if not f1.endswith("\\"): f1+="\\" | |
| li1=[f[len(f1):] for f in listdir(f1,walk=1)][::-1] | |
| for fe in li1: | |
| src=jofn(f1,fe) | |
| dst=jofn(f2,fe) | |
| assert dst.startswith(f2),(f1,f2,fe,dst) | |
| inidi(lfnd(dst)) | |
| if isdir(src): | |
| inidi(dst) | |
| else: | |
| copy=1 | |
| if ifexist(dst): | |
| copy=0 | |
| if "f" in fl:# force, modi | |
| copy=1 | |
| elif "m" in fl and (mtime(src)-mtime(dst) > 1): | |
| copy=1 | |
| if copy: | |
| l4<(fe) | |
| shutil.copy2(src, dst) | |
| return l4 | |
| #prexit(merge([[r"C:\v\T\lvlv",r"r:\hono"]],"m")) | |
| def listDrive(ignore="ABD"): | |
| return [L for L in (chr(c) for c in range(65,90+1)) if os.path.exists(L+':') and (L)not in ignore] | |
| def getFolderSize(folder): | |
| total_size = 0 #os.path.getsize(folder)#4096 | |
| for item in os.listdir(folder): | |
| itempath = jofn(folder, item) | |
| if os.path.isfile(itempath): | |
| total_size += os.path.getsize(itempath) | |
| elif os.path.isdir(itempath): | |
| total_size += getFolderSize(itempath) | |
| return total_size | |
| def lamrec(fp1,fn, fpEnum,F=0,pare=None): | |
| fp1(fn,pare,F,0) | |
| #print(" "*F, fn) | |
| for f2 in fpEnum(fn): | |
| lamrec(fp1,f2, fpEnum,F+1,fn) | |
| fp1(fn,pare,F,1) | |
| def abSize(size,M="",_1024=1024):# 1234 > 1,234 | |
| # return f"{size:,}" | |
| li=[];mb="" | |
| for heavy in "KMGTE": | |
| m= size % _1024 | |
| size= size // _1024 | |
| li.append(m) | |
| if(heavy==M): | |
| li=[] | |
| mb=M | |
| if(size):mb | |
| else: break | |
| return jw(",",("{:03}".format(f) for f in li[::-1])).lstrip("0")+mb | |
| ##prexit(_:=(1,2026,3,4) ,abSize(sum([1024**n*f for n,f in enumerate(_[::-1])]),"K"))# | |
| def crbs(li): | |
| def binarySearchRec(goal,q0,q1,fpSave): | |
| mid = q0+(q1-q0)/2 | |
| if q0>q1: return | |
| size=fpSave(mid) | |
| if goal == size: | |
| return mid | |
| elif goal > size: | |
| return binarySearchRec(goal,mid+1,q1,fpSave) | |
| else: | |
| return binarySearchRec(goal,q0,mid-1,fpSave) | |
| return binarySearchRec | |
| def binarySearch(fpSave,goal,q0,q1,li): | |
| while q0<=q1: | |
| mid = int(q0+(q1-q0)/2) | |
| size=fpSave(mid) | |
| li.append((mid,size)) | |
| if(goal == size): | |
| return li#mid | |
| elif goal > size: | |
| q0 = mid + 1 | |
| else: | |
| q1 = mid - 1 | |
| if 0: | |
| mid = (q0+(q1-q0)/2) | |
| size=fpSave(mid) | |
| li.append((mid,size)) | |
| return li | |
| ##print(binarySearch(lambda e:e*100,501,0,20,[])) | |
| def mvvideo(src,vfl,suffix):#VideoFolder,拡張子 | |
| ire = re.compile(suffix,re.I) | |
| files = os.listdir(src) | |
| count=0 | |
| for f in files: | |
| mo= ire.match(f) | |
| if(mo): | |
| sfi= src+"\\"+f; | |
| vfi= vfl+"\\"+f; | |
| #print(vfi,sfi) | |
| os.rename(sfi,vfi) | |
| count+=1; | |
| return count; | |
| def mvdir(src,vfl,suffix):#VideoFolder,拡張子 | |
| ire = re.compile(suffix,re.I) | |
| files = os.walk(src) | |
| count=0 | |
| for r,ds,fs in files: | |
| for f in ds: | |
| mo= ire.match(f) | |
| if(mo): | |
| sfi= r+"\\"+f; | |
| vfi= vfl+"\\"+f; | |
| #print(vfi,sfi) | |
| try: | |
| os.rename(sfi,vfi) | |
| except a as XP: | |
| pass | |
| count+=1; | |
| return count; | |
| def copyTree(src,dist,pat): | |
| pass | |
| def nxnum(WorkDir,fn):#Create sequencial number filename 001~99999 | |
| 'r=nxnum(".","%sx.jpg")' | |
| pat=fn%r"(\d{1,3})" | |
| ire=re.compile(pat); | |
| xmax=0; | |
| for n in os.listdir(WorkDir): | |
| mo=ire.search(n); | |
| if mo: | |
| m1=mo.group(1) | |
| xi = int(m1) | |
| if(xmax < xi): | |
| xmax = xi | |
| xmax+=1 | |
| rr = str(xmax).zfill(3); | |
| rr=fn%rr; | |
| return rr; | |
| def nxnu2m(WorkDir,fn,nZfill=3): | |
| ire=re.compile(re.escape(fn)%r"(\d{1,})"); | |
| xmax=max([0]+[int(mo.group(1)) for mo in [ire.search(f) for f in os.listdir(WorkDir)] if mo]) | |
| rr = str(xmax+1).zfill(nZfill); | |
| rr=fn%rr; | |
| return rr; | |
| def nxNumFull(WorkDir,fn,nZfill=3):#return FullPath | |
| resFn=nxnu2m(WorkDir,fn,nZfill=nZfill) | |
| return jofn(WorkDir,resFn) | |
| def nxNumFullSplit(fn,nZfill=3):#FullPath | |
| resFn=nxnu2m(*os.path.split(fn),nZfill=nZfill) | |
| return jofn(os.path.split(fn)[0],resFn) | |
| # | |
| montail=(0,31,28,31,30,31,30 ,31,31,30,31,30,31) | |
| import csv | |
| class oc:#orcsv | |
| ordelimiter="\t" | |
| def wcsw(fn,li): | |
| for code in ("cp932","utf-16"): | |
| try: | |
| with open(fn, 'w',encoding=code) as fpw: | |
| writer = csv.writer(fpw, delimiter=oc.ordelimiter, lineterminator='\n') | |
| for f in li:# | |
| writer.writerow(f); | |
| break | |
| except UnicodeEncodeError as XP: | |
| continue; | |
| def writecs8(fn,li): | |
| return wcsv(fn,li,("cp932","utf-8")) | |
| def wcsv(fn,li,cs=("utf-8",)): | |
| for code in cs: | |
| try: | |
| with open(fn, 'w',encoding=code) as fpw: | |
| writer = csv.writer(fpw, delimiter=oc.ordelimiter, lineterminator='\n') | |
| for f in li:# | |
| writer.writerow(f); | |
| break | |
| except UnicodeEncodeError as XP: | |
| continue; | |
| def acsw(fn,li,code="cp932"): | |
| with open(fn, 'a',encoding=code) as fpw: | |
| writer = csv.writer(fpw, delimiter=oc.ordelimiter, lineterminator='\n') | |
| for f in li:# | |
| writer.writerow(f); | |
| def acswvp84n534983v(fn,li): | |
| for code in ("cp932","utf-16"):#No good | |
| try: | |
| with open(fn, 'a',encoding=code) as fpw: | |
| writer = csv.writer(fpw, delimiter=oc.ordelimiter, lineterminator='\n') | |
| for f in li:# | |
| writer.writerow(f); | |
| break | |
| except UnicodeEncodeError as XP: | |
| continue; | |
| def rcsr(fn): | |
| for code in ("utf-8",):#("cp932","utf-8","utf-8"): | |
| try: | |
| lines =[]; | |
| with open(fn, 'r',encoding=code, newline='') as fpr: | |
| reader = csv.reader(fpr, delimiter=oc.ordelimiter, lineterminator='\n') | |
| for line in reader: | |
| ## print(line) | |
| lines.append(line); | |
| return lines; | |
| except UnicodeDecodeError as XP: | |
| continue; | |
| #list(csv.reader(['"-f" 2 9'],delimiter=" ")) | |
| ##X/ | |
| def zelp0(lio,fi,irz0=re.compile(r"h/",re.I),irs=0,irx=()): | |
| "oList, fn, ir, List" | |
| tel=rfdlv(fi) | |
| for k,f in enumerate(tel): | |
| mo=irz0.search(f); | |
| if mo and not (irx and any(x.search(f) for x in irx)): | |
| if(irs): | |
| f=rnz(f,irs) | |
| lio.append((k,f)) | |
| return lio | |
| def orgrepir(li,fi,ir1): | |
| tel=rfdlv(fi) | |
| for k,f in enumerate(tel): | |
| mo=irz0.search(f); | |
| if mo: | |
| lio.append((k,f)) | |
| return lio | |
| def orgrep(li,fi,pat): | |
| ir1=re.compile(pat); | |
| li=orgrepir(li,fi,ir1); | |
| return lio; | |
| def orgrepdir(currentdir,pat): | |
| filelist=os.listdir(currentdir) | |
| matchlist=[orgrep(f) for f in filelist] | |
| return matchlist; | |
| if 1:#time | |
| #time.strptime("1970,1,1, ","%Y,%m,%d, ") | |
| #time.mktime(time.strptime("1976,2,29, 9,3,4.56","%Y,%m,%d, %H,%M,%S.%f")) | |
| #time.gmtime(232.324) | |
| #time.strftime("%Y") | |
| #time.time();time.mktime(time.localtime()) | |
| def timea(te): | |
| time.mktime((1970,1,1, 9,10,10, 3,1,0)) | |
| time.mktime((1970,2,31, 25,66,66, 1,1,1)) | |
| return | |
| def hourmin(te): return te.replace("hour","H").replace("min","M").replace("second","S") | |
| letters='abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY' | |
| def letter_digit(te,ln=2,zfill=0): | |
| for c in te:1 | |
| def i2l(d,letters=letters): | |
| li2=[] | |
| while d: | |
| d,e=divmod(d,len(letters)) | |
| li2.append(letters[e]) | |
| return jw("",li2[::-1]) or letters[0] | |
| # | |
| #graph | |
| def fncore(fn,exist=False,cc=1,fldn=0): | |
| fn=fn.replace("\\","/") | |
| fnli=fn.split("/")#.__iter__() | |
| for nc,f in enumerate(fnli): | |
| if f not in ("Downloads","downfile","freerapid") and (len(f) >= 8 or f.endswith("-") or len(f) != len(f.encode("mbcs"))) and not(f.endswith("@")): | |
| if fldn: return jw("/",fnli[:nc+1]) | |
| fn=jw("/",fnli[nc:]) | |
| break | |
| pat=[("#.*?#",""),(r"[:_/]"," "),(r"\bv?(\d+)[sbw]?[e]?",r"\1"),(r" z(\d+)","")] | |
| ## pat+=[("\(.*?\)","")]#(1) | |
| if not exist: fn=rnz(fn,pat).strip() | |
| if cc==1:fn=fn.lower() | |
| if cc==2:pass # camel case | |
| return fn | |
| def fncx(fn): return fncore(fn,True) | |
| def findzv(fn): | |
| dir,fn=lfn.split(fn) | |
| if not dir:dir=os.getcwd() | |
| for f in range(9): | |
| #zl+[dir,fn] | |
| with pushd(dir): | |
| if ifexist(fn): return lfn.abspath(fn).replace("\\","/") | |
| if not lfnb(dir): return | |
| dir,_=lfn.split(dir) | |
| class clfn: | |
| def __init__(sl,**kw): | |
| sl.__dict__.update(kw) | |
| def __call__(sl,fn,dirs=()): | |
| for dn in dirs or sl.dirs: | |
| if lfn.exists(f2:=(dn+"/"+fn)): | |
| return f2 | |
| if cpa: | |
| pmfolder=(#r"c:\v\jext", | |
| r"C:\Users\user\Downloads\dval\n2", | |
| #r"C:\Users\user\Downloads\dval\t1", | |
| r"C:\Users\user\Downloads\dval\t2", | |
| r"C:\Users\user\Downloads\dval\t5", | |
| r"C:\Users\user\Downloads\dval\t9", | |
| )+tuple(jofn(r"c:\v\zv",f) for f in os.listdir(r"c:\v\zv")) | |
| xcore=clfn(dirs=pmfolder) | |
| # | |
| def _gettps(fnzv,dncore): | |
| fnzv= fnzv or jofn(mdir("mtm"),"data","zv.txt") | |
| itemdict=eval(wfd(fnzv).r()) | |
| tps=itemdict.setdefault(dncore,dict()) | |
| return tps | |
| def gettps(fnzv,dncore=None): | |
| fnzv=jofn(*[fnzv] if fnzv else (mdir("mtm"),"data","zv"),dncore) | |
| if ifexist(fnzv): | |
| tps=puni(eval(wfd(fnzv).r())) | |
| else:tps=puni() | |
| tps.fn=fnzv | |
| return tps | |
| # | |
| ##class hhwwproto(dict):pass | |
| class hhwwproto(p310, dict): | |
| def __init__(zl,*aw,**kw): | |
| ## super | |
| for f in aw: zl.update(f) | |
| zl.update(kw) | |
| for f,v in kw.items(): | |
| if v==None: zl.pop(f) | |
| def str(zl,order=None, sp=" : ", lf=lf, ls=repr): | |
| return jw(lf,(key +sp+ ls(zl[key]) for key in order or zl if key in zl)) | |
| def __setattr__(zl,at,v): | |
| zl[at]=v | |
| def __mod__(zl,li):pass | |
| def __sub__(zl,li): return zl.__x(li) | |
| def __truediv__(zl,l): return zl.__x((l,)) | |
| def __x(zl,li):#exclude | |
| for f in li: | |
| zl.pop(f,0) | |
| return zl | |
| #def copy(): | |
| def hh(zl,li=None): | |
| zl.parser = ArgumentParser() | |
| zl.parser.add_argument("fil",nargs="*")#all other | |
| if li: zl+li | |
| return zl | |
| def __add__(zl,li): | |
| for f in li: | |
| f1,t=f[:2] | |
| lenli,default= f[2:] if(len(f)==4) else (None,None) | |
| if not isinstance(t,type): | |
| lenli=0 | |
| if isinstance(t, (tuple,list)): lenli=len(t) | |
| default=t | |
| t=type(t) | |
| if t==bool and "store true": zl.parser.add_argument(f1, action="store_true") | |
| else: | |
| zl.parser.add_argument(f1, type=t, nargs=lenli or None, default=default) | |
| return zl | |
| def ho(zl,te=None): | |
| w=zl.parser.parse_args(te and csv.reader([te.strip()],delimiter=" ").__next__()) | |
| zl.update(w.__dict__) | |
| zl.pop("parser")# need vn pickle | |
| return zl | |
| def __getattr__(zl,at): | |
| return zl[at] | |
| ## def __vars__(zl):wefw | |
| class hhww(hhwwproto): | |
| def __getattr__(zl,at): | |
| return zl.get(at) | |
| return None | |
| hhwwproto().str | |
| ##prexit((hhww(w=2,f=4) - ("w",)).str()) | |
| ##prexit((hhww(w=2,f=4,ff=4)/"w"/"f").str()) | |
| ##w=hhww();w.f=2;pr(w.f) | |
| ##print(hhww({"e":1},{"e":4})) | |
| ##print("vars;",vars(w)) | |
| ###print(hhww().hh([("-f",str),("-re",str),("-ns",str)]).ho()) | |
| ##print(dict(**hhww(w=2)), {"ww":2}) | |
| ##prexit(hhww(w=2)==hhww(w=3), hhww()==hhww()) | |
| cls=hhwwproto() | |
| cls.mp4="mp3|mp4|mkv|flv|ogg|webm" | |
| # | |
| def set2(sl,ob,value): | |
| for f in value.split(): ob.__dict__[f]=sl.__dict__.get(f) | |
| import json | |
| ##def pl(fn,tfn="",pl="p"): return jsonload(fn,tfn=tfn,pl=pl) | |
| ##def typejson(te): | |
| ## try: json.loads(te) | |
| def jsontext(li):return json.dumps(li) | |
| def jsonload(fn,tfn="",pl="json",flw=0,fltmp=1): | |
| if pl=="json": | |
| fp=(json.loads,json.dumps) | |
| elif pl=="p": | |
| import pickle | |
| fp=(pickle.loads, pickle.dumps) | |
| else:fp=() | |
| if not tfn: | |
| import hashlib | |
| te=hashlib.sha256(fn.encode()).hexdigest() | |
| tfn=jofn(tfolder,"wft;"+te) | |
| tfn=lfn.abspath(tfn) | |
| #print(tfn) | |
| if ifexist(tfn) and flw==0: | |
| if pl=="json": te=wfd(tfn).r() | |
| if pl=="p": te=wfd(tfn).rb() | |
| js=fp[0](te or "") | |
| else:js=hhww() | |
| def log(te=js): | |
| if fltmp:wfd(tfn).t(fp[1](te)) | |
| else: wfd(tfn).w(fp[1](te), copy=0) | |
| if flw!=0: log(flw) | |
| table=hhww(t=js,l=len(js),fn=fn,tfn=tfn,log=log) | |
| return table, js, tfn, log | |
| def wfupdate(fn,pat,count,te=""): | |
| if fn: | |
| imw=wfd(fn) | |
| te=imw.r() | |
| if callable(pat):te=pat(te) | |
| else: te=rnz(te,pat) | |
| cs=[te.count(f) for f,c in count] | |
| assert not any(c!=co for (f,c),co in zip(count,cs)),cs | |
| if fn: | |
| imw.w(te,copy=0) | |
| return te | |
| if 1: | |
| def pmobile(*w,**W): | |
| pmobilelib=impt((os.environ["cpy"]+f"/escape/nagano/e3escapeMtm"),reload=0); | |
| return pmobilelib.pmobile(*w,**W) | |
| def fppmobile(*w,**W): | |
| pmobilelib=impt((os.environ["cpy"]+f"/escape/nagano/e3escapeMtm"),reload=0); | |
| p=membile(pmobilelib.pmobile)(2,presort=1) | |
| return p(*w,**W) | |
| def note(): | |
| return impt(os.environ["cpy"]+r"/qt/lib"+"/qNote1", reload=0) | |
| global_app=iniap() | |
| return "note+" | |
| def x4(): | |
| return impt(cpy+"/Generator/x4orlexi") | |
| def xfil(ap,flinput=1): | |
| hh=hhww().hh(ap).ho() | |
| fl=hh.fil | |
| if hh.fil:fl= hh.fil | |
| elif flinput: | |
| fl=input("w copy:") | |
| if fl: | |
| if fl[0]==";": fl=hh.ho(fl) | |
| else: fl=fl.split() | |
| #else:fl=[] | |
| return hh,fl | |
| hhfl=xfil | |
| ##def genefp(li): | |
| ## def fp1(fn,pare,F,after):l | |
| ## def fpEnum(fn): | |
| ## lamrec(fp1,li,fpEnum) | |
| import importlib; from importlib import import_module | |
| find_spec=getattr(importlib,b'\x75\x74\x69\x6C'.decode()).find_spec | |
| module_from_spec=getattr(importlib,b'\x75\x74\x69\x6C'.decode()).module_from_spec | |
| importtool=getattr(importlib,b'\x75\x74\x69\x6C'.decode()) | |
| def impt1(fn,reload=True, lazy=False, **_): | |
| dir,fir=lfn.split(fn) | |
| sys.path.append(os.path.abspath(dir)) | |
| cf=cfile(fn) | |
| if cf in sys.modules: | |
| mod=sys.modules[cf] | |
| if reload: importlib.reload(mod)# orText() not found | |
| else: | |
| mod=import_module(cf)#pass | |
| if dir: sys.path.pop() | |
| return mod | |
| def impt(fn,reload=True, lazy=False, **_): | |
| dir,fir=lfn.split(fn) | |
| #sys.path.append(os.path.abspath(dir)) | |
| cf=cfile(fn) | |
| if cf in sys.modules and not reload: | |
| mod=sys.modules[cf] | |
| #if reload: importlib.reload(mod)# orText() not found | |
| else: | |
| f9=fn | |
| if not dir: | |
| for p in [os.getcwd(), *sys.path]: | |
| if ifexist(f9:=jwdir(p,fn)): break | |
| if ifexist(f9:=(f9+".py")):break | |
| if 1: | |
| if not ifexist(f9): f9+=".py" | |
| assert ifexist(f9), "module not found: "+fn | |
| spec=importtool.spec_from_file_location(cf,f9) | |
| assert spec, "import from file location;"+f9 | |
| #print("spec;",[ spec.name, spec.origin], flush=True) | |
| if lazy: spec.loader = LazyLoader(spec.loader) | |
| mod = module_from_spec(spec) | |
| sys.modules[cf] = mod | |
| if "import": getattr(spec.loader, b'\x65\x78\x65\x63_\x6D\x6F\x64\x75\x6C\x65'.decode())(mod) | |
| #if dir: sys.path.pop() | |
| return mod | |
| def zen(wfn): | |
| wfn=orsub({":":":", "<":"(",">":")","\\":"/"},wfn) | |
| return wfn | |
| def newthan(tfn,fn): return mtime(tfn)>mtime(fn) | |
| def memof(fp): | |
| fp._memof={} | |
| def p(zl,*w): | |
| #print(fp._memof, w) | |
| if(mf:=fp._memof.get(w)): return mf | |
| else: | |
| pm=fp(zl,*w) | |
| fp._memof[w]=pm | |
| return pm | |
| return p | |
| if __name__ == '__main__': | |
| print(os.getcwd()); | |
| hh={ | |
| ## "ast":1, | |
| ## "dif3":5, | |
| } | |
| hw,fl=xfil([]) | |
| hw.new36=1200 | |
| if "dif3" in hw: | |
| t1="am,mm,gf,jpefg".split(",") | |
| t2="pm,mm,gif,jpg".split(",") | |
| prexit(dif3(t1,t2)) | |
| if(0): | |
| eu=esfn(url); | |
| wfdt(eu,"lkjl"); | |
| e2=exfn(eu); | |
| pr(bool(url==e2)); | |
| pr(url,lf,e2,lf,eu); | |
| if "ast" in fl: | |
| import ast | |
| def pcompile(te):1 | |
| print(ast.dump(ast.parse("if 1:1"))) | |
| w=ast.parse("sn.l[2]") | |
| q=[(f,list(ast.iter_fields(f))) for f in ast.walk(w)] | |
| for f,n in q: | |
| if n:print(len(n),n) | |
| ## prexit(emrestore("c")) | |
| if hw.new36:# f-string | |
| print(f"f-string: {hw.new36:,} string:left,{hh!s:>22}") | |
| #Operator precedence() ~ / + >> & ^ | in > not and or if | |
| ##npp(r'"C:/cpy/Mjmoji/pr/give it try.pyw" -n2') | |
| #compilev(r"(?<=1).*?(?=\n)").sub("2","1\nfw\n") | |
| if 1: | |
| import socket | |
| def better_send(feeding, host=(),cb=()): | |
| socket_port_web = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| socket_port_web.settimeout(1) | |
| #socket_port_web.connect(("localhost",5010)) | |
| socket_port_web.connect(("127.0.0.1",5010)) | |
| # | |
| sent = 0 | |
| while sent < len(feeding): | |
| sent = sent + socket_port_web.send(feeding[sent:]) | |
| # | |
| while True: | |
| long = socket_port_web.recv(4096) | |
| if len(long) == 0: # No more data received | |
| break | |
| #response = response + long; | |
| yield long | |
| #return response | |
| def transfer(feeding, host): | |
| tea=b"" | |
| for et in better_send(feeding,host): | |
| tea+=et | |
| return tea | |
| if 1: | |
| finalcb=cbTry | |
| cbstop=finalcb | |