Skip to content

Commit 3bbf7eb

Browse files
changed built-in list types to typing.List (#235)
* changed built-in list types to typing.List * fixed zbstumbler byte type mismatches
1 parent 5f54af1 commit 3bbf7eb

7 files changed

Lines changed: 21 additions & 24 deletions

File tree

killerbee/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Any, Dict, Union
1+
from typing import Optional, Any, Dict, Union, List
22

33
import struct
44
import glob
@@ -211,7 +211,7 @@ def __device_is(self, vendorId, productId):
211211
if self.dev.idVendor == vendorId and self.dev.idProduct == productId: return True
212212
else: return False
213213

214-
def get_dev_info(self) -> list[str]:
214+
def get_dev_info(self) -> List[str]:
215215
'''
216216
Returns device information in a list identifying the device. Implemented by the loaded driver.
217217
@rtype: List
@@ -272,7 +272,7 @@ def frequency(self, channel: Optional[int]=None, page: int=0) -> int:
272272

273273
return self.driver.capabilities.frequency(channel, page)
274274

275-
def get_capabilities(self) -> list[Any]:
275+
def get_capabilities(self) -> List[Any]:
276276
'''
277277
Returns a list of capability information for the device.
278278
@rtype: List
@@ -295,7 +295,7 @@ def enter_bootloader(self) -> Any:
295295

296296
return self.driver.enter_bootloader()
297297

298-
def get_bootloader_version(self) -> list[int]:
298+
def get_bootloader_version(self) -> List[int]:
299299
'''
300300
Gets the bootloader major and minor version.
301301
@rtype: List
@@ -307,7 +307,7 @@ def get_bootloader_version(self) -> list[int]:
307307

308308
return self.driver.get_bootloader_version()
309309

310-
def get_bootloader_signature(self) -> list[int]:
310+
def get_bootloader_signature(self) -> List[int]:
311311
'''
312312
Gets the bootloader chip signature.
313313
@rtype: List

killerbee/daintree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def close(self) -> None:
9191

9292
del(self._fh)
9393

94-
def pnext(self) -> Optional[list[Any]]:
94+
def pnext(self) -> Optional[List[Any]]:
9595
'''
9696
Retrieves the next packet from the capture file. Returns a list of
9797
[Hdr, packet] where Hdr is a list of [timestamp, snaplen, plen] and

killerbee/dev_apimote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- Platform recognition (ApiMote versons)
1313
'''
1414

15-
from typing import Optional, Dict, Union, Any
15+
from typing import Optional, Dict, Union, Any, List
1616

1717
import os
1818
import time
@@ -82,7 +82,7 @@ def __set_capabilities(self) -> None:
8282
return
8383

8484
# KillerBee expects the driver to implement this function
85-
def get_dev_info(self) -> list[Union[str, Any]]:
85+
def get_dev_info(self) -> List[Union[str, Any]]:
8686
'''
8787
Returns device information in a list identifying the device.
8888
@rtype: List

killerbee/dev_template.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from typing import Optional
2-
from typing import Dict
3-
from typing import Union
4-
from typing import Any
1+
from typing import Optional, Dict, Union, Any, List
52

63
import os
74
import time
@@ -60,7 +57,7 @@ def check_capability(self, capab: int) -> bool:
6057
def get_capabilities(self) -> Dict[int, bool]:
6158
return self.capabilities.getlist()
6259

63-
def get_dev_info(self) -> list[Union[str, Any]]:
60+
def get_dev_info(self) -> List[Union[str, Any]]:
6461
return [self.dev, "GoodFET Apimote", ""]
6562

6663
def sniffer_on(self, channel: Optional[int]=None, page: int=0) -> None:

killerbee/kbutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def __call__(self, device: Any) -> bool:
203203

204204
return False
205205

206-
def devlist_usb_v1x(vendor: Optional[Any]=None, product: Optional[Any]=None) -> list[Any]:
206+
def devlist_usb_v1x(vendor: Optional[Any]=None, product: Optional[Any]=None) -> List[Any]:
207207
'''
208208
Private function. Do not call from tools/scripts/etc.
209209
'''
@@ -246,7 +246,7 @@ def is_valid_ipv6_address(address: str) -> bool:
246246
return True
247247
return ( is_valid_ipv6_address(ip) or is_valid_ipv4_address(ip) )
248248

249-
def devlist(vendor: Optional[Any]=None, product: Optional[Any]=None, gps: Optional[str]=None, include: Optional[str]=None) -> list[Any]:
249+
def devlist(vendor: Optional[Any]=None, product: Optional[Any]=None, gps: Optional[str]=None, include: Optional[str]=None) -> List[Any]:
250250
'''
251251
Return device information for all present devices,
252252
filtering if requested by vendor and/or product IDs on USB devices, and

killerbee/scapy_extensions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __kb_send(kb: KillerBee, x: Union[str, Gen], channel: Optional[int]=None, pa
7272
pass
7373
return n
7474

75-
def __kb_recv(kb: KillerBee, count: int=0, store: int=1, prn: Optional[Any]=None, lfilter: Optional[Any]=None, stop_filter: Optional[Any]=None, verbose: Optional[int]=None, timeout: Optional[int]=None) -> list[bytes]:
75+
def __kb_recv(kb: KillerBee, count: int=0, store: int=1, prn: Optional[Any]=None, lfilter: Optional[Any]=None, stop_filter: Optional[Any]=None, verbose: Optional[int]=None, timeout: Optional[int]=None) -> List[bytes]:
7676
kb.sniffer_on()
7777
if timeout is not None:
7878
stoptime = time.time()+timeout
@@ -290,7 +290,7 @@ def kbrddain(filename: str, count: int=-1, skip: int=0) -> plist.PacketList:
290290
packetcount: int = 0
291291

292292
while 1:
293-
packet: Optional[list[Any]] = cap.pnext()
293+
packet: Optional[List[Any]] = cap.pnext()
294294
if packet is None:
295295
break;
296296
packetcount += 1

tools/zbstumbler

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def display_details(routerdata):
2929
stackprofile = stackprofilever & 0x0f
3030
stackver = (stackprofilever & 0xf0) >>4
3131

32-
print("New Network: PANID 0x{0:02X}{1:02X} Source 0x{2:02X}{3:02X}".format(ord(spanid[0]), ord(spanid[1]), ord(source[0]), ord(source[1])))
32+
print("New Network: PANID 0x{0:02X}{1:02X} Source 0x{2:02X}{3:02X}".format(spanid[0], spanid[1], source[0], source[1]))
3333

3434
try:
3535
extpanidstr=""
3636
for ind in range(0,7):
37-
extpanidstr += "%02x:"%ord(extpanid[ind])
38-
extpanidstr += "%02X"%ord(extpanid[-1])
37+
extpanidstr += "%02x:"%extpanid[ind]
38+
extpanidstr += "%02X"%extpanid[-1]
3939
sys.stdout.write("\tExt PANID: " + extpanidstr)
4040
except IndexError:
4141
sys.stdout.write("\tExt PANID: Unknown")
@@ -57,7 +57,7 @@ def display_details(routerdata):
5757
print(("\tChannel: {0}".format(channel)))
5858

5959
if args.csvfile is not None:
60-
csvfile.write("0x%02X%02X,0x%02X%02X,%s,%s,%s,%d\n"%(ord(spanid[0]), ord(spanid[1]), ord(source[0]), ord(source[1]), extpanidstr, stackprofilestr, stackverstr, channel))
60+
csvfile.write("0x%02X%02X,0x%02X%02X,%s,%s,%s,%d\n"%(spanid[0], spanid[1], source[0], source[1], extpanidstr, stackprofilestr, stackverstr, channel))
6161

6262

6363
def response_handler(stumbled, packet, channel):
@@ -99,7 +99,7 @@ def response_handler(stumbled, packet, channel):
9999
return value
100100

101101
if args.verbose:
102-
print(("Received frame is not a beacon (FCF={0}).".format(pktdecode[0].encode('utf-8').hex())))
102+
print("Received frame is not a beacon (FCF={0}).".format(pktdecode[0]))
103103

104104
return None
105105

@@ -137,7 +137,7 @@ if __name__ == '__main__':
137137
csvfile.write("panid,source,extpanid,stackprofile,stackversion,channel\n")
138138

139139
# Beacon frame
140-
beacon = "\x03\x08\x00\xff\xff\xff\xff\x07"
140+
beacon = b"\x03\x08\x00\xff\xff\xff\xff\x07"
141141
# Immutable strings - split beacon around sequence number field
142142
beaconp1 = beacon[0:2]
143143
beaconp2 = beacon[3:]
@@ -179,7 +179,7 @@ if __name__ == '__main__':
179179
if args.verbose:
180180
print("Transmitting beacon request.")
181181

182-
beaconinj = ''.join([beaconp1, "%c" % seqnum, beaconp2])
182+
beaconinj = b''.join([beaconp1, b"%c" % seqnum, beaconp2])
183183

184184
# Process packets for arg_delay seconds looking for the beacon
185185
# response frame.

0 commit comments

Comments
 (0)