Skip to content

Commit

Permalink
Update implementation to work with jaraco.text 3.10 (casefold)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 13, 2023
1 parent b82fe23 commit 0c2a0ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
33 changes: 23 additions & 10 deletions irc/strings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import string

from jaraco.text import FoldedCase


Expand All @@ -14,24 +12,39 @@ class IRCFoldedCase(FoldedCase):
>>> IRCFoldedCase('[this]') == IRCFoldedCase('{THIS}')
True
>>> IRCFoldedCase('[This]').casefold()
'{this}'
>>> IRCFoldedCase().lower()
''
"""

translation = dict(
zip(
map(ord, string.ascii_uppercase + r"[]\^"),
map(ord, string.ascii_lowercase + r"{}|~"),
map(ord, r"[]\^"),
map(ord, r"{}|~"),
)
)

def lower(self):
return (
self.translate(self.translation)
if self
# bypass translate, which returns self
else super().lower()
)
return super().lower().translate(self.translation)

def casefold(self):
"""
Ensure cached superclass value doesn't supersede.
>>> ob = IRCFoldedCase('[This]')
>>> ob.casefold()
'{this}'
>>> ob.casefold()
'{this}'
"""
return super().casefold().translate(self.translation)

def __setattr__(self, key, val):
if key == 'casefold':
return
return super().__setattr__(key, val)


def lower(str):
Expand Down
5 changes: 1 addition & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include_package_data = true
python_requires = >=3.8
install_requires =
jaraco.collections
jaraco.text
jaraco.text >= 3.10
jaraco.logging
jaraco.functools>=1.20
jaraco.stream
Expand All @@ -27,9 +27,6 @@ install_requires =
tempora>=1.6
importlib_metadata; python_version < "3.8"

# workaround for #213
jaraco.text < 3.10

[options.packages.find]
exclude =
build*
Expand Down

0 comments on commit 0c2a0ee

Please sign in to comment.