@@ -193,10 +193,9 @@ def window_opened(self, event):
193
193
for data in self ._flow_controlled_data .values ():
194
194
self ._stream_data .put_nowait (data )
195
195
196
- self ._flow_controlled_data = {}
196
+ self ._flow_controlled_data . clear ()
197
197
198
- @asyncio .coroutine
199
- def sending_loop (self ):
198
+ async def sending_loop (self ):
200
199
"""
201
200
A call that loops forever, attempting to send data. This sending loop
202
201
contains most of the flow-control smarts of this class: it pulls data
@@ -216,7 +215,7 @@ def sending_loop(self):
216
215
This coroutine explicitly *does not end*.
217
216
"""
218
217
while True :
219
- stream_id , data , event = yield from self ._stream_data .get ()
218
+ stream_id , data , event = await self ._stream_data .get ()
220
219
221
220
# If this stream got reset, just drop the data on the floor. Note
222
221
# that we need to reset the event here to make sure that
@@ -327,7 +326,7 @@ def reset_stream(self, event):
327
326
data.
328
327
"""
329
328
if event .stream_id in self ._flow_controlled_data :
330
- del self ._flow_controlled_data
329
+ del self ._flow_controlled_data [ event . stream_id ]
331
330
332
331
self ._reset_streams .add (event .stream_id )
333
332
self .end_stream (event )
@@ -534,23 +533,9 @@ def readline(self, hint=None):
534
533
def readlines (self , hint = None ):
535
534
"""
536
535
Called by the WSGI application to read several lines of data.
537
-
538
- This method is really pretty stupid. It rigorously observes the
539
- ``hint`` parameter, and quite happily returns the input split into
540
- lines.
541
536
"""
542
- # This method is *crazy inefficient*, but it's also a pretty stupid
543
- # method to call.
544
537
data = self .read (hint )
545
- lines = data .split (b'\n ' )
546
-
547
- # Split removes the newline character, but we want it, so put it back.
548
- lines = [line + b'\n ' for line in lines ]
549
-
550
- # Except if the last character was a newline character we now have an
551
- # extra line that is just a newline: pull that out.
552
- if lines [- 1 ] == b'\n ' :
553
- lines = lines [:- 1 ]
538
+ lines = data .splitlines (True )
554
539
return lines
555
540
556
541
def start_response (self , status , response_headers , exc_info = None ):
@@ -688,41 +673,41 @@ def _build_environ_dict(headers, stream):
688
673
version you'd want to fix it.
689
674
"""
690
675
header_dict = dict (headers )
691
- path = header_dict .pop (u ':path' )
676
+ path = header_dict .pop (':path' )
692
677
try :
693
- path , query = path .split (u '?' , 1 )
678
+ path , query = path .split ('?' , 1 )
694
679
except ValueError :
695
- query = u ""
696
- server_name = header_dict .pop (u ':authority' )
680
+ query = ""
681
+ server_name = header_dict .pop (':authority' )
697
682
try :
698
- server_name , port = server_name .split (u ':' , 1 )
699
- except ValueError as e :
683
+ server_name , port = server_name .split (':' , 1 )
684
+ except ValueError :
700
685
port = "8443"
701
686
702
687
environ = {
703
- u 'REQUEST_METHOD' : header_dict .pop (u ':method' ),
704
- u 'SCRIPT_NAME' : u '' ,
705
- u 'PATH_INFO' : path ,
706
- u 'QUERY_STRING' : query ,
707
- u 'SERVER_NAME' : server_name ,
708
- u 'SERVER_PORT' : port ,
709
- u 'SERVER_PROTOCOL' : u 'HTTP/2' ,
710
- u 'HTTPS' : u "on" ,
711
- u 'SSL_PROTOCOL' : u 'TLSv1.2' ,
712
- u 'wsgi.version' : (1 , 0 ),
713
- u 'wsgi.url_scheme' : header_dict .pop (u ':scheme' ),
714
- u 'wsgi.input' : stream ,
715
- u 'wsgi.errors' : sys .stderr ,
716
- u 'wsgi.multithread' : True ,
717
- u 'wsgi.multiprocess' : False ,
718
- u 'wsgi.run_once' : False ,
688
+ 'REQUEST_METHOD' : header_dict .pop (':method' ),
689
+ 'SCRIPT_NAME' : '' ,
690
+ 'PATH_INFO' : path ,
691
+ 'QUERY_STRING' : query ,
692
+ 'SERVER_NAME' : server_name ,
693
+ 'SERVER_PORT' : port ,
694
+ 'SERVER_PROTOCOL' : 'HTTP/2' ,
695
+ 'HTTPS' : "on" ,
696
+ 'SSL_PROTOCOL' : 'TLSv1.2' ,
697
+ 'wsgi.version' : (1 , 0 ),
698
+ 'wsgi.url_scheme' : header_dict .pop (':scheme' ),
699
+ 'wsgi.input' : stream ,
700
+ 'wsgi.errors' : sys .stderr ,
701
+ 'wsgi.multithread' : True ,
702
+ 'wsgi.multiprocess' : False ,
703
+ 'wsgi.run_once' : False ,
719
704
}
720
- if u 'content-type' in header_dict :
721
- environ [u 'CONTENT_TYPE' ] = header_dict [ u 'content-type']
722
- if u 'content-length' in header_dict :
723
- environ [u 'CONTENT_LENGTH' ] = header_dict [ u 'content-length']
705
+ if 'content-type' in header_dict :
706
+ environ ['CONTENT_TYPE' ] = header_dict . pop ( 'content-type' )
707
+ if 'content-length' in header_dict :
708
+ environ ['CONTENT_LENGTH' ] = header_dict . pop ( 'content-length' )
724
709
for name , value in header_dict .items ():
725
- environ [u 'HTTP_' + name .upper ()] = value
710
+ environ ['HTTP_' + name .upper ()] = value
726
711
return environ
727
712
728
713
@@ -753,8 +738,8 @@ def _build_environ_dict(headers, stream):
753
738
loop .run_forever ()
754
739
except KeyboardInterrupt :
755
740
pass
756
-
757
- # Close the server
758
- server .close ()
759
- loop .run_until_complete (server .wait_closed ())
760
- loop .close ()
741
+ finally :
742
+ # Close the server
743
+ server .close ()
744
+ loop .run_until_complete (server .wait_closed ())
745
+ loop .close ()
0 commit comments