1
- # -*- coding: utf-8 -*-
2
1
"""
3
2
hyperframe/frame
4
3
~~~~~~~~~~~~~~~~
9
8
"""
10
9
import struct
11
10
import binascii
11
+ from typing import Any , Iterable , Optional , Type
12
12
13
13
from .exceptions import (
14
14
UnknownFrameError , InvalidPaddingError , InvalidFrameError , InvalidDataError
15
15
)
16
16
from .flags import Flag , Flags
17
- from typing import Optional , Tuple , List , Iterable , Any , Dict , Type
18
17
19
18
20
19
# The maximum initial length of a frame. Some frames have shorter maximum
@@ -44,7 +43,7 @@ class Frame:
44
43
The base class for all HTTP/2 frames.
45
44
"""
46
45
#: The flags defined on this type of frame.
47
- defined_flags : List [Flag ] = []
46
+ defined_flags : list [Flag ] = []
48
47
49
48
#: The byte used to define the type of the frame.
50
49
type : Optional [int ] = None
@@ -99,7 +98,7 @@ def _body_repr(self) -> str:
99
98
return _raw_data_repr (self .serialize_body ())
100
99
101
100
@staticmethod
102
- def explain (data : memoryview ) -> Tuple ["Frame" , int ]:
101
+ def explain (data : memoryview ) -> tuple ["Frame" , int ]:
103
102
"""
104
103
Takes a bytestring and tries to parse a single frame and print it.
105
104
@@ -116,7 +115,7 @@ def explain(data: memoryview) -> Tuple["Frame", int]:
116
115
return frame , length
117
116
118
117
@staticmethod
119
- def parse_frame_header (header : memoryview , strict : bool = False ) -> Tuple ["Frame" , int ]:
118
+ def parse_frame_header (header : memoryview , strict : bool = False ) -> tuple ["Frame" , int ]:
120
119
"""
121
120
Takes a 9-byte frame header and returns a tuple of the appropriate
122
121
Frame object and the length that needs to be read from the socket.
@@ -343,7 +342,7 @@ class PriorityFrame(Priority, Frame):
343
342
reprioritisation of existing streams.
344
343
"""
345
344
#: The flags defined for PRIORITY frames.
346
- defined_flags : List [Flag ] = []
345
+ defined_flags : list [Flag ] = []
347
346
348
347
#: The type byte defined for PRIORITY frames.
349
348
type = 0x02
@@ -381,7 +380,7 @@ class RstStreamFrame(Frame):
381
380
occurred.
382
381
"""
383
382
#: The flags defined for RST_STREAM frames.
384
- defined_flags : List [Flag ] = []
383
+ defined_flags : list [Flag ] = []
385
384
386
385
#: The type byte defined for RST_STREAM frames.
387
386
type = 0x03
@@ -454,7 +453,7 @@ class SettingsFrame(Frame):
454
453
#: The byte that signals SETTINGS_ENABLE_CONNECT_PROTOCOL setting.
455
454
ENABLE_CONNECT_PROTOCOL = 0x08
456
455
457
- def __init__ (self , stream_id : int = 0 , settings : Optional [Dict [int , int ]] = None , ** kwargs : Any ) -> None :
456
+ def __init__ (self , stream_id : int = 0 , settings : Optional [dict [int , int ]] = None , ** kwargs : Any ) -> None :
458
457
super ().__init__ (stream_id , ** kwargs )
459
458
460
459
if settings and "ACK" in kwargs .get ("flags" , ()):
@@ -463,7 +462,7 @@ def __init__(self, stream_id: int = 0, settings: Optional[Dict[int, int]] = None
463
462
)
464
463
465
464
#: A dictionary of the setting type byte to the value of the setting.
466
- self .settings = settings or {}
465
+ self .settings : dict [ int , int ] = settings or {}
467
466
468
467
def _body_repr (self ) -> str :
469
468
return "settings={}" .format (
@@ -611,7 +610,7 @@ class GoAwayFrame(Frame):
611
610
connection.
612
611
"""
613
612
#: The flags defined for GOAWAY frames.
614
- defined_flags : List [Flag ] = []
613
+ defined_flags : list [Flag ] = []
615
614
616
615
#: The type byte defined for GOAWAY frames.
617
616
type = 0x07
@@ -679,7 +678,7 @@ class WindowUpdateFrame(Frame):
679
678
original sender.
680
679
"""
681
680
#: The flags defined for WINDOW_UPDATE frames.
682
- defined_flags : List [Flag ] = []
681
+ defined_flags : list [Flag ] = []
683
682
684
683
#: The type byte defined for WINDOW_UPDATE frames.
685
684
type = 0x08
@@ -951,7 +950,7 @@ def _raw_data_repr(data: Optional[bytes]) -> str:
951
950
return "<hex:" + r + ">"
952
951
953
952
954
- _FRAME_CLASSES : List [Type [Frame ]] = [
953
+ _FRAME_CLASSES : list [Type [Frame ]] = [
955
954
DataFrame ,
956
955
HeadersFrame ,
957
956
PriorityFrame ,
0 commit comments