FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
hyperframe/src/hyperframe/flags.py at master · python-hyper/hyperframe · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python-hyper
/
hyperframe
Public
Notifications
You must be signed in to change notification settings
Fork
40
Star
65
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
hyperframe
/
src
/
hyperframe
/
flags.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (34 loc) · 1.26 KB
Breadcrumbs
hyperframe
/
src
/
hyperframe
/
flags.py
Copy path
File metadata and controls
47 lines (34 loc) · 1.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Basic Flag and Flags data structures.
"""
from
__future__
import
annotations
from
collections
.
abc
import
Iterable
,
Iterator
,
MutableSet
from
typing
import
NamedTuple
class
Flag
(
NamedTuple
):
name
:
str
bit
:
int
class
Flags
(
MutableSet
):
# type: ignore
"""
A simple MutableSet implementation that will only accept known flags as
elements.
Will behave like a regular set(), except that a ValueError will be thrown
when .add()ing unexpected flags.
"""
def
__init__
(
self
,
defined_flags
:
Iterable
[
Flag
])
->
None
:
self
.
_valid_flags
=
{
flag
.
name
for
flag
in
defined_flags
}
self
.
_flags
:
set
[
str
]
=
set
()
def
__repr__
(
self
)
->
str
:
return
repr
(
sorted
(
self
.
_flags
))
def
__contains__
(
self
,
x
:
object
)
->
bool
:
return
self
.
_flags
.
__contains__
(
x
)
def
__iter__
(
self
)
->
Iterator
[
str
]:
return
self
.
_flags
.
__iter__
()
def
__len__
(
self
)
->
int
:
return
self
.
_flags
.
__len__
()
def
discard
(
self
,
value
:
str
)
->
None
:
return
self
.
_flags
.
discard
(
value
)
def
add
(
self
,
value
:
str
)
->
None
:
if
value
not
in
self
.
_valid_flags
:
msg
=
f"Unexpected flag:
{
value
}
. Valid flags are:
{
self
.
_valid_flags
}
"
raise
ValueError
(
msg
)
return
self
.
_flags
.
add
(
value
)
Back
|
FazBrowse Home
|
New Git URL