33
33
import socket
34
34
import sys
35
35
import re
36
+ import warnings
36
37
37
38
from tornado .concurrent import Future
38
39
from tornado import ioloop
@@ -342,6 +343,12 @@ def read_until_regex(self, regex, callback=None, max_bytes=None):
342
343
.. versionchanged:: 4.0
343
344
Added the ``max_bytes`` argument. The ``callback`` argument is
344
345
now optional and a `.Future` will be returned if it is omitted.
346
+
347
+ .. deprecated:: 5.1
348
+
349
+ The ``callback`` argument is deprecated and will be removed
350
+ in Tornado 6.0. Use the returned `.Future` instead.
351
+
345
352
"""
346
353
future = self ._set_read_callback (callback )
347
354
self ._read_regex = re .compile (regex )
@@ -375,6 +382,11 @@ def read_until(self, delimiter, callback=None, max_bytes=None):
375
382
.. versionchanged:: 4.0
376
383
Added the ``max_bytes`` argument. The ``callback`` argument is
377
384
now optional and a `.Future` will be returned if it is omitted.
385
+
386
+ .. deprecated:: 5.1
387
+
388
+ The ``callback`` argument is deprecated and will be removed
389
+ in Tornado 6.0. Use the returned `.Future` instead.
378
390
"""
379
391
future = self ._set_read_callback (callback )
380
392
self ._read_delimiter = delimiter
@@ -408,12 +420,23 @@ def read_bytes(self, num_bytes, callback=None, streaming_callback=None,
408
420
.. versionchanged:: 4.0
409
421
Added the ``partial`` argument. The callback argument is now
410
422
optional and a `.Future` will be returned if it is omitted.
423
+
424
+ .. deprecated:: 5.1
425
+
426
+ The ``callback`` and ``streaming_callback`` arguments are
427
+ deprecated and will be removed in Tornado 6.0. Use the
428
+ returned `.Future` (and ``partial=True`` for
429
+ ``streaming_callback``) instead.
430
+
411
431
"""
412
432
future = self ._set_read_callback (callback )
413
433
assert isinstance (num_bytes , numbers .Integral )
414
434
self ._read_bytes = num_bytes
415
435
self ._read_partial = partial
416
- self ._streaming_callback = stack_context .wrap (streaming_callback )
436
+ if streaming_callback is not None :
437
+ warnings .warn ("streaming_callback is deprecated, use partial instead" ,
438
+ DeprecationWarning )
439
+ self ._streaming_callback = stack_context .wrap (streaming_callback )
417
440
try :
418
441
self ._try_inline_read ()
419
442
except :
@@ -434,6 +457,12 @@ def read_into(self, buf, callback=None, partial=False):
434
457
entirely filled with read data.
435
458
436
459
.. versionadded:: 5.0
460
+
461
+ .. deprecated:: 5.1
462
+
463
+ The ``callback`` argument is deprecated and will be removed
464
+ in Tornado 6.0. Use the returned `.Future` instead.
465
+
437
466
"""
438
467
future = self ._set_read_callback (callback )
439
468
@@ -485,9 +514,19 @@ def read_until_close(self, callback=None, streaming_callback=None):
485
514
The callback argument is now optional and a `.Future` will
486
515
be returned if it is omitted.
487
516
517
+ .. deprecated:: 5.1
518
+
519
+ The ``callback`` and ``streaming_callback`` arguments are
520
+ deprecated and will be removed in Tornado 6.0. Use the
521
+ returned `.Future` (and `read_bytes` with ``partial=True``
522
+ for ``streaming_callback``) instead.
523
+
488
524
"""
489
525
future = self ._set_read_callback (callback )
490
- self ._streaming_callback = stack_context .wrap (streaming_callback )
526
+ if streaming_callback is not None :
527
+ warnings .warn ("streaming_callback is deprecated, use read_bytes(partial=True) instead" ,
528
+ DeprecationWarning )
529
+ self ._streaming_callback = stack_context .wrap (streaming_callback )
491
530
if self .closed ():
492
531
if self ._streaming_callback is not None :
493
532
self ._run_read_callback (self ._read_buffer_size , True )
@@ -521,6 +560,12 @@ def write(self, data, callback=None):
521
560
522
561
.. versionchanged:: 4.5
523
562
Added support for `memoryview` arguments.
563
+
564
+ .. deprecated:: 5.1
565
+
566
+ The ``callback`` argument is deprecated and will be removed
567
+ in Tornado 6.0. Use the returned `.Future` instead.
568
+
524
569
"""
525
570
self ._check_closed ()
526
571
if data :
@@ -530,6 +575,8 @@ def write(self, data, callback=None):
530
575
self ._write_buffer .append (data )
531
576
self ._total_write_index += len (data )
532
577
if callback is not None :
578
+ warnings .warn ("callback argument is deprecated, use returned Future instead" ,
579
+ DeprecationWarning )
533
580
self ._write_callback = stack_context .wrap (callback )
534
581
future = None
535
582
else :
@@ -546,9 +593,14 @@ def write(self, data, callback=None):
546
593
def set_close_callback (self , callback ):
547
594
"""Call the given callback when the stream is closed.
548
595
549
- This is not necessary for applications that use the `.Future`
550
- interface; all outstanding ``Futures`` will resolve with a
551
- `StreamClosedError` when the stream is closed.
596
+ This mostly is not necessary for applications that use the
597
+ `.Future` interface; all outstanding ``Futures`` will resolve
598
+ with a `StreamClosedError` when the stream is closed. However,
599
+ it is still useful as a way to signal that the stream has been
600
+ closed while no other read or write is in progress.
601
+
602
+ Unlike other callback-based interfaces, ``set_close_callback``
603
+ will not be removed in Tornado 6.0.
552
604
"""
553
605
self ._close_callback = stack_context .wrap (callback )
554
606
self ._maybe_add_error_listener ()
@@ -807,6 +859,8 @@ def _set_read_callback(self, callback):
807
859
assert self ._read_callback is None , "Already reading"
808
860
assert self ._read_future is None , "Already reading"
809
861
if callback is not None :
862
+ warnings .warn ("callbacks are deprecated, use returned Future instead" ,
863
+ DeprecationWarning )
810
864
self ._read_callback = stack_context .wrap (callback )
811
865
else :
812
866
self ._read_future = Future ()
@@ -1237,9 +1291,17 @@ class is recommended instead of calling this method directly.
1237
1291
``ssl_options=dict(cert_reqs=ssl.CERT_NONE)`` or a
1238
1292
suitably-configured `ssl.SSLContext` to the
1239
1293
`SSLIOStream` constructor to disable.
1294
+
1295
+ .. deprecated:: 5.1
1296
+
1297
+ The ``callback`` argument is deprecated and will be removed
1298
+ in Tornado 6.0. Use the returned `.Future` instead.
1299
+
1240
1300
"""
1241
1301
self ._connecting = True
1242
1302
if callback is not None :
1303
+ warnings .warn ("callback argument is deprecated, use returned Future instead" ,
1304
+ DeprecationWarning )
1243
1305
self ._connect_callback = stack_context .wrap (callback )
1244
1306
future = None
1245
1307
else :
@@ -1523,9 +1585,13 @@ def _handle_write(self):
1523
1585
1524
1586
def connect (self , address , callback = None , server_hostname = None ):
1525
1587
self ._server_hostname = server_hostname
1526
- # Pass a dummy callback to super.connect(), which is slightly
1527
- # more efficient than letting it return a Future we ignore.
1528
- super (SSLIOStream , self ).connect (address , callback = lambda : None )
1588
+ # Ignore the result of connect(). If it fails,
1589
+ # wait_for_handshake will raise an error too. This is
1590
+ # necessary for the old semantics of the connect callback
1591
+ # (which takes no arguments). In 6.0 this can be refactored to
1592
+ # be a regular coroutine.
1593
+ fut = super (SSLIOStream , self ).connect (address )
1594
+ fut .add_done_callback (lambda f : f .exception ())
1529
1595
return self .wait_for_handshake (callback )
1530
1596
1531
1597
def _handle_connect (self ):
@@ -1569,11 +1635,19 @@ def wait_for_handshake(self, callback=None):
1569
1635
handshake to complete). It may only be called once per stream.
1570
1636
1571
1637
.. versionadded:: 4.2
1638
+
1639
+ .. deprecated:: 5.1
1640
+
1641
+ The ``callback`` argument is deprecated and will be removed
1642
+ in Tornado 6.0. Use the returned `.Future` instead.
1643
+
1572
1644
"""
1573
1645
if (self ._ssl_connect_callback is not None or
1574
1646
self ._ssl_connect_future is not None ):
1575
1647
raise RuntimeError ("Already waiting" )
1576
1648
if callback is not None :
1649
+ warnings .warn ("callback argument is deprecated, use returned Future instead" ,
1650
+ DeprecationWarning )
1577
1651
self ._ssl_connect_callback = stack_context .wrap (callback )
1578
1652
future = None
1579
1653
else :
0 commit comments