Skip to content

Commit

Permalink
2to3 applied
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Sep 25, 2019
1 parent ffa68ef commit 2dc3409
Show file tree
Hide file tree
Showing 38 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion board/tools/enter_download_mode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function


import sys
import time
Expand Down
4 changes: 2 additions & 2 deletions examples/can_bit_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def load(self, filename, start, end):

def PrintUnique(log_file, low_range, high_range):
# find messages with bits that are always low
start, end = map(float, low_range.split('-'))
start, end = list(map(float, low_range.split('-')))
low = Info()
low.load(log_file, start, end)
# find messages with bits that are always high
start, end = map(float, high_range.split('-'))
start, end = list(map(float, high_range.split('-')))
high = Info()
high.load(log_file, start, end)
# print messages that go from low to high
Expand Down
2 changes: 1 addition & 1 deletion examples/can_logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import binascii
import csv
import sys
Expand Down
14 changes: 7 additions & 7 deletions python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# python library to interface with panda
from __future__ import print_function

import binascii
import struct
import hashlib
Expand All @@ -9,12 +9,12 @@
import time
import traceback
import subprocess
from dfu import PandaDFU
from esptool import ESPROM, CesantaFlasher
from flash_release import flash_release
from update import ensure_st_up_to_date
from serial import PandaSerial
from isotp import isotp_send, isotp_recv
from .dfu import PandaDFU
from .esptool import ESPROM, CesantaFlasher
from .flash_release import flash_release
from .update import ensure_st_up_to_date
from .serial import PandaSerial
from .isotp import isotp_send, isotp_recv

__version__ = '0.0.9'

Expand Down
2 changes: 1 addition & 1 deletion python/dfu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import os
import usb1
import struct
Expand Down
6 changes: 3 additions & 3 deletions python/esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, port=None, baud=ESP_ROM_BAUD):

""" Read a SLIP packet from the serial port """
def read(self):
return self._slip_reader.next()
return next(self._slip_reader)

""" Write bytes to the serial port while performing SLIP escaping """
def write(self, packet):
Expand Down Expand Up @@ -991,7 +991,7 @@ def elf2image(args):

def read_mac(esp, args):
mac = esp.read_mac()
print('MAC: %s' % ':'.join(map(lambda x: '%02x' % x, mac)))
print('MAC: %s' % ':'.join(['%02x' % x for x in mac]))


def chip_id(esp, args):
Expand Down Expand Up @@ -1203,7 +1203,7 @@ def add_spi_flash_subparsers(parent, auto_detect=False):
'version', help='Print esptool version')

# internal sanity check - every operation matches a module function of the same name
for operation in subparsers.choices.keys():
for operation in list(subparsers.choices.keys()):
assert operation in globals(), "%s should be a module function" % operation

args = parser.parse_args()
Expand Down
6 changes: 3 additions & 3 deletions python/flash_release.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
from __future__ import print_function

import sys
import time
import requests
import json
import StringIO
import io

def flash_release(path=None, st_serial=None):
from panda import Panda, PandaDFU, ESPROM, CesantaFlasher
Expand All @@ -29,7 +29,7 @@ def status(x):
url = json.loads(r.text)['url']
r = requests.get(url)
print("Fetching firmware from %s" % url)
path = StringIO.StringIO(r.content)
path = io.StringIO(r.content)

zf = ZipFile(path)
zf.printdir()
Expand Down
2 changes: 1 addition & 1 deletion python/isotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def recv(panda, cnt, addr, nbus):
# leave around
nmsgs.append((ids, ts, dat, bus))
kmsgs = nmsgs[-256:]
return map(str, ret)
return list(map(str, ret))

def isotp_recv_subaddr(panda, addr, bus, sendaddr, subaddr):
msg = recv(panda, 1, addr, bus)[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/all_wifi_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import requests
import json
from automated.helpers import _connect_wifi
from .automated.helpers import _connect_wifi
from panda import Panda
from nose.tools import assert_equal

Expand Down
2 changes: 1 addition & 1 deletion tests/automated/1_program.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from panda import Panda
from helpers import panda_type_to_serial, test_white_and_grey, test_all_pandas, panda_connect_and_init
from .helpers import panda_type_to_serial, test_white_and_grey, test_all_pandas, panda_connect_and_init

@test_all_pandas
@panda_connect_and_init
Expand Down
18 changes: 9 additions & 9 deletions tests/automated/2_usb_to_can.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import print_function

import os
import sys
import time
from panda import Panda
from nose.tools import assert_equal, assert_less, assert_greater
from helpers import SPEED_NORMAL, SPEED_GMLAN, time_many_sends, test_white_and_grey, panda_type_to_serial, test_all_pandas, panda_connect_and_init
from .helpers import SPEED_NORMAL, SPEED_GMLAN, time_many_sends, test_white_and_grey, panda_type_to_serial, test_all_pandas, panda_connect_and_init

@test_all_pandas
@panda_connect_and_init
Expand All @@ -30,8 +30,8 @@ def test_can_loopback(p):
# confirm receive both on loopback and send receipt
time.sleep(0.05)
r = p.can_recv()
sr = filter(lambda x: x[3] == 0x80 | bus, r)
lb = filter(lambda x: x[3] == bus, r)
sr = [x for x in r if x[3] == 0x80 | bus]
lb = [x for x in r if x[3] == bus]
assert len(sr) == 1
assert len(lb) == 1

Expand Down Expand Up @@ -67,7 +67,7 @@ def test_reliability(p):
p.set_can_loopback(True)
p.set_can_speed_kbps(0, 1000)

addrs = range(100, 100+MSG_COUNT)
addrs = list(range(100, 100+MSG_COUNT))
ts = [(j, 0, "\xaa"*8, 0) for j in addrs]

# 100 loops
Expand All @@ -80,11 +80,11 @@ def test_reliability(p):
while len(r) < 200 and (time.time() - st) < 0.5:
r.extend(p.can_recv())

sent_echo = filter(lambda x: x[3] == 0x80, r)
loopback_resp = filter(lambda x: x[3] == 0, r)
sent_echo = [x for x in r if x[3] == 0x80]
loopback_resp = [x for x in r if x[3] == 0]

assert_equal(sorted(map(lambda x: x[0], loopback_resp)), addrs)
assert_equal(sorted(map(lambda x: x[0], sent_echo)), addrs)
assert_equal(sorted([x[0] for x in loopback_resp]), addrs)
assert_equal(sorted([x[0] for x in sent_echo]), addrs)
assert_equal(len(r), 200)

# take sub 20ms
Expand Down
4 changes: 2 additions & 2 deletions tests/automated/3_wifi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import print_function

import os
import time
from panda import Panda
from helpers import connect_wifi, test_white, test_all_pandas, panda_type_to_serial, panda_connect_and_init
from .helpers import connect_wifi, test_white, test_all_pandas, panda_type_to_serial, panda_connect_and_init
import requests

@test_all_pandas
Expand Down
4 changes: 2 additions & 2 deletions tests/automated/4_wifi_functionality.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function

import time
from panda import Panda
from helpers import time_many_sends, connect_wifi, test_white, panda_type_to_serial
from .helpers import time_many_sends, connect_wifi, test_white, panda_type_to_serial
from nose.tools import timed, assert_equal, assert_less, assert_greater

@test_white
Expand Down
6 changes: 3 additions & 3 deletions tests/automated/5_wifi_udp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function

import sys
import time
from helpers import time_many_sends, connect_wifi, test_white, panda_type_to_serial
from .helpers import time_many_sends, connect_wifi, test_white, panda_type_to_serial
from panda import Panda, PandaWifiStreaming
from nose.tools import timed, assert_equal, assert_less, assert_greater

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_udp_doesnt_drop(serials=None):
missing = True
while len(r) > 0:
r = p.can_recv()
r = filter(lambda x: x[3] == bus and x[0] == msg_id, r)
r = [x for x in r if x[3] == bus and x[0] == msg_id]
if len(r) > 0:
missing = False
usb_ok_cnt += len(r)
Expand Down
4 changes: 2 additions & 2 deletions tests/automated/6_two_panda.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import print_function

import os
import time
import random
from panda import Panda
from nose.tools import assert_equal, assert_less, assert_greater
from helpers import time_many_sends, test_two_panda, test_two_black_panda, panda_type_to_serial, clear_can_buffers, panda_connect_and_init
from .helpers import time_many_sends, test_two_panda, test_two_black_panda, panda_type_to_serial, clear_can_buffers, panda_connect_and_init

@test_two_panda
@panda_type_to_serial
Expand Down
14 changes: 7 additions & 7 deletions tests/automated/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import random
import subprocess
import requests
import thread
import _thread
from functools import wraps
from panda import Panda
from nose.tools import timed, assert_equal, assert_less, assert_greater
Expand Down Expand Up @@ -75,7 +75,7 @@ def _connect_wifi(dongle_id, pw, insecure_okay=False):
print("WIFI: scanning %d" % cnt)
os.system("iwlist %s scanning > /dev/null" % wlan_interface)
os.system("nmcli device wifi rescan")
wifi_scan = filter(lambda x: ssid in x, subprocess.check_output(["nmcli","dev", "wifi", "list"]).split("\n"))
wifi_scan = [x for x in subprocess.check_output(["nmcli","dev", "wifi", "list"]).split("\n") if ssid in x]
if len(wifi_scan) != 0:
break
time.sleep(0.1)
Expand Down Expand Up @@ -153,11 +153,11 @@ def time_many_sends(p, bus, precv=None, msg_count=100, msg_id=None, two_pandas=F
while len(r_echo) < r_echo_len_exected and (time.time() - st) < 10:
r_echo.extend(p.can_recv())

sent_echo = filter(lambda x: x[3] == 0x80 | bus and x[0] == msg_id, r)
sent_echo.extend(filter(lambda x: x[3] == 0x80 | bus and x[0] == msg_id, r_echo))
resp = filter(lambda x: x[3] == bus and x[0] == msg_id, r)
sent_echo = [x for x in r if x[3] == 0x80 | bus and x[0] == msg_id]
sent_echo.extend([x for x in r_echo if x[3] == 0x80 | bus and x[0] == msg_id])
resp = [x for x in r if x[3] == bus and x[0] == msg_id]

leftovers = filter(lambda x: (x[3] != 0x80 | bus and x[3] != bus) or x[0] != msg_id, r)
leftovers = [x for x in r if (x[3] != 0x80 | bus and x[3] != bus) or x[0] != msg_id]
assert_equal(len(leftovers), 0)

assert_equal(len(resp), msg_count)
Expand Down Expand Up @@ -230,7 +230,7 @@ def wrapper(panda_serials=None, **kwargs):
for bus, speed in [(0, SPEED_NORMAL), (1, SPEED_NORMAL), (2, SPEED_NORMAL), (3, SPEED_GMLAN)]:
panda.set_can_speed_kbps(bus, speed)
clear_can_buffers(panda)
thread.start_new_thread(heartbeat_thread, (panda,))
_thread.start_new_thread(heartbeat_thread, (panda,))

# Run test function
ret = fn(*pandas, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion tests/black_loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Tests all buses, including OBD CAN, which is on the same bus as CAN0 in this test.
# To be sure, the test should be run with both harness orientations

from __future__ import print_function

import os
import sys
import time
Expand Down
2 changes: 1 addition & 1 deletion tests/black_white_loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Tests all buses, including OBD CAN, which is on the same bus as CAN0 in this test.
# To be sure, the test should be run with both harness orientations

from __future__ import print_function

import os
import sys
import time
Expand Down
2 changes: 1 addition & 1 deletion tests/black_white_relay_endurance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Tests all buses, including OBD CAN, which is on the same bus as CAN0 in this test.
# To be sure, the test should be run with both harness orientations

from __future__ import print_function

import os
import sys
import time
Expand Down
2 changes: 1 addition & 1 deletion tests/black_white_relay_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Relay test with loopback between black panda (+ harness and power) and white/grey panda
# Tests the relay switching multiple times / second by looking at the buses on which loop occurs.

from __future__ import print_function

import os
import sys
import time
Expand Down
4 changes: 2 additions & 2 deletions tests/can_printer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import os
import sys
import time
Expand Down Expand Up @@ -30,7 +30,7 @@ def can_printer():
if sec_since_boot() - lp > 0.1:
dd = chr(27) + "[2J"
dd += "%5.2f\n" % (sec_since_boot() - start)
for k,v in sorted(zip(msgs.keys(), map(lambda x: binascii.hexlify(x[-1]), msgs.values()))):
for k,v in sorted(zip(list(msgs.keys()), [binascii.hexlify(x[-1]) for x in list(msgs.values())])):
dd += "%s(%6d) %s\n" % ("%04X(%4d)" % (k,k),len(msgs[k]), v)
print(dd)
lp = sec_since_boot()
Expand Down
6 changes: 3 additions & 3 deletions tests/debug_console.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import os
import sys
import time
Expand All @@ -19,9 +19,9 @@

serials = Panda.list()
if os.getenv("SERIAL"):
serials = filter(lambda x: x==os.getenv("SERIAL"), serials)
serials = [x for x in serials if x==os.getenv("SERIAL")]

pandas = list(map(lambda x: Panda(x, claim=claim), serials))
pandas = list([Panda(x, claim=claim) for x in serials])

if not len(pandas):
sys.exit("no pandas found")
Expand Down
2 changes: 1 addition & 1 deletion tests/elm_car_simulator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""Used to Reverse/Test ELM protocol auto detect and OBD message response without a car."""
from __future__ import print_function

import sys
import os
import struct
Expand Down
2 changes: 1 addition & 1 deletion tests/elm_throughput.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import socket
import threading
import select
Expand Down
4 changes: 2 additions & 2 deletions tests/elm_wifi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import os
import sys
import time
Expand All @@ -8,7 +8,7 @@
import struct

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
import elm_car_simulator
from . import elm_car_simulator
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", ".."))
from panda import Panda

Expand Down
Loading

0 comments on commit 2dc3409

Please sign in to comment.