182 |
182 |
183 buf = raw_input() |
183 buf = raw_input() |
184 if size >= 0: |
184 if size >= 0: |
185 buf = buf[:size] |
185 buf = buf[:size] |
186 return buf |
186 return buf |
187 |
187 |
|
188 def readCommand(self): |
|
189 """ |
|
190 Public method to read a length prefixed command string. |
|
191 |
|
192 @return command string |
|
193 @rtype str |
|
194 """ |
|
195 # The command string is prefixed by a 9 character long length field. |
|
196 length = self.sock.recv(9) |
|
197 length = int(length) |
|
198 data = b'' |
|
199 while len(data) < length: |
|
200 newData = self.sock.recv(length - len(data)) |
|
201 data += newData |
|
202 |
|
203 # step 2: convert the data |
|
204 return data.decode('utf8', 'backslashreplace') |
|
205 |
188 def readline_p(self, size=-1): |
206 def readline_p(self, size=-1): |
189 """ |
207 """ |
190 Public method to read a line from this file. |
208 Public method to read a line from this file. |
191 |
209 |
192 <b>Note</b>: This method will not block and may return |
210 <b>Note</b>: This method will not block and may return |