Skip to content

Commit

Permalink
drop WideUnicode; it was only needed for Python 2, and we're Python 3…
Browse files Browse the repository at this point in the history
… now
  • Loading branch information
snarfed committed May 20, 2024
1 parent 78f4147 commit ed20045
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions granary/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion granary/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def status_to_object(self, status):
reblog_account = reblog.get('account')
content = f"Boosted <a href=\"{reblog_account.get('url')}\">@{reblog_account.get('username')}</a>: " + content

obj['content'] = util.WideUnicode(content)
obj['content'] = content

# inReplyTo
reply_to_id = status.get('in_reply_to_id')
Expand Down
6 changes: 3 additions & 3 deletions granary/microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}<a href=\"{tag['url']}\">{orig[start:end]}</a>")
content = f"{content}{orig[last_end:start]}<a href=\"{tag['url']}\">{orig[start:end]}</a>"
last_end = end

content += orig[last_end:]
Expand Down
7 changes: 3 additions & 4 deletions granary/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand Down

0 comments on commit ed20045

Please sign in to comment.