Skip to content

Commit 336420b

Browse files
mrKazzilalukebakken
authored andcommitted
style: change double quotes to single quotes (where possible)
style: sort imports & format parameters onto separate lines for better clarity Format all python files using `black`
1 parent b958631 commit 336420b

12 files changed

+127
-78
lines changed

python/emit_log.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import pika
55

66
connection = pika.BlockingConnection(
7-
pika.ConnectionParameters(host='localhost'))
7+
pika.ConnectionParameters(host="localhost"),
8+
)
89
channel = connection.channel()
910

10-
channel.exchange_declare(exchange='logs', exchange_type='fanout')
11+
channel.exchange_declare(exchange="logs", exchange_type="fanout")
1112

12-
message = ' '.join(sys.argv[1:]) or "info: Hello World!"
13-
channel.basic_publish(exchange='logs', routing_key='', body=message)
13+
message = " ".join(sys.argv[1:]) or "info: Hello World!"
14+
channel.basic_publish(exchange="logs", routing_key="", body=message)
1415
print(f" [x] Sent {message}")
16+
1517
connection.close()

python/emit_log_direct.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
import pika
55

66
connection = pika.BlockingConnection(
7-
pika.ConnectionParameters(host='localhost'))
7+
pika.ConnectionParameters(host="localhost"),
8+
)
89
channel = connection.channel()
910

10-
channel.exchange_declare(exchange='direct_logs', exchange_type='direct')
11+
channel.exchange_declare(exchange="direct_logs", exchange_type="direct")
1112

12-
severity = sys.argv[1] if len(sys.argv) > 2 else 'info'
13-
message = ' '.join(sys.argv[2:]) or 'Hello World!'
13+
severity = sys.argv[1] if len(sys.argv) > 2 else "info"
14+
message = " ".join(sys.argv[2:]) or "Hello World!"
1415
channel.basic_publish(
15-
exchange='direct_logs', routing_key=severity, body=message)
16+
exchange="direct_logs",
17+
routing_key=severity,
18+
body=message,
19+
)
1620
print(f" [x] Sent {severity}:{message}")
21+
1722
connection.close()

python/emit_log_topic.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
import pika
55

66
connection = pika.BlockingConnection(
7-
pika.ConnectionParameters(host='localhost'))
7+
pika.ConnectionParameters(host="localhost"),
8+
)
89
channel = connection.channel()
910

10-
channel.exchange_declare(exchange='topic_logs', exchange_type='topic')
11+
channel.exchange_declare(exchange="topic_logs", exchange_type="topic")
1112

12-
routing_key = sys.argv[1] if len(sys.argv) > 2 else 'anonymous.info'
13-
message = ' '.join(sys.argv[2:]) or 'Hello World!'
13+
routing_key = sys.argv[1] if len(sys.argv) > 2 else "anonymous.info"
14+
message = " ".join(sys.argv[2:]) or "Hello World!"
1415
channel.basic_publish(
15-
exchange='topic_logs', routing_key=routing_key, body=message)
16+
exchange="topic_logs",
17+
routing_key=routing_key,
18+
body=message,
19+
)
1620
print(f" [x] Sent {routing_key}:{message}")
21+
1722
connection.close()

python/new_task.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
import pika
55

66
connection = pika.BlockingConnection(
7-
pika.ConnectionParameters(host='localhost'))
7+
pika.ConnectionParameters(host="localhost"),
8+
)
89
channel = connection.channel()
910

10-
channel.queue_declare(queue='task_queue', durable=True)
11+
channel.queue_declare(queue="task_queue", durable=True)
1112

12-
message = ' '.join(sys.argv[1:]) or "Hello World!"
13+
message = " ".join(sys.argv[1:]) or "Hello World!"
1314
channel.basic_publish(
14-
exchange='',
15-
routing_key='task_queue',
15+
exchange="",
16+
routing_key="task_queue",
1617
body=message,
1718
properties=pika.BasicProperties(
1819
delivery_mode=pika.DeliveryMode.Persistent,
19-
))
20+
),
21+
)
2022
print(f" [x] Sent {message}")
23+
2124
connection.close()

python/receive.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
#!/usr/bin/env python
22
import os
3-
import pika
43
import sys
54

5+
import pika
6+
67

78
def main():
8-
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
9+
connection = pika.BlockingConnection(
10+
pika.ConnectionParameters(host="localhost"),
11+
)
912
channel = connection.channel()
1013

11-
channel.queue_declare(queue='hello')
14+
channel.queue_declare(queue="hello")
1215

1316
def callback(ch, method, properties, body):
1417
print(f" [x] Received {body.decode()}")
1518

16-
channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=True)
19+
channel.basic_consume(
20+
queue="hello",
21+
on_message_callback=callback,
22+
auto_ack=True,
23+
)
1724

18-
print(' [*] Waiting for messages. To exit press CTRL+C')
25+
print(" [*] Waiting for messages. To exit press CTRL+C")
1926
channel.start_consuming()
2027

2128

22-
if __name__ == '__main__':
29+
if __name__ == "__main__":
2330
try:
2431
main()
2532
except KeyboardInterrupt:
26-
print('Interrupted')
33+
print("Interrupted")
2734
try:
2835
sys.exit(0)
2936
except SystemExit:

python/receive_logs.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
#!/usr/bin/env python
22
import os
3-
import pika
43
import sys
54

5+
import pika
6+
67

78
def main():
89
connection = pika.BlockingConnection(
9-
pika.ConnectionParameters(host='localhost'))
10+
pika.ConnectionParameters(host="localhost"),
11+
)
1012
channel = connection.channel()
1113

12-
channel.exchange_declare(exchange='logs', exchange_type='fanout')
14+
channel.exchange_declare(exchange="logs", exchange_type="fanout")
1315

14-
result = channel.queue_declare(queue='', exclusive=True)
16+
result = channel.queue_declare(queue="", exclusive=True)
1517
queue_name = result.method.queue
1618

17-
channel.queue_bind(exchange='logs', queue=queue_name)
19+
channel.queue_bind(exchange="logs", queue=queue_name)
1820

1921
def callback(ch, method, properties, body):
2022
print(f" [x] {body.decode()}")
2123

22-
print(' [*] Waiting for logs. To exit press CTRL+C')
24+
print(" [*] Waiting for logs. To exit press CTRL+C")
2325
channel.basic_consume(
24-
queue=queue_name, on_message_callback=callback, auto_ack=True)
26+
queue=queue_name,
27+
on_message_callback=callback,
28+
auto_ack=True,
29+
)
2530

2631
channel.start_consuming()
2732

2833

29-
if __name__ == '__main__':
34+
if __name__ == "__main__":
3035
try:
3136
main()
3237
except KeyboardInterrupt:
33-
print('Interrupted')
38+
print("Interrupted")
3439
try:
3540
sys.exit(0)
3641
except SystemExit:

python/receive_logs_direct.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env python
22
import os
3-
import pika
43
import sys
54

5+
import pika
6+
67

78
def main():
89
connection = pika.BlockingConnection(
9-
pika.ConnectionParameters(host='localhost'))
10+
pika.ConnectionParameters(host="localhost"),
11+
)
1012
channel = connection.channel()
1113

12-
channel.exchange_declare(exchange='direct_logs', exchange_type='direct')
14+
channel.exchange_declare(exchange="direct_logs", exchange_type="direct")
1315

14-
result = channel.queue_declare(queue='', exclusive=True)
16+
result = channel.queue_declare(queue="", exclusive=True)
1517
queue_name = result.method.queue
1618

1719
severities = sys.argv[1:]
@@ -21,24 +23,30 @@ def main():
2123

2224
for severity in severities:
2325
channel.queue_bind(
24-
exchange='direct_logs', queue=queue_name, routing_key=severity)
26+
exchange="direct_logs",
27+
queue=queue_name,
28+
routing_key=severity,
29+
)
2530

26-
print(' [*] Waiting for logs. To exit press CTRL+C')
31+
print(" [*] Waiting for logs. To exit press CTRL+C")
2732

2833
def callback(ch, method, properties, body):
2934
print(f" [x] {method.routing_key}:{body.decode()}")
3035

3136
channel.basic_consume(
32-
queue=queue_name, on_message_callback=callback, auto_ack=True)
37+
queue=queue_name,
38+
on_message_callback=callback,
39+
auto_ack=True,
40+
)
3341

3442
channel.start_consuming()
3543

3644

37-
if __name__ == '__main__':
45+
if __name__ == "__main__":
3846
try:
3947
main()
4048
except KeyboardInterrupt:
41-
print('Interrupted')
49+
print("Interrupted")
4250
try:
4351
sys.exit(0)
4452
except SystemExit:

python/receive_logs_topic.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env python
22
import os
3-
import pika
43
import sys
54

5+
import pika
6+
67

78
def main():
89
connection = pika.BlockingConnection(
9-
pika.ConnectionParameters(host='localhost'))
10+
pika.ConnectionParameters(host="localhost"),
11+
)
1012
channel = connection.channel()
1113

12-
channel.exchange_declare(exchange='topic_logs', exchange_type='topic')
14+
channel.exchange_declare(exchange="topic_logs", exchange_type="topic")
1315

14-
result = channel.queue_declare(queue='', exclusive=True)
16+
result = channel.queue_declare(queue="", exclusive=True)
1517
queue_name = result.method.queue
1618

1719
binding_keys = sys.argv[1:]
@@ -21,24 +23,30 @@ def main():
2123

2224
for binding_key in binding_keys:
2325
channel.queue_bind(
24-
exchange='topic_logs', queue=queue_name, routing_key=binding_key)
26+
exchange="topic_logs",
27+
queue=queue_name,
28+
routing_key=binding_key,
29+
)
2530

26-
print(' [*] Waiting for logs. To exit press CTRL+C')
31+
print(" [*] Waiting for logs. To exit press CTRL+C")
2732

2833
def callback(ch, method, properties, body):
2934
print(f" [x] {method.routing_key}:{body.decode()}")
3035

3136
channel.basic_consume(
32-
queue=queue_name, on_message_callback=callback, auto_ack=True)
37+
queue=queue_name,
38+
on_message_callback=callback,
39+
auto_ack=True,
40+
)
3341

3442
channel.start_consuming()
3543

3644

37-
if __name__ == '__main__':
45+
if __name__ == "__main__":
3846
try:
3947
main()
4048
except KeyboardInterrupt:
41-
print('Interrupted')
49+
print("Interrupted")
4250
try:
4351
sys.exit(0)
4452
except SystemExit:

python/rpc_client.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55

66

77
class FibonacciRpcClient(object):
8-
98
def __init__(self):
109
self.connection = pika.BlockingConnection(
11-
pika.ConnectionParameters(host='localhost'))
10+
pika.ConnectionParameters(host="localhost"),
11+
)
1212

1313
self.channel = self.connection.channel()
1414

15-
result = self.channel.queue_declare(queue='', exclusive=True)
15+
result = self.channel.queue_declare(queue="", exclusive=True)
1616
self.callback_queue = result.method.queue
1717

1818
self.channel.basic_consume(
1919
queue=self.callback_queue,
2020
on_message_callback=self.on_response,
21-
auto_ack=True)
21+
auto_ack=True,
22+
)
2223

2324
self.response = None
2425
self.corr_id = None
@@ -31,13 +32,14 @@ def call(self, n):
3132
self.response = None
3233
self.corr_id = str(uuid.uuid4())
3334
self.channel.basic_publish(
34-
exchange='',
35-
routing_key='rpc_queue',
35+
exchange="",
36+
routing_key="rpc_queue",
3637
properties=pika.BasicProperties(
3738
reply_to=self.callback_queue,
3839
correlation_id=self.corr_id,
3940
),
40-
body=str(n))
41+
body=str(n),
42+
)
4143
self.connection.process_data_events(time_limit=None)
4244
return int(self.response)
4345

python/rpc_server.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import pika
33

44
connection = pika.BlockingConnection(
5-
pika.ConnectionParameters(host='localhost'))
6-
5+
pika.ConnectionParameters(host="localhost"),
6+
)
77
channel = connection.channel()
88

9-
channel.queue_declare(queue='rpc_queue')
9+
channel.queue_declare(queue="rpc_queue")
1010

1111

1212
def fib(n):
@@ -24,16 +24,17 @@ def on_request(ch, method, props, body):
2424
print(f" [.] fib({n})")
2525
response = fib(n)
2626

27-
ch.basic_publish(exchange='',
28-
routing_key=props.reply_to,
29-
properties=pika.BasicProperties(correlation_id= \
30-
props.correlation_id),
31-
body=str(response))
27+
ch.basic_publish(
28+
exchange="",
29+
routing_key=props.reply_to,
30+
properties=pika.BasicProperties(correlation_id=props.correlation_id),
31+
body=str(response),
32+
)
3233
ch.basic_ack(delivery_tag=method.delivery_tag)
3334

3435

3536
channel.basic_qos(prefetch_count=1)
36-
channel.basic_consume(queue='rpc_queue', on_message_callback=on_request)
37+
channel.basic_consume(queue="rpc_queue", on_message_callback=on_request)
3738

3839
print(" [x] Awaiting RPC requests")
3940
channel.start_consuming()

0 commit comments

Comments
 (0)