server.py
import sys, socket, zlib, lxml, hashlib
import xml.etree.ElementTree as etree
tmpfile=sys.argv[2]
host=sys.argv[3]
port=int(sys.argv[4])
def mdhashing(instring):
m=hashlib.md5()
m.update(instring)
hashed=etree.Element("hashed",mdhash=m.digest())
return(etree.tostring(hashed))
def compressing(instring):
comptext=zlib.compress(instring,5)
return (comptext)
...
def fromfile(tmpfile):
f=open(tmpfile, "rb")#тут текстовик на 8 с копейками метров с данными формата: int:int!hex:int,hex:int:hex:int
h=f.read()
p=etree.Element("p", px=str(h))
restree=etree.tostring(p)
f.close()
return(restree+mdhashing(restree))
a=compressing(fromfile(tmpfile))
srv=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.bind((host,port))
srv.listen(1)
sock,addr=srv.accept()
sock.send(a,1024)
sock.close()
import socket, zlib, sys
from BeautifulSoup import BeautifulStoneSoup
host=sys.argv[2]
port=int(sys.argv[3])
def decompressing (instring):
decomp=zlib.decompress(instring)
return(decomp)
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host,port))
result1=sock.recv(1024)
result=decompress(result1)
tree=BeautifulStoneSoup(result)
print tree.prettify()
если запустить код:
import zlib
f=open("tmpfile", 'rb')
string=f.read()
cstring=zlib.compress(string)
dcstring=zlib.decompress(cstring)
print dcstring
f.close()
Подскажите, что я делаю не так?