Skip to content

Commit ce8bdd8

Browse files
author
chrispyduck
committed
porting from python2 to python3
1 parent 2835dd9 commit ce8bdd8

9 files changed

Lines changed: 35 additions & 38 deletions

File tree

obd/OBDCommand.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import re
3-
from utils import *
4-
from debug import debug
3+
from .utils import *
4+
from .debug import debug
55

66

77

@@ -46,17 +46,17 @@ def compute(self, _data):
4646
r = Response(_data)
4747

4848
# split by lines, and remove empty lines
49-
lines = filter(bool, re.split("[\r\n]", _data))
49+
lines = list(filter(bool, re.split("[\r\n]", _data)))
5050

5151
# splits each line by spaces (each element should be a hex byte)
5252
lines = [line.split() for line in lines]
5353

5454
# filter by minimum response length (number of space delimited chunks (bytes))
55-
lines = filter(lambda line: len(line) >= 7, lines)
55+
lines = [line for line in lines if len(line) >= 7]
5656

5757
if len(lines) > 1:
5858
# filter for ECU 10 (engine)
59-
lines = filter(lambda line: line[2] == '10', lines)
59+
lines = [line for line in lines if line[2] == '10']
6060

6161
# by now, we should have only one line.
6262
# Any more, and its a multiline response (which this library can't handle yet)

obd/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
__version__ = '0.3.0'
3232

33-
from obd import OBD
34-
from OBDCommand import OBDCommand
35-
from commands import commands
36-
from utils import scanSerial, Unit
37-
from debug import debug
38-
from async import Async
33+
from .obd import OBD
34+
from .OBDCommand import OBDCommand
35+
from .commands import commands
36+
from .utils import scanSerial, Unit
37+
from .debug import debug
38+
from .async import Async

obd/async.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@
2828
# #
2929
########################################################################
3030

31-
import obd
3231
import time
3332
import threading
34-
from utils import Response
35-
from commands import OBDCommand
36-
from debug import debug
33+
from .utils import Response
34+
from .debug import debug
35+
from . import OBD
3736

38-
39-
40-
class Async(obd.OBD):
37+
class Async(OBD):
4138
""" subclass representing an OBD-II connection """
4239

4340
def __init__(self, portstr=None):
@@ -85,7 +82,7 @@ def watch(self, c, callback=None, force=False):
8582
return
8683

8784
# new command being watched, store the command
88-
if not self.commands.has_key(c):
85+
if c not in self.commands:
8986
debug("Watching command: %s" % str(c))
9087
self.commands[c] = Response() # give it an initial value
9188
self.callbacks[c] = [] # create an empty list
@@ -130,7 +127,7 @@ def unwatch_all(self):
130127

131128

132129
def query(self, c):
133-
if self.commands.has_key(c):
130+
if c in self.commands:
134131
return self.commands[c]
135132
else:
136133
return Response()

obd/commands.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
# #
2929
########################################################################
3030

31-
from OBDCommand import OBDCommand
32-
from decoders import *
33-
from debug import debug
31+
from .OBDCommand import OBDCommand
32+
from .decoders import *
33+
from .debug import debug
3434

3535

3636

@@ -202,7 +202,7 @@ def __init__(self):
202202
def __getitem__(self, key):
203203
if isinstance(key, int):
204204
return self.modes[key]
205-
elif isinstance(key, basestring):
205+
elif isinstance(key, str):
206206
return self.__dict__[key]
207207
else:
208208
debug("OBD commands can only be retrieved by PID value or dict name", True)
@@ -249,7 +249,7 @@ def has_command(self, c):
249249

250250
# checks for existance of command by name
251251
def has_name(self, s):
252-
if isinstance(s, basestring):
252+
if isinstance(s, str):
253253
return s.isupper() and (s in self.__dict__.keys())
254254
else:
255255
debug("has_name() only accepts string names for commands", True)

obd/decoders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
########################################################################
3030

3131
import math
32-
from utils import *
33-
from codes import *
34-
from debug import debug
32+
from .utils import *
33+
from .codes import *
34+
from .debug import debug
3535

3636
'''
3737
All decoders take the form:

obd/obd.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
########################################################################
3030

3131
import time
32-
from port import OBDPort, State
33-
from commands import commands
34-
from utils import scanSerial, Response
35-
from debug import debug
32+
from .port import OBDPort, State
33+
from .commands import commands
34+
from .utils import scanSerial, Response
35+
from .debug import debug
3636

3737

3838

@@ -135,7 +135,7 @@ def load_commands(self):
135135

136136
def print_commands(self):
137137
for c in self.supported_commands:
138-
print str(c)
138+
print(str(c))
139139

140140

141141
def supports(self, c):

obd/port.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import serial
3232
import string
3333
import time
34-
from utils import Response, unhex
35-
from debug import debug
34+
from .utils import Response, unhex
35+
from .debug import debug
3636

3737

3838
class State():

obd/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import time
3535
import glob
3636
import sys
37-
from debug import debug
37+
from .debug import debug
3838

3939

4040
class Unit:
@@ -87,7 +87,7 @@ def __init__(self, name, available, incomplete):
8787
def __str__(self):
8888
a = "Available" if self.available else "Unavailable"
8989
c = "Incomplete" if self.incomplete else "Complete"
90-
return "Test %s: %s, %s" % (name, a, c)
90+
return "Test %s: %s, %s" % (self.name, a, c)
9191

9292

9393

tests/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_unique_names():
2828

2929
for cmds in obd.commands.modes:
3030
for cmd in cmds:
31-
assert not names.has_key(cmd.name), "Two commands share the same name: %s" % cmd.name
31+
assert not names.__contains__(cmd.name), "Two commands share the same name: %s" % cmd.name
3232
names[cmd.name] = True
3333

3434

0 commit comments

Comments
 (0)