Merge pull request #37 from hubertmis/add-option-size2
Add Size2 option handling according to RFC7959
This commit is contained in:
commit
f6a3c25cde
3 changed files with 18 additions and 4 deletions
|
@ -125,7 +125,7 @@ class OptionRegistry(object):
|
|||
LOCATION_QUERY = OptionItem(20,"Location-Query",STRING, True, None)
|
||||
BLOCK2 = OptionItem(23, "Block2", INTEGER, False, None)
|
||||
BLOCK1 = OptionItem(27, "Block1", INTEGER, False, None)
|
||||
SIZE2 = OptionItem(28, "Size2", INTEGER, False, None)
|
||||
SIZE2 = OptionItem(28, "Size2", INTEGER, False, 0)
|
||||
PROXY_URI = OptionItem(35, "Proxy-Uri", STRING, False, None)
|
||||
PROXY_SCHEME = OptionItem(39, "Proxy-Schema", STRING, False, None)
|
||||
SIZE1 = OptionItem(60, "Size1", INTEGER, False, None)
|
||||
|
|
|
@ -233,6 +233,7 @@ class BlockLayer(object):
|
|||
|
||||
self._block2_receive[key_token] = BlockItem(byte, num, m, size)
|
||||
|
||||
|
||||
# correct m
|
||||
m = 0 if ((num * size) + size) > len(transaction.response.payload) else 1
|
||||
# add size2 if requested or if payload is bigger than one datagram
|
||||
|
@ -240,6 +241,7 @@ class BlockLayer(object):
|
|||
if (transaction.request.size2 is not None and transaction.request.size2 == 0) or \
|
||||
(transaction.response.payload is not None and len(transaction.response.payload) > defines.MAX_PAYLOAD):
|
||||
transaction.response.size2 = len(transaction.response.payload)
|
||||
|
||||
transaction.response.payload = transaction.response.payload[byte:byte + size]
|
||||
del transaction.response.block2
|
||||
transaction.response.block2 = (num, m, size)
|
||||
|
|
|
@ -645,8 +645,7 @@ class Message(object):
|
|||
Delete the Block2 option.
|
||||
"""
|
||||
self.del_option_by_number(defines.OptionRegistry.BLOCK2.number)
|
||||
|
||||
@property
|
||||
|
||||
def size1(self):
|
||||
value = None
|
||||
for option in self.options:
|
||||
|
@ -667,14 +666,24 @@ class Message(object):
|
|||
|
||||
@property
|
||||
def size2(self):
|
||||
"""
|
||||
Get the Size2 option.
|
||||
|
||||
:return: the Size2 value
|
||||
"""
|
||||
value = None
|
||||
for option in self.options:
|
||||
if option.number == defines.OptionRegistry.SIZE2.number:
|
||||
value = option.value if option.value is not None else 0
|
||||
value = option.value
|
||||
return value
|
||||
|
||||
@size2.setter
|
||||
def size2(self, value):
|
||||
"""
|
||||
Set the Size2 option.
|
||||
|
||||
:param value: the Block2 value
|
||||
"""
|
||||
option = Option()
|
||||
option.number = defines.OptionRegistry.SIZE2.number
|
||||
option.value = value
|
||||
|
@ -682,6 +691,9 @@ class Message(object):
|
|||
|
||||
@size2.deleter
|
||||
def size2(self):
|
||||
"""
|
||||
Delete the Size2 option.
|
||||
"""
|
||||
self.del_option_by_number(defines.OptionRegistry.SIZE2.number)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in a new issue