mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 12:49:24 +01:00
Fix Python 2 support.
This commit is contained in:
parent
030ce5e6d4
commit
39dacf6e5b
@ -309,7 +309,10 @@ def perlVariableSubstitute(vars, text):
|
|||||||
def byteTextWrap(text, size, break_on_hyphens=False, break_long_words=True):
|
def byteTextWrap(text, size, break_on_hyphens=False, break_long_words=True):
|
||||||
"""Similar to textwrap.wrap(), but considers the size of strings (in bytes)
|
"""Similar to textwrap.wrap(), but considers the size of strings (in bytes)
|
||||||
instead of their length (in characters)."""
|
instead of their length (in characters)."""
|
||||||
words = textwrap.TextWrapper()._split_chunks(text)
|
try:
|
||||||
|
words = textwrap.TextWrapper()._split_chunks(text)
|
||||||
|
except AttributeError: # Python 2
|
||||||
|
words = textwrap.TextWrapper()._split(text)
|
||||||
words.reverse() # use it as a stack
|
words.reverse() # use it as a stack
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
words = [w.encode() for w in words]
|
words = [w.encode() for w in words]
|
||||||
|
@ -184,7 +184,12 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
self.assertTrue(max(map(pred, r)) <= 100)
|
self.assertTrue(max(map(pred, r)) <= 100)
|
||||||
self.assertEqual(''.join(r), s)
|
self.assertEqual(''.join(r), s)
|
||||||
|
|
||||||
s = (''.join([chr(0x1f527), chr(0x1f527), chr(0x1f527), ' ']) * 100)\
|
if sys.version_info[0] < 3:
|
||||||
|
chr = unichr
|
||||||
|
u = lambda s: s.decode('utf8')
|
||||||
|
else:
|
||||||
|
u = lambda x: x
|
||||||
|
s = (u('').join([chr(0x1f527), chr(0x1f527), chr(0x1f527), u(' ')]) * 100)\
|
||||||
[0:-1]
|
[0:-1]
|
||||||
|
|
||||||
r = ircutils.wrap(s, 20)
|
r = ircutils.wrap(s, 20)
|
||||||
|
Loading…
Reference in New Issue
Block a user