From ed200452d6635b67fe649e124818d74701de44de Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sun, 19 May 2024 17:22:41 -0700 Subject: [PATCH] drop WideUnicode; it was only needed for Python 2, and we're Python 3 now --- granary/facebook.py | 4 ++-- granary/mastodon.py | 2 +- granary/microformats2.py | 6 +++--- granary/twitter.py | 7 +++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/granary/facebook.py b/granary/facebook.py index d60431b6..79e8b181 100644 --- a/granary/facebook.py +++ b/granary/facebook.py @@ -1193,7 +1193,7 @@ def post_to_object(self, post, type=None): # reusing e.g. cgi.escape, so that we can shuffle over each tag startIndex # appropriately. :( if message: - content = util.WideUnicode(copy.copy(message)) + content = copy.copy(message) tags = sorted([t for t in obj['tags'] if t.get('startIndex')], key=lambda t: t['startIndex']) @@ -1204,7 +1204,7 @@ def post_to_object(self, post, type=None): tags.pop(0) entity = entities.get(content[i]) if entity: - content = util.WideUnicode(content[:i] + entity + content[i + 1:]) + content = content[:i] + entity + content[i + 1:] for tag in tags: tag['startIndex'] += len(entity) - 1 i += 1 diff --git a/granary/mastodon.py b/granary/mastodon.py index fc9e4042..9282f092 100644 --- a/granary/mastodon.py +++ b/granary/mastodon.py @@ -431,7 +431,7 @@ def status_to_object(self, status): reblog_account = reblog.get('account') content = f"Boosted @{reblog_account.get('username')}: " + content - obj['content'] = util.WideUnicode(content) + obj['content'] = content # inReplyTo reply_to_id = status.get('in_reply_to_id') diff --git a/granary/microformats2.py b/granary/microformats2.py index d2fe2929..da9eca43 100644 --- a/granary/microformats2.py +++ b/granary/microformats2.py @@ -1001,12 +1001,12 @@ def render_content(obj, include_location=True, synthesize_content=True, if mentions: mentions.sort(key=lambda t: t['startIndex']) last_end = 0 - orig = util.WideUnicode(content) - content = util.WideUnicode('') + orig = content + content = '' for tag in mentions: start = tag['startIndex'] end = start + tag['length'] - content = util.WideUnicode(f"{content}{orig[last_end:start]}{orig[start:end]}") + content = f"{content}{orig[last_end:start]}{orig[start:end]}" last_end = end content += orig[last_end:] diff --git a/granary/twitter.py b/granary/twitter.py index 75912600..22bb37c2 100644 --- a/granary/twitter.py +++ b/granary/twitter.py @@ -1216,8 +1216,7 @@ def tweet_to_object(self, tweet): entities = self._get_entities(base_tweet) # text content - text = util.WideUnicode( - base_tweet.get('full_text') or base_tweet.get('text') or '') + text = base_tweet.get('full_text') or base_tweet.get('text') or '' text_start, text_end = (base_tweet.get('display_text_range') or (0, len(text))) @@ -1331,7 +1330,7 @@ def tweet_to_object(self, tweet): and tag.get('indices')[1] <= text_start) # replace entities with display URLs, convert start/end indices to start/length - content = util.WideUnicode(rt_prefix + text[text_start:text_end]) + content = rt_prefix + text[text_start:text_end] offset = len(rt_prefix) - text_start for t in obj['tags']: start, end = t.pop('indices', None) or (0, 0) @@ -1342,7 +1341,7 @@ def tweet_to_object(self, tweet): if t['objectType'] in ('article', 'image'): tag_text = t.get('displayName', t.get('url')) if tag_text is not None: - content = util.WideUnicode(content[:start] + tag_text + content[end:]) + content = content[:start] + tag_text + content[end:] offset += len(tag_text) - length length = len(tag_text) t.update({'startIndex': start, 'length': length})