1
1
from .entities import BindingSpecification
2
2
3
3
4
+ def binding_path_with_exchange_queue (bind_specification : BindingSpecification ) -> str :
5
+ binding_path_wth_exchange_queue_key = (
6
+ "/bindings"
7
+ + "/"
8
+ + "src="
9
+ + bind_specification .source_exchange
10
+ + ";"
11
+ + "dstq="
12
+ + bind_specification .destination_queue
13
+ + ";key="
14
+ + bind_specification .binding_key
15
+ + ";args="
16
+ )
17
+ return binding_path_wth_exchange_queue_key
18
+
19
+
20
+ def encode_path_segment (input : str ) -> str :
21
+ encoded_input = ""
22
+ for character in input :
23
+ if is_unreserved (character ):
24
+ encoded_input += character
25
+
26
+ else :
27
+ # encoded_input += "%%%02X" % character
28
+ encoded_input += hex (ord (character ))
29
+
30
+ return encoded_input
31
+
32
+
4
33
def exchange_address (exchange_name : str , routing_key : str = "" ) -> str :
5
34
if routing_key == "" :
6
- path = "/exchanges/" + exchange_name
35
+ path = "/exchanges/" + encode_path_segment ( exchange_name )
7
36
else :
8
- path = "/exchanges/" + exchange_name + "/" + routing_key
37
+ path = (
38
+ "/exchanges/"
39
+ + encode_path_segment (exchange_name )
40
+ + "/"
41
+ + encode_path_segment (routing_key )
42
+ )
9
43
10
44
return path
11
45
12
46
13
- def queue_address (name : str ) -> str :
14
- path = "/queues/" + name
47
+ def queue_address (queue_name : str ) -> str :
48
+ path = "/queues/" + encode_path_segment (queue_name )
49
+
50
+ return path
51
+
52
+
53
+ def purge_queue_address (queue_name : str ) -> str :
54
+ path = "/queues/" + encode_path_segment (queue_name ) + "/messages"
15
55
16
56
return path
17
57
@@ -28,17 +68,29 @@ def path_address() -> str:
28
68
return path
29
69
30
70
71
+ def is_unreserved (input : str ) -> bool :
72
+ return (
73
+ (input >= "A" and input <= "Z" )
74
+ or (input >= "a" and input <= "z" )
75
+ or (input >= "0" and input <= "9" )
76
+ or input == "-"
77
+ or input == "."
78
+ or input == "_"
79
+ or input == "~"
80
+ )
81
+
82
+
31
83
def binding_path_with_exchange_queue (bind_specification : BindingSpecification ) -> str :
32
84
binding_path_wth_exchange_queue_key = (
33
85
"/bindings"
34
86
+ "/"
35
87
+ "src="
36
- + bind_specification .source_exchange
88
+ + encode_path_segment ( bind_specification .source_exchange )
37
89
+ ";"
38
90
+ "dstq="
39
- + bind_specification .destination_queue
91
+ + encode_path_segment ( bind_specification .destination_queue )
40
92
+ ";key="
41
- + bind_specification .binding_key
93
+ + encode_path_segment ( bind_specification .binding_key )
42
94
+ ";args="
43
95
)
44
96
return binding_path_wth_exchange_queue_key
0 commit comments