aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/utils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-24 15:09:21 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-24 15:09:21 +1200
commitf22bc0b4c74776bcc312fed1f4ceede83f869a6e (patch)
tree7d8b947d9940bb0faa68fe21d924642f6c3d1667 /netlib/utils.py
parent3519871f340cb0466fc6935d6e8e3b7822d36c52 (diff)
downloadmitmproxy-f22bc0b4c74776bcc312fed1f4ceede83f869a6e.tar.gz
mitmproxy-f22bc0b4c74776bcc312fed1f4ceede83f869a6e.tar.bz2
mitmproxy-f22bc0b4c74776bcc312fed1f4ceede83f869a6e.zip
websocket: interface refactoring
- Separate out FrameHeader. We need to deal with this separately in many circumstances. - Simpler equality scheme. - Bits are now specified by truthiness - we don't care about the integer value. This means lots of validation is not needed any more.
Diffstat (limited to 'netlib/utils.py')
-rw-r--r--netlib/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/netlib/utils.py b/netlib/utils.py
index 66bbdb5e..44bed43a 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -49,3 +49,19 @@ def hexdump(s):
(o, x, cleanBin(part, True))
)
return parts
+
+
+def setbit(byte, offset, value):
+ """
+ Set a bit in a byte to 1 if value is truthy, 0 if not.
+ """
+ if value:
+ return byte | (1 << offset)
+ else:
+ return byte & ~(1 << offset)
+
+
+def getbit(byte, offset):
+ mask = 1 << offset
+ if byte & mask:
+ return True