This repository was archived by the owner on Jan 13, 2021. It is now read-only.
File tree 4 files changed +147
-52
lines changed
hyper/packages/hyperframe
4 files changed +147
-52
lines changed Original file line number Diff line number Diff line change 5
5
6
6
A module for providing a pure-Python HTTP/2 framing layer.
7
7
"""
8
- __version__ = '1 .1.1 '
8
+ __version__ = '2 .1.0 '
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ hyperframe/flags
4
+ ~~~~~~~~~~~~~~~~
5
+
6
+ Defines basic Flag and Flags data structures.
7
+ """
8
+ import collections
9
+
10
+
11
+ Flag = collections .namedtuple ("Flag" , ["name" , "bit" ])
12
+
13
+
14
+ class Flags (collections .MutableSet ):
15
+ """
16
+ A simple MutableSet implementation that will only accept known flags as elements.
17
+
18
+ Will behave like a regular set(), except that a ValueError will be thrown when .add()ing
19
+ unexpected flags.
20
+ """
21
+ def __init__ (self , defined_flags ):
22
+ self ._valid_flags = set (flag .name for flag in defined_flags )
23
+ self ._flags = set ()
24
+
25
+ def __contains__ (self , x ):
26
+ return self ._flags .__contains__ (x )
27
+
28
+ def __iter__ (self ):
29
+ return self ._flags .__iter__ ()
30
+
31
+ def __len__ (self ):
32
+ return self ._flags .__len__ ()
33
+
34
+ def discard (self , value ):
35
+ return self ._flags .discard (value )
36
+
37
+ def add (self , value ):
38
+ if value not in self ._valid_flags :
39
+ raise ValueError ("Unexpected flag: {}" .format (value ))
40
+ return self ._flags .add (value )
You can’t perform that action at this time.
0 commit comments