Avoid cyclic imports on older Python versions

This commit is contained in:
Lonami Exo
2018-06-29 11:04:42 +02:00
parent 3c2ff45b0b
commit d64eb7ea2b
3 changed files with 23 additions and 25 deletions

View File

@@ -7,13 +7,12 @@ import math
import mimetypes
import os
import re
import struct
import types
from collections import UserList
from mimetypes import guess_extension
from .extensions import markdown, html
from .tl import TLObject
from .helpers import add_surrogate, del_surrogate
from .tl.types import (
Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull,
ChatPhoto, InputPeerChannel, InputPeerChat, InputPeerUser, InputPeerEmpty,
@@ -586,19 +585,6 @@ def _fix_peer_id(peer_id):
return int(peer_id)
def add_surrogate(text):
return ''.join(
# SMP -> Surrogate Pairs (Telegram offsets are calculated with these).
# See https://en.wikipedia.org/wiki/Plane_(Unicode)#Overview for more.
''.join(chr(y) for y in struct.unpack('<HH', x.encode('utf-16le')))
if (0x10000 <= ord(x) <= 0x10FFFF) else x for x in text
)
def del_surrogate(text):
return text.encode('utf-16', 'surrogatepass').decode('utf-16')
def get_inner_text(text, entities):
"""
Gets the inner text that's surrounded by the given entities.