Skip to content

Commit 2849b80

Browse files
committed
lint /examples per PEP8
1 parent d01487f commit 2849b80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+858
-816
lines changed

examples/common/async_asyncio_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,27 @@ async def start_async_test(client):
7575
rq = await client.write_coil(0, True, unit=UNIT)
7676
rr = await client.read_coils(0, 1, unit=UNIT)
7777
assert(rq.function_code < 0x80) # test that we are not an error
78-
assert(rr.bits[0] == True) # test the expected value
78+
assert(rr.bits[0]) # test the expected value
7979

8080
log.debug("Write to multiple coils and read back- test 1")
81-
rq = await client.write_coils(1, [True]*8, unit=UNIT)
81+
rq = await client.write_coils(1, [True] * 8, unit=UNIT)
8282
assert(rq.function_code < 0x80) # test that we are not an error
8383
rr = await client.read_coils(1, 21, unit=UNIT)
8484
assert(rr.function_code < 0x80) # test that we are not an error
85-
resp = [True]*21
85+
resp = [True] * 21
8686

8787
# If the returned output quantity is not a multiple of eight,
8888
# the remaining bits in the final data byte will be padded with zeros
8989
# (toward the high order end of the byte).
9090

91-
resp.extend([False]*3)
91+
resp.extend([False] * 3)
9292
assert(rr.bits == resp) # test the expected value
9393

9494
log.debug("Write to multiple coils and read back - test 2")
95-
rq = await client.write_coils(1, [False]*8, unit=UNIT)
95+
rq = await client.write_coils(1, [False] * 8, unit=UNIT)
9696
rr = await client.read_coils(1, 8, unit=UNIT)
9797
assert(rq.function_code < 0x80) # test that we are not an error
98-
assert(rr.bits == [False]*8) # test the expected value
98+
assert(rr.bits == [False] * 8) # test the expected value
9999

100100
log.debug("Read discrete inputs")
101101
rr = await client.read_discrete_inputs(0, 8, unit=UNIT)
@@ -108,27 +108,27 @@ async def start_async_test(client):
108108
assert(rr.registers[0] == 10) # test the expected value
109109

110110
log.debug("Write to multiple holding registers and read back")
111-
rq = await client.write_registers(1, [10]*8, unit=UNIT)
111+
rq = await client.write_registers(1, [10] * 8, unit=UNIT)
112112
rr = await client.read_holding_registers(1, 8, unit=UNIT)
113113
assert(rq.function_code < 0x80) # test that we are not an error
114-
assert(rr.registers == [10]*8) # test the expected value
114+
assert(rr.registers == [10] * 8) # test the expected value
115115

116116
log.debug("Read input registers")
117117
rr = await client.read_input_registers(1, 8, unit=UNIT)
118118
assert(rq.function_code < 0x80) # test that we are not an error
119119

120120
arguments = {
121-
'read_address': 1,
122-
'read_count': 8,
123-
'write_address': 1,
124-
'write_registers': [20]*8,
121+
'read_address': 1,
122+
'read_count': 8,
123+
'write_address': 1,
124+
'write_registers': [20] * 8,
125125
}
126126
log.debug("Read write registeres simulataneously")
127127
rq = await client.readwrite_registers(unit=UNIT, **arguments)
128128
rr = await client.read_holding_registers(1, 8, unit=UNIT)
129129
assert(rq.function_code < 0x80) # test that we are not an error
130-
assert(rq.registers == [20]*8) # test the expected value
131-
assert(rr.registers == [20]*8) # test the expected value
130+
assert(rq.registers == [20] * 8) # test the expected value
131+
assert(rr.registers == [20] * 8) # test the expected value
132132
await asyncio.sleep(1)
133133

134134

examples/common/async_asyncio_serial_client.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ async def start_async_test(client):
4949
# which defaults to `0x00`
5050
# ----------------------------------------------------------------------- #
5151
try:
52-
# ----------------------------------------------------------------------- #
52+
# ----------------------------------------------------------------------- #
5353
# example requests
54-
# ----------------------------------------------------------------------- #
54+
# ----------------------------------------------------------------------- #
5555
# simply call the methods that you would like to use.
5656
# An example session is displayed below along with some assert checks.
5757
# Note that some modbus implementations differentiate holding/
@@ -61,32 +61,32 @@ async def start_async_test(client):
6161
# so a change to one is a change to the other.
6262
# Keep both of these cases in mind when testing as the following will
6363
# _only_ pass with the supplied asynchronous modbus server (script supplied).
64-
# ----------------------------------------------------------------------- #
64+
# ----------------------------------------------------------------------- #
6565
log.debug("Write to a Coil and read back")
6666
rq = await client.write_coil(0, True, unit=UNIT)
6767
rr = await client.read_coils(0, 1, unit=UNIT)
6868
assert(rq.function_code < 0x80) # test that we are not an error
69-
assert(rr.bits[0] == True) # test the expected value
69+
assert(rr.bits[0]) # test the expected value
7070

7171
log.debug("Write to multiple coils and read back- test 1")
72-
rq = await client.write_coils(1, [True]*8, unit=UNIT)
72+
rq = await client.write_coils(1, [True] * 8, unit=UNIT)
7373
assert(rq.function_code < 0x80) # test that we are not an error
7474
rr = await client.read_coils(1, 21, unit=UNIT)
7575
assert(rr.function_code < 0x80) # test that we are not an error
76-
resp = [True]*21
76+
resp = [True] * 21
7777

7878
# If the returned output quantity is not a multiple of eight,
7979
# the remaining bits in the final data byte will be padded with zeros
8080
# (toward the high order end of the byte).
8181

82-
resp.extend([False]*3)
82+
resp.extend([False] * 3)
8383
assert(rr.bits == resp) # test the expected value
8484

8585
log.debug("Write to multiple coils and read back - test 2")
86-
rq = await client.write_coils(1, [False]*8, unit=UNIT)
86+
rq = await client.write_coils(1, [False] * 8, unit=UNIT)
8787
rr = await client.read_coils(1, 8, unit=UNIT)
8888
assert(rq.function_code < 0x80) # test that we are not an error
89-
assert(rr.bits == [False]*8) # test the expected value
89+
assert(rr.bits == [False] * 8) # test the expected value
9090

9191
log.debug("Read discrete inputs")
9292
rr = await client.read_discrete_inputs(0, 8, unit=UNIT)
@@ -99,27 +99,27 @@ async def start_async_test(client):
9999
assert(rr.registers[0] == 10) # test the expected value
100100

101101
log.debug("Write to multiple holding registers and read back")
102-
rq = await client.write_registers(1, [10]*8, unit=UNIT)
102+
rq = await client.write_registers(1, [10] * 8, unit=UNIT)
103103
rr = await client.read_holding_registers(1, 8, unit=UNIT)
104104
assert(rq.function_code < 0x80) # test that we are not an error
105-
assert(rr.registers == [10]*8) # test the expected value
105+
assert(rr.registers == [10] * 8) # test the expected value
106106

107107
log.debug("Read input registers")
108108
rr = await client.read_input_registers(1, 8, unit=UNIT)
109109
assert(rq.function_code < 0x80) # test that we are not an error
110110

111111
arguments = {
112-
'read_address': 1,
113-
'read_count': 8,
114-
'write_address': 1,
115-
'write_registers': [20]*8,
112+
'read_address': 1,
113+
'read_count': 8,
114+
'write_address': 1,
115+
'write_registers': [20] * 8,
116116
}
117117
log.debug("Read write registers simulataneously")
118118
rq = await client.readwrite_registers(unit=UNIT, **arguments)
119119
rr = await client.read_holding_registers(1, 8, unit=UNIT)
120120
assert(rq.function_code < 0x80) # test that we are not an error
121-
assert(rq.registers == [20]*8) # test the expected value
122-
assert(rr.registers == [20]*8) # test the expected value
121+
assert(rq.registers == [20] * 8) # test the expected value
122+
assert(rr.registers == [20] * 8) # test the expected value
123123
except Exception as e:
124124
log.exception(e)
125125
client.transport.close()
@@ -137,4 +137,3 @@ async def start_async_test(client):
137137
baudrate=9600, method="rtu")
138138
loop.run_until_complete(start_async_test(client.protocol))
139139
loop.close()
140-

examples/common/async_tornado_client.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def beginAsynchronousTest(client, protocol):
8181
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
8282
dassert(rr, _print) # test the expected value
8383

84-
rq = client.write_coils(1, [False]*8, unit=UNIT)
84+
rq = client.write_coils(1, [False] * 8, unit=UNIT)
8585
rr = client.read_coils(1, 8, unit=UNIT)
8686
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
8787
dassert(rr, _print) # test the expected value
8888

89-
rq = client.write_coils(1, [False]*8, unit=UNIT)
89+
rq = client.write_coils(1, [False] * 8, unit=UNIT)
9090
rr = client.read_discrete_inputs(1, 8, unit=UNIT)
9191
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
9292
dassert(rr, _print) # test the expected value
@@ -96,20 +96,20 @@ def beginAsynchronousTest(client, protocol):
9696
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
9797
dassert(rr, _print) # test the expected value
9898

99-
rq = client.write_registers(1, [10]*8, unit=UNIT)
99+
rq = client.write_registers(1, [10] * 8, unit=UNIT)
100100
rr = client.read_input_registers(1, 8, unit=UNIT)
101101
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
102102
dassert(rr, _print) # test the expected value
103103

104104
arguments = {
105-
'read_address': 1,
106-
'read_count': 8,
107-
'write_address': 1,
108-
'write_registers': [20]*8,
105+
'read_address': 1,
106+
'read_count': 8,
107+
'write_address': 1,
108+
'write_registers': [20] * 8,
109109
}
110110
rq = client.readwrite_registers(**arguments, unit=UNIT)
111-
rr = client.read_input_registers(1,8, unit=UNIT)
112-
dassert(rq, lambda r: r.registers == [20]*8) # test the expected value
111+
rr = client.read_input_registers(1, 8, unit=UNIT)
112+
dassert(rq, lambda r: r.registers == [20] * 8) # test the expected value
113113
dassert(rr, _print) # test the expected value
114114

115115
# -----------------------------------------------------------------------#
@@ -144,6 +144,3 @@ def callback(protocol, future):
144144
if __name__ == "__main__":
145145
protocol, future = ModbusClient(schedulers.IO_LOOP, port=5020)
146146
future.add_done_callback(functools.partial(callback, protocol))
147-
148-
149-

examples/common/async_tornado_client_serial.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def dassert(future, callback):
4040

4141
def _assertor(value):
4242
# by pass assertion, an error here stops the write callbacks
43-
assert value
43+
assert value
4444

4545
def on_done(f):
4646
exc = f.exception()
@@ -85,12 +85,12 @@ def beginAsynchronousTest(client, protocol):
8585
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
8686
dassert(rr, _print) # test the expected value
8787

88-
rq = client.write_coils(1, [False]*8, unit=UNIT)
88+
rq = client.write_coils(1, [False] * 8, unit=UNIT)
8989
rr = client.read_coils(1, 8, unit=UNIT)
9090
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
9191
dassert(rr, _print) # test the expected value
9292

93-
rq = client.write_coils(1, [False]*8, unit=UNIT)
93+
rq = client.write_coils(1, [False] * 8, unit=UNIT)
9494
rr = client.read_discrete_inputs(1, 8, unit=UNIT)
9595
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
9696
dassert(rr, _print) # test the expected value
@@ -100,20 +100,20 @@ def beginAsynchronousTest(client, protocol):
100100
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
101101
dassert(rr, _print) # test the expected value
102102

103-
rq = client.write_registers(1, [10]*8, unit=UNIT)
103+
rq = client.write_registers(1, [10] * 8, unit=UNIT)
104104
rr = client.read_input_registers(1, 8, unit=UNIT)
105105
dassert(rq, lambda r: r.function_code < 0x80) # test for no error
106106
dassert(rr, _print) # test the expected value
107107

108108
arguments = {
109-
'read_address': 1,
110-
'read_count': 8,
111-
'write_address': 1,
112-
'write_registers': [20]*8,
109+
'read_address': 1,
110+
'read_count': 8,
111+
'write_address': 1,
112+
'write_registers': [20] * 8,
113113
}
114114
rq = client.readwrite_registers(**arguments, unit=UNIT)
115-
rr = client.read_input_registers(1,8, unit=UNIT)
116-
dassert(rq, lambda r: r.registers == [20]*8) # test the expected value
115+
rr = client.read_input_registers(1, 8, unit=UNIT)
116+
dassert(rq, lambda r: r.registers == [20] * 8) # test the expected value
117117
dassert(rr, _print) # test the expected value
118118

119119
# -----------------------------------------------------------------------#

examples/common/async_twisted_client.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# choose the requested modbus protocol
2121
# --------------------------------------------------------------------------- #
2222

23-
from twisted.internet import reactor, protocol
23+
from twisted.internet import protocol
2424

2525
# --------------------------------------------------------------------------- #
2626
# configure the client logging
@@ -98,38 +98,38 @@ def beginAsynchronousTest(client):
9898
rq = client.write_coil(1, True, unit=UNIT)
9999
rr = client.read_coils(1, 1, unit=UNIT)
100100
dassert(rq, lambda r: not r.isError()) # test for no error
101-
dassert(rr, lambda r: r.bits[0] == True) # test the expected value
101+
dassert(rr, lambda r: r.bits[0]) # test the expected value
102102

103-
rq = client.write_coils(1, [True]*8, unit=UNIT)
103+
rq = client.write_coils(1, [True] * 8, unit=UNIT)
104104
rr = client.read_coils(1, 8, unit=UNIT)
105105
dassert(rq, lambda r: not r.isError()) # test for no error
106-
dassert(rr, lambda r: r.bits == [True]*8) # test the expected value
106+
dassert(rr, lambda r: r.bits == [True] * 8) # test the expected value
107107

108-
rq = client.write_coils(1, [False]*8, unit=UNIT)
108+
rq = client.write_coils(1, [False] * 8, unit=UNIT)
109109
rr = client.read_discrete_inputs(1, 8, unit=UNIT)
110110
dassert(rq, lambda r: not r.isError()) # test for no error
111-
dassert(rr, lambda r: r.bits == [True]*8) # test the expected value
111+
dassert(rr, lambda r: r.bits == [True] * 8) # test the expected value
112112

113113
rq = client.write_register(1, 10, unit=UNIT)
114114
rr = client.read_holding_registers(1, 1, unit=UNIT)
115115
dassert(rq, lambda r: not r.isError()) # test for no error
116116
dassert(rr, lambda r: r.registers[0] == 10) # test the expected value
117117

118-
rq = client.write_registers(1, [10]*8, unit=UNIT)
118+
rq = client.write_registers(1, [10] * 8, unit=UNIT)
119119
rr = client.read_input_registers(1, 8, unit=UNIT)
120120
dassert(rq, lambda r: not r.isError()) # test for no error
121-
dassert(rr, lambda r: r.registers == [17]*8) # test the expected value
121+
dassert(rr, lambda r: r.registers == [17] * 8) # test the expected value
122122

123123
arguments = {
124-
'read_address': 1,
125-
'read_count': 8,
126-
'write_address': 1,
127-
'write_registers': [20]*8,
124+
'read_address': 1,
125+
'read_count': 8,
126+
'write_address': 1,
127+
'write_registers': [20] * 8,
128128
}
129129
rq = client.readwrite_registers(arguments, unit=UNIT)
130130
rr = client.read_input_registers(1, 8, unit=UNIT)
131-
dassert(rq, lambda r: r.registers == [20]*8) # test the expected value
132-
dassert(rr, lambda r: r.registers == [17]*8) # test the expected value
131+
dassert(rq, lambda r: r.registers == [20] * 8) # test the expected value
132+
dassert(rr, lambda r: r.registers == [17] * 8) # test the expected value
133133
stopAsynchronousTest(client)
134134

135135
# ----------------------------------------------------------------------- #
@@ -165,8 +165,5 @@ def beginAsynchronousTest(client):
165165

166166
if __name__ == "__main__":
167167
protocol, deferred = AsyncModbusTCPClient(schedulers.REACTOR, port=5020)
168-
# protocol, deferred = AsyncModbusUDPClient(schedulers.REACTOR, port=5020)
169-
# callback=beginAsynchronousTest,
170-
# errback=err)
171168
deferred.addCallback(beginAsynchronousTest)
172169
deferred.addErrback(err)

examples/common/async_twisted_client_serial.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
CLIENT_DELAY = 1
2828
UNIT = 0x01
2929

30+
3031
class ExampleProtocol(ModbusClientProtocol):
3132

3233
def __init__(self, framer):
@@ -77,12 +78,10 @@ def error_handler(self, failure):
7778
if __name__ == "__main__":
7879
import time
7980
proto, client = AsyncModbusSerialClient(schedulers.REACTOR,
80-
method="rtu",
81-
port=SERIAL_PORT,
82-
timeout=2,
81+
method="rtu",
82+
port=SERIAL_PORT,
83+
timeout=2,
8384
proto_cls=ExampleProtocol)
8485
proto.start()
8586
time.sleep(10) # Wait for operation to complete
8687
# proto.stop()
87-
88-

examples/common/asynchronous_processor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,3 @@ def main():
188188

189189
if __name__ == "__main__":
190190
main()
191-

0 commit comments

Comments
 (0)