mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-15 21:30:45 +00:00
Clarify who can use methods in the documentation
This commit is contained in:
@@ -3,9 +3,10 @@ import re
|
||||
|
||||
from .tlarg import TLArg
|
||||
from .tlobject import TLObject
|
||||
from ..methods import Usability
|
||||
|
||||
|
||||
def _from_line(line, is_function, layer):
|
||||
def _from_line(line, is_function, method_info, layer):
|
||||
match = re.match(
|
||||
r'^([\w.]+)' # 'name'
|
||||
r'(?:#([0-9a-fA-F]+))?' # '#optionalcode'
|
||||
@@ -26,27 +27,33 @@ def _from_line(line, is_function, layer):
|
||||
r'}?',
|
||||
line
|
||||
)
|
||||
|
||||
name = match.group(1)
|
||||
if name in method_info:
|
||||
usability = method_info[name].usability
|
||||
else:
|
||||
usability = Usability.UNKNOWN
|
||||
|
||||
return TLObject(
|
||||
fullname=match.group(1),
|
||||
fullname=name,
|
||||
object_id=match.group(2),
|
||||
result=match.group(3),
|
||||
is_function=is_function,
|
||||
layer=layer,
|
||||
usability=usability,
|
||||
args=[TLArg(name, arg_type, brace != '')
|
||||
for brace, name, arg_type in args_match]
|
||||
)
|
||||
|
||||
|
||||
def parse_tl(file_path, layer, invalid_bot_methods=None):
|
||||
def parse_tl(file_path, layer, methods=None):
|
||||
"""
|
||||
This method yields TLObjects from a given .tl file.
|
||||
|
||||
Note that the file is parsed completely before the function yields
|
||||
because references to other objects may appear later in the file.
|
||||
"""
|
||||
if invalid_bot_methods is None:
|
||||
invalid_bot_methods = set()
|
||||
|
||||
method_info = {m.name: m for m in (methods or [])}
|
||||
obj_all = []
|
||||
obj_by_name = {}
|
||||
obj_by_type = collections.defaultdict(list)
|
||||
@@ -68,8 +75,9 @@ def parse_tl(file_path, layer, invalid_bot_methods=None):
|
||||
continue
|
||||
|
||||
try:
|
||||
result = _from_line(line, is_function, layer=layer)
|
||||
result.bot_usable = result.fullname not in invalid_bot_methods
|
||||
result = _from_line(
|
||||
line, is_function, method_info, layer=layer)
|
||||
|
||||
obj_all.append(result)
|
||||
if not result.is_function:
|
||||
obj_by_name[result.fullname] = result
|
||||
|
||||
@@ -14,7 +14,8 @@ for i in range(77, 83):
|
||||
|
||||
|
||||
class TLObject:
|
||||
def __init__(self, fullname, object_id, args, result, is_function, layer):
|
||||
def __init__(self, fullname, object_id, args, result,
|
||||
is_function, usability, layer):
|
||||
"""
|
||||
Initializes a new TLObject, given its properties.
|
||||
|
||||
@@ -24,6 +25,7 @@ class TLObject:
|
||||
:param args: The arguments, if any, of the TL object
|
||||
:param result: The result type of the TL object
|
||||
:param is_function: Is the object a function or a type?
|
||||
:param usability: The usability for this method.
|
||||
:param layer: The layer this TLObject belongs to.
|
||||
"""
|
||||
# The name can or not have a namespace
|
||||
@@ -36,7 +38,7 @@ class TLObject:
|
||||
self.args = args
|
||||
self.result = result
|
||||
self.is_function = is_function
|
||||
self.bot_usable = None
|
||||
self.usability = usability
|
||||
self.id = None
|
||||
if object_id is None:
|
||||
self.id = self.infer_id()
|
||||
|
||||
Reference in New Issue
Block a user