failed hopes

This commit is contained in:
Christine Dodrill 2015-11-15 09:13:12 -08:00
parent 94738dd5db
commit c0d4330383
3 changed files with 11 additions and 6 deletions

View File

@ -66,7 +66,9 @@ class crlf_tcp(object):
while True: while True:
try: try:
data = self.recv_from_socket(4096) data = self.recv_from_socket(4096)
self.ibuffer += data print(type(self.ibuffer))
print(type(data))
self.ibuffer += (data.decode('utf-8'))
if data: if data:
last_timestamp = time.time() last_timestamp = time.time()
else: else:
@ -88,9 +90,11 @@ class crlf_tcp(object):
while True: while True:
line = self.oqueue.get().splitlines()[0][:500] line = self.oqueue.get().splitlines()[0][:500]
print(">>> %r" % line) print(">>> %r" % line)
self.obuffer += line.encode('utf-8', 'replace') + '\r\n'
while self.obuffer: self.obuffer += (line + '\r\n')
sent = self.socket.send(self.obuffer)
while len(self.obuffer) > 0:
sent = self.socket.send(self.obuffer.encode('utf-8', 'replace'))
self.obuffer = self.obuffer[sent:] self.obuffer = self.obuffer[sent:]

View File

@ -1,6 +1,7 @@
import fuckit import fuckit
import _thread import _thread
import traceback import traceback
import queue
_thread.stack_size(1024 * 512) # reduce vm size _thread.stack_size(1024 * 512) # reduce vm size
@ -99,7 +100,7 @@ class Handler(object):
def __init__(self, func): def __init__(self, func):
self.func = func self.func = func
self.input_queue = Queue.Queue() self.input_queue = queue.Queue()
_thread.start_new_thread(self.start, ()) _thread.start_new_thread(self.start, ())
def start(self): def start(self):

View File

@ -73,7 +73,7 @@ def normalize(url):
# Always use uppercase A-through-F characters when percent-encoding. # Always use uppercase A-through-F characters when percent-encoding.
# All portions of the URI must be utf-8 encoded NFC from Unicode strings # All portions of the URI must be utf-8 encoded NFC from Unicode strings
def clean(string): def clean(string):
string = str(unquote(string), 'utf-8', 'replace') string = b""+(unquote(string)).decode('utf-8', 'replace')
return unicodedata.normalize('NFC', string).encode('utf-8') return unicodedata.normalize('NFC', string).encode('utf-8')
path = quote(clean(path), "~:/?#[]@!$&'()*+,;=") path = quote(clean(path), "~:/?#[]@!$&'()*+,;=")
fragment = quote(clean(fragment), "~") fragment = quote(clean(fragment), "~")