Issue #3602 - Code Review (original) (raw)

OLD

NEW

1 # -*- Mode: Python; tab-width: 4 -*-

1 # -*- Mode: Python; tab-width: 4 -*-

2 # Id: asynchat.py,v 2.26 2000/09/07 22:29:26 rushing Exp

2 # Id: asynchat.py,v 2.26 2000/09/07 22:29:26 rushing Exp

3 # Author: Sam Rushing rushing@nightmare.com

3 # Author: Sam Rushing rushing@nightmare.com

4

4

5 # ======================================================================

5 # ======================================================================

6 # Copyright 1996 by Sam Rushing

6 # Copyright 1996 by Sam Rushing

7 #

7 #

8 # All Rights Reserved

8 # All Rights Reserved

9 #

9 #

10 # Permission to use, copy, modify, and distribute this software and

10 # Permission to use, copy, modify, and distribute this software and

(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...

42 order to process the single-line greeting. Just before issuing a

42 order to process the single-line greeting. Just before issuing a

43 'LIST' command you'll set it to '\r\n.\r\n'. The output of the LIST

43 'LIST' command you'll set it to '\r\n.\r\n'. The output of the LIST

44 command will be accumulated (using your own 'collect_incoming_data'

44 command will be accumulated (using your own 'collect_incoming_data'

45 method) up to the terminator, and then control will be returned to

45 method) up to the terminator, and then control will be returned to

46 you - by calling your self.found_terminator() method.

46 you - by calling your self.found_terminator() method.

47 """

47 """

48

48

49 import socket

49 import socket

50 import asyncore

50 import asyncore

51 from collections import deque

51 from collections import deque

52 from sys import py3kwarning

52 from test.test_support import catch_warning

53 from test.test_support import catch_warning

53 from warnings import filterwarnings

54 from warnings import filterwarnings, catch_warnings

54

55

55 class async_chat (asyncore.dispatcher):

56 class async_chat (asyncore.dispatcher):

56 """This is an abstract class. You must derive from this class, and add

57 """This is an abstract class. You must derive from this class, and add

57 the two methods collect_incoming_data() and found_terminator()"""

58 the two methods collect_incoming_data() and found_terminator()"""

58

59

59 # these are overridable defaults

60 # these are overridable defaults

60

61

61 ac_in_buffer_size = 4096

62 ac_in_buffer_size = 4096

62 ac_out_buffer_size = 4096

63 ac_out_buffer_size = 4096

63

64

(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...

211 # handle empty string/buffer or None entry

212 # handle empty string/buffer or None entry

212 if not first:

213 if not first:

213 del self.producer_fifo[0]

214 del self.producer_fifo[0]

214 if first is None:

215 if first is None:

215 self.handle_close()

216 self.handle_close()

216 return

217 return

217

218

218 # handle classic producer behavior

219 # handle classic producer behavior

219 obs = self.ac_out_buffer_size

220 obs = self.ac_out_buffer_size

220 try:

221 try:

221 with catch_warning(record=False):

222 with catch_warnings():

222 filterwarnings("ignore", ".*buffer", DeprecationWarning)

223 if py3kwarning:

224 filterwarnings("ignore", ".*buffer", DeprecationWarning)

223 data = buffer(first, 0, obs)

225 data = buffer(first, 0, obs)

224 except TypeError:

226 except TypeError:

225 data = first.more()

227 data = first.more()

226 if data:

228 if data:

227 self.producer_fifo.appendleft(data)

229 self.producer_fifo.appendleft(data)

228 else:

230 else:

229 del self.producer_fifo[0]

231 del self.producer_fifo[0]

230 continue

232 continue

231

233

232 # send the data

234 # send the data

(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...

304 # new python: 28961/s

306 # new python: 28961/s

305 # old python: 18307/s

307 # old python: 18307/s

306 # re: 12820/s

308 # re: 12820/s

307 # regex: 14035/s

309 # regex: 14035/s

308

310

309 def find_prefix_at_end (haystack, needle):

311 def find_prefix_at_end (haystack, needle):

310 l = len(needle) - 1

312 l = len(needle) - 1

311 while l and not haystack.endswith(needle[:l]):

313 while l and not haystack.endswith(needle[:l]):

312 l -= 1

314 l -= 1

313 return l

315 return l

OLD

NEW