fix tests for py26 and py33
This commit is contained in:
@@ -585,8 +585,8 @@ class Entry(Py3kObject):
|
||||
|
||||
def url_fix(s, charset='utf-8'):
|
||||
scheme, netloc, path, querystring, fragment = urlsplit(s)
|
||||
path = quote(path, '/%')
|
||||
querystring = quote_plus(querystring, ':&=')
|
||||
path = quote(path, b'/%')
|
||||
querystring = quote_plus(querystring, b':&=')
|
||||
return urlunsplit((scheme, netloc, path, querystring, fragment))
|
||||
|
||||
|
||||
|
||||
@@ -130,4 +130,4 @@ def test_using_httpretty_with_other_tcp_protocols(context):
|
||||
|
||||
expect(got1).to.equal(b'BAR')
|
||||
|
||||
expect(context.client.send("foobar")).to.equal("RECEIVED: foobar")
|
||||
expect(context.client.send("foobar")).to.equal(b"RECEIVED: foobar")
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import io
|
||||
@@ -43,6 +44,21 @@ from tornado.httpserver import HTTPServer
|
||||
from tornado.ioloop import IOLoop
|
||||
from multiprocessing import Process
|
||||
|
||||
PY3 = sys.version_info[0] == 3
|
||||
if PY3:
|
||||
text_type = str
|
||||
byte_type = bytes
|
||||
else:
|
||||
text_type = unicode
|
||||
byte_type = str
|
||||
|
||||
|
||||
def utf8(s):
|
||||
if isinstance(s, text_type):
|
||||
s = s.encode('utf-8')
|
||||
|
||||
return byte_type(s)
|
||||
|
||||
true_socket = socket.socket
|
||||
|
||||
|
||||
@@ -111,11 +127,11 @@ class TCPServer(object):
|
||||
|
||||
while True:
|
||||
data = conn.recv(1024)
|
||||
conn.send("RECEIVED: " + data)
|
||||
conn.send(b"RECEIVED: " + data)
|
||||
|
||||
print "*" * 100
|
||||
print data
|
||||
print "*" * 100
|
||||
print("*" * 100)
|
||||
print(data)
|
||||
print("*" * 100)
|
||||
|
||||
conn.close()
|
||||
|
||||
@@ -140,7 +156,7 @@ class TCPClient(object):
|
||||
self.sock.connect(('localhost', self.port))
|
||||
|
||||
def send(self, what):
|
||||
self.sock.sendall(str(what))
|
||||
self.sock.sendall(utf8(what))
|
||||
return self.sock.recv(len(what) + 11)
|
||||
|
||||
def close(self):
|
||||
|
||||
Reference in New Issue
Block a user