mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Remove code specific to Python 2.{3,4,5}.
This commit is contained in:
parent
93ecc2424f
commit
6ffcf122a7
@ -35,10 +35,7 @@ import time
|
||||
import socket
|
||||
import linecache
|
||||
|
||||
if sys.version_info >= (2, 5, 0):
|
||||
import re as sre
|
||||
else:
|
||||
import sre
|
||||
import re
|
||||
|
||||
import supybot.log as log
|
||||
import supybot.conf as conf
|
||||
@ -385,8 +382,8 @@ class Owner(callbacks.Plugin):
|
||||
L = []
|
||||
if level == 'high':
|
||||
L.append(format('Regexp cache flushed: %n cleared.',
|
||||
(len(sre._cache), 'regexp')))
|
||||
sre.purge()
|
||||
(len(re._cache), 'regexp')))
|
||||
re.purge()
|
||||
L.append(format('Pattern cache flushed: %n cleared.',
|
||||
(len(ircutils._patternCache), 'compiled pattern')))
|
||||
ircutils._patternCache.clear()
|
||||
|
@ -56,44 +56,6 @@ def force(x):
|
||||
return x
|
||||
(__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
|
||||
# __builtins__ appropriately.
|
||||
from gen import *
|
||||
|
@ -29,11 +29,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info < (2, 5, 0):
|
||||
from md5 import md5
|
||||
from sha import sha
|
||||
else:
|
||||
from hashlib import md5
|
||||
from hashlib import sha1 as sha
|
||||
from hashlib import md5
|
||||
from hashlib import sha1 as sha
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
@ -50,23 +50,6 @@ def trueCycle(iterable):
|
||||
if not yielded:
|
||||
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):
|
||||
"""Partitions an iterable based on a predicate p.
|
||||
Returns a (yes,no) tuple"""
|
||||
|
@ -105,13 +105,8 @@ class Synchronized(type):
|
||||
|
||||
# Translate glob to regular expression, trimming the "match EOL" portion of
|
||||
# the regular expression.
|
||||
if sys.version_info < (2, 6, 0):
|
||||
# Pre-2.6 just uses the $ anchor
|
||||
def glob2re(g):
|
||||
return fnmatch.translate(g)[:-1]
|
||||
else:
|
||||
# Post-2.6 uses \Z(?ms) per http://issues.python.org/6665
|
||||
def glob2re(g):
|
||||
# Post-2.6 uses \Z(?ms) per http://issues.python.org/6665
|
||||
def glob2re(g):
|
||||
return fnmatch.translate(g)[:-7]
|
||||
|
||||
|
||||
|
@ -47,13 +47,6 @@ internationalizeFunction = _.internationalizeFunction
|
||||
|
||||
def rsplit(s, sep=None, maxsplit=-1):
|
||||
"""Equivalent to str.split, except splitting from the right."""
|
||||
if sys.version_info < (2, 4, 0):
|
||||
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):
|
||||
|
@ -39,10 +39,7 @@ import atexit
|
||||
import threading
|
||||
import multiprocessing # python 2.6 and later!
|
||||
|
||||
if sys.version_info >= (2, 5, 0):
|
||||
import re as sre
|
||||
else:
|
||||
import sre
|
||||
import re
|
||||
|
||||
import supybot.log as log
|
||||
import supybot.conf as conf
|
||||
@ -160,7 +157,7 @@ def upkeep():
|
||||
# registry.open(registryFilename)
|
||||
if not dying:
|
||||
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('HostmaskPatternEqual cache size: %s',
|
||||
len(ircutils._hostmaskPatternEqualCache))
|
||||
|
Loading…
Reference in New Issue
Block a user