@@ -151,7 +151,6 @@ VERSION_HEX = 0x000217
151151
152152cdef int _I = I, _M = M, _S = S, _U = U, _X = X, _L = L
153153cdef int current_notification = FALLBACK_QUIETLY
154- cdef bint PY2 = PY_MAJOR_VERSION == 2
155154
156155# Type of compiled re object from Python stdlib
157156SREPattern = type (re.compile(' ' ))
@@ -252,7 +251,7 @@ def escape(pattern):
252251 """ Escape all non-alphanumeric characters in pattern."""
253252 cdef bint uni = isinstance (pattern, unicode )
254253 cdef list s
255- if PY2 or uni:
254+ if uni:
256255 s = list (pattern)
257256 else :
258257 s = [bytes([c]) for c in pattern]
@@ -350,9 +349,9 @@ cdef inline unicode_to_bytes(object pystring, int * encoded,
350349 encoded[0 ] = 1 if origlen == len (pystring) else 2
351350 else :
352351 encoded[0 ] = 0
353- if not PY2 and checkotherencoding > 0 and not encoded[0 ]:
352+ if checkotherencoding > 0 and not encoded[0 ]:
354353 raise TypeError (" can't use a string pattern on a bytes-like object" )
355- elif not PY2 and checkotherencoding == 0 and encoded[0 ]:
354+ elif checkotherencoding == 0 and encoded[0 ]:
356355 raise TypeError (" can't use a bytes pattern on a string-like object" )
357356 return pystring
358357
@@ -366,14 +365,7 @@ cdef inline int pystring_to_cstring(
366365 cdef int result = - 1
367366 cstring[0 ] = NULL
368367 size[0 ] = 0
369- if PY2:
370- # Although the new-style buffer interface was backported to Python 2.6,
371- # some modules, notably mmap, only support the old buffer interface.
372- # Cf. http://bugs.python.org/issue9229
373- if PyObject_CheckReadBuffer(pystring) == 1 :
374- result = PyObject_AsReadBuffer(
375- pystring, < const void ** > cstring, size)
376- elif PyObject_CheckBuffer(pystring) == 1 : # new-style Buffer interface
368+ if PyObject_CheckBuffer(pystring) == 1 : # new-style Buffer interface
377369 result = PyObject_GetBuffer(pystring, buf, PyBUF_SIMPLE)
378370 if result == 0 :
379371 cstring[0 ] = < char * > buf.buf
@@ -383,8 +375,7 @@ cdef inline int pystring_to_cstring(
383375
384376cdef inline void release_cstring(Py_buffer * buf):
385377 """ Release buffer if necessary."""
386- if not PY2:
387- PyBuffer_Release(buf)
378+ PyBuffer_Release(buf)
388379
389380
390381cdef utf8indices(char * cstring, int size, int * pos, int * endpos):
0 commit comments