Skip to content

Commit b6c8752

Browse files
Peter Andersenfelixdivo
authored andcommitted
Updated instances of **config to **kwargs, closes hardbyte#492
1 parent 6090e94 commit b6c8752

8 files changed

Lines changed: 70 additions & 71 deletions

File tree

can/bus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BusABC(object):
3333
RECV_LOGGING_LEVEL = 9
3434

3535
@abstractmethod
36-
def __init__(self, channel, can_filters=None, **config):
36+
def __init__(self, channel, can_filters=None, **kwargs):
3737
"""Construct and open a CAN bus instance of the specified type.
3838
3939
Subclasses should call though this method with all given parameters
@@ -45,7 +45,7 @@ def __init__(self, channel, can_filters=None, **config):
4545
:param list can_filters:
4646
See :meth:`~can.BusABC.set_filters` for details.
4747
48-
:param dict config:
48+
:param dict kwargs:
4949
Any backend dependent configurations are passed in this dictionary
5050
"""
5151
self._periodic_tasks = []

can/interface.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Bus(BusABC):
7575
"""
7676

7777
@staticmethod
78-
def __new__(cls, channel=None, *args, **config):
78+
def __new__(cls, channel=None, *args, **kwargs):
7979
"""
8080
Takes the same arguments as :class:`can.BusABC.__init__`.
8181
Some might have a special meaning, see below.
@@ -86,7 +86,7 @@ def __new__(cls, channel=None, *args, **config):
8686
8787
Expected type is backend dependent.
8888
89-
:param dict config:
89+
:param dict kwargs:
9090
Should contain an ``interface`` key with a valid interface name. If not,
9191
it is completed using :meth:`can.util.load_config`.
9292
@@ -99,32 +99,32 @@ def __new__(cls, channel=None, *args, **config):
9999

100100
# figure out the rest of the configuration; this might raise an error
101101
if channel is not None:
102-
config['channel'] = channel
103-
if 'context' in config:
104-
context = config['context']
105-
del config['context']
102+
kwargs['channel'] = channel
103+
if 'context' in kwargs:
104+
context = kwargs['context']
105+
del kwargs['context']
106106
else:
107107
context = None
108-
config = load_config(config=config, context=context)
108+
kwargs = load_config(config=kwargs, context=context)
109109

110110
# resolve the bus class to use for that interface
111-
cls = _get_class_for_interface(config['interface'])
111+
cls = _get_class_for_interface(kwargs['interface'])
112112

113113
# remove the 'interface' key so it doesn't get passed to the backend
114-
del config['interface']
114+
del kwargs['interface']
115115

116116
# make sure the bus can handle this config format
117-
if 'channel' not in config:
117+
if 'channel' not in kwargs:
118118
raise ValueError("'channel' argument missing")
119119
else:
120-
channel = config['channel']
121-
del config['channel']
120+
channel = kwargs['channel']
121+
del kwargs['channel']
122122

123123
if channel is None:
124124
# Use the default channel for the backend
125-
return cls(*args, **config)
125+
return cls(*args, **kwargs)
126126
else:
127-
return cls(channel, *args, **config)
127+
return cls(channel, *args, **kwargs)
128128

129129

130130
def detect_available_configs(interfaces=None):

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class NeoViBus(BusABC):
6666
https://github.com/intrepidcs/python_ics
6767
"""
6868

69-
def __init__(self, channel, can_filters=None, **config):
69+
def __init__(self, channel, can_filters=None, **kwargs):
7070
"""
7171
:param channel:
7272
The channel ids to create this bus with.
@@ -98,13 +98,13 @@ def __init__(self, channel, can_filters=None, **config):
9898
raise ImportError('Please install python-ics')
9999

100100
super(NeoViBus, self).__init__(
101-
channel=channel, can_filters=can_filters, **config)
101+
channel=channel, can_filters=can_filters, **kwargs)
102102

103103
logger.info("CAN Filters: {}".format(can_filters))
104-
logger.info("Got configuration of: {}".format(config))
104+
logger.info("Got configuration of: {}".format(kwargs))
105105

106-
if 'override_library_name' in config:
107-
ics.override_library_name(config.get('override_library_name'))
106+
if 'override_library_name' in kwargs:
107+
ics.override_library_name(kwargs.get('override_library_name'))
108108

109109
if isinstance(channel, (list, tuple)):
110110
self.channels = channel
@@ -115,26 +115,26 @@ def __init__(self, channel, can_filters=None, **config):
115115
self.channels = [ch.strip() for ch in channel.split(',')]
116116
self.channels = [NeoViBus.channel_to_netid(ch) for ch in self.channels]
117117

118-
type_filter = config.get('type_filter')
119-
serial = config.get('serial')
118+
type_filter = kwargs.get('type_filter')
119+
serial = kwargs.get('serial')
120120
self.dev = self._find_device(type_filter, serial)
121121
ics.open_device(self.dev)
122122

123-
if 'bitrate' in config:
123+
if 'bitrate' in kwargs:
124124
for channel in self.channels:
125-
ics.set_bit_rate(self.dev, config.get('bitrate'), channel)
125+
ics.set_bit_rate(self.dev, kwargs.get('bitrate'), channel)
126126

127-
fd = config.get('fd', False)
127+
fd = kwargs.get('fd', False)
128128
if fd:
129-
if 'data_bitrate' in config:
129+
if 'data_bitrate' in kwargs:
130130
for channel in self.channels:
131131
ics.set_fd_bit_rate(
132-
self.dev, config.get('data_bitrate'), channel)
132+
self.dev, kwargs.get('data_bitrate'), channel)
133133

134134
self._use_system_timestamp = bool(
135-
config.get('use_system_timestamp', False)
135+
kwargs.get('use_system_timestamp', False)
136136
)
137-
self._receive_own_messages = config.get('receive_own_messages', True)
137+
self._receive_own_messages = kwargs.get('receive_own_messages', True)
138138

139139
self.channel_info = '%s %s CH:%s' % (
140140
self.dev.Name,

can/interfaces/ixxat/canlib.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class IXXATBus(BusABC):
272272
}
273273
}
274274

275-
def __init__(self, channel, can_filters=None, **config):
275+
def __init__(self, channel, can_filters=None, **kwargs):
276276
"""
277277
:param int channel:
278278
The Channel id to create this bus with.
@@ -292,13 +292,13 @@ def __init__(self, channel, can_filters=None, **config):
292292
if _canlib is None:
293293
raise ImportError("The IXXAT VCI library has not been initialized. Check the logs for more details.")
294294
log.info("CAN Filters: %s", can_filters)
295-
log.info("Got configuration of: %s", config)
295+
log.info("Got configuration of: %s", kwargs)
296296
# Configuration options
297-
bitrate = config.get('bitrate', 500000)
298-
UniqueHardwareId = config.get('UniqueHardwareId', None)
299-
rxFifoSize = config.get('rxFifoSize', 16)
300-
txFifoSize = config.get('txFifoSize', 16)
301-
self._receive_own_messages = config.get('receive_own_messages', False)
297+
bitrate = kwargs.get('bitrate', 500000)
298+
UniqueHardwareId = kwargs.get('UniqueHardwareId', None)
299+
rxFifoSize = kwargs.get('rxFifoSize', 16)
300+
txFifoSize = kwargs.get('txFifoSize', 16)
301+
self._receive_own_messages = kwargs.get('receive_own_messages', False)
302302
# Usually comes as a string from the config file
303303
channel = int(channel)
304304

@@ -395,7 +395,7 @@ def __init__(self, channel, can_filters=None, **config):
395395
except (VCITimeout, VCIRxQueueEmptyError):
396396
break
397397

398-
super(IXXATBus, self).__init__(channel=channel, can_filters=None, **config)
398+
super(IXXATBus, self).__init__(channel=channel, can_filters=None, **kwargs)
399399

400400
def _inWaiting(self):
401401
try:

can/interfaces/kvaser/canlib.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class KvaserBus(BusABC):
302302
The CAN Bus implemented for the Kvaser interface.
303303
"""
304304

305-
def __init__(self, channel, can_filters=None, **config):
305+
def __init__(self, channel, can_filters=None, **kwargs):
306306
"""
307307
:param int channel:
308308
The Channel id to create this bus with.
@@ -353,18 +353,18 @@ def __init__(self, channel, can_filters=None, **config):
353353
"""
354354

355355
log.info("CAN Filters: {}".format(can_filters))
356-
log.info("Got configuration of: {}".format(config))
357-
bitrate = config.get('bitrate', 500000)
358-
tseg1 = config.get('tseg1', 0)
359-
tseg2 = config.get('tseg2', 0)
360-
sjw = config.get('sjw', 0)
361-
no_samp = config.get('no_samp', 0)
362-
driver_mode = config.get('driver_mode', DRIVER_MODE_NORMAL)
363-
single_handle = config.get('single_handle', False)
364-
receive_own_messages = config.get('receive_own_messages', False)
365-
accept_virtual = config.get('accept_virtual', True)
366-
fd = config.get('fd', False)
367-
data_bitrate = config.get('data_bitrate', None)
356+
log.info("Got configuration of: {}".format(kwargs))
357+
bitrate = kwargs.get('bitrate', 500000)
358+
tseg1 = kwargs.get('tseg1', 0)
359+
tseg2 = kwargs.get('tseg2', 0)
360+
sjw = kwargs.get('sjw', 0)
361+
no_samp = kwargs.get('no_samp', 0)
362+
driver_mode = kwargs.get('driver_mode', DRIVER_MODE_NORMAL)
363+
single_handle = kwargs.get('single_handle', False)
364+
receive_own_messages = kwargs.get('receive_own_messages', False)
365+
accept_virtual = kwargs.get('accept_virtual', True)
366+
fd = kwargs.get('fd', False)
367+
data_bitrate = kwargs.get('data_bitrate', None)
368368

369369
try:
370370
channel = int(channel)
@@ -400,7 +400,7 @@ def __init__(self, channel, can_filters=None, **config):
400400
4)
401401

402402
if fd:
403-
if 'tseg1' not in config and bitrate in BITRATE_FD:
403+
if 'tseg1' not in kwargs and bitrate in BITRATE_FD:
404404
# Use predefined bitrate for arbitration
405405
bitrate = BITRATE_FD[bitrate]
406406
if data_bitrate in BITRATE_FD:
@@ -411,7 +411,7 @@ def __init__(self, channel, can_filters=None, **config):
411411
data_bitrate = bitrate
412412
canSetBusParamsFd(self._read_handle, data_bitrate, tseg1, tseg2, sjw)
413413
else:
414-
if 'tseg1' not in config and bitrate in BITRATE_OBJS:
414+
if 'tseg1' not in kwargs and bitrate in BITRATE_OBJS:
415415
bitrate = BITRATE_OBJS[bitrate]
416416
canSetBusParams(self._read_handle, bitrate, tseg1, tseg2, sjw, no_samp, 0)
417417

@@ -446,7 +446,7 @@ def __init__(self, channel, can_filters=None, **config):
446446
self._timestamp_offset = time.time() - (timer.value * TIMESTAMP_FACTOR)
447447

448448
self._is_filtered = False
449-
super(KvaserBus, self).__init__(channel=channel, can_filters=can_filters, **config)
449+
super(KvaserBus, self).__init__(channel=channel, can_filters=can_filters, **kwargs)
450450

451451
def _apply_filters(self, filters):
452452
if filters and len(filters) == 1:

can/interfaces/systec/ucanbus.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class UcanBus(BusABC):
4848
1000000: Baudrate.BAUD_1MBit
4949
}
5050

51-
def __init__(self, channel, can_filters=None, **config):
51+
def __init__(self, channel, can_filters=None, **kwargs):
5252
"""
5353
:param int channel:
5454
The Channel id to create this bus with.
@@ -96,14 +96,14 @@ def __init__(self, channel, can_filters=None, **config):
9696
raise ImportError("The SYSTEC ucan library has not been initialized.")
9797

9898
self.channel = int(channel)
99-
device_number = int(config.get('device_number', ANY_MODULE))
99+
device_number = int(kwargs.get('device_number', ANY_MODULE))
100100

101101
# configuration options
102-
bitrate = config.get('bitrate', 500000)
102+
bitrate = kwargs.get('bitrate', 500000)
103103
if bitrate not in self.BITRATES:
104104
raise ValueError("Invalid bitrate {}".format(bitrate))
105105

106-
state = config.get('state', BusState.ACTIVE)
106+
state = kwargs.get('state', BusState.ACTIVE)
107107
if state is BusState.ACTIVE or BusState.PASSIVE:
108108
self._state = state
109109
else:
@@ -112,15 +112,15 @@ def __init__(self, channel, can_filters=None, **config):
112112
# get parameters
113113
self._params = {
114114
"mode": Mode.MODE_NORMAL |
115-
(Mode.MODE_TX_ECHO if config.get('receive_own_messages') else 0) |
115+
(Mode.MODE_TX_ECHO if kwargs.get('receive_own_messages') else 0) |
116116
(Mode.MODE_LISTEN_ONLY if state is BusState.PASSIVE else 0),
117117
"BTR": self.BITRATES[bitrate]
118118
}
119119
# get extra parameters
120-
if config.get("rx_buffer_entries"):
121-
self._params["rx_buffer_entries"] = int(config.get("rx_buffer_entries"))
122-
if config.get("tx_buffer_entries"):
123-
self._params["tx_buffer_entries"] = int(config.get("tx_buffer_entries"))
120+
if kwargs.get("rx_buffer_entries"):
121+
self._params["rx_buffer_entries"] = int(kwargs.get("rx_buffer_entries"))
122+
if kwargs.get("tx_buffer_entries"):
123+
self._params["tx_buffer_entries"] = int(kwargs.get("tx_buffer_entries"))
124124

125125
self._ucan.init_hardware(device_number=device_number)
126126
self._ucan.init_can(self.channel, **self._params)
@@ -131,7 +131,7 @@ def __init__(self, channel, can_filters=None, **config):
131131
self.channel,
132132
self._ucan.get_baudrate_message(self.BITRATES[bitrate])
133133
)
134-
super(UcanBus, self).__init__(channel=channel, can_filters=can_filters, **config)
134+
super(UcanBus, self).__init__(channel=channel, can_filters=can_filters, **kwargs)
135135

136136
def _recv_internal(self, timeout):
137137
message, _ = self._ucan.read_can_msg(self.channel, 1, timeout)

can/interfaces/vector/canlib.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class VectorBus(BusABC):
4949

5050
def __init__(self, channel, can_filters=None, poll_interval=0.01,
5151
receive_own_messages=False,
52-
bitrate=None, rx_queue_size=2**14, app_name="CANalyzer", serial=None, fd=False, data_bitrate=None, sjwAbr=2, tseg1Abr=6, tseg2Abr=3, sjwDbr=2, tseg1Dbr=6, tseg2Dbr=3, **config):
52+
bitrate=None, rx_queue_size=2**14, app_name="CANalyzer",
53+
serial=None, fd=False, data_bitrate=None, sjwAbr=2, tseg1Abr=6,
54+
tseg2Abr=3, sjwDbr=2, tseg1Dbr=6, tseg2Dbr=3, **kwargs):
5355
"""
5456
:param list channel:
5557
The channel indexes to create this bus with.
@@ -208,8 +210,7 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
208210
self._time_offset = time.time() - offset.value * 1e-9
209211

210212
self._is_filtered = False
211-
super(VectorBus, self).__init__(channel=channel, can_filters=can_filters,
212-
**config)
213+
super(VectorBus, self).__init__(channel=channel, can_filters=can_filters, **kwargs)
213214

214215
def _apply_filters(self, filters):
215216
if filters:

can/interfaces/virtual.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ class VirtualBus(BusABC):
4747
if a message is sent to 5 receivers with the timeout set to 1.0.
4848
"""
4949

50-
def __init__(self, channel=None, receive_own_messages=False,
51-
rx_queue_size=0, **config):
52-
super(VirtualBus, self).__init__(channel=channel,
53-
receive_own_messages=receive_own_messages, **config)
50+
def __init__(self, channel=None, receive_own_messages=False, rx_queue_size=0, **kwargs):
51+
super(VirtualBus, self).__init__(channel=channel, receive_own_messages=receive_own_messages, **kwargs)
5452

5553
# the channel identifier may be an arbitrary object
5654
self.channel_id = channel

0 commit comments

Comments
 (0)