Break api packet.parse
-> packet.parse7
Rename the main `twnet_parser.packet.parse()` method. Into more explicit `parse6()` and `parse7()`
This commit is contained in:
parent
03efdeba83
commit
c8f8ca6a21
|
@ -10,7 +10,7 @@ pip install twnet_parser
|
|||
|
||||
```python
|
||||
import twnet_parser.packet
|
||||
packet = twnet_parser.packet.parse(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
|
||||
packet = twnet_parser.packet.parse7(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
|
||||
|
||||
print(packet) # => <class: 'TwPacket'>: {'version': '0.7', 'header': <class: 'Header'>, 'messages': [<class: 'CtrlMessage'>]}
|
||||
print(packet.header) # => <class: 'Header'>: {'flags': <class: 'PacketFlags7, 'size': 0, 'ack': 10, 'token': b'\xcf.\xde\x1d', 'num_chunks': 0}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from twnet_parser.packet import *
|
||||
|
||||
def test_parse_7_close():
|
||||
packet = parse(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
|
||||
packet = parse7(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
|
||||
|
||||
assert packet.version == '0.7'
|
||||
assert packet.header.flags.control == True
|
||||
|
@ -10,7 +10,7 @@ def test_parse_7_close():
|
|||
assert len(packet.messages) == 1
|
||||
|
||||
def test_parse_7_close_with_reason():
|
||||
packet = parse(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04shutdown\x00') # 0.7 close
|
||||
packet = parse7(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04shutdown\x00') # 0.7 close
|
||||
|
||||
assert packet.version == '0.7'
|
||||
assert packet.header.flags.control == True
|
||||
|
|
|
@ -3,7 +3,7 @@ from twnet_parser.packet import *
|
|||
# TODO: uncomment and adjust ack/size when 0.6 is done
|
||||
|
||||
# def test_parse_065_close():
|
||||
# packet = parse(b'\x10\x10\x00\x04\x9a\xcb\x09\xc9') # 0.6.5 close
|
||||
# packet = parse7(b'\x10\x10\x00\x04\x9a\xcb\x09\xc9') # 0.6.5 close
|
||||
#
|
||||
# assert packet.version == '0.6.5'
|
||||
#
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from twnet_parser.packet import *
|
||||
|
||||
def test_parse_7_close():
|
||||
packet = parse(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
|
||||
packet = parse7(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
|
||||
|
||||
assert packet.version == '0.7'
|
||||
|
||||
|
@ -19,7 +19,7 @@ def test_parse_7_close():
|
|||
assert len(packet.messages) == 1
|
||||
|
||||
def test_parse_7_close_fake_resend():
|
||||
packet = parse(b'\x0c\x0a\x00\xaa\xbb\xcc\xdd\04') # 0.7 close
|
||||
packet = parse7(b'\x0c\x0a\x00\xaa\xbb\xcc\xdd\04') # 0.7 close
|
||||
# ^
|
||||
# resending ctrl close
|
||||
# probably never happens
|
||||
|
@ -40,7 +40,7 @@ def test_parse_7_close_fake_resend():
|
|||
assert len(packet.messages) == 1
|
||||
|
||||
def test_parse_7_close_fake_num_chunks():
|
||||
packet = parse(b'\x04\x0a\x01\xcf\xee\xde\x2d\04') # 0.7 close
|
||||
packet = parse7(b'\x04\x0a\x01\xcf\xee\xde\x2d\04') # 0.7 close
|
||||
# ^
|
||||
# 1 chunk makes no sense
|
||||
# because control messages should
|
||||
|
|
|
@ -5,7 +5,7 @@ def test_parse_7_close():
|
|||
# the last byte of the token and the message id
|
||||
# is missing
|
||||
try:
|
||||
packet = parse(b'\x04\x0a\x00\xcf\x2e\xde')
|
||||
packet = parse7(b'\x04\x0a\x00\xcf\x2e\xde')
|
||||
except IndexError:
|
||||
# def parse7(self, data: bytes) -> TwPacket:
|
||||
# pck = TwPacket()
|
||||
|
|
|
@ -107,8 +107,8 @@ class PacketParser():
|
|||
return pck
|
||||
return pck
|
||||
|
||||
def parse(data: bytes) -> TwPacket:
|
||||
# TODO: think about api
|
||||
# do we have `parse6` and `parse7` and `parse_detect`
|
||||
# or just `parse` that does detect
|
||||
def parse6(data: bytes) -> TwPacket:
|
||||
raise NotImplementedError()
|
||||
|
||||
def parse7(data: bytes) -> TwPacket:
|
||||
return PacketParser().parse7(data)
|
||||
|
|
Loading…
Reference in a new issue