Remove code specific to Python 2.{3,4,5}.

This commit is contained in:
Valentin Lorentz 2013-05-13 15:27:26 +02:00
parent 93ecc2424f
commit 6ffcf122a7
7 changed files with 11 additions and 88 deletions

View File

@ -35,10 +35,7 @@ import time
import socket import socket
import linecache import linecache
if sys.version_info >= (2, 5, 0): import re
import re as sre
else:
import sre
import supybot.log as log import supybot.log as log
import supybot.conf as conf import supybot.conf as conf
@ -385,8 +382,8 @@ class Owner(callbacks.Plugin):
L = [] L = []
if level == 'high': if level == 'high':
L.append(format('Regexp cache flushed: %n cleared.', L.append(format('Regexp cache flushed: %n cleared.',
(len(sre._cache), 'regexp'))) (len(re._cache), 'regexp')))
sre.purge() re.purge()
L.append(format('Pattern cache flushed: %n cleared.', L.append(format('Pattern cache flushed: %n cleared.',
(len(ircutils._patternCache), 'compiled pattern'))) (len(ircutils._patternCache), 'compiled pattern')))
ircutils._patternCache.clear() ircutils._patternCache.clear()

View File

@ -56,44 +56,6 @@ def force(x):
return x return x
(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['force'] = force (__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['force'] = force
if sys.version_info < (2, 4, 0):
def reversed(L):
"""Iterates through a sequence in reverse."""
for i in xrange(len(L) - 1, -1, -1):
yield L[i]
(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['reversed'] = reversed
def sorted(iterable, cmp=None, key=None, reversed=False):
L = list(iterable)
if key is not None:
assert cmp is None, 'Can\'t use both cmp and key.'
sortBy(key, L)
else:
L.sort(cmp)
if reversed:
L.reverse()
return L
(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['sorted'] = sorted
import operator
def itemgetter(i):
return lambda x: x[i]
def attrgetter(attr):
return lambda x: getattr(x, attr)
operator.itemgetter = itemgetter
operator.attrgetter = attrgetter
import sets
(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['set'] = sets.Set
(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['frozenset'] = sets.ImmutableSet
import socket
# Some socket modules don't have sslerror, so we'll just make it an error.
if not hasattr(socket, 'sslerror'):
socket.sslerror = socket.error
# These imports need to happen below the block above, so things get put into # These imports need to happen below the block above, so things get put into
# __builtins__ appropriately. # __builtins__ appropriately.
from gen import * from gen import *

View File

@ -29,11 +29,7 @@
import sys import sys
if sys.version_info < (2, 5, 0): from hashlib import md5
from md5 import md5 from hashlib import sha1 as sha
from sha import sha
else:
from hashlib import md5
from hashlib import sha1 as sha
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -50,23 +50,6 @@ def trueCycle(iterable):
if not yielded: if not yielded:
raise StopIteration raise StopIteration
if sys.version_info < (2, 4, 0):
def groupby(key, iterable):
if key is None:
key = lambda x: x
it = iter(iterable)
value = it.next() # If there are no items, this takes an early exit
oldkey = key(value)
group = [value]
for value in it:
newkey = key(value)
if newkey != oldkey:
yield group
group = []
oldkey = newkey
group.append(value)
yield group
def partition(p, iterable): def partition(p, iterable):
"""Partitions an iterable based on a predicate p. """Partitions an iterable based on a predicate p.
Returns a (yes,no) tuple""" Returns a (yes,no) tuple"""

View File

@ -105,14 +105,9 @@ class Synchronized(type):
# Translate glob to regular expression, trimming the "match EOL" portion of # Translate glob to regular expression, trimming the "match EOL" portion of
# the regular expression. # the regular expression.
if sys.version_info < (2, 6, 0): # Post-2.6 uses \Z(?ms) per http://issues.python.org/6665
# Pre-2.6 just uses the $ anchor def glob2re(g):
def glob2re(g): return fnmatch.translate(g)[:-7]
return fnmatch.translate(g)[:-1]
else:
# Post-2.6 uses \Z(?ms) per http://issues.python.org/6665
def glob2re(g):
return fnmatch.translate(g)[:-7]
# From http://code.activestate.com/recipes/52215-get-more-information-from-tracebacks/ # From http://code.activestate.com/recipes/52215-get-more-information-from-tracebacks/

View File

@ -47,14 +47,7 @@ internationalizeFunction = _.internationalizeFunction
def rsplit(s, sep=None, maxsplit=-1): def rsplit(s, sep=None, maxsplit=-1):
"""Equivalent to str.split, except splitting from the right.""" """Equivalent to str.split, except splitting from the right."""
if sys.version_info < (2, 4, 0): return s.rsplit(sep, maxsplit)
if sep is not None:
sep = sep[::-1]
L = s[::-1].split(sep, maxsplit)
L.reverse()
return [s[::-1] for s in L]
else:
return s.rsplit(sep, maxsplit)
def normalizeWhitespace(s, removeNewline=True): def normalizeWhitespace(s, removeNewline=True):
"""Normalizes the whitespace in a string; \s+ becomes one space.""" """Normalizes the whitespace in a string; \s+ becomes one space."""

View File

@ -39,10 +39,7 @@ import atexit
import threading import threading
import multiprocessing # python 2.6 and later! import multiprocessing # python 2.6 and later!
if sys.version_info >= (2, 5, 0): import re
import re as sre
else:
import sre
import supybot.log as log import supybot.log as log
import supybot.conf as conf import supybot.conf as conf
@ -160,7 +157,7 @@ def upkeep():
# registry.open(registryFilename) # registry.open(registryFilename)
if not dying: if not dying:
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
log.debug('Regexp cache size: %s', len(sre._cache)) log.debug('Regexp cache size: %s', len(re._cache))
log.debug('Pattern cache size: %s', len(ircutils._patternCache)) log.debug('Pattern cache size: %s', len(ircutils._patternCache))
log.debug('HostmaskPatternEqual cache size: %s', log.debug('HostmaskPatternEqual cache size: %s',
len(ircutils._hostmaskPatternEqualCache)) len(ircutils._hostmaskPatternEqualCache))