Spaces:
Paused
Paused
t5
commited on
Commit
·
aeea18d
1
Parent(s):
7395924
apple
Browse files- altEdit.py +0 -267
- mlwebOrWeb.py +549 -0
- wr.py → mw.py +36 -31
- neo server.py +13 -8
- tofu_edit.py +10 -5
- zipOrZip.py +386 -0
altEdit.py
DELETED
|
@@ -1,267 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
##import sys;sys.path.append("N:\\afilen\\program\\python\\Mjmoji");from wr import *
|
| 3 |
-
import sys
|
| 4 |
-
import time
|
| 5 |
-
from ctypes import *
|
| 6 |
-
import subprocess as p
|
| 7 |
-
from wr import *
|
| 8 |
-
|
| 9 |
-
def scroll(*ww):
|
| 10 |
-
import edit_
|
| 11 |
-
#
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def ctockai( text ):
|
| 16 |
-
import os
|
| 17 |
-
logfile=[fr"{tfolder}/1.txt",fr"{tfolder}/2er.txt"]
|
| 18 |
-
## for f in logfile: os.path.exists(f) and os.remove(f)
|
| 19 |
-
ip = p.Popen( ['cmd'], stdin=p.PIPE, shell=True )
|
| 20 |
-
#text="%s > %s 2>&1 \n"%(text,erfile)#write
|
| 21 |
-
text="{} 1> {} 2> {} \n".format(text,*logfile)#write
|
| 22 |
-
## orror(text);
|
| 23 |
-
ip.stdin.write( text.encode("cp932"))
|
| 24 |
-
shuttown(ip.stdin)
|
| 25 |
-
retcode = ip.wait()
|
| 26 |
-
#
|
| 27 |
-
lir=list(open(f,"rb").read() for f in logfile)
|
| 28 |
-
## lir=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n").decode("mbcs") for te in lir]
|
| 29 |
-
lir=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n").decode("utf8") for te in lir]
|
| 30 |
-
return (retcode,lir[0],lir[1])
|
| 31 |
-
def ctod( text ,sh=True,cp="cp932",si=None):
|
| 32 |
-
ip = p.Popen( ['cmd']if(sh)else text, stdin=p.PIPE, stdout=p.PIPE,stderr=p.PIPE,shell=sh )
|
| 33 |
-
if 0:#no
|
| 34 |
-
ip.stdin.write("echo 1\n".encode())
|
| 35 |
-
for x in iter(ip.stdout.readline, b''):x
|
| 36 |
-
if 0:#no
|
| 37 |
-
ip.stdin.write("chcp 65001\n".encode("cp932"))
|
| 38 |
-
ip.stdin.flush()
|
| 39 |
-
ip.stdout.flush()
|
| 40 |
-
print(ip.stdout.read());
|
| 41 |
-
if(sh):
|
| 42 |
-
text+="\n";
|
| 43 |
-
ip.stdin.write( text.encode("cp932"))
|
| 44 |
-
shuttown(ip.stdin)
|
| 45 |
-
elif(si):
|
| 46 |
-
ip.stdin.write(si)
|
| 47 |
-
shuttown(ip.stdin)
|
| 48 |
-
|
| 49 |
-
retcode=None
|
| 50 |
-
try:
|
| 51 |
-
## retcode = ip.wait(timeout=0)
|
| 52 |
-
retcode = ip.wait()
|
| 53 |
-
res=(ip.stdout.read()[96:],
|
| 54 |
-
ip.stderr.read())
|
| 55 |
-
## for f in range(212): er=ip.stdout.read(2)
|
| 56 |
-
except p.TimeoutExpired as e:
|
| 57 |
-
## return ip.stdout.readline(21)
|
| 58 |
-
res=(ip.stdout.read()[96:],
|
| 59 |
-
ip.stderr.read())
|
| 60 |
-
fds
|
| 61 |
-
## cp="utf8"
|
| 62 |
-
## try:
|
| 63 |
-
## return retcode,r.decode(cp),er.decode(cp),ip
|
| 64 |
-
## except:
|
| 65 |
-
## cp="cp932"
|
| 66 |
-
## return retcode,r.decode(cp),er.decode(cp),ip
|
| 67 |
-
res=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n") for te in res]
|
| 68 |
-
from wr import vcs
|
| 69 |
-
res=[vcs(te) for te in res]
|
| 70 |
-
return retcode,*res,ip
|
| 71 |
-
def Runw(li): ctod(li,sh=False)
|
| 72 |
-
##(ctockai(jw(" ",["node",r"C:\v\P\electron\electron-quick-start\or1.js"])))
|
| 73 |
-
##print(ctockai("dir ."))
|
| 74 |
-
##print(ctod(jw(" ",["node",r"C:\v\P\electron\electron-quick-start\or1.js"])))
|
| 75 |
-
import os
|
| 76 |
-
import th
|
| 77 |
-
class cltof():
|
| 78 |
-
def __init__(zl):
|
| 79 |
-
#zl.mutex=fwe
|
| 80 |
-
zl.ev=th.Event()
|
| 81 |
-
zl.lock=th.Lock()
|
| 82 |
-
os.environ['PYTHONIOENCODING'] = 'utf-8'
|
| 83 |
-
def ctof(zl,cb,to, text ,null=""):
|
| 84 |
-
from wr import vcs, tp, wfd
|
| 85 |
-
zl.ev.clear()
|
| 86 |
-
if 0==to:to=3600*12
|
| 87 |
-
time0=time.perf_counter()
|
| 88 |
-
def fppc():
|
| 89 |
-
return time.perf_counter()-time0
|
| 90 |
-
def fpin(cb,text):
|
| 91 |
-
date=tp()
|
| 92 |
-
if isinstance(text,(list,tuple)): c=os.path.basename((text[0]))
|
| 93 |
-
elif isinstance(text,(str)): c= "C"
|
| 94 |
-
logfile=zl.logfile=[fr"{tfolder}/ctof_{c}_{x}_{date}.txt" for x in ("1","2")]
|
| 95 |
-
## print(text,cb)
|
| 96 |
-
for f in logfile: os.path.exists(f) and os.remove(f)
|
| 97 |
-
## ip = p.Popen( [("echo ff"),"1>",logfile[0],"2>",logfile[1]], shell=True )
|
| 98 |
-
if isinstance(text,(list,tuple)): te= [*text,"1>",logfile[0],"2>",logfile[1]]
|
| 99 |
-
elif isinstance(text,(str)):te= text+" 1> {} 2> {}".format(*logfile)
|
| 100 |
-
if not null or 1:
|
| 101 |
-
zl.ip=ip=p.Popen(text,shell=True, stdout=open(logfile[0],"w"), stderr=open(logfile[1],"w"), stdin=p.PIPE)
|
| 102 |
-
#
|
| 103 |
-
while any([False==os.path.exists(f) for f in logfile]):
|
| 104 |
-
print("not ready;",[os.path.exists(f) for f in logfile],te)
|
| 105 |
-
sleep(0.1)
|
| 106 |
-
while 1:
|
| 107 |
-
## try:
|
| 108 |
-
#with open(logfile[0],"rb") as fo:
|
| 109 |
-
lifo=[open(f,"rb") for f in logfile]
|
| 110 |
-
while 1:
|
| 111 |
-
poll=zl.poll=ip.poll()
|
| 112 |
-
for x,fo in enumerate(lifo):
|
| 113 |
-
bit=fo.read()
|
| 114 |
-
## print("p;",poll,bit)#lwt
|
| 115 |
-
if bit and cb: cb(x+1, vcs(bit))
|
| 116 |
-
if poll!=None: break
|
| 117 |
-
sleep(0.2)
|
| 118 |
-
if poll!=None: break
|
| 119 |
-
if to<(d:=fppc()):return
|
| 120 |
-
## print(d)
|
| 121 |
-
## except 2: f
|
| 122 |
-
if ip.poll()!=None:break
|
| 123 |
-
if to<(d:=fppc()):break
|
| 124 |
-
def fpin1(*w):
|
| 125 |
-
cb,*_=w
|
| 126 |
-
try:
|
| 127 |
-
res=fpin(*w)
|
| 128 |
-
## except Exception as e:
|
| 129 |
-
## wfd("r:\\logEdit.txt").t(str(e))
|
| 130 |
-
finally:
|
| 131 |
-
zl.ev.set()
|
| 132 |
-
return res
|
| 133 |
-
t=th.run(fpin1,(cb,text))
|
| 134 |
-
return t
|
| 135 |
-
@property
|
| 136 |
-
def te(zl):
|
| 137 |
-
from wr import vcs
|
| 138 |
-
if 1:
|
| 139 |
-
logfile=zl.logfile
|
| 140 |
-
lir=list(open(f,"rb").read() for f in logfile)
|
| 141 |
-
## lir=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n").decode("mbcs") for te in lir]
|
| 142 |
-
## print(lir[0].decode("cp932"),poll)
|
| 143 |
-
lir=[vcs(te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n"))for te in lir]
|
| 144 |
-
return (zl.poll,lir[0],lir[1])
|
| 145 |
-
@property
|
| 146 |
-
def wa(zl):
|
| 147 |
-
try:zl.ev.wait()
|
| 148 |
-
except KeyboardInterrupt as e:e
|
| 149 |
-
return zl
|
| 150 |
-
@staticmethod
|
| 151 |
-
def cbpr(std,b): print(f"{std} cblen({len(b)}) {b}")
|
| 152 |
-
def put(p,te):
|
| 153 |
-
p.ip.stdin.write(te.encode())
|
| 154 |
-
p.ip.stdin.flush()
|
| 155 |
-
def ctof(*w):
|
| 156 |
-
p=cltof()
|
| 157 |
-
p.ctof(*w)
|
| 158 |
-
return p
|
| 159 |
-
##def watofin(*w):
|
| 160 |
-
## p=ctof(*w).wa
|
| 161 |
-
## return p
|
| 162 |
-
##def returnwat():
|
| 163 |
-
def watof(*w):
|
| 164 |
-
p=ctof(*w)
|
| 165 |
-
te=p.wa.te
|
| 166 |
-
return te[1]+"\n"+te[2]
|
| 167 |
-
def tofu(*w):
|
| 168 |
-
return ctof(*w).wa.te
|
| 169 |
-
import subprocess, shlex
|
| 170 |
-
from threading import Timer
|
| 171 |
-
|
| 172 |
-
def run(cmd, timeout_sec):
|
| 173 |
-
proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE,
|
| 174 |
-
stderr=subprocess.PIPE)
|
| 175 |
-
kill_proc = lambda p: p.kill()
|
| 176 |
-
timer = Timer(timeout_sec, kill_proc, [proc])
|
| 177 |
-
try:
|
| 178 |
-
timer.start()
|
| 179 |
-
stdout,stderr = proc.communicate()
|
| 180 |
-
finally:
|
| 181 |
-
timer.cancel()
|
| 182 |
-
#
|
| 183 |
-
import time
|
| 184 |
-
import signal,os
|
| 185 |
-
def reloadFull(timeout=2.2, me=[sys.argv[0],"-r"]):
|
| 186 |
-
ip=p.Popen(me,shell=True)
|
| 187 |
-
try:
|
| 188 |
-
ri=ip.wait(timeout=timeout)#idea
|
| 189 |
-
print("eof. continue")
|
| 190 |
-
except subprocess.TimeoutExpired as e:
|
| 191 |
-
print("reload",e)
|
| 192 |
-
sys.exit(0)
|
| 193 |
-
def r1reloadFull(dure,me):
|
| 194 |
-
def handler(signum, frame):
|
| 195 |
-
print("reload,handler",signum)
|
| 196 |
-
def handlerth(signum, frame):
|
| 197 |
-
print("reload",signum)
|
| 198 |
-
## sys.exit(0)#no
|
| 199 |
-
os.kill(os.getpid(),signal.SIGINT)
|
| 200 |
-
## os.kill(os.getpid(),signal.SIGTERM)#ideaLk
|
| 201 |
-
signal.signal(signal.SIGTERM, handler)
|
| 202 |
-
signal.signal(signal.SIGINT, handler)
|
| 203 |
-
timer=Timer(dure-0.2,handlerth,args=[1,2])
|
| 204 |
-
#
|
| 205 |
-
try:
|
| 206 |
-
timer.start()
|
| 207 |
-
ip=p.Popen( me,bufsize=2, stdin=p.PIPE, stdout=p.PIPE,stderr=p.PIPE,shell=True )
|
| 208 |
-
while ip.poll() is None:
|
| 209 |
-
sleep(0.2)
|
| 210 |
-
print("while_poll",ip.poll())
|
| 211 |
-
pass
|
| 212 |
-
## print(ip.stdout.read())
|
| 213 |
-
print("poll2",ip.poll())
|
| 214 |
-
try:
|
| 215 |
-
## ri=ip.wait(timeout=dure)#idea
|
| 216 |
-
ri=ip.wait()
|
| 217 |
-
except subprocess.TimeoutExpired as e:
|
| 218 |
-
print(e)
|
| 219 |
-
## sys.exit(0)
|
| 220 |
-
## ri
|
| 221 |
-
finally:
|
| 222 |
-
timer.cancel()
|
| 223 |
-
|
| 224 |
-
if __name__ == '__main__':
|
| 225 |
-
import edit_
|
| 226 |
-
acs()
|
| 227 |
-
fil=sys.argv
|
| 228 |
-
c1=fil[1]if(len(fil)>=2)else None
|
| 229 |
-
def reheasal():
|
| 230 |
-
import multiprocessing as mlti
|
| 231 |
-
sys.stdin.conn
|
| 232 |
-
|
| 233 |
-
if(c1=="-out"):
|
| 234 |
-
for j in fil[2]:
|
| 235 |
-
sleep(0.3)
|
| 236 |
-
sys.stdout.write(j)
|
| 237 |
-
if(c1=="-c"):
|
| 238 |
-
for f in ":苍天\n:":
|
| 239 |
-
print(f)
|
| 240 |
-
## sys.stdout.write(f)
|
| 241 |
-
if(c1=="-e"): fwf
|
| 242 |
-
if(c1=="-lf"):
|
| 243 |
-
for f in "123\n234":
|
| 244 |
-
print(f)
|
| 245 |
-
print(" start ",end="")
|
| 246 |
-
## input("pw")
|
| 247 |
-
sys.stdout.flush()
|
| 248 |
-
print("", flush=True)#,file=stdout
|
| 249 |
-
sleep(1)
|
| 250 |
-
if not c1:
|
| 251 |
-
print("c1;")
|
| 252 |
-
## reloadFull([r"dir"])
|
| 253 |
-
## reloadFull(2,[r"N:\afilen\program\python\work\ClipArg.py"] + args)
|
| 254 |
-
## r1reloadFull(5,[r"N:\afilen\program\python\qt\ClipProcess2.pyw"] + args)
|
| 255 |
-
## r1reloadFull(5,[fil[0],"-out", jw(".",[str(j)for j in list(range(2))])] )
|
| 256 |
-
## ctof(__file__,"-out","21212")
|
| 257 |
-
## print(";;",ctof(f'{__file__} -out 21\n\n\n'))
|
| 258 |
-
#? print(";;",ctof(f'{__file__}',"-out", '"21\n21"'))
|
| 259 |
-
## print(";;",ctof(f'{__file__}',"-out", "21"))
|
| 260 |
-
#lwt
|
| 261 |
-
def cb(std,b): print(f"{std} cblen({len(b)}) {b}")
|
| 262 |
-
## print(";",ctof(cb,'ffmpeg',"-y","-i",r"r:\\p9.mkv","r:\\fw.mp4"))
|
| 263 |
-
## print(";;",ctof(f'{__file__}',"-c",''))
|
| 264 |
-
## print(";;",ctof(f'{__file__}',"-e"))
|
| 265 |
-
## print(";;",watof(cb,10,(f'{__file__}',"-lf")))
|
| 266 |
-
print(";;",watof(cb,10,(f'{__file__}'+" -lf")))
|
| 267 |
-
## print(";;",watof(f'{__file__}',"-out",'21212苍天\nf'))#?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# MarkUp Language
|
| 4 |
+
import zipOrZip as oz
|
| 5 |
+
import mw; from mw import *
|
| 6 |
+
import re,os
|
| 7 |
+
import urllib.request
|
| 8 |
+
from urllib.parse import urlparse,quote,quote_plus,unquote,unquote_plus,urlencode
|
| 9 |
+
|
| 10 |
+
orror=mw.orro3("roml.txt");
|
| 11 |
+
urltmpdir="r:\\TEMP\\"
|
| 12 |
+
hp="https://"
|
| 13 |
+
class webrap:
|
| 14 |
+
user_agents = [
|
| 15 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
|
| 16 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
|
| 17 |
+
## 'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.129 Mobile Safari/537.36'
|
| 18 |
+
'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11',
|
| 19 |
+
'Opera/9.25 (Windows NT 5.1; U; en)',
|
| 20 |
+
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
|
| 21 |
+
'Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)',
|
| 22 |
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12'
|
| 23 |
+
'Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9'
|
| 24 |
+
]
|
| 25 |
+
headers=[]
|
| 26 |
+
headers.append( ('User-agent', user_agents[0]))
|
| 27 |
+
headers.append((b'\x41\x63\x63\x65\x70\x74-\x65\x6E\x63\x6F\x64\x69\x6E\x67'.decode(), 'gzip'))# encoding
|
| 28 |
+
def __init__(zl):
|
| 29 |
+
zl.user_agent=webrap.user_agents[0];
|
| 30 |
+
zl.code="utf-8";
|
| 31 |
+
def gZip(zl):
|
| 32 |
+
byte = zl.httpres.read()
|
| 33 |
+
hs={f.lower():v for f,v in zl.httpres.getheaders()}
|
| 34 |
+
if('content-encoding' in hs and hs['content-encoding'] == 'gzip'):
|
| 35 |
+
byte = oz.extgz(byte);
|
| 36 |
+
return byte
|
| 37 |
+
def g0(zl):
|
| 38 |
+
opener = urllib.request.build_opener() #
|
| 39 |
+
opener.addheaders = zl.headers
|
| 40 |
+
#print(zl.url)
|
| 41 |
+
zl.httpres = opener.open(zl.url)#,timeout=2)
|
| 42 |
+
return zl.gZip();
|
| 43 |
+
def getCache(zl):#offline cache
|
| 44 |
+
esurl=zl.url
|
| 45 |
+
esurl=mw.esfn(esurl.replace(hp,""))
|
| 46 |
+
# esurl=unquote_plus(esurl,zl.code)
|
| 47 |
+
zl.offfile=urltmpdir+esurl
|
| 48 |
+
## zl.offfile=zl.offfile[:255]
|
| 49 |
+
if(zl.url.find("://")==-1):
|
| 50 |
+
zl.url=hp+zl.url
|
| 51 |
+
if(mw.ifexist(zl.offfile)):
|
| 52 |
+
byte=mw.rfdb(zl.offfile)
|
| 53 |
+
zl.byte=byte;
|
| 54 |
+
return zl.byte
|
| 55 |
+
return None;
|
| 56 |
+
def orwgetof0(zl):
|
| 57 |
+
if(not zl.getCache()):
|
| 58 |
+
## zl.url=quote_plus(zl.url,encoding=code,safe=":/")
|
| 59 |
+
zl.byte = zl.g0();
|
| 60 |
+
wfdb(zl.offfile,zl.byte); orRemove(zl.offfile, rembat="wget cache remove.bat")
|
| 61 |
+
return zl.byte;
|
| 62 |
+
def orwgetoff(url,post=0):
|
| 63 |
+
zl=webrap()
|
| 64 |
+
zl.url=url;
|
| 65 |
+
return zl.orwgetof0()
|
| 66 |
+
def utf(zl,url):
|
| 67 |
+
zl.url=url;
|
| 68 |
+
t1=zl.orwgetof0();
|
| 69 |
+
t2=t1.decode(zl.code);
|
| 70 |
+
return t2;
|
| 71 |
+
def gton(zl,*aw): return zl.gtoff(*aw,on=True)
|
| 72 |
+
def gtoff(zl,url,code="",on=False):
|
| 73 |
+
if "#" in url: url=url.split("#")[0]
|
| 74 |
+
zl.url=quote(unquote_plus(url),safe=":/?=")
|
| 75 |
+
## print(zl.url)
|
| 76 |
+
zl.code=code;
|
| 77 |
+
t1=zl.g0() if on else zl.orwgetof0();
|
| 78 |
+
if code==bytes: return t1
|
| 79 |
+
t2=t1.decode(code) if code else vcs(t1);
|
| 80 |
+
return t2;
|
| 81 |
+
def wget(zl,*aw):return zl.gtoff(*aw,on=False)
|
| 82 |
+
#
|
| 83 |
+
def orwget(zl,url,post=0,off=1):#legacy
|
| 84 |
+
esurl=url
|
| 85 |
+
esurl=esfn(esurl.replace(hp,""))
|
| 86 |
+
esurl=unquote_plus(esurl,encoding=zl.code)
|
| 87 |
+
zl.offfile=urltmpdir+esurl
|
| 88 |
+
if(url.find(hp)==-1):
|
| 89 |
+
url=hp+url
|
| 90 |
+
if(ifexist(zl.offfile) and off):
|
| 91 |
+
byte=rfdb(zl.offfile)
|
| 92 |
+
else:
|
| 93 |
+
## url=quote_plus(url,encoding=code,safe=":/")
|
| 94 |
+
user_agent=webrap.user_agents[0];
|
| 95 |
+
opener = urllib.request.build_opener()
|
| 96 |
+
opener.addheaders = [ ('User-agent', user_agent), ('Accept-encoding', 'gzip')]
|
| 97 |
+
qpost=zl.mkpost(post) if post else None#
|
| 98 |
+
zl.res = opener.open(url,qpost.encode("utf8"))#zl.res
|
| 99 |
+
byte = zl.res.read()
|
| 100 |
+
hs={k:v for k,v in zl.res.getheaders()}
|
| 101 |
+
if('Content-Encoding' in hs and hs['Content-Encoding'] == 'gzip'):
|
| 102 |
+
byte = oz.extgz(byte);
|
| 103 |
+
if off: wfdb(zl.offfile,byte)
|
| 104 |
+
return byte.decode(zl.code);
|
| 105 |
+
def mkpost(zl,q):
|
| 106 |
+
return jw("&",[jw("=",[quote_plus(str(w),encoding=zl.code) for w in f]) for f in q])
|
| 107 |
+
## return tea
|
| 108 |
+
## l = []
|
| 109 |
+
if 1:
|
| 110 |
+
tea=""
|
| 111 |
+
for k, v in q:
|
| 112 |
+
k = quote_plus(str(k),encoding=zl.code)
|
| 113 |
+
v = quote_plus(str(v),encoding=zl.code)
|
| 114 |
+
#l.append(k + '=' + v)
|
| 115 |
+
tea+=k+"="+v+"&"
|
| 116 |
+
return tea[:-1]
|
| 117 |
+
irle=re.compile(r'<a href="(?P<href>.+?)".*?>(?P<te>.*?)</a>');
|
| 118 |
+
def le(te):
|
| 119 |
+
"link extracter"
|
| 120 |
+
zl.links=webrap.irle.findall(te);
|
| 121 |
+
return zl.links;
|
| 122 |
+
def nx(zl,reg,te,url,page=1):
|
| 123 |
+
"pager"
|
| 124 |
+
#par=urlparse(zl.url)#netloc path query
|
| 125 |
+
irnx=re.compile(reg)
|
| 126 |
+
def fpnxurl(tefp):
|
| 127 |
+
if not(mo:=irnx.search(tefp)):print("not match regnx"); return
|
| 128 |
+
else:
|
| 129 |
+
if type(page)!=int:
|
| 130 |
+
nxquery=mo.group(1)
|
| 131 |
+
nxquery=nxquery.replace("&","&")
|
| 132 |
+
nxurl=jw("------",url, nxquery)
|
| 133 |
+
print(nxquery)
|
| 134 |
+
## print((zl.url, nxquery), nxurl)
|
| 135 |
+
return nxurl
|
| 136 |
+
return True
|
| 137 |
+
nxurl=url
|
| 138 |
+
if te:
|
| 139 |
+
yield te
|
| 140 |
+
if type(page)==int: page+=1
|
| 141 |
+
nxurl=fpnxurl(te)
|
| 142 |
+
for n in range(page or 0,987987987):
|
| 143 |
+
if page: nxurl=url.format(n)
|
| 144 |
+
## print(nxurl)
|
| 145 |
+
te=zl.gtoff(nxurl,zl.code, on=1)
|
| 146 |
+
yield te
|
| 147 |
+
if not(nxurl:=fpnxurl(te)): break
|
| 148 |
+
def firefox(zl,url):
|
| 149 |
+
import webbrowser
|
| 150 |
+
webbrowser.open(url)
|
| 151 |
+
def ggle(zl,q):
|
| 152 |
+
zl.code="utf-8"
|
| 153 |
+
zl.code="shift-jis"
|
| 154 |
+
post=(("q",q),("hl","ja"))#japan
|
| 155 |
+
qp=zl.mkpost(post)
|
| 156 |
+
q2="http://www.google.co.jp/search?"+qp
|
| 157 |
+
te=zl.orwget(q2)
|
| 158 |
+
return te
|
| 159 |
+
def chr(sl,te):lwt
|
| 160 |
+
## 文字参照や実体参照を通常の文字に戻す [Python, Tips] - Programming Magic5
|
| 161 |
+
# 実体参照 & 文字参照を通常の文字に戻す
|
| 162 |
+
@staticmethod
|
| 163 |
+
def htmlentity2unicode(text):
|
| 164 |
+
import html.entities as htmlentitydefs
|
| 165 |
+
# 正規表現のコンパイル
|
| 166 |
+
reference_regex = re.compile('&(#x?[0-9a-f]+|[a-z]+);', re.IGNORECASE)
|
| 167 |
+
num16_regex = re.compile('#x\d+', re.IGNORECASE)
|
| 168 |
+
num10_regex = re.compile('#\d+', re.IGNORECASE)
|
| 169 |
+
|
| 170 |
+
result = ""
|
| 171 |
+
i = 0
|
| 172 |
+
while True:
|
| 173 |
+
# 実体参照 or 文字参照を見つける
|
| 174 |
+
match = reference_regex.search(text, i)
|
| 175 |
+
if match is None:
|
| 176 |
+
result += text[i:]
|
| 177 |
+
break
|
| 178 |
+
|
| 179 |
+
result += text[i:match.start()]
|
| 180 |
+
i = match.end()
|
| 181 |
+
name = match.group(1)
|
| 182 |
+
|
| 183 |
+
# 実体参照
|
| 184 |
+
if name in htmlentitydefs.name2codepoint.keys():
|
| 185 |
+
result += chr(htmlentitydefs.name2codepoint[name])
|
| 186 |
+
# 文字参照
|
| 187 |
+
elif num16_regex.match(name):
|
| 188 |
+
# 16進数
|
| 189 |
+
result += chr(int('0'+name[1:], 16))
|
| 190 |
+
elif num10_regex.match(name):
|
| 191 |
+
# 10進数
|
| 192 |
+
result += chr(int(name[1:]))
|
| 193 |
+
|
| 194 |
+
return result
|
| 195 |
+
|
| 196 |
+
if 0:
|
| 197 |
+
webrap().ggle("かんこれ");
|
| 198 |
+
def yaho(zl,q):
|
| 199 |
+
zl.code="utf-8"
|
| 200 |
+
post=(("ei","UTF-8"),("p",q),("n","40"))#nPageNum10|15|20|30|40|100
|
| 201 |
+
qp=zl.mkpost(post)
|
| 202 |
+
q2="http://search.yahoo.co.jp/search?"+qp
|
| 203 |
+
te=zl.orwget(q2)
|
| 204 |
+
return te
|
| 205 |
+
def bing(zl,url):
|
| 206 |
+
esurl=url
|
| 207 |
+
esurl=esfn(esurl.replace(hp,""))
|
| 208 |
+
zl.code=code="utf-8"
|
| 209 |
+
esurl=unquote_plus(esurl,encoding=code)
|
| 210 |
+
zl.offfile=urltmpdir+esurl
|
| 211 |
+
if(url.find(hp)==-1):
|
| 212 |
+
url=hp+url
|
| 213 |
+
if(ifexist(zl.offfile)):
|
| 214 |
+
byte=rfdb(zl.offfile)
|
| 215 |
+
else:
|
| 216 |
+
#url=quote_plus(url,encoding=code,safe=":/")
|
| 217 |
+
user_agent=webrap.user_agents[0];
|
| 218 |
+
opener = urllib.request.build_opener()
|
| 219 |
+
## opener.addheaders = [ ('','')]
|
| 220 |
+
opener.addheaders= [('Host',' www.bing.com')]
|
| 221 |
+
opener.addheaders= [('User-Agent',' Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0')]
|
| 222 |
+
opener.addheaders= [('Accept',' text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]
|
| 223 |
+
opener.addheaders= [('Accept-Language',' ja,en-us;q=0.7,en;q=0.3')]
|
| 224 |
+
opener.addheaders= [('Accept-Encoding',' gzip, deflate')]
|
| 225 |
+
qpost=zl.mkpost(post) if post else None#
|
| 226 |
+
zl.res = opener.open(url)#zl.res
|
| 227 |
+
byte = zl.res.read()
|
| 228 |
+
hs={k:v for k,v in zl.res.getheaders()}#header had raised TypeError
|
| 229 |
+
if('Content-Encoding' in hs and hs['Content-Encoding'] == 'gzip'):
|
| 230 |
+
byte = oz.extgz(byte);
|
| 231 |
+
wfdb(zl.offfile,byte)
|
| 232 |
+
return byte.decode(code);
|
| 233 |
+
def quotesafe(zl,url):
|
| 234 |
+
qurl=quote_plus(url,encoding=code,safe=":/&?")
|
| 235 |
+
write8(r"r:\url1",url)
|
| 236 |
+
write8(r"r:\url2",qurl)
|
| 237 |
+
if 0:#getoff
|
| 238 |
+
im=webrap()
|
| 239 |
+
im.url=r"http://blog.livedoor.jp/yuriss/"
|
| 240 |
+
te=im.orwgetoff(im.url)
|
| 241 |
+
wfdb(r"r:\get.txt",te);
|
| 242 |
+
#ftp
|
| 243 |
+
from ftplib import FTP
|
| 244 |
+
class owf:
|
| 245 |
+
def login(sl,url,aka,pwd):
|
| 246 |
+
sl.imf=FTP(url)
|
| 247 |
+
sl.imf.login(aka,pwd)
|
| 248 |
+
def list(sl):
|
| 249 |
+
return sl.imf.retrlines("LIST")
|
| 250 |
+
def cbO(sl,blockData):
|
| 251 |
+
sl.res+=blockData#packet
|
| 252 |
+
def o(sl,fn):
|
| 253 |
+
sl.res=b""
|
| 254 |
+
ri=sl.imf.retrbinary('RETR '+fn,sl.cbO)
|
| 255 |
+
return sl.res
|
| 256 |
+
def uf(sl,fn):
|
| 257 |
+
with open(fn, "rb")as fo:
|
| 258 |
+
#_ftp.cwd("/target_dir/")
|
| 259 |
+
return sl.imf.storbinary("STOR "+os.path.split(fn)[1], fo)
|
| 260 |
+
def u(sl,fn,fo):#file object
|
| 261 |
+
return sl.imf.storbinary("STOR "+fn, fo)
|
| 262 |
+
def dele(sl):
|
| 263 |
+
sl.imf.quit()
|
| 264 |
+
#------------
|
| 265 |
+
##from __future__ import print_function
|
| 266 |
+
from threading import Thread,Lock,Event,Condition
|
| 267 |
+
import socket
|
| 268 |
+
from contextlib import closing
|
| 269 |
+
import select
|
| 270 |
+
defaultPort=4000
|
| 271 |
+
class orListen(Thread):
|
| 272 |
+
#python listen
|
| 273 |
+
def __init__(sl,cb=None,fil=(),ercb=(),**kw):
|
| 274 |
+
super().__init__(**kw)
|
| 275 |
+
sl.owari=False
|
| 276 |
+
if cb: sl._cb=cb
|
| 277 |
+
sl.fil=fil
|
| 278 |
+
sl.ercb=ercb or (sl._ercb, [])
|
| 279 |
+
#
|
| 280 |
+
sl.port = defaultPort
|
| 281 |
+
def i4l(sl,port,cb=None,fil=(),ercb=(),**kw):
|
| 282 |
+
super().__init__(**kw)
|
| 283 |
+
sl.owari=False
|
| 284 |
+
assert sl._cb, "reimmpriment cb"
|
| 285 |
+
sl.fil=fil
|
| 286 |
+
sl.ercb=(sl._ercb, [])
|
| 287 |
+
#
|
| 288 |
+
sl.host = '127.0.0.1'
|
| 289 |
+
sl.port = port
|
| 290 |
+
return sl
|
| 291 |
+
def main(sl):#, port = defaultPort):
|
| 292 |
+
backlog = 10
|
| 293 |
+
bufsize = 4096
|
| 294 |
+
|
| 295 |
+
server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 296 |
+
sl.server_sock=server_sock
|
| 297 |
+
Set = set([server_sock])
|
| 298 |
+
try:
|
| 299 |
+
server_sock.bind((sl.host, sl.port))
|
| 300 |
+
server_sock.listen(backlog)
|
| 301 |
+
|
| 302 |
+
while True:
|
| 303 |
+
rready, wready, xready = select.select(Set, [], [],5.0)
|
| 304 |
+
## print("ready")
|
| 305 |
+
if sl.owari:
|
| 306 |
+
print("owari select")
|
| 307 |
+
break
|
| 308 |
+
for sock in rready:
|
| 309 |
+
try:
|
| 310 |
+
if sock is server_sock:
|
| 311 |
+
conn, address = server_sock.accept()
|
| 312 |
+
Set.add(conn)#peer
|
| 313 |
+
else:
|
| 314 |
+
te = sock.recv(bufsize)
|
| 315 |
+
if len(te) == 0:pass
|
| 316 |
+
elif te==b"owari":
|
| 317 |
+
sock.send(b"len-0;")
|
| 318 |
+
Set.remove(sock)
|
| 319 |
+
sl.owari=1
|
| 320 |
+
shuttown(sock)
|
| 321 |
+
else:
|
| 322 |
+
sl.sock=sock
|
| 323 |
+
sl._cb(te, sl.fil)
|
| 324 |
+
except Exception as e:
|
| 325 |
+
except2(edit=1)
|
| 326 |
+
Set.remove(sock)
|
| 327 |
+
shuttown(sock)
|
| 328 |
+
#sl.ercb[0](e,sl.ercb[1])
|
| 329 |
+
except Exception as e:
|
| 330 |
+
print(e)
|
| 331 |
+
except2(edit=1)
|
| 332 |
+
#sl.ercb[0](e,sl.ercb[1])
|
| 333 |
+
finally:
|
| 334 |
+
for sock in Set:
|
| 335 |
+
shuttown(sock)
|
| 336 |
+
return
|
| 337 |
+
def run(sl):#start
|
| 338 |
+
sl.main()
|
| 339 |
+
## except ConnectionResetError as er:
|
| 340 |
+
|
| 341 |
+
def chkbind(sl):
|
| 342 |
+
server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 343 |
+
Set = set([server_sock])
|
| 344 |
+
try:
|
| 345 |
+
server_sock.bind((sl.host, sl.port))
|
| 346 |
+
## server_sock.listen(backlog)
|
| 347 |
+
except Exception as e:
|
| 348 |
+
e2=traceback.format_exc()
|
| 349 |
+
rn=0
|
| 350 |
+
else:
|
| 351 |
+
rn=1
|
| 352 |
+
finally:
|
| 353 |
+
for sock in Set:
|
| 354 |
+
shuttown(sock)
|
| 355 |
+
return rn
|
| 356 |
+
def Release(sl):#finalist
|
| 357 |
+
if sl.chkbind(): return
|
| 358 |
+
send1("127.0.0.1", port=sl.port, te="owari")#4 unblock select
|
| 359 |
+
sl.owari=True
|
| 360 |
+
class _orListen(orListen):
|
| 361 |
+
def _cb(sl,te,fil):
|
| 362 |
+
te=te.decode()
|
| 363 |
+
print(te)
|
| 364 |
+
if(te=="x"): sl.Release()
|
| 365 |
+
#sl.sock.send(te.encode())
|
| 366 |
+
sl.cb2(te,fil)
|
| 367 |
+
## _cb=cb
|
| 368 |
+
def cb2(sl,te,fil):
|
| 369 |
+
pn=sl.sock.getpeername()
|
| 370 |
+
## print(te)
|
| 371 |
+
so=sl.sock
|
| 372 |
+
if 2:#local
|
| 373 |
+
lcl=dict(locals())
|
| 374 |
+
lcl.update({"r":"r:"})
|
| 375 |
+
try:
|
| 376 |
+
exec(te,globals(),lcl)
|
| 377 |
+
except Exception as e:
|
| 378 |
+
print("exec:", traceback.format_exc())
|
| 379 |
+
for i in dict(locals()): lcl.pop(i,55)
|
| 380 |
+
#sl.sock.lcl=lcl
|
| 381 |
+
#
|
| 382 |
+
sl.sock.send(lcl["r"].encode())
|
| 383 |
+
def _ercb(sl,erte,fil):
|
| 384 |
+
print("---",erte)
|
| 385 |
+
def chkbind(port):
|
| 386 |
+
return _orListen().i4l(port).chkbind()
|
| 387 |
+
def send1(host, port, te):
|
| 388 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 389 |
+
with closing(sock):
|
| 390 |
+
sock.connect((host, port))
|
| 391 |
+
sock.send(te.encode("utf8"))
|
| 392 |
+
def mainClient(fil=(0,),sp=(),iLi=(),host = '127.0.0.1',port = defaultPort,bufsize = 4096,timeout=2.0):
|
| 393 |
+
let=[]
|
| 394 |
+
once,=fil
|
| 395 |
+
|
| 396 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 397 |
+
with closing(sock):
|
| 398 |
+
sock.connect((host, port))
|
| 399 |
+
if iLi:
|
| 400 |
+
for te in iLi:
|
| 401 |
+
try:
|
| 402 |
+
sock.send(te.encode('utf-8'))
|
| 403 |
+
sock.settimeout(timeout)
|
| 404 |
+
#let.append(sock.recv(bufsize))
|
| 405 |
+
if 1:
|
| 406 |
+
for x1 in range(99):
|
| 407 |
+
te=sock.recv(bufsize)
|
| 408 |
+
if(te):let.append(te)
|
| 409 |
+
#print(let)
|
| 410 |
+
except Exception as e:
|
| 411 |
+
e2=traceback.format_exc()
|
| 412 |
+
print(e2)
|
| 413 |
+
return let
|
| 414 |
+
if once:
|
| 415 |
+
for n in range(once):
|
| 416 |
+
try:
|
| 417 |
+
sock.send(str(n).encode('utf-8'))
|
| 418 |
+
print(" clientz:",sock.recv(bufsize))
|
| 419 |
+
except Exception as e:
|
| 420 |
+
e2=traceback.format_exc()
|
| 421 |
+
print(e2)
|
| 422 |
+
while not once:
|
| 423 |
+
line = sys.stdin.readline().rstrip()
|
| 424 |
+
if len(line) == 0:
|
| 425 |
+
print("send x to quit.")
|
| 426 |
+
break
|
| 427 |
+
sock.send(line.encode('utf-8'))
|
| 428 |
+
print(" client:",sock.recv(bufsize))
|
| 429 |
+
return
|
| 430 |
+
send=mainClient
|
| 431 |
+
if __name__ == '__main__':
|
| 432 |
+
from subprocess import *
|
| 433 |
+
import time
|
| 434 |
+
import sys
|
| 435 |
+
import traceback
|
| 436 |
+
hh,fl=hhfl([])
|
| 437 |
+
hh=hhww()
|
| 438 |
+
## hh.getaddrinfo=1
|
| 439 |
+
#
|
| 440 |
+
if hh.getaddrinfo:
|
| 441 |
+
print(socket.getaddrinfo("localhost",4000))
|
| 442 |
+
print(socket.getaddrinfo("localhost",8080))
|
| 443 |
+
#
|
| 444 |
+
## post=[3:4,5:6]
|
| 445 |
+
post=[(1,1),(2,2),(3,3),("q","検索")]
|
| 446 |
+
q=urlencode(post)
|
| 447 |
+
print(q)
|
| 448 |
+
im=webrap()
|
| 449 |
+
im.code="cp932"
|
| 450 |
+
## print(im.mkpost(post))
|
| 451 |
+
if 0:#?
|
| 452 |
+
rn=webrap().yaho("そのだうみ")
|
| 453 |
+
## print(rn)
|
| 454 |
+
rn=webrap.orwgetoff("http://search.yahoo.co.jp/search?")
|
| 455 |
+
rn=webrap().bing("http://www.bing.com/search?q=かんこれ&qs=n&form=QBLH&filt=all&pq=かんこれ&sc=8-4&sp=-1&sk=")#404repair by delete quote process
|
| 456 |
+
rn=webrap.orwgetoff("http://livedoor-search.naver.jp/search?c=ld_blog_sb&o_st=livedoor&sm=ldb_top&q=かよちん&search_btn=検索")
|
| 457 |
+
webrap().bing(r"http://livedoor-search.naver.jp/search?c=ld_blog_sb&o_st=livedoor&sm=ldb_top&q=かよちん&search_btn=検索");
|
| 458 |
+
if {"ftp"}.issubset(hh):
|
| 459 |
+
imf=owf()
|
| 460 |
+
# imf.login("ftp:shinuno.comxa.com","a6091821","heikou2zero")#exc
|
| 461 |
+
imf.login("red.ribbon.to","shinuno","forget")#exc
|
| 462 |
+
if {"ftp","ftp1"}.issubset(hh):
|
| 463 |
+
#all stdout
|
| 464 |
+
li=imf.list()
|
| 465 |
+
print("----",li)
|
| 466 |
+
li=imf.imf.retrlines("NLST")
|
| 467 |
+
print("----",li)
|
| 468 |
+
li=imf.imf.retrlines("MLSD")
|
| 469 |
+
print("----",li)
|
| 470 |
+
def mkBody(te):
|
| 471 |
+
t2="""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
| 472 |
+
<html>
|
| 473 |
+
<head>
|
| 474 |
+
<title>Index of /video</title>
|
| 475 |
+
</head>
|
| 476 |
+
<body>
|
| 477 |
+
%s
|
| 478 |
+
</body></html>
|
| 479 |
+
"""%(te)
|
| 480 |
+
return t2
|
| 481 |
+
if {"ftp","ftp2"}.issubset(hh):
|
| 482 |
+
imf.imf.cwd("/public_html/video")
|
| 483 |
+
print(imf.imf.pwd())
|
| 484 |
+
print(imf.imf.nlst())
|
| 485 |
+
#sendcmd("LIST")
|
| 486 |
+
#
|
| 487 |
+
from io import BytesIO
|
| 488 |
+
import time
|
| 489 |
+
t=time.localtime();
|
| 490 |
+
t2=("d_dd_d"%(t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec))
|
| 491 |
+
fn="|"+t2+".txt"
|
| 492 |
+
fnh="|"+t2+".htm"
|
| 493 |
+
#no fn932=fn.encode("cp932")
|
| 494 |
+
ri=imf.u(fn,BytesIO(b"fwfwf"))
|
| 495 |
+
ri
|
| 496 |
+
ri=imf.u(fnh,BytesIO(mkBody(time.strftime("%Y_%m/%d %H%M %A %B %c")).encode("utf8")))
|
| 497 |
+
if {"ftp","ftp3"}.issubset(hh):
|
| 498 |
+
imf.imf.cwd("/public_html/cgi")
|
| 499 |
+
#
|
| 500 |
+
fn=r"N:\afilen\program\html\award\cgi\Dirr1.php"
|
| 501 |
+
fn=r"N:\afilen\program\html\award\cgi\wget.php"
|
| 502 |
+
ri=imf.uf(fn)
|
| 503 |
+
## dn=r"N:\afilen\program\html\award\cgi"
|
| 504 |
+
## for fn in os.listdir(dn):imf.uf(jofn(dn,fn))
|
| 505 |
+
## tes2()
|
| 506 |
+
## tes1()
|
| 507 |
+
imf.dele()
|
| 508 |
+
import jk987
|
| 509 |
+
#
|
| 510 |
+
iml=_orListen()
|
| 511 |
+
if "client"==arps.f:#?
|
| 512 |
+
try:
|
| 513 |
+
## q8erw
|
| 514 |
+
mainClient([2])
|
| 515 |
+
except ConnectionRefusedError as er:
|
| 516 |
+
print(" connectEr: ", str(er))
|
| 517 |
+
except Exception as e:
|
| 518 |
+
e2=traceback.format_exc()
|
| 519 |
+
print(e2)
|
| 520 |
+
input("owari\n")
|
| 521 |
+
elif "listen" in hh:
|
| 522 |
+
iml.start()
|
| 523 |
+
## Popen(["E:\Python34\python.exe",sys.argv[0]]+["-f","client"],shell=True)
|
| 524 |
+
## Popen(["start","E:\Python34\python.exe "+jw(" ",[sys.argv[0],"-f","client"])],shell=True)
|
| 525 |
+
## Popen(["start",r"E:\Python34\python.exe",r"N:\afilen\program\python\qt\ClipProcess2.pyw"],shell=True)#ok
|
| 526 |
+
## Popen(["start",r"N:\afilen\program\python\qt\ClipProcess2.pyw"],shell=True)#ok
|
| 527 |
+
for _ in range(4):
|
| 528 |
+
Popen(["start",sys.argv[0], "-f","client"],shell=True)
|
| 529 |
+
for f in range(2):
|
| 530 |
+
print("listen:",f)
|
| 531 |
+
time.sleep(2.0)
|
| 532 |
+
iml.owari=True
|
| 533 |
+
if "clien2"==arps.f:#
|
| 534 |
+
try:
|
| 535 |
+
mainClient([None])
|
| 536 |
+
except Exception as e:
|
| 537 |
+
e2=traceback.format_exc()
|
| 538 |
+
print(e2)
|
| 539 |
+
input("owari\n")
|
| 540 |
+
elif "ser2" in hh:
|
| 541 |
+
for i in range(2):
|
| 542 |
+
Popen(["start",sys.argv[0], "-f","clien2"],shell=True)
|
| 543 |
+
iml.main()
|
| 544 |
+
for i in range(2):
|
| 545 |
+
print("listen:",i)
|
| 546 |
+
time.sleep(2.0)
|
| 547 |
+
iml.owari=True
|
| 548 |
+
#sys.exit()
|
| 549 |
+
#
|
wr.py → mw.py
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
robe_version="1;;"
|
| 3 |
-
##import sys;import os;sys.path.append(os.environ["cpy"]+r"\Mjmoji");from
|
| 4 |
##import mlwebOrWeb as ml
|
| 5 |
## wardrobe
|
| 6 |
|
|
@@ -33,6 +33,10 @@ else:
|
|
| 33 |
|
| 34 |
class p310:# require version
|
| 35 |
def __getstate__(zl):return #pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def typeint(w):
|
| 37 |
try:
|
| 38 |
int(w)
|
|
@@ -335,7 +339,7 @@ class pushd:
|
|
| 335 |
os.chdir(sl.dL)
|
| 336 |
def chdirc(fil=0,idx=1):# mv to z droped file
|
| 337 |
if not fil:fil=sys.argv[1:]
|
| 338 |
-
if isinstance(fil,(
|
| 339 |
if not fil:
|
| 340 |
pr("please drop off the file");input("chdirc()");
|
| 341 |
else:
|
|
@@ -439,8 +443,7 @@ def dq(te):#double quote
|
|
| 439 |
return '"'+te+'"';
|
| 440 |
def prit(*w):
|
| 441 |
te=jw(" ", [str(f) for f in w])+lf;
|
| 442 |
-
|
| 443 |
-
print("exit-")
|
| 444 |
print(te, end="");
|
| 445 |
if w[:1]==(1,):input("*")
|
| 446 |
sys.exit();
|
|
@@ -553,12 +556,14 @@ def perf_counter():
|
|
| 553 |
return time.perf_counter()-_perf_counter0
|
| 554 |
def timepref(w=5,n=2):# zero width, after z decimal point
|
| 555 |
return time.strftime("%Y%m%d-%H%M%S")+"-{t:0{w}d}".format(w=w,t=time.perf_counter_ns()//(1000000000//10**n))
|
| 556 |
-
from datetime import datetime
|
|
|
|
|
|
|
| 557 |
_now=0
|
| 558 |
-
def tp(te="%Y%m%d-%H%M%S",n=2):#%f
|
| 559 |
global _now
|
| 560 |
while 1:
|
| 561 |
-
((t:=datetime.now()))
|
| 562 |
now=t.strftime(te)
|
| 563 |
if n:now+="-{}".format(f"{t.microsecond:06}"[:n])
|
| 564 |
if _now!=now:break
|
|
@@ -782,7 +787,7 @@ def sas(reg,te,bug=False,**ww):
|
|
| 782 |
#li2.extend([f for f in ri[0].sub(lambda e:ri[0].sub(ri[1],e), ta) if f])
|
| 783 |
li2.extend([f for f in ri.findall(ta) if f])
|
| 784 |
teli=li2
|
| 785 |
-
if bug: afdt(r"r:\
|
| 786 |
return teli
|
| 787 |
def traverse(reg,te,bug=False,**ww):
|
| 788 |
fn=reg; #fn.teli=[te]
|
|
@@ -956,10 +961,10 @@ def popen1(cmd,shell=True):
|
|
| 956 |
return p.Popen(cmd,shell=shell).wait()
|
| 957 |
##orPOA(r'start cmd /c "r:\c f.bat"')
|
| 958 |
def wiff(w):
|
| 959 |
-
orPOA([
|
| 960 |
def npp(*w):
|
| 961 |
-
if not w: return
|
| 962 |
-
orPOA([
|
| 963 |
def nppw(lis,fn=tfolder+"/log"):
|
| 964 |
wfd(fn).t(lis)
|
| 965 |
npp(fn)
|
|
@@ -1282,7 +1287,7 @@ def ywalk(dn=None,dr=0,pop=-1):
|
|
| 1282 |
continue
|
| 1283 |
break
|
| 1284 |
while 0:
|
| 1285 |
-
sn=
|
| 1286 |
dnd=os.path.dirname(sn.dn)
|
| 1287 |
if(dnd in [r"c:\v"]): break
|
| 1288 |
for cd,fs,fp in ywalk(dnd):
|
|
@@ -1602,12 +1607,12 @@ r"C:\Users\user\Downloads\dval\t9",
|
|
| 1602 |
xcore=clfn(dirs=pmfolder)
|
| 1603 |
#
|
| 1604 |
def _gettps(fnzv,dncore):
|
| 1605 |
-
fnzv= fnzv or jofn(
|
| 1606 |
itemdict=eval(wfd(fnzv).r())
|
| 1607 |
tps=itemdict.setdefault(dncore,dict())
|
| 1608 |
return tps
|
| 1609 |
def gettps(fnzv,dncore=None):
|
| 1610 |
-
fnzv=jofn(*[fnzv] if fnzv else (
|
| 1611 |
if ifexist(fnzv):
|
| 1612 |
tps=puni(eval(wfd(fnzv).r()))
|
| 1613 |
else:tps=puni()
|
|
@@ -1615,8 +1620,8 @@ def gettps(fnzv,dncore=None):
|
|
| 1615 |
return tps
|
| 1616 |
#
|
| 1617 |
|
| 1618 |
-
##class
|
| 1619 |
-
class
|
| 1620 |
def __init__(zl,*aw,**kw):
|
| 1621 |
## super
|
| 1622 |
for f in aw: zl.update(f)
|
|
@@ -1635,7 +1640,6 @@ class hhwrproto(p310, dict):
|
|
| 1635 |
zl.pop(f,0)
|
| 1636 |
return zl
|
| 1637 |
#def copy():
|
| 1638 |
-
#class hhwrx(hhwr):
|
| 1639 |
def hh(zl,li=None):
|
| 1640 |
zl.parser = ArgumentParser()
|
| 1641 |
zl.parser.add_argument("fil",nargs="*")#all other
|
|
@@ -1662,20 +1666,20 @@ class hhwrproto(p310, dict):
|
|
| 1662 |
def __getattr__(zl,at):
|
| 1663 |
return zl[at]
|
| 1664 |
## def __vars__(zl):wefw
|
| 1665 |
-
class
|
| 1666 |
def __getattr__(zl,at):
|
| 1667 |
return zl.get(at)
|
| 1668 |
return None
|
| 1669 |
-
|
| 1670 |
-
##prexit((
|
| 1671 |
-
##prexit((
|
| 1672 |
-
##w=
|
| 1673 |
-
##print(
|
| 1674 |
##print("vars;",vars(w))
|
| 1675 |
-
###print(
|
| 1676 |
-
##print(dict(**
|
| 1677 |
-
##prexit(
|
| 1678 |
-
cls=
|
| 1679 |
cls.mp4="mp3|mp4|mkv|flv|ogg|webm"
|
| 1680 |
#
|
| 1681 |
def set2(sl,ob,value):
|
|
@@ -1701,12 +1705,12 @@ def jsonload(fn,tfn="",pl="json",flw=0,fltmp=1):
|
|
| 1701 |
if pl=="json": te=wfd(tfn).r()
|
| 1702 |
if pl=="p": te=wfd(tfn).rb()
|
| 1703 |
js=fp[0](te or "")
|
| 1704 |
-
else:js=
|
| 1705 |
def log(te=js):
|
| 1706 |
if fltmp:wfd(tfn).t(fp[1](te))
|
| 1707 |
else: wfd(tfn).w(fp[1](te), copy=0)
|
| 1708 |
if flw: log(flw)
|
| 1709 |
-
table=
|
| 1710 |
return table, js, tfn, log
|
| 1711 |
def wfupdate(fn,pat,count):
|
| 1712 |
imw=wfd(fn)
|
|
@@ -1731,7 +1735,7 @@ if 1:
|
|
| 1731 |
def x4():
|
| 1732 |
return impt(cpy+"/Generator/x4orlexi")
|
| 1733 |
def xfil(ap,flinput=1):
|
| 1734 |
-
hh=
|
| 1735 |
fl=hh.fil
|
| 1736 |
if hh.fil:fl= hh.fil
|
| 1737 |
elif flinput:
|
|
@@ -1776,9 +1780,10 @@ def impt(fn,reload=True, lazy=False, **_):
|
|
| 1776 |
if ifexist(f9:=(f9+".py")):break
|
| 1777 |
if 1:
|
| 1778 |
if not ifexist(f9): f9+=".py"
|
|
|
|
| 1779 |
spec=importtool.spec_from_file_location(cf,f9)
|
| 1780 |
assert spec, "import from file location;"+f9
|
| 1781 |
-
|
| 1782 |
if lazy: spec.loader = LazyLoader(spec.loader)
|
| 1783 |
mod = module_from_spec(spec)
|
| 1784 |
sys.modules[cf] = mod
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
robe_version="1;;"
|
| 3 |
+
##import sys;import os;sys.path.append(os.environ["cpy"]+r"\Mjmoji");from mw import * ;
|
| 4 |
##import mlwebOrWeb as ml
|
| 5 |
## wardrobe
|
| 6 |
|
|
|
|
| 33 |
|
| 34 |
class p310:# require version
|
| 35 |
def __getstate__(zl):return #pickle
|
| 36 |
+
def rint(w):
|
| 37 |
+
if not typeint(w):
|
| 38 |
+
assert 0,"not rint"
|
| 39 |
+
return int(w)
|
| 40 |
def typeint(w):
|
| 41 |
try:
|
| 42 |
int(w)
|
|
|
|
| 339 |
os.chdir(sl.dL)
|
| 340 |
def chdirc(fil=0,idx=1):# mv to z droped file
|
| 341 |
if not fil:fil=sys.argv[1:]
|
| 342 |
+
if isinstance(fil,(hhww)): fil=fil.fil
|
| 343 |
if not fil:
|
| 344 |
pr("please drop off the file");input("chdirc()");
|
| 345 |
else:
|
|
|
|
| 443 |
return '"'+te+'"';
|
| 444 |
def prit(*w):
|
| 445 |
te=jw(" ", [str(f) for f in w])+lf;
|
| 446 |
+
print("---")
|
|
|
|
| 447 |
print(te, end="");
|
| 448 |
if w[:1]==(1,):input("*")
|
| 449 |
sys.exit();
|
|
|
|
| 556 |
return time.perf_counter()-_perf_counter0
|
| 557 |
def timepref(w=5,n=2):# zero width, after z decimal point
|
| 558 |
return time.strftime("%Y%m%d-%H%M%S")+"-{t:0{w}d}".format(w=w,t=time.perf_counter_ns()//(1000000000//10**n))
|
| 559 |
+
from datetime import datetime, timedelta, timezone
|
| 560 |
+
JST = timezone(timedelta(hours=+9), 'JST')
|
| 561 |
+
##def today():
|
| 562 |
_now=0
|
| 563 |
+
def tp(te="%Y%m%d-%H%M%S",n=2, JST=JST ):#%f
|
| 564 |
global _now
|
| 565 |
while 1:
|
| 566 |
+
((t:=datetime.now(JST)))
|
| 567 |
now=t.strftime(te)
|
| 568 |
if n:now+="-{}".format(f"{t.microsecond:06}"[:n])
|
| 569 |
if _now!=now:break
|
|
|
|
| 787 |
#li2.extend([f for f in ri[0].sub(lambda e:ri[0].sub(ri[1],e), ta) if f])
|
| 788 |
li2.extend([f for f in ri.findall(ta) if f])
|
| 789 |
teli=li2
|
| 790 |
+
if bug: afdt(r"r:\fwfw-search.txt","mrk{}\n".format(ix)+ppf(teli))
|
| 791 |
return teli
|
| 792 |
def traverse(reg,te,bug=False,**ww):
|
| 793 |
fn=reg; #fn.teli=[te]
|
|
|
|
| 961 |
return p.Popen(cmd,shell=shell).wait()
|
| 962 |
##orPOA(r'start cmd /c "r:\c f.bat"')
|
| 963 |
def wiff(w):
|
| 964 |
+
orPOA([mdir("wiff"),*w])
|
| 965 |
def npp(*w):
|
| 966 |
+
if not w: return mdir("npp")
|
| 967 |
+
orPOA([mdir("npp"),*w])
|
| 968 |
def nppw(lis,fn=tfolder+"/log"):
|
| 969 |
wfd(fn).t(lis)
|
| 970 |
npp(fn)
|
|
|
|
| 1287 |
continue
|
| 1288 |
break
|
| 1289 |
while 0:
|
| 1290 |
+
sn=hhww(dn=listdir(r"c:\v\t",iref=isdir)[0])
|
| 1291 |
dnd=os.path.dirname(sn.dn)
|
| 1292 |
if(dnd in [r"c:\v"]): break
|
| 1293 |
for cd,fs,fp in ywalk(dnd):
|
|
|
|
| 1607 |
xcore=clfn(dirs=pmfolder)
|
| 1608 |
#
|
| 1609 |
def _gettps(fnzv,dncore):
|
| 1610 |
+
fnzv= fnzv or jofn(mdir("mtm"),"data","zv.txt")
|
| 1611 |
itemdict=eval(wfd(fnzv).r())
|
| 1612 |
tps=itemdict.setdefault(dncore,dict())
|
| 1613 |
return tps
|
| 1614 |
def gettps(fnzv,dncore=None):
|
| 1615 |
+
fnzv=jofn(*[fnzv] if fnzv else (mdir("mtm"),"data","zv"),dncore)
|
| 1616 |
if ifexist(fnzv):
|
| 1617 |
tps=puni(eval(wfd(fnzv).r()))
|
| 1618 |
else:tps=puni()
|
|
|
|
| 1620 |
return tps
|
| 1621 |
#
|
| 1622 |
|
| 1623 |
+
##class hhwwproto(dict):pass
|
| 1624 |
+
class hhwwproto(p310, dict):
|
| 1625 |
def __init__(zl,*aw,**kw):
|
| 1626 |
## super
|
| 1627 |
for f in aw: zl.update(f)
|
|
|
|
| 1640 |
zl.pop(f,0)
|
| 1641 |
return zl
|
| 1642 |
#def copy():
|
|
|
|
| 1643 |
def hh(zl,li=None):
|
| 1644 |
zl.parser = ArgumentParser()
|
| 1645 |
zl.parser.add_argument("fil",nargs="*")#all other
|
|
|
|
| 1666 |
def __getattr__(zl,at):
|
| 1667 |
return zl[at]
|
| 1668 |
## def __vars__(zl):wefw
|
| 1669 |
+
class hhww(hhwwproto):
|
| 1670 |
def __getattr__(zl,at):
|
| 1671 |
return zl.get(at)
|
| 1672 |
return None
|
| 1673 |
+
hhwwproto().str
|
| 1674 |
+
##prexit((hhww(w=2,f=4) - ("w",)).str())
|
| 1675 |
+
##prexit((hhww(w=2,f=4,ff=4)/"w"/"f").str())
|
| 1676 |
+
##w=hhww();w.f=2;pr(w.f)
|
| 1677 |
+
##print(hhww({"e":1},{"e":4}))
|
| 1678 |
##print("vars;",vars(w))
|
| 1679 |
+
###print(hhww().hh([("-f",str),("-re",str),("-ns",str)]).ho())
|
| 1680 |
+
##print(dict(**hhww(w=2)), {"ww":2})
|
| 1681 |
+
##prexit(hhww(w=2)==hhww(w=3), hhww()==hhww())
|
| 1682 |
+
cls=hhwwproto()
|
| 1683 |
cls.mp4="mp3|mp4|mkv|flv|ogg|webm"
|
| 1684 |
#
|
| 1685 |
def set2(sl,ob,value):
|
|
|
|
| 1705 |
if pl=="json": te=wfd(tfn).r()
|
| 1706 |
if pl=="p": te=wfd(tfn).rb()
|
| 1707 |
js=fp[0](te or "")
|
| 1708 |
+
else:js=hhww()
|
| 1709 |
def log(te=js):
|
| 1710 |
if fltmp:wfd(tfn).t(fp[1](te))
|
| 1711 |
else: wfd(tfn).w(fp[1](te), copy=0)
|
| 1712 |
if flw: log(flw)
|
| 1713 |
+
table=hhww(t=js,l=len(js),fn=fn,tfn=tfn,log=log)
|
| 1714 |
return table, js, tfn, log
|
| 1715 |
def wfupdate(fn,pat,count):
|
| 1716 |
imw=wfd(fn)
|
|
|
|
| 1735 |
def x4():
|
| 1736 |
return impt(cpy+"/Generator/x4orlexi")
|
| 1737 |
def xfil(ap,flinput=1):
|
| 1738 |
+
hh=hhww().hh(ap).ho()
|
| 1739 |
fl=hh.fil
|
| 1740 |
if hh.fil:fl= hh.fil
|
| 1741 |
elif flinput:
|
|
|
|
| 1780 |
if ifexist(f9:=(f9+".py")):break
|
| 1781 |
if 1:
|
| 1782 |
if not ifexist(f9): f9+=".py"
|
| 1783 |
+
assert ifexist(f9), "module not found: "+fn
|
| 1784 |
spec=importtool.spec_from_file_location(cf,f9)
|
| 1785 |
assert spec, "import from file location;"+f9
|
| 1786 |
+
#print("spec;",[ spec.name, spec.origin], flush=True)
|
| 1787 |
if lazy: spec.loader = LazyLoader(spec.loader)
|
| 1788 |
mod = module_from_spec(spec)
|
| 1789 |
sys.modules[cf] = mod
|
neo server.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
|
|
|
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
##!kill -9 "$(pgrep ngrok)"
|
| 4 |
import sys; import os; cpa=os.environ.get("cpa")
|
|
@@ -12,7 +13,9 @@ if not os.path.isdir(f:="c2"): repo_clone("https://huggingface.co/spaces/compile
|
|
| 12 |
#
|
| 13 |
face="1000"
|
| 14 |
##face="face"
|
| 15 |
-
if os.environ.get("SPACE_HOST"):
|
|
|
|
|
|
|
| 16 |
if face=="face":1
|
| 17 |
elif not cpa:
|
| 18 |
## from google.colab import drive
|
|
@@ -24,8 +27,8 @@ elif not cpa:
|
|
| 24 |
os.environ["tmp"]="/tmp"; os.makedirs("/tmp",exist_ok=True)
|
| 25 |
else:
|
| 26 |
import sys;import os;sys.path.append(os.environ["cpy"]+r"\Mjmoji");
|
| 27 |
-
##from
|
| 28 |
-
from
|
| 29 |
|
| 30 |
|
| 31 |
import flask as flas
|
|
@@ -39,7 +42,7 @@ disablelog()
|
|
| 39 |
|
| 40 |
import json
|
| 41 |
app = Flask(__name__)
|
| 42 |
-
app.mimi=
|
| 43 |
app.t0=time.perf_counter()
|
| 44 |
handle_post="/handle_post"
|
| 45 |
if face=="face":
|
|
@@ -53,12 +56,13 @@ elif not cpa:
|
|
| 53 |
port=5000
|
| 54 |
conf.get_default().monitor_thread = False
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
except:
|
| 58 |
ngrok.kill()
|
| 59 |
sys.exit()
|
| 60 |
-
print("tunnel \"{}\" -> \"
|
| 61 |
-
|
|
|
|
| 62 |
#
|
| 63 |
|
| 64 |
def pr2(*w): print(*w)
|
|
@@ -79,7 +83,8 @@ def run1(data):
|
|
| 79 |
@app.post(handle_post)
|
| 80 |
def handle_post():
|
| 81 |
header=(dict(request.headers));
|
| 82 |
-
if
|
|
|
|
| 83 |
try:
|
| 84 |
#print(request.get_data())
|
| 85 |
if request.is_json and (data:=request.get_json()):
|
|
|
|
| 1 |
|
| 2 |
+
|
| 3 |
# -*- coding: utf-8 -*-
|
| 4 |
##!kill -9 "$(pgrep ngrok)"
|
| 5 |
import sys; import os; cpa=os.environ.get("cpa")
|
|
|
|
| 13 |
#
|
| 14 |
face="1000"
|
| 15 |
##face="face"
|
| 16 |
+
if os.environ.get("SPACE_HOST"):
|
| 17 |
+
face="face"
|
| 18 |
+
saty=os.environ.get("saty")
|
| 19 |
if face=="face":1
|
| 20 |
elif not cpa:
|
| 21 |
## from google.colab import drive
|
|
|
|
| 27 |
os.environ["tmp"]="/tmp"; os.makedirs("/tmp",exist_ok=True)
|
| 28 |
else:
|
| 29 |
import sys;import os;sys.path.append(os.environ["cpy"]+r"\Mjmoji");
|
| 30 |
+
##from mw import wfd, inidi, impt, time
|
| 31 |
+
from mw import *
|
| 32 |
|
| 33 |
|
| 34 |
import flask as flas
|
|
|
|
| 42 |
|
| 43 |
import json
|
| 44 |
app = Flask(__name__)
|
| 45 |
+
app.mimi=hhww()
|
| 46 |
app.t0=time.perf_counter()
|
| 47 |
handle_post="/handle_post"
|
| 48 |
if face=="face":
|
|
|
|
| 56 |
port=5000
|
| 57 |
conf.get_default().monitor_thread = False
|
| 58 |
try:
|
| 59 |
+
p = ngrok.connect(port).public_url
|
| 60 |
except:
|
| 61 |
ngrok.kill()
|
| 62 |
sys.exit()
|
| 63 |
+
print("tunnel \"{}\" -> \"://127.0.0.1:{}\"".format(p, port))
|
| 64 |
+
apl({"fp":"up2", "dir":"w", "fn":"f", "te":json.dumps({"dres":p, "date":repr(time.time())})})
|
| 65 |
+
app.config["BASE_URL"] = p
|
| 66 |
#
|
| 67 |
|
| 68 |
def pr2(*w): print(*w)
|
|
|
|
| 83 |
@app.post(handle_post)
|
| 84 |
def handle_post():
|
| 85 |
header=(dict(request.headers));
|
| 86 |
+
if not saty: '{"e2":"set pass"}'
|
| 87 |
+
if header.get("Saty")!=saty:return '{"e2":"set header"}'
|
| 88 |
try:
|
| 89 |
#print(request.get_data())
|
| 90 |
if request.is_json and (data:=request.get_json()):
|
tofu_edit.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
-
##import sys;sys.path.append("N:\\afilen\\program\\python\\Mjmoji");from
|
| 3 |
import sys
|
| 4 |
import time
|
| 5 |
from ctypes import *
|
| 6 |
import subprocess as p
|
| 7 |
-
from
|
| 8 |
|
| 9 |
def scroll(*ww):
|
| 10 |
import edit_
|
|
@@ -65,7 +65,7 @@ def ctod( text ,sh=True,cp="cp932",si=None):
|
|
| 65 |
## cp="cp932"
|
| 66 |
## return retcode,r.decode(cp),er.decode(cp),ip
|
| 67 |
res=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n") for te in res]
|
| 68 |
-
from
|
| 69 |
res=[vcs(te) for te in res]
|
| 70 |
return retcode,*res,ip
|
| 71 |
def Runw(li): ctod(li,sh=False)
|
|
@@ -81,7 +81,7 @@ class cltof():
|
|
| 81 |
zl.lock=th.Lock()
|
| 82 |
os.environ['PYTHONIOENCODING'] = 'utf-8'
|
| 83 |
def ctof(zl,cb,to, text ,null=""):
|
| 84 |
-
from
|
| 85 |
zl.ev.clear()
|
| 86 |
if 0==to:to=3600*12
|
| 87 |
time0=time.perf_counter()
|
|
@@ -134,7 +134,7 @@ class cltof():
|
|
| 134 |
return t
|
| 135 |
@property
|
| 136 |
def te(zl):
|
| 137 |
-
from
|
| 138 |
if 1:
|
| 139 |
logfile=zl.logfile
|
| 140 |
lir=list(open(f,"rb").read() for f in logfile)
|
|
@@ -152,6 +152,11 @@ class cltof():
|
|
| 152 |
def put(p,te):
|
| 153 |
p.ip.stdin.write(te.encode())
|
| 154 |
p.ip.stdin.flush()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
def ctof(*w):
|
| 156 |
p=cltof()
|
| 157 |
p.ctof(*w)
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
+
##import sys;sys.path.append("N:\\afilen\\program\\python\\Mjmoji");from mw import *
|
| 3 |
import sys
|
| 4 |
import time
|
| 5 |
from ctypes import *
|
| 6 |
import subprocess as p
|
| 7 |
+
from mw import *
|
| 8 |
|
| 9 |
def scroll(*ww):
|
| 10 |
import edit_
|
|
|
|
| 65 |
## cp="cp932"
|
| 66 |
## return retcode,r.decode(cp),er.decode(cp),ip
|
| 67 |
res=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n") for te in res]
|
| 68 |
+
from mw import vcs
|
| 69 |
res=[vcs(te) for te in res]
|
| 70 |
return retcode,*res,ip
|
| 71 |
def Runw(li): ctod(li,sh=False)
|
|
|
|
| 81 |
zl.lock=th.Lock()
|
| 82 |
os.environ['PYTHONIOENCODING'] = 'utf-8'
|
| 83 |
def ctof(zl,cb,to, text ,null=""):
|
| 84 |
+
from mw import vcs, tp, wfd
|
| 85 |
zl.ev.clear()
|
| 86 |
if 0==to:to=3600*12
|
| 87 |
time0=time.perf_counter()
|
|
|
|
| 134 |
return t
|
| 135 |
@property
|
| 136 |
def te(zl):
|
| 137 |
+
from mw import vcs
|
| 138 |
if 1:
|
| 139 |
logfile=zl.logfile
|
| 140 |
lir=list(open(f,"rb").read() for f in logfile)
|
|
|
|
| 152 |
def put(p,te):
|
| 153 |
p.ip.stdin.write(te.encode())
|
| 154 |
p.ip.stdin.flush()
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
def ctof(*w):
|
| 161 |
p=cltof()
|
| 162 |
p.ctof(*w)
|
zipOrZip.py
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 12 |
+
f = gzip.GzipFile(fileobj=buf)
|
| 13 |
+
data = f.read()
|
| 14 |
+
return data;
|
| 15 |
+
def wbgz(te):#writeBuffer
|
| 16 |
+
buf = BytesIO()
|
| 17 |
+
f = gzip.GzipFile(fileobj=buf,mode="wb")
|
| 18 |
+
f.write(te);
|
| 19 |
+
f.close()#neccesery
|
| 20 |
+
return buf.getvalue();
|
| 21 |
+
def wfgz(fn,te):#writeFile
|
| 22 |
+
f = gzip.open(fn,"wb")
|
| 23 |
+
data = f.write(te)
|
| 24 |
+
f.close()#同じ名前のファイルがあるとRenameと同じ挙動に
|
| 25 |
+
def wfbz(fn,te):#writeFile
|
| 26 |
+
f = bz2.BZ2File(fn,"wb")
|
| 27 |
+
data = f.write(te)
|
| 28 |
+
f.close()
|
| 29 |
+
def writebzb(te):#writeFilebz Buffer
|
| 30 |
+
buf = BytesIO()
|
| 31 |
+
f = bz2.BZ2File(fileobj=buf,mode="wb")#fileobj not work
|
| 32 |
+
data = f.write(te)
|
| 33 |
+
f.close()
|
| 34 |
+
return buf.getvalue()
|
| 35 |
+
def tarlist(fn):
|
| 36 |
+
with tf.open(fn,"r") as ta:
|
| 37 |
+
return tf.list()
|
| 38 |
+
def tarprint(fn):
|
| 39 |
+
## with tarfile.open(fn,"r") as ta:
|
| 40 |
+
## print(ta.list())
|
| 41 |
+
ta=tarfile.open(fn,"r")
|
| 42 |
+
print(ta.list())
|
| 43 |
+
for tarinfo in ta:
|
| 44 |
+
print(tarinfo.name,tarinfo.size, ## datetime.fromtimestamp(tarinfo.mtime),
|
| 45 |
+
tarinfo.mtime, oct(tarinfo.mode), tarinfo.uname, tarinfo.gname)
|
| 46 |
+
ta.close()
|
| 47 |
+
def tfread(tfn,fn):
|
| 48 |
+
with tarfile.open(tfn,"r") as ta:
|
| 49 |
+
ti = ta.getmember(fn)
|
| 50 |
+
f = ta.extractfile(ti)
|
| 51 |
+
te= f.read()
|
| 52 |
+
return te ;
|
| 53 |
+
def writeExtract(dist,fns=()):
|
| 54 |
+
if(type(fns)==str):
|
| 55 |
+
with tarfile.open(fns) as ta:
|
| 56 |
+
ta.extractall(dist)
|
| 57 |
+
def writexz(fn,li3,mode='w|xz'):codetar(li3=li3,mode=mode,fn=fn);
|
| 58 |
+
def codetar(li3,mode='w|',bio=BytesIO(),fn=""):
|
| 59 |
+
with tarfile.open(name=fn, mode=mode, fileobj=(bio if not fn else None))as ta:
|
| 60 |
+
for src,dist in li3:
|
| 61 |
+
ta.add(src,dist)
|
| 62 |
+
return bio
|
| 63 |
+
def zipread(zfn,fn="",pwd=None):
|
| 64 |
+
with zipfile.ZipFile(zfn,"r") as zfo:
|
| 65 |
+
if not fn:return zfo.infolist()
|
| 66 |
+
#fo=zfo.open(fn,"r",pwd=pwd)
|
| 67 |
+
data=zfo.read(fn,pwd=pwd)
|
| 68 |
+
return data
|
| 69 |
+
def zipwrites_full(zfn,li,compress=zipfile.ZIP_DEFLATED, pwd=None):
|
| 70 |
+
#passward not supported
|
| 71 |
+
with zipfile.ZipFile(zfn,"w",compression=compress) as zfo:
|
| 72 |
+
for rfn,wfn in li:
|
| 73 |
+
zfo.write(rfn,wfn)
|
| 74 |
+
return zfo.infolist()
|
| 75 |
+
def zipwrites(zfn,li,compress=zipfile.ZIP_DEFLATED, pwd=None):
|
| 76 |
+
zipwrites_full(zfn,[(fn,fn) for fn in li],compress=compress, pwd=pwd)
|
| 77 |
+
def zipwrites_dir(zfn,dirn,*aw,**kw):
|
| 78 |
+
import itertools
|
| 79 |
+
imw=(itertools.chain.from_iterable(([jofn(r,fn) for fn in (ds+fs)] for r, ds, fs in os.walk(dirn) ) ))
|
| 80 |
+
## dire=kah.split("\\")[-1]
|
| 81 |
+
li=[(i,i[len(dirn):]) for i in imw]
|
| 82 |
+
zipwrites_full(zfn,li,*aw,**kw)
|
| 83 |
+
#zipwrites_dir(r"r:\isshonisino.zip",r"r:\temp",compress=zipfile.ZIP_STORED)
|
| 84 |
+
def zipbufi(li):
|
| 85 |
+
buf = BytesIO()
|
| 86 |
+
with zipfile.ZipFile(buf,mode="w") as fo:
|
| 87 |
+
for p,te in li:
|
| 88 |
+
fo.writestr(p,te);
|
| 89 |
+
## if type(te)==str: fo.writestr(p,te);
|
| 90 |
+
## else: fo.write(p,te)
|
| 91 |
+
#print(buf.getvalue())
|
| 92 |
+
return buf;
|
| 93 |
+
def zipbuf():
|
| 94 |
+
#buf=zipbufi([(r"v/w.txt","vw"),("new folder/",""),(r"ほのか","weffw")])
|
| 95 |
+
buf=zipbufi([(r"nf/nf/0.txt","vw"),("cmczip.com.url",""),(r"nf/nf/cmczip.com.url","")])
|
| 96 |
+
#buf=BytesIO(buflk)
|
| 97 |
+
inf=zipread(buf)
|
| 98 |
+
wr.wfdb(r"c:\v\t\ziptst.zip",buf.getbuffer())
|
| 99 |
+
print(inf)
|
| 100 |
+
#zipbuf()
|
| 101 |
+
def ziplvlv():
|
| 102 |
+
b1 = BytesIO()
|
| 103 |
+
zipwrites_dir(b1,r"c:\v\t\lvlv")
|
| 104 |
+
buf=zipbufi([(r"v1.zip",b1.getbuffer()),("v2.zip",b1.getbuffer())])
|
| 105 |
+
zfn=r"c:\v\t\ziptst.zip"
|
| 106 |
+
wr.wfdb(zfn,buf.getbuffer())
|
| 107 |
+
print(zipread(zfn))
|
| 108 |
+
##ziplvlv()
|
| 109 |
+
|
| 110 |
+
#https://www.rarlab.com/rar_add.htm
|
| 111 |
+
os.environ["UNRAR_LIB_PATH"]=r"C:\dll\unrar64.dll"
|
| 112 |
+
try:
|
| 113 |
+
from unrar import rarfile
|
| 114 |
+
except:0
|
| 115 |
+
def ur(fn):
|
| 116 |
+
ro=rarfile.RarFile(fn)
|
| 117 |
+
#ro.comment
|
| 118 |
+
## print(ro.namelist())
|
| 119 |
+
## ro.printdir()
|
| 120 |
+
fs=ro.infolist()
|
| 121 |
+
for fo in fs[:4]+fs[-2:]:
|
| 122 |
+
print(fo.filename)
|
| 123 |
+
ro.extract(fo,dstfolder)
|
| 124 |
+
#for fn in (r"C:\v\jd\Nagato Yuki Shoushitsu v0%d.rar"%d for d in range(6,10)): #exc
|
| 125 |
+
from mw import rfdb, jofn, lfnb
|
| 126 |
+
class zo:
|
| 127 |
+
def ini1(self,zfn,tmpfolder=""):
|
| 128 |
+
self.zfn=zfn
|
| 129 |
+
self.tdn=tdn=jofn(tmpfolder,lfnb(zfn[0]))
|
| 130 |
+
if not os.path.exists(tdn):
|
| 131 |
+
os.makedirs(tdn)
|
| 132 |
+
else: return self
|
| 133 |
+
if 1:
|
| 134 |
+
self.tfread=self.tfread
|
| 135 |
+
for f in zfn: writeExtract(tdn,f)#4 bcmodified
|
| 136 |
+
else:
|
| 137 |
+
self.tfread=self.tfread
|
| 138 |
+
return self
|
| 139 |
+
def fpfn(self,fn): return jofn(self.tdn, fn)
|
| 140 |
+
def tfread(self,zfn,fn):
|
| 141 |
+
return rfdb(jofn(self.tdn, fn))
|
| 142 |
+
## def __iter__(self):
|
| 143 |
+
## for f in tempfolder
|
| 144 |
+
def __enter__(self):
|
| 145 |
+
return 1
|
| 146 |
+
def __exit__(self, _type, value, traceback):
|
| 147 |
+
self.tdn
|
| 148 |
+
def rmtmp(self):
|
| 149 |
+
import shutil
|
| 150 |
+
from datetime import datetime, date, timedelta
|
| 151 |
+
import time
|
| 152 |
+
ctime=os.path.getctime(self.tdn)
|
| 153 |
+
ctime=datetime.fromtimestamp(ctime)
|
| 154 |
+
flnew=datetime.now()-timedelta(hours=2) < ctime
|
| 155 |
+
print("remove;",ctime, self.tdn, f"{flnew=}")
|
| 156 |
+
if flnew: shutil.rmtree(self.tdn)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
#
|
| 160 |
+
import random
|
| 161 |
+
import string
|
| 162 |
+
import uuid
|
| 163 |
+
import hashlib
|
| 164 |
+
#hashlib.sha1(b"kanata").hexdigest()
|
| 165 |
+
def mkOneTime():return mkPas(uuid.uuid4())
|
| 166 |
+
def mk1p():return print(mkPas(uuid.uuid4(),l=12,letters="d!?-_#"))#keyboard friendly pass
|
| 167 |
+
def mkPas(k,l=24,letters="ad"):
|
| 168 |
+
diLe={"a":string.ascii_letters, "d": string.digits, "p":string.punctuation}
|
| 169 |
+
diLe.update([(p,p)for p in string.punctuation])
|
| 170 |
+
letters=jw("",[diLe[c]for c in letters])
|
| 171 |
+
print(letters)
|
| 172 |
+
#
|
| 173 |
+
random.seed(k)
|
| 174 |
+
return (jw('',[random.choice(letters) for i in range(l)]))
|
| 175 |
+
def mkKey(k,l=1234,l2=1):#initial vector, rn key len, range*256
|
| 176 |
+
random.seed(k)
|
| 177 |
+
rn=[random.randrange(0,l2*0x100) for i in range(l)]
|
| 178 |
+
return rn
|
| 179 |
+
def visunel(k,te):
|
| 180 |
+
t2=[(v+k[i%len(k)])%6 for i,v in enumerate(te)]
|
| 181 |
+
return t2
|
| 182 |
+
def visuner(k,te):
|
| 183 |
+
t2=[(v+256-k[i%len(k)])%6 for i,v in enumerate(te)]
|
| 184 |
+
return t2
|
| 185 |
+
def visunex(k,te):return bytearray([(v^k[i%len(k)]) for i,v in enumerate(te)])#xor
|
| 186 |
+
import array
|
| 187 |
+
import struct
|
| 188 |
+
#http://docs.python.jp/3/library/struct.html
|
| 189 |
+
def pwdlen(pwd):
|
| 190 |
+
if(type(pwd)==int):
|
| 191 |
+
a
|
| 192 |
+
def imagineL(pwd,data,fn):
|
| 193 |
+
datas=[bytes(v)for v in [fn,pwd,data]]
|
| 194 |
+
lens=[len(i)for i in datas];#(len(pwd),len(data),len(fn),)
|
| 195 |
+
ba=bytearray(4*len(lens)+ sum(lens))
|
| 196 |
+
## p1=struct.pack("III"+jw("",[(str(i)+"s")for i in lens]), *lens)
|
| 197 |
+
p1=struct.pack("III"+jw("",[(str(i)+"s")for i in lens]), *lens+datas)
|
| 198 |
+
#struct.pack_into("2s",ba,0,b"j")
|
| 199 |
+
## return p1
|
| 200 |
+
##def imagineL(pwd,data,fn):
|
| 201 |
+
datas=[fn,pwd,data]
|
| 202 |
+
lens=struct.unpack("III", p1[:12])
|
| 203 |
+
p2r=struct.unpack("III"+jw("",[(str(i)+"s")for i in lens]), p1)
|
| 204 |
+
print(p2r)
|
| 205 |
+
return p2r
|
| 206 |
+
def main():
|
| 207 |
+
hh=wr.hhww(mojibake=0)
|
| 208 |
+
z="gz";
|
| 209 |
+
fn="fn."+z;
|
| 210 |
+
te=wr.rfdb(wr.sys.argv[0]);
|
| 211 |
+
tfn=r"N:\dpDict\naist-jdic-0.4.3.tar.gz"
|
| 212 |
+
tfn2=["unimj.txt","orror00.txt"]
|
| 213 |
+
import os
|
| 214 |
+
import re
|
| 215 |
+
if 0:
|
| 216 |
+
wr.inidir("testfldr\\")
|
| 217 |
+
tarprint(tfn)
|
| 218 |
+
ta=tarfile.open("testfldr\\ふぁいる.tar.gz","w:gz")
|
| 219 |
+
for n in tfn2 : ta.add(n)
|
| 220 |
+
ta.close()
|
| 221 |
+
print(tfread(tfn,"naist-jdic-0.4.3/README").decode("cp932"))
|
| 222 |
+
if 0:
|
| 223 |
+
wfgz(fn,te);
|
| 224 |
+
wfbz("fあみn.txt.bz2",te);#文字化け
|
| 225 |
+
## wfbz(str("あいう.txt.bz2".encode("mbcs")),te);
|
| 226 |
+
bf=wbgz(te);
|
| 227 |
+
wr.wfdb("f2.txt.gz",bf);
|
| 228 |
+
pass
|
| 229 |
+
if 0:#NoWork
|
| 230 |
+
bf=writebzb(te);
|
| 231 |
+
def tes2():
|
| 232 |
+
randkey=mkKey("key",22,1)
|
| 233 |
+
print(randkey)
|
| 234 |
+
randkey=mkKey("key2",22,1)
|
| 235 |
+
print(randkey)
|
| 236 |
+
coded=visunel(randkey, "amiあみ".encode("utf8"))
|
| 237 |
+
raw=visuner(randkey,coded)
|
| 238 |
+
print(coded,bytes(coded),raw, bytes(raw).decode())
|
| 239 |
+
print("xor",visunex(randkey, visunex(randkey, "amiあみ".encode("utf8"))))
|
| 240 |
+
#
|
| 241 |
+
imagineL(randkey,coded,b"ami.c")
|
| 242 |
+
#
|
| 243 |
+
mk1p();print(mkOneTime())
|
| 244 |
+
## class ca(io.m):
|
| 245 |
+
class ca(io.BufferedIOBase):
|
| 246 |
+
## class ca(io.BytesIO):
|
| 247 |
+
def __init__(sl,ar):
|
| 248 |
+
sl.ar=ar
|
| 249 |
+
sl.p=0
|
| 250 |
+
def read(sl,ln):
|
| 251 |
+
## ri=io.BytesIO.read(sl,ln)
|
| 252 |
+
## return ri
|
| 253 |
+
ro=sl.ar[sl.p:sl.p+ln]
|
| 254 |
+
sl.p=sl.p+ln
|
| 255 |
+
return bytes(ro)
|
| 256 |
+
def write(sl,te):
|
| 257 |
+
sl.ar.extend(list(te))
|
| 258 |
+
## ri=io.BufferedWriter.write(sl,te)
|
| 259 |
+
## return ri
|
| 260 |
+
def getvalue(sl):
|
| 261 |
+
return bytes(sl.ar)
|
| 262 |
+
def j1():#no
|
| 263 |
+
return
|
| 264 |
+
buf=ca([])
|
| 265 |
+
with gzip.GzipFile(fileobj=buf,mode="wb") as go:
|
| 266 |
+
go.write(b"fwefwe")
|
| 267 |
+
wd=buf.getvalue()
|
| 268 |
+
with gzip.GzipFile(fileobj=buf) as go:
|
| 269 |
+
rd=go.read()
|
| 270 |
+
print(wd,rd)
|
| 271 |
+
#12
|
| 272 |
+
with open(r"r:\j12.gz","wb") as fo:
|
| 273 |
+
fo
|
| 274 |
+
def j2():#print sorted punctuation
|
| 275 |
+
"explorer '- !#$%&(),.;@[]^_`{}~+=0"#'- is ordered by following sign
|
| 276 |
+
cant=r'"*./:<>?\|'#'unaviable'
|
| 277 |
+
az="!#$%&'()+,-019;=@AZ[]^_`az{}~"#aviable
|
| 278 |
+
#
|
| 279 |
+
import os, time
|
| 280 |
+
if not(wr.ifexist(r"r:\fn")):os.makedirs(r"r:\fn")
|
| 281 |
+
#
|
| 282 |
+
diLe={"a":string.ascii_letters, "d": string.digits, "p":string.punctuation}
|
| 283 |
+
li1=[i for j in diLe.values() for i in j]+list("わあ")
|
| 284 |
+
li1.sort()
|
| 285 |
+
print(jw("",li1))
|
| 286 |
+
print(jw("",[ c for c in li1 if not c in cant]))
|
| 287 |
+
#
|
| 288 |
+
eFn=[]
|
| 289 |
+
for i,c in enumerate(li1):
|
| 290 |
+
if(c in r'"*/:<>?\|'):continue
|
| 291 |
+
try:
|
| 292 |
+
fn1=r"r:\fn\%s_d_x%x"%(c,i,ord(c))
|
| 293 |
+
wr.write8(fn1+".exe","")#exe 4 sendto
|
| 294 |
+
wr.write8(r"r:\fn\%c"%(c)+".exe","")
|
| 295 |
+
## os.utime(fn1,(time.mktime((2000,1,1,5,55,55,1,1,1)),0.0))
|
| 296 |
+
except Exception as e:# lkFileNotFoundError as e:
|
| 297 |
+
eFn.append((c,e))
|
| 298 |
+
print("eFn " + jw("",(c for c,e in eFn)))
|
| 299 |
+
ap=r"N:\driveK\applic\7za920\7za.exe"
|
| 300 |
+
def j4(fn=r"N:\afilen\program\python\Mjmoji",alias="files",pwd=""):#7z
|
| 301 |
+
with wr.cldir(fn):
|
| 302 |
+
fd=os.walk(fn)
|
| 303 |
+
fn1=[jofn(r,f) for r,ds,fs in fd for f in fs]
|
| 304 |
+
fn2=[os.path.relpath(j) for j in fn1]
|
| 305 |
+
if 1:
|
| 306 |
+
## fnt=[(f,os.path.split(f)[1]) for f in fn1]
|
| 307 |
+
fnt=[(f,os.path.relpath(f)) for f in fn1]
|
| 308 |
+
buf=codetar(fnt,mode="w|")
|
| 309 |
+
xz=r"r:\tar.tar.xz"
|
| 310 |
+
codetar(fnt,mode="w|xz",fn=xz)#idea. encoding="utf-8"
|
| 311 |
+
#
|
| 312 |
+
## codetar([(fp,"alfa\\"+rp)for fp,rp in fnt],mode="a",fn=r"r:\alf.tar.gz")
|
| 313 |
+
tarprint(xz)
|
| 314 |
+
#open
|
| 315 |
+
## with open(xz+"2","wb") as fo:
|
| 316 |
+
## fo
|
| 317 |
+
fns=fn2
|
| 318 |
+
j=fns[9]
|
| 319 |
+
cline=[ap,'a', 'r:\\j4.7z','-si']
|
| 320 |
+
print(cline)
|
| 321 |
+
ri=ctod(cline,sh=False,si=buf.getvalue())
|
| 322 |
+
print(jw(" ",[str(j)for j in ri]))
|
| 323 |
+
def j3(fn=r"N:\afilen\program\python\file",alias="files",pwd=""):#7z
|
| 324 |
+
with wr.cldir(fn):
|
| 325 |
+
ap=r"N:\driveK\applic\7za920\7za.exe"
|
| 326 |
+
#fns=os.listdir(fn);
|
| 327 |
+
fd=os.walk(fn)
|
| 328 |
+
fn1=[jofn(r,f) for r,ds,fs in fd for f in fs]
|
| 329 |
+
fn2=[os.path.relpath(j) for j in fn1]
|
| 330 |
+
fns=fn2
|
| 331 |
+
## jf=jw(" ",[jofn(fn,j)for j in fns])
|
| 332 |
+
#### print(jf)
|
| 333 |
+
## cline=ap+" a "+("-p%s "%pwd if pwd else "")+r"r:\j.7z "+jf
|
| 334 |
+
## ri=ctod(cline)
|
| 335 |
+
## print(ri)
|
| 336 |
+
## cline=ap+" a "+("-p%s "%pwd if pwd else "")+r"r:\stdin.7z -siSI/a "+jf
|
| 337 |
+
#### cline=ap+" a "+("-p%s "%pwd if pwd else "")+r'r:\stdin.7z -sir@list < '+jf
|
| 338 |
+
## cline=ap+" a "+("-p%s "%pwd if pwd else "")+r'r:\stdin.7z kakomj/mj.py'#idea
|
| 339 |
+
if 0:
|
| 340 |
+
ri=ctod(cline)
|
| 341 |
+
else:
|
| 342 |
+
for j in fns:
|
| 343 |
+
cline=ap+" a "+("-p%s "%pwd if pwd else "")+r"r:\j.7z "+'"%s"'%j
|
| 344 |
+
cline=[ap," a "+("-p%s "%pwd if pwd else "")+r"r:\j.7z "+'%s'%j]
|
| 345 |
+
cline=[ap,'a', 'r:\\j32.7z',j]#idea
|
| 346 |
+
print(cline)
|
| 347 |
+
ri=ctod(cline,sh=False)
|
| 348 |
+
print(ri)
|
| 349 |
+
## wr.prexit()
|
| 350 |
+
print(ri)
|
| 351 |
+
#
|
| 352 |
+
if 0:#no
|
| 353 |
+
cline=ap+" a "+("-p%s "%pwd if 0 else "")+r"r:/j3.7z "+r"-ir!N:\afilen\program\python\file\*.txt"
|
| 354 |
+
cline=ap+" a "+r" r:/j2.7z "+r" -ir!R:\temp\*.txt"#idea
|
| 355 |
+
cline=ap+" a "+r" j2 "+r' -ir!"N:\afilen\program\python\file\*.txt"'
|
| 356 |
+
## cline=ap+" a "+r" j2 "+r' -ir!"N:/afilen/program/python/file/*.txt"'
|
| 357 |
+
print(cline)
|
| 358 |
+
ri=ctod(cline)
|
| 359 |
+
print(ri)
|
| 360 |
+
## j4(fn=r"N:\afilen\program\python\file")
|
| 361 |
+
## j3()
|
| 362 |
+
## j2()
|
| 363 |
+
## j1()
|
| 364 |
+
if hh.mojibake:
|
| 365 |
+
zfn=r"C:\v\jd\Pic201377.zip"
|
| 366 |
+
info=zipread(zfn)
|
| 367 |
+
print(info)
|
| 368 |
+
#
|
| 369 |
+
with zipfile.ZipFile(zfn,"r") as zfo:
|
| 370 |
+
for im in zfo.infolist():#|namelist()
|
| 371 |
+
fn=im.filename
|
| 372 |
+
print(fn.encode('cp437').decode('cp932'))
|
| 373 |
+
def m0():
|
| 374 |
+
te=wr.rfdb(r"N:\afilen\program\python\work\d.html")
|
| 375 |
+
## buf = StringIO( te.decode("utf-8"))
|
| 376 |
+
buf = BytesIO( te)
|
| 377 |
+
f = gzip.GzipFile(fileobj=buf)
|
| 378 |
+
data = f.read()
|
| 379 |
+
|
| 380 |
+
f = open("tenkaiAfter"+".html","wb")
|
| 381 |
+
f.write(data)
|
| 382 |
+
f.close()
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
if __name__ == '__main__':
|
| 386 |
+
main()
|