Show More
@@ -48,10 +48,10 b" configitem(b'badserver', b'closeafteracc" | |||||
48 | default=False, |
|
48 | default=False, | |
49 | ) |
|
49 | ) | |
50 | configitem(b'badserver', b'closeafterrecvbytes', |
|
50 | configitem(b'badserver', b'closeafterrecvbytes', | |
51 | default='0', |
|
51 | default=b'0', | |
52 | ) |
|
52 | ) | |
53 | configitem(b'badserver', b'closeaftersendbytes', |
|
53 | configitem(b'badserver', b'closeaftersendbytes', | |
54 | default='0', |
|
54 | default=b'0', | |
55 | ) |
|
55 | ) | |
56 | configitem(b'badserver', b'closebeforeaccept', |
|
56 | configitem(b'badserver', b'closebeforeaccept', | |
57 | default=False, |
|
57 | default=False, | |
@@ -127,10 +127,10 b' class fileobjectproxy(object):' | |||||
127 | setattr(object.__getattribute__(self, '_orig'), name, value) |
|
127 | setattr(object.__getattribute__(self, '_orig'), name, value) | |
128 |
|
128 | |||
129 | def _writelog(self, msg): |
|
129 | def _writelog(self, msg): | |
130 | msg = msg.replace('\r', '\\r').replace('\n', '\\n') |
|
130 | msg = msg.replace(b'\r', b'\\r').replace(b'\n', b'\\n') | |
131 |
|
131 | |||
132 | object.__getattribute__(self, '_logfp').write(msg) |
|
132 | object.__getattribute__(self, '_logfp').write(msg) | |
133 | object.__getattribute__(self, '_logfp').write('\n') |
|
133 | object.__getattribute__(self, '_logfp').write(b'\n') | |
134 | object.__getattribute__(self, '_logfp').flush() |
|
134 | object.__getattribute__(self, '_logfp').flush() | |
135 |
|
135 | |||
136 | def read(self, size=-1): |
|
136 | def read(self, size=-1): | |
@@ -139,9 +139,9 b' class fileobjectproxy(object):' | |||||
139 | # No read limit. Call original function. |
|
139 | # No read limit. Call original function. | |
140 | if not remaining: |
|
140 | if not remaining: | |
141 | result = object.__getattribute__(self, '_orig').read(size) |
|
141 | result = object.__getattribute__(self, '_orig').read(size) | |
142 | self._writelog('read(%d) -> (%d) (%s) %s' % (size, |
|
142 | self._writelog(b'read(%d) -> (%d) (%s) %s' % (size, | |
143 |
|
|
143 | len(result), | |
144 |
|
|
144 | result)) | |
145 | return result |
|
145 | return result | |
146 |
|
146 | |||
147 | origsize = size |
|
147 | origsize = size | |
@@ -154,13 +154,13 b' class fileobjectproxy(object):' | |||||
154 | result = object.__getattribute__(self, '_orig').read(size) |
|
154 | result = object.__getattribute__(self, '_orig').read(size) | |
155 | remaining -= len(result) |
|
155 | remaining -= len(result) | |
156 |
|
156 | |||
157 | self._writelog('read(%d from %d) -> (%d) %s' % ( |
|
157 | self._writelog(b'read(%d from %d) -> (%d) %s' % ( | |
158 | size, origsize, len(result), result)) |
|
158 | size, origsize, len(result), result)) | |
159 |
|
159 | |||
160 | object.__setattr__(self, '_closeafterrecvbytes', remaining) |
|
160 | object.__setattr__(self, '_closeafterrecvbytes', remaining) | |
161 |
|
161 | |||
162 | if remaining <= 0: |
|
162 | if remaining <= 0: | |
163 | self._writelog('read limit reached, closing socket') |
|
163 | self._writelog(b'read limit reached, closing socket') | |
164 | self._sock.close() |
|
164 | self._sock.close() | |
165 | # This is the easiest way to abort the current request. |
|
165 | # This is the easiest way to abort the current request. | |
166 | raise Exception('connection closed after receiving N bytes') |
|
166 | raise Exception('connection closed after receiving N bytes') | |
@@ -173,7 +173,7 b' class fileobjectproxy(object):' | |||||
173 | # No read limit. Call original function. |
|
173 | # No read limit. Call original function. | |
174 | if not remaining: |
|
174 | if not remaining: | |
175 | result = object.__getattribute__(self, '_orig').readline(size) |
|
175 | result = object.__getattribute__(self, '_orig').readline(size) | |
176 | self._writelog('readline(%d) -> (%d) %s' % ( |
|
176 | self._writelog(b'readline(%d) -> (%d) %s' % ( | |
177 | size, len(result), result)) |
|
177 | size, len(result), result)) | |
178 | return result |
|
178 | return result | |
179 |
|
179 | |||
@@ -187,13 +187,13 b' class fileobjectproxy(object):' | |||||
187 | result = object.__getattribute__(self, '_orig').readline(size) |
|
187 | result = object.__getattribute__(self, '_orig').readline(size) | |
188 | remaining -= len(result) |
|
188 | remaining -= len(result) | |
189 |
|
189 | |||
190 | self._writelog('readline(%d from %d) -> (%d) %s' % ( |
|
190 | self._writelog(b'readline(%d from %d) -> (%d) %s' % ( | |
191 | size, origsize, len(result), result)) |
|
191 | size, origsize, len(result), result)) | |
192 |
|
192 | |||
193 | object.__setattr__(self, '_closeafterrecvbytes', remaining) |
|
193 | object.__setattr__(self, '_closeafterrecvbytes', remaining) | |
194 |
|
194 | |||
195 | if remaining <= 0: |
|
195 | if remaining <= 0: | |
196 | self._writelog('read limit reached; closing socket') |
|
196 | self._writelog(b'read limit reached; closing socket') | |
197 | self._sock.close() |
|
197 | self._sock.close() | |
198 | # This is the easiest way to abort the current request. |
|
198 | # This is the easiest way to abort the current request. | |
199 | raise Exception('connection closed after receiving N bytes') |
|
199 | raise Exception('connection closed after receiving N bytes') | |
@@ -205,7 +205,7 b' class fileobjectproxy(object):' | |||||
205 |
|
205 | |||
206 | # No byte limit on this operation. Call original function. |
|
206 | # No byte limit on this operation. Call original function. | |
207 | if not remaining: |
|
207 | if not remaining: | |
208 | self._writelog('write(%d) -> %s' % (len(data), data)) |
|
208 | self._writelog(b'write(%d) -> %s' % (len(data), data)) | |
209 | result = object.__getattribute__(self, '_orig').write(data) |
|
209 | result = object.__getattribute__(self, '_orig').write(data) | |
210 | return result |
|
210 | return result | |
211 |
|
211 | |||
@@ -216,7 +216,7 b' class fileobjectproxy(object):' | |||||
216 |
|
216 | |||
217 | remaining -= len(newdata) |
|
217 | remaining -= len(newdata) | |
218 |
|
218 | |||
219 | self._writelog('write(%d from %d) -> (%d) %s' % ( |
|
219 | self._writelog(b'write(%d from %d) -> (%d) %s' % ( | |
220 | len(newdata), len(data), remaining, newdata)) |
|
220 | len(newdata), len(data), remaining, newdata)) | |
221 |
|
221 | |||
222 | result = object.__getattribute__(self, '_orig').write(newdata) |
|
222 | result = object.__getattribute__(self, '_orig').write(newdata) | |
@@ -224,7 +224,7 b' class fileobjectproxy(object):' | |||||
224 | object.__setattr__(self, '_closeaftersendbytes', remaining) |
|
224 | object.__setattr__(self, '_closeaftersendbytes', remaining) | |
225 |
|
225 | |||
226 | if remaining <= 0: |
|
226 | if remaining <= 0: | |
227 | self._writelog('write limit reached; closing socket') |
|
227 | self._writelog(b'write limit reached; closing socket') | |
228 | self._sock.close() |
|
228 | self._sock.close() | |
229 | raise Exception('connection closed after sending N bytes') |
|
229 | raise Exception('connection closed after sending N bytes') | |
230 |
|
230 | |||
@@ -239,10 +239,10 b' def extsetup(ui):' | |||||
239 | super(badserver, self).__init__(ui, *args, **kwargs) |
|
239 | super(badserver, self).__init__(ui, *args, **kwargs) | |
240 |
|
240 | |||
241 | recvbytes = self._ui.config(b'badserver', b'closeafterrecvbytes') |
|
241 | recvbytes = self._ui.config(b'badserver', b'closeafterrecvbytes') | |
242 | recvbytes = recvbytes.split(',') |
|
242 | recvbytes = recvbytes.split(b',') | |
243 | self.closeafterrecvbytes = [int(v) for v in recvbytes if v] |
|
243 | self.closeafterrecvbytes = [int(v) for v in recvbytes if v] | |
244 | sendbytes = self._ui.config(b'badserver', b'closeaftersendbytes') |
|
244 | sendbytes = self._ui.config(b'badserver', b'closeaftersendbytes') | |
245 | sendbytes = sendbytes.split(',') |
|
245 | sendbytes = sendbytes.split(b',') | |
246 | self.closeaftersendbytes = [int(v) for v in sendbytes if v] |
|
246 | self.closeaftersendbytes = [int(v) for v in sendbytes if v] | |
247 |
|
247 | |||
248 | # Need to inherit object so super() works. |
|
248 | # Need to inherit object so super() works. | |
@@ -270,7 +270,7 b' def extsetup(ui):' | |||||
270 | # Simulate failure to stop processing this request. |
|
270 | # Simulate failure to stop processing this request. | |
271 | raise socket.error('close before accept') |
|
271 | raise socket.error('close before accept') | |
272 |
|
272 | |||
273 | if self._ui.configbool('badserver', 'closeafteraccept'): |
|
273 | if self._ui.configbool(b'badserver', b'closeafteraccept'): | |
274 | request, client_address = super(badserver, self).get_request() |
|
274 | request, client_address = super(badserver, self).get_request() | |
275 | request.close() |
|
275 | request.close() | |
276 | raise socket.error('close after accept') |
|
276 | raise socket.error('close after accept') |
General Comments 0
You need to be logged in to leave comments.
Login now