@@ -30,8 +30,8 @@ def wrapper(self, *args, **kwargs):
30
30
sd = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
31
31
sd .settimeout (30000 )
32
32
sd .connect ((self .host , self .port ))
33
- sd .sendall (cmd )
34
- self .match (resp , sd .recv (4096 ))
33
+ sd .sendall (cmd . encode ( 'utf-8' ) )
34
+ self .match (resp , sd .recv (4096 ). decode ( 'utf-8' ) )
35
35
setattr (self , cname , sd )
36
36
try :
37
37
r = m (self , * args , ** kwargs )
@@ -62,13 +62,13 @@ def match(self, pattern, data):
62
62
matched = re .match (pattern , data )
63
63
if matched :
64
64
return matched .groups ()
65
- self .assertTrue (False , 'No match:\n %r \n %r' % (pattern , data ) )
65
+ self .assertTrue (False , 'No match:\n {} \n \n {}' . format (pattern , data ))
66
66
67
67
def recv_atleast (self , bufsize ):
68
68
recvhead = []
69
69
rl = bufsize
70
70
while rl > 0 :
71
- buf = self .cd .recv (rl )
71
+ buf = self .cd .recv (rl ). decode ( 'utf-8' )
72
72
bl = len (buf )
73
73
if bl == 0 : break
74
74
recvhead .append ( buf )
@@ -78,14 +78,15 @@ def recv_atleast(self, bufsize):
78
78
79
79
@connect (['cd' ])
80
80
def test_newline_after_nul (self ):
81
- self .cd .sendall ('\n '
82
- 'SUBSCRIBE\n '
83
- 'destination:/exchange/amq.fanout\n '
84
- '\n \x00 \n '
85
- 'SEND\n '
86
- 'content-type:text/plain\n '
87
- 'destination:/exchange/amq.fanout\n \n '
88
- 'hello\n \x00 \n ' )
81
+ cmd = ('\n '
82
+ 'SUBSCRIBE\n '
83
+ 'destination:/exchange/amq.fanout\n '
84
+ '\n \x00 \n '
85
+ 'SEND\n '
86
+ 'content-type:text/plain\n '
87
+ 'destination:/exchange/amq.fanout\n \n '
88
+ 'hello\n \x00 \n ' )
89
+ self .cd .sendall (cmd .encode ('utf-8' ))
89
90
resp = ('MESSAGE\n '
90
91
'destination:/exchange/amq.fanout\n '
91
92
'message-id:Q_/exchange/amq.fanout@@session-(.*)\n '
@@ -94,56 +95,58 @@ def test_newline_after_nul(self):
94
95
'content-length:6\n '
95
96
'\n '
96
97
'hello\n \0 ' )
97
- self .match (resp , self .cd .recv (4096 ))
98
+ self .match (resp , self .cd .recv (4096 ). decode ( 'utf-8' ) )
98
99
99
100
@connect (['cd' ])
100
101
def test_send_without_content_type (self ):
101
- self .cd .sendall ('\n '
102
- 'SUBSCRIBE\n '
103
- 'destination:/exchange/amq.fanout\n '
104
- '\n \x00 \n '
105
- 'SEND\n '
106
- 'destination:/exchange/amq.fanout\n \n '
107
- 'hello\n \x00 ' )
102
+ cmd = ('\n '
103
+ 'SUBSCRIBE\n '
104
+ 'destination:/exchange/amq.fanout\n '
105
+ '\n \x00 \n '
106
+ 'SEND\n '
107
+ 'destination:/exchange/amq.fanout\n \n '
108
+ 'hello\n \x00 ' )
109
+ self .cd .sendall (cmd .encode ('utf-8' ))
108
110
resp = ('MESSAGE\n '
109
111
'destination:/exchange/amq.fanout\n '
110
112
'message-id:Q_/exchange/amq.fanout@@session-(.*)\n '
111
113
'redelivered:false\n '
112
114
'content-length:6\n '
113
115
'\n '
114
116
'hello\n \0 ' )
115
- self .match (resp , self .cd .recv (4096 ))
117
+ self .match (resp , self .cd .recv (4096 ). decode ( 'utf-8' ) )
116
118
117
119
@connect (['cd' ])
118
120
def test_send_without_content_type_binary (self ):
119
- msg = u'\u0ca0 \ufffd \x00 \n \x01 hello\x00 ' .encode ('utf-8' )
120
- self .cd .sendall ('\n '
121
- 'SUBSCRIBE\n '
122
- 'destination:/exchange/amq.fanout\n '
123
- '\n \x00 \n '
124
- 'SEND\n '
125
- 'destination:/exchange/amq.fanout\n '
126
- 'content-length:' + str (len (msg ))+ '\n \n '
127
- + msg + '\x00 ' )
121
+ msg = 'hello'
122
+ cmd = ('\n '
123
+ 'SUBSCRIBE\n '
124
+ 'destination:/exchange/amq.fanout\n '
125
+ '\n \x00 \n '
126
+ 'SEND\n '
127
+ 'destination:/exchange/amq.fanout\n ' +
128
+ 'content-length:{}\n \n ' .format (len (msg )) +
129
+ '{}\x00 ' .format (msg ))
130
+ self .cd .sendall (cmd .encode ('utf-8' ))
128
131
resp = ('MESSAGE\n '
129
132
'destination:/exchange/amq.fanout\n '
130
133
'message-id:Q_/exchange/amq.fanout@@session-(.*)\n '
131
- 'redelivered:false\n '
132
- 'content-length:' + str (len (msg ))+ '\n '
133
- '\n '
134
- + msg + '\0 ' )
135
- self .match (resp , self .cd .recv (4096 ))
134
+ 'redelivered:false\n ' +
135
+ 'content-length:{}\n ' .format (len (msg )) +
136
+ '\n {}\0 ' .format (msg ))
137
+ self .match (resp , self .cd .recv (4096 ).decode ('utf-8' ))
136
138
137
139
@connect (['cd' ])
138
140
def test_newline_after_nul_and_leading_nul (self ):
139
- self .cd .sendall ('\n '
140
- '\x00 SUBSCRIBE\n '
141
- 'destination:/exchange/amq.fanout\n '
142
- '\n \x00 \n '
143
- '\x00 SEND\n '
144
- 'destination:/exchange/amq.fanout\n '
145
- 'content-type:text/plain\n '
146
- '\n hello\n \x00 \n ' )
141
+ cmd = ('\n '
142
+ '\x00 SUBSCRIBE\n '
143
+ 'destination:/exchange/amq.fanout\n '
144
+ '\n \x00 \n '
145
+ '\x00 SEND\n '
146
+ 'destination:/exchange/amq.fanout\n '
147
+ 'content-type:text/plain\n '
148
+ '\n hello\n \x00 \n ' )
149
+ self .cd .sendall (cmd .encode ('utf-8' ))
147
150
resp = ('MESSAGE\n '
148
151
'destination:/exchange/amq.fanout\n '
149
152
'message-id:Q_/exchange/amq.fanout@@session-(.*)\n '
@@ -152,15 +155,16 @@ def test_newline_after_nul_and_leading_nul(self):
152
155
'content-length:6\n '
153
156
'\n '
154
157
'hello\n \0 ' )
155
- self .match (resp , self .cd .recv (4096 ))
158
+ self .match (resp , self .cd .recv (4096 ). decode ( 'utf-8' ) )
156
159
157
160
@connect (['cd' ])
158
161
def test_bad_command (self ):
159
162
''' Trigger an error message. '''
160
- self .cd .sendall ('WRONGCOMMAND\n '
161
- 'destination:a\n '
162
- 'exchange:amq.fanout\n '
163
- '\n \0 ' )
163
+ cmd = ('WRONGCOMMAND\n '
164
+ 'destination:a\n '
165
+ 'exchange:amq.fanout\n '
166
+ '\n \0 ' )
167
+ self .cd .sendall (cmd .encode ('utf-8' ))
164
168
resp = ('ERROR\n '
165
169
'message:Bad command\n '
166
170
'content-type:text/plain\n '
@@ -169,7 +173,7 @@ def test_bad_command(self):
169
173
'\n '
170
174
'Could not interpret command "WRONGCOMMAND"\n '
171
175
'\0 ' )
172
- self .match (resp , self .cd .recv (4096 ))
176
+ self .match (resp , self .cd .recv (4096 ). decode ( 'utf-8' ) )
173
177
174
178
@connect (['sd' , 'cd1' , 'cd2' ])
175
179
def test_broadcast (self ):
@@ -182,16 +186,17 @@ def test_broadcast(self):
182
186
'destination:/exchange/amq.topic/da9d4779\n '
183
187
'\n \0 ' )
184
188
for cd in [self .cd1 , self .cd2 ]:
185
- cd .sendall (subscribe )
189
+ cd .sendall (subscribe . encode ( 'utf-8' ) )
186
190
187
191
time .sleep (0.1 )
188
192
189
- self .sd .sendall ('SEND\n '
190
- 'content-type:text/plain\n '
191
- 'destination:/exchange/amq.topic/da9d4779\n '
192
- '\n '
193
- 'message'
194
- '\n \0 ' )
193
+ cmd = ('SEND\n '
194
+ 'content-type:text/plain\n '
195
+ 'destination:/exchange/amq.topic/da9d4779\n '
196
+ '\n '
197
+ 'message'
198
+ '\n \0 ' )
199
+ self .sd .sendall (cmd .encode ('utf-8' ))
195
200
196
201
resp = ('MESSAGE\n '
197
202
'subscription:(.*)\n '
@@ -204,7 +209,7 @@ def test_broadcast(self):
204
209
'message'
205
210
'\n \x00 ' )
206
211
for cd in [self .cd1 , self .cd2 ]:
207
- self .match (resp , cd .recv (4096 ))
212
+ self .match (resp , cd .recv (4096 ). decode ( 'utf-8' ) )
208
213
209
214
@connect (['cd' ])
210
215
def test_message_with_embedded_nulls (self ):
@@ -215,7 +220,7 @@ def test_message_with_embedded_nulls(self):
215
220
'id:xxx\n '
216
221
+ dest +
217
222
'\n \0 ' )
218
- self .cd .sendall (subscribe )
223
+ self .cd .sendall (subscribe . encode ( 'utf-8' ) )
219
224
220
225
boilerplate = '0123456789' * 1024 # large enough boilerplate
221
226
message = '01'
@@ -225,13 +230,14 @@ def test_message_with_embedded_nulls(self):
225
230
oldi = i
226
231
msg_len = len (message )
227
232
228
- self .cd .sendall ('SEND\n '
229
- + dest +
230
- 'content-type:text/plain\n '
231
- 'content-length:%i\n '
232
- '\n '
233
- '%s'
234
- '\0 ' % (len (message ), message ) )
233
+ cmd = ('SEND\n '
234
+ + dest +
235
+ 'content-type:text/plain\n '
236
+ 'content-length:%i\n '
237
+ '\n '
238
+ '%s'
239
+ '\0 ' % (len (message ), message ))
240
+ self .cd .sendall (cmd .encode ('utf-8' ))
235
241
236
242
headresp = ('MESSAGE\n ' # 8
237
243
'subscription:(.*)\n ' # 14 + subscription
@@ -271,7 +277,7 @@ def test_message_in_packets(self):
271
277
'id:xxx\n '
272
278
+ dest +
273
279
'\n \0 ' )
274
- self .cd .sendall (subscribe )
280
+ self .cd .sendall (subscribe . encode ( 'utf-8' ) )
275
281
276
282
boilerplate = '0123456789' * 1024 # large enough boilerplate
277
283
@@ -290,7 +296,7 @@ def test_message_in_packets(self):
290
296
while part_index < msg_to_send_len :
291
297
part = msg_to_send [part_index :part_index + packet_size ]
292
298
time .sleep (0.1 )
293
- self .cd .sendall (part )
299
+ self .cd .sendall (part . encode ( 'utf-8' ) )
294
300
part_index += packet_size
295
301
296
302
headresp = ('MESSAGE\n ' # 8
0 commit comments