Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions maugclib/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import time

import aiohttp
import async_timeout

from mautrix.util.opt_prometheus import Counter

Expand Down Expand Up @@ -445,7 +444,7 @@ async def _longpoll_request(self) -> None:
await self._send_initial_ping()

while True:
async with async_timeout.timeout(PUSH_TIMEOUT):
async with asyncio.timeout(PUSH_TIMEOUT):
chunk = await res.content.read(MAX_READ_BYTES)
if not chunk:
break
Expand Down
13 changes: 10 additions & 3 deletions maugclib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from __future__ import annotations

from typing import Iterator
from typing import Dict, Iterator
from email.message import EmailMessage
from urllib.parse import urlencode
import asyncio
import base64
import binascii
import cgi
import datetime
import json
import logging
Expand All @@ -34,6 +34,13 @@
wiz_pattern = re.compile(r">window.WIZ_global_data = ({.+?});</script>")


def parse_header(header: str) -> Dict[str, str]:
"""Replacement for the old cgi.parse_header()"""
msg = EmailMessage()
msg["Content-Disposition"] = header
return msg["Content-Disposition"].params


class Client:
"""Instant messaging client for Google Chat.

Expand Down Expand Up @@ -224,7 +231,7 @@ async def download_attachment(

resp.raise_for_status()
try:
_, params = cgi.parse_header(resp.headers["Content-Disposition"])
params = parse_header(resp.headers["Content-Disposition"])
filename = params.get("filename") or url.path.split("/")[-1]
except KeyError:
filename = url.path.split("/")[-1]
Expand Down
3 changes: 1 addition & 2 deletions maugclib/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from yarl import URL
import aiohttp
import async_timeout

from . import exceptions

Expand Down Expand Up @@ -143,7 +142,7 @@ async def fetch(
allow_redirects=allow_redirects,
data=data,
) as res:
async with async_timeout.timeout(REQUEST_TIMEOUT):
async with asyncio.timeout(REQUEST_TIMEOUT):
body = await res.read()
log_body = body
if isinstance(url, str) and "/u/0/mole/world" in url:
Expand Down
24 changes: 12 additions & 12 deletions mautrix_googlechat/formatter/from_matrix/gc_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ class GCUserMentionType(Enum):
class GCEntityType(Enum):
"""EntityType is a Matrix formatting entity type."""

BOLD = GCFormatType.BOLD
ITALIC = GCFormatType.ITALIC
STRIKETHROUGH = GCFormatType.STRIKE
UNDERLINE = GCFormatType.UNDERLINE
BOLD = (GCFormatType.BOLD).value
ITALIC = (GCFormatType.ITALIC).value
STRIKETHROUGH = (GCFormatType.STRIKE).value
UNDERLINE = (GCFormatType.UNDERLINE).value
URL = auto()
EMAIL = auto()
USER_MENTION = GCUserMentionType.MENTION
MENTION_ALL = GCUserMentionType.MENTION_ALL
PREFORMATTED = GCFormatType.MONOSPACE_BLOCK
INLINE_CODE = GCFormatType.MONOSPACE
COLOR = GCFormatType.FONT_COLOR
USER_MENTION = (GCUserMentionType.MENTION).value
MENTION_ALL = (GCUserMentionType.MENTION_ALL).value
PREFORMATTED = (GCFormatType.MONOSPACE_BLOCK).value
INLINE_CODE = (GCFormatType.MONOSPACE).value
COLOR = (GCFormatType.FONT_COLOR).value

# Google Chat specific types, not present in mautrix-python's EntityType
LIST = GCFormatType.BULLETED_LIST
LIST_ITEM = GCFormatType.BULLETED_LIST_ITEM
HIDDEN = GCFormatType.HIDDEN
LIST = (GCFormatType.BULLETED_LIST).value
LIST_ITEM = (GCFormatType.BULLETED_LIST_ITEM).value
HIDDEN = (GCFormatType.HIDDEN).value


class GCEntity(SemiAbstractEntity):
Expand Down
Loading