Commit 824c89f4 authored by Fantix King's avatar Fantix King Committed by Denis Bilenko

replace unicode with text_type

parent a7b17d41
......@@ -33,6 +33,7 @@ PY3 = sys.version_info[0] >= 3
if PY3:
string_types = str,
integer_types = int,
text_type = str
xrange = range
def reraise(tp, value, tb=None):
......@@ -43,6 +44,7 @@ if PY3:
else:
import __builtin__
string_types = __builtin__.basestring,
text_type = __builtin__.unicode
integer_types = (int, __builtin__.long)
xrange = __builtin__.xrange
......
......@@ -2,7 +2,7 @@
from __future__ import absolute_import
import os
from _socket import getservbyname, getaddrinfo, gaierror, error
from gevent.hub import Waiter, get_hub, string_types
from gevent.hub import Waiter, get_hub, string_types, text_type
from gevent.socket import AF_UNSPEC, AF_INET, AF_INET6, SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, AI_NUMERICHOST, EAI_SERVICE, AI_PASSIVE
from gevent.ares import channel, InvalidIP
......@@ -52,7 +52,7 @@ class Resolver(object):
return self.gethostbyname_ex(hostname, family)[-1][0]
def gethostbyname_ex(self, hostname, family=AF_INET):
if isinstance(hostname, unicode):
if isinstance(hostname, text_type):
hostname = hostname.encode('ascii')
elif not isinstance(hostname, str):
raise TypeError('Expected string, not %s' % type(hostname).__name__)
......@@ -117,7 +117,7 @@ class Resolver(object):
return port, socktypes
def _getaddrinfo(self, host, port, family=0, socktype=0, proto=0, flags=0):
if isinstance(host, unicode):
if isinstance(host, text_type):
host = host.encode('idna')
elif not isinstance(host, str) or (flags & AI_NUMERICHOST):
# this handles cases which do not require network access
......@@ -191,7 +191,7 @@ class Resolver(object):
raise
def _gethostbyaddr(self, ip_address):
if isinstance(ip_address, unicode):
if isinstance(ip_address, text_type):
ip_address = ip_address.encode('ascii')
elif not isinstance(ip_address, str):
raise TypeError('Expected string, not %s' % type(ip_address).__name__)
......@@ -228,7 +228,7 @@ class Resolver(object):
raise TypeError('getnameinfo() argument 1 must be a tuple')
address = sockaddr[0]
if isinstance(address, unicode):
if isinstance(address, text_type):
address = address.encode('ascii')
if not isinstance(address, str):
......
......@@ -20,6 +20,7 @@ if PY3:
del builtins
xrange = range
string_types = str,
text_type = str
else:
def exec_(code, globs=None, locs=None):
......@@ -37,3 +38,4 @@ else:
import __builtin__ as builtins
xrange = builtins.xrange
string_types = builtins.basestring,
text_type = builtins.unicode
......@@ -7,6 +7,7 @@ import traceback
import time
import greentest
from functools import wraps
import six
# we use threading on purpose so that we can test both regular and gevent sockets with the same code
from threading import Thread as _Thread
......@@ -77,7 +78,7 @@ class TestTCP(greentest.TestCase):
self._test_sendall(self.long_data)
def test_sendall_unicode(self):
self._test_sendall(unicode(self.long_data))
self._test_sendall(six.text_type(self.long_data))
def test_sendall_array(self):
data = array.array("B", self.long_data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment