/usr/share/pyshared/irc/strings.py is in python-irc 8.5.3+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | from __future__ import absolute_import, unicode_literals
import re
import string
import six
# from jaraco.util.string
class FoldedCase(six.text_type):
"""
A case insensitive string class; behaves just like str
except compares equal when the only variation is case.
>>> s = FoldedCase('hello world')
>>> s == 'Hello World'
True
>>> 'Hello World' == s
True
>>> s.index('O')
4
>>> s.split('O') == ['hell', ' w', 'rld']
True
>>> in_order = sorted(map(FoldedCase, ['GAMMA', 'alpha', 'Beta']))
>>> in_order == ['alpha', 'Beta', 'GAMMA']
True
It's still possible to compare against non-FoldedCase dicts
>>> s == None
False
>>> s == 1
False
"""
def __lt__(self, other):
if hasattr(other, 'lower'):
other = other.lower()
return self.lower() < other
def __gt__(self, other):
if hasattr(other, 'lower'):
other = other.lower()
return self.lower() > other
def __eq__(self, other):
if hasattr(other, 'lower'):
other = other.lower()
return self.lower() == other
def __hash__(self):
return hash(self.lower())
# cache lower since it's likely to be called frequently.
def lower(self):
self._lower = super(FoldedCase, self).lower()
self.lower = lambda: self._lower
return self._lower
def index(self, sub):
return self.lower().index(sub.lower())
def split(self, splitter=' ', maxsplit=0):
pattern = re.compile(re.escape(splitter), re.I)
return pattern.split(self, maxsplit)
class IRCFoldedCase(FoldedCase):
"""
A version of FoldedCase that honors the IRC specification for lowercased
strings (RFC 1459).
>>> IRCFoldedCase('Foo^').lower() == 'foo~'
True
>>> IRCFoldedCase('[this]') == IRCFoldedCase('{THIS}')
True
"""
translation = dict(zip(
map(ord, string.ascii_uppercase + r"[]\^"),
map(ord, string.ascii_lowercase + r"{}|~"),
))
def lower(self):
return self.translate(self.translation)
def lower(str):
return IRCFoldedCase(str).lower()
|