mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-26 03:13:45 +03:00
Create a default module to use as a sentinel value
This looks better in the documentation than utils.Default, cleans the utils with specific stuff like this, and users may use it more easily.
This commit is contained in:
parent
0fcc2e5e52
commit
d392939018
|
@ -2,8 +2,8 @@ import itertools
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .users import UserMethods
|
from .users import UserMethods
|
||||||
from .. import utils
|
from .. import default, utils
|
||||||
from ..tl import types, custom
|
from ..tl import types
|
||||||
|
|
||||||
|
|
||||||
class MessageParseMethods(UserMethods):
|
class MessageParseMethods(UserMethods):
|
||||||
|
@ -62,7 +62,7 @@ class MessageParseMethods(UserMethods):
|
||||||
"""
|
"""
|
||||||
Returns a (parsed message, entities) tuple depending on ``parse_mode``.
|
Returns a (parsed message, entities) tuple depending on ``parse_mode``.
|
||||||
"""
|
"""
|
||||||
if parse_mode == utils.Default:
|
if parse_mode == default:
|
||||||
parse_mode = self._parse_mode
|
parse_mode = self._parse_mode
|
||||||
else:
|
else:
|
||||||
parse_mode = utils.sanitize_parse_mode(parse_mode)
|
parse_mode = utils.sanitize_parse_mode(parse_mode)
|
||||||
|
|
|
@ -8,8 +8,8 @@ from async_generator import async_generator, yield_
|
||||||
from .messageparse import MessageParseMethods
|
from .messageparse import MessageParseMethods
|
||||||
from .uploads import UploadMethods
|
from .uploads import UploadMethods
|
||||||
from .buttons import ButtonMethods
|
from .buttons import ButtonMethods
|
||||||
from .. import utils, helpers
|
from .. import default, helpers, utils
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions
|
||||||
|
|
||||||
__log__ = logging.getLogger(__name__)
|
__log__ = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
|
|
||||||
async def send_message(
|
async def send_message(
|
||||||
self, entity, message='', *, reply_to=None,
|
self, entity, message='', *, reply_to=None,
|
||||||
parse_mode=utils.Default, link_preview=True, file=None,
|
parse_mode=default, link_preview=True, file=None,
|
||||||
force_document=False, clear_draft=False, buttons=None,
|
force_document=False, clear_draft=False, buttons=None,
|
||||||
silent=None):
|
silent=None):
|
||||||
"""
|
"""
|
||||||
|
@ -584,7 +584,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
|
|
||||||
async def edit_message(
|
async def edit_message(
|
||||||
self, entity, message=None, text=None,
|
self, entity, message=None, text=None,
|
||||||
*, parse_mode=utils.Default, link_preview=True, file=None,
|
*, parse_mode=default, link_preview=True, file=None,
|
||||||
buttons=None):
|
buttons=None):
|
||||||
"""
|
"""
|
||||||
Edits the given message ID (to change its contents or disable preview).
|
Edits the given message ID (to change its contents or disable preview).
|
||||||
|
|
|
@ -5,11 +5,11 @@ import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from mimetypes import guess_type
|
|
||||||
|
|
||||||
|
from .buttons import ButtonMethods
|
||||||
from .messageparse import MessageParseMethods
|
from .messageparse import MessageParseMethods
|
||||||
from .users import UserMethods
|
from .users import UserMethods
|
||||||
from .buttons import ButtonMethods
|
from .. import default
|
||||||
from .. import utils, helpers
|
from .. import utils, helpers
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
async def send_file(
|
async def send_file(
|
||||||
self, entity, file, *, caption='', force_document=False,
|
self, entity, file, *, caption='', force_document=False,
|
||||||
progress_callback=None, reply_to=None, attributes=None,
|
progress_callback=None, reply_to=None, attributes=None,
|
||||||
thumb=None, allow_cache=True, parse_mode=utils.Default,
|
thumb=None, allow_cache=True, parse_mode=default,
|
||||||
voice_note=False, video_note=False, buttons=None, silent=None,
|
voice_note=False, video_note=False, buttons=None, silent=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -180,7 +180,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
|
|
||||||
async def _send_album(self, entity, files, caption='',
|
async def _send_album(self, entity, files, caption='',
|
||||||
progress_callback=None, reply_to=None,
|
progress_callback=None, reply_to=None,
|
||||||
parse_mode=utils.Default, silent=None):
|
parse_mode=default, silent=None):
|
||||||
"""Specialized version of .send_file for albums"""
|
"""Specialized version of .send_file for albums"""
|
||||||
# We don't care if the user wants to avoid cache, we will use it
|
# We don't care if the user wants to avoid cache, we will use it
|
||||||
# anyway. Why? The cached version will be exactly the same thing
|
# anyway. Why? The cached version will be exactly the same thing
|
||||||
|
|
5
telethon/default.py
Normal file
5
telethon/default.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
"""
|
||||||
|
Sentinel module to signify that a parameter should use its default value.
|
||||||
|
|
||||||
|
Useful when the default value or ``None`` are both valid options.
|
||||||
|
"""
|
|
@ -1,6 +1,5 @@
|
||||||
"""Various helpers not related to the Telegram API itself"""
|
"""Various helpers not related to the Telegram API itself"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
from hashlib import sha1, sha256
|
from hashlib import sha1, sha256
|
||||||
|
|
|
@ -3,9 +3,10 @@ import datetime
|
||||||
from .. import TLObject
|
from .. import TLObject
|
||||||
from ..functions.messages import SaveDraftRequest
|
from ..functions.messages import SaveDraftRequest
|
||||||
from ..types import UpdateDraftMessage, DraftMessage
|
from ..types import UpdateDraftMessage, DraftMessage
|
||||||
|
from ... import default
|
||||||
from ...errors import RPCError
|
from ...errors import RPCError
|
||||||
from ...extensions import markdown
|
from ...extensions import markdown
|
||||||
from ...utils import Default, get_peer_id, get_input_peer
|
from ...utils import get_peer_id, get_input_peer
|
||||||
|
|
||||||
|
|
||||||
class Draft:
|
class Draft:
|
||||||
|
@ -116,7 +117,7 @@ class Draft:
|
||||||
return not self._text
|
return not self._text
|
||||||
|
|
||||||
async def set_message(
|
async def set_message(
|
||||||
self, text=None, reply_to=0, parse_mode=Default,
|
self, text=None, reply_to=0, parse_mode=default,
|
||||||
link_preview=None):
|
link_preview=None):
|
||||||
"""
|
"""
|
||||||
Changes the draft message on the Telegram servers. The changes are
|
Changes the draft message on the Telegram servers. The changes are
|
||||||
|
@ -163,7 +164,7 @@ class Draft:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def send(self, clear=True, parse_mode=Default):
|
async def send(self, clear=True, parse_mode=default):
|
||||||
"""
|
"""
|
||||||
Sends the contents of this draft to the dialog. This is just a
|
Sends the contents of this draft to the dialog. This is just a
|
||||||
wrapper around ``send_message(dialog.input_entity, *args, **kwargs)``.
|
wrapper around ``send_message(dialog.input_entity, *args, **kwargs)``.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from .. import functions, types
|
from .. import functions, types
|
||||||
from ... import utils
|
from ... import default, utils
|
||||||
|
|
||||||
|
|
||||||
class InlineBuilder:
|
class InlineBuilder:
|
||||||
|
@ -55,7 +55,7 @@ class InlineBuilder:
|
||||||
async def article(
|
async def article(
|
||||||
self, title, description=None,
|
self, title, description=None,
|
||||||
*, url=None, thumb=None, content=None,
|
*, url=None, thumb=None, content=None,
|
||||||
id=None, text=None, parse_mode=utils.Default, link_preview=True,
|
id=None, text=None, parse_mode=default, link_preview=True,
|
||||||
geo=None, period=60, contact=None, game=False, buttons=None
|
geo=None, period=60, contact=None, game=False, buttons=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -105,7 +105,7 @@ class InlineBuilder:
|
||||||
|
|
||||||
async def photo(
|
async def photo(
|
||||||
self, file, *, id=None,
|
self, file, *, id=None,
|
||||||
text=None, parse_mode=utils.Default, link_preview=True,
|
text=None, parse_mode=default, link_preview=True,
|
||||||
geo=None, period=60, contact=None, game=False, buttons=None
|
geo=None, period=60, contact=None, game=False, buttons=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -144,7 +144,7 @@ class InlineBuilder:
|
||||||
self, file, title=None, *, description=None, type=None,
|
self, file, title=None, *, description=None, type=None,
|
||||||
mime_type=None, attributes=None, force_document=False,
|
mime_type=None, attributes=None, force_document=False,
|
||||||
voice_note=False, video_note=False, use_cache=True, id=None,
|
voice_note=False, video_note=False, use_cache=True, id=None,
|
||||||
text=None, parse_mode=utils.Default, link_preview=True,
|
text=None, parse_mode=default, link_preview=True,
|
||||||
geo=None, period=60, contact=None, game=False, buttons=None
|
geo=None, period=60, contact=None, game=False, buttons=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -219,7 +219,7 @@ class InlineBuilder:
|
||||||
|
|
||||||
async def game(
|
async def game(
|
||||||
self, short_name, *, id=None,
|
self, short_name, *, id=None,
|
||||||
text=None, parse_mode=utils.Default, link_preview=True,
|
text=None, parse_mode=default, link_preview=True,
|
||||||
geo=None, period=60, contact=None, game=False, buttons=None
|
geo=None, period=60, contact=None, game=False, buttons=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -247,7 +247,7 @@ class InlineBuilder:
|
||||||
|
|
||||||
async def _message(
|
async def _message(
|
||||||
self, *,
|
self, *,
|
||||||
text=None, parse_mode=utils.Default, link_preview=True,
|
text=None, parse_mode=default, link_preview=True,
|
||||||
geo=None, period=60, contact=None, game=False, buttons=None
|
geo=None, period=60, contact=None, game=False, buttons=None
|
||||||
):
|
):
|
||||||
if sum(1 for x in (text, geo, contact, game) if x) != 1:
|
if sum(1 for x in (text, geo, contact, game) if x) != 1:
|
||||||
|
|
|
@ -45,14 +45,6 @@ VALID_USERNAME_RE = re.compile(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Default:
|
|
||||||
"""
|
|
||||||
Sentinel value to indicate that the default value should be used.
|
|
||||||
Currently used for the ``parse_mode``, where a ``None`` mode should
|
|
||||||
be considered different from using the default.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def chunks(iterable, size=100):
|
def chunks(iterable, size=100):
|
||||||
"""
|
"""
|
||||||
Turns the given iterable into chunks of the specified size,
|
Turns the given iterable into chunks of the specified size,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user