File tornado_5.patch of Package python-thriftpy

Index: thriftpy-0.3.9/setup.py
===================================================================
--- thriftpy-0.3.9.orig/setup.py
+++ thriftpy-0.3.9/setup.py
@@ -18,7 +18,7 @@ install_requires = [
 ]
 
 tornado_requires = [
-    "tornado>=4.0,<5.0",
+    "tornado>=4.0,<6.0",
     "toro==0.6"
 ]
 
Index: thriftpy-0.3.9/thriftpy/tornado.py
===================================================================
--- thriftpy-0.3.9.orig/thriftpy/tornado.py
+++ thriftpy-0.3.9/thriftpy/tornado.py
@@ -18,7 +18,8 @@
 from __future__ import absolute_import
 
 from contextlib import contextmanager
-from tornado import tcpserver, ioloop, iostream, gen
+from tornado import tcpserver, iostream, gen
+from tornado import version as tornado_version
 from io import BytesIO
 from datetime import timedelta
 
@@ -32,7 +33,11 @@ from .protocol.binary import TBinaryProt
 import logging
 import socket
 import struct
-import toro
+
+try:
+    from tornado.locks import Lock
+except ImportError:
+    from toro import Lock
 
 
 logger = logging.getLogger(__name__)
@@ -47,12 +52,12 @@ class TTornadoStreamTransport(TTransport
                  read_timeout=DEFAULT_READ_TIMEOUT):
         self.host = host
         self.port = port
-        self.io_loop = io_loop or ioloop.IOLoop.current()
+        self.io_loop = io_loop
         self.read_timeout = read_timeout
         self.is_queuing_reads = False
         self.read_queue = []
         self.__wbuf = BytesIO()
-        self._read_lock = toro.Lock()
+        self._read_lock = Lock()
         self.ssl_options = ssl_options
 
         # servers provide a ready-to-go stream
@@ -60,8 +65,12 @@ class TTornadoStreamTransport(TTransport
         if self.stream is not None:
             self._set_close_callback()
 
-    def with_timeout(self, timeout, future):
-        return gen.with_timeout(timeout, future, self.io_loop)
+    if tornado_version >= '5.0':
+        def with_timeout(self, timeout, future):
+            return gen.with_timeout(timeout, future)
+    else:
+        def with_timeout(self, timeout, future):
+            return gen.with_timeout(timeout, future, self.io_loop)
 
     @gen.coroutine
     def open(self, timeout=DEFAULT_CONNECT_TIMEOUT):
@@ -157,12 +166,15 @@ class TTornadoServer(tcpserver.TCPServer
                                else iprot_factory)
         self.transport_read_timeout = transport_read_timeout
 
+        # `io_loop` has been deprecated since tornado 4.1 and removed in 5.0
+        self.__io_loop = getattr(self, 'io_loop', None)
+
     @gen.coroutine
     def handle_stream(self, stream, address):
         host, port = address
         trans = TTornadoStreamTransport(
             host=host, port=port, stream=stream,
-            io_loop=self.io_loop, read_timeout=self.transport_read_timeout)
+            io_loop=self.__io_loop, read_timeout=self.transport_read_timeout)
         try:
             oprot = self._oprot_factory.get_protocol(trans)
             iprot = self._iprot_factory.get_protocol(TMemoryBuffer())
@@ -213,9 +225,14 @@ def make_server(
         io_loop=None, ssl_options=None,
         transport_read_timeout=TTornadoStreamTransport.DEFAULT_READ_TIMEOUT):
     processor = TProcessor(service, handler)
-    server = TTornadoServer(processor, iprot_factory=proto_factory,
-                            transport_read_timeout=transport_read_timeout,
-                            io_loop=io_loop, ssl_options=ssl_options)
+    if tornado_version >= '5.0':
+        server = TTornadoServer(processor, iprot_factory=proto_factory,
+                                transport_read_timeout=transport_read_timeout,
+                                ssl_options=ssl_options)
+    else:
+        server = TTornadoServer(processor, iprot_factory=proto_factory,
+                                transport_read_timeout=transport_read_timeout,
+                                io_loop=io_loop, ssl_options=ssl_options)
     return server