2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-27 20:37:54 +00:00

Handle mismatches in a more pythonic way

This commit is contained in:
Dan 2018-03-18 12:12:27 +01:00
parent 1d25b84cde
commit cbd3b71b79

View File

@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import base64 import base64
import binascii
import json import json
import logging import logging
import math import math
@ -919,9 +920,11 @@ class Client:
match = self.INVITE_LINK_RE.match(peer_id) match = self.INVITE_LINK_RE.match(peer_id)
if match: try:
decoded = base64.b64decode(match.group(1) + "=" * (-len(match.group(1)) % 4), altchars="-_") decoded = base64.b64decode(match.group(1) + "=" * (-len(match.group(1)) % 4), "-_")
return self.resolve_peer(struct.unpack(">2iq", decoded)[1]) return self.resolve_peer(struct.unpack(">2iq", decoded)[1])
except (AttributeError, binascii.Error, struct.error):
pass
peer_id = peer_id.lower().strip("@+") peer_id = peer_id.lower().strip("@+")