mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 13:29:47 +00:00
Add support for flags2 in the TL
This commit is contained in:
@@ -100,9 +100,9 @@ class TLArg:
|
||||
|
||||
# Default values
|
||||
self.is_vector = False
|
||||
self.is_flag = False
|
||||
self.flag = None # name of the flag to check if self is present
|
||||
self.skip_constructor_id = False
|
||||
self.flag_index = -1
|
||||
self.flag_index = -1 # bit index of the flag to check if self is present
|
||||
self.cls = None
|
||||
|
||||
# Special case: some types can be inferred, which makes it
|
||||
@@ -122,16 +122,14 @@ class TLArg:
|
||||
# Strip the exclamation mark always to have only the name
|
||||
self.type = arg_type.lstrip('!')
|
||||
|
||||
# The type may be a flag (flags.IDX?REAL_TYPE)
|
||||
# Note that 'flags' is NOT the flags name; this
|
||||
# is determined by a previous argument
|
||||
# However, we assume that the argument will always be called 'flags'
|
||||
flag_match = re.match(r'flags.(\d+)\?([\w<>.]+)', self.type)
|
||||
# The type may be a flag (FLAGS.IDX?REAL_TYPE)
|
||||
# FLAGS can be any name, but it should have appeared previously.
|
||||
flag_match = re.match(r'(\w+).(\d+)\?([\w<>.]+)', self.type)
|
||||
if flag_match:
|
||||
self.is_flag = True
|
||||
self.flag_index = int(flag_match.group(1))
|
||||
self.flag = flag_match.group(1)
|
||||
self.flag_index = int(flag_match.group(2))
|
||||
# Update the type to match the exact type, not the "flagged" one
|
||||
self.type = flag_match.group(2)
|
||||
self.type = flag_match.group(3)
|
||||
|
||||
# Then check if the type is a Vector<REAL_TYPE>
|
||||
vector_match = re.match(r'[Vv]ector<([\w\d.]+)>', self.type)
|
||||
@@ -180,7 +178,7 @@ class TLArg:
|
||||
}.get(cls, "'Type{}'".format(cls))
|
||||
if self.is_vector:
|
||||
result = 'List[{}]'.format(result)
|
||||
if self.is_flag and cls != 'date':
|
||||
if self.flag and cls != 'date':
|
||||
result = 'Optional[{}]'.format(result)
|
||||
|
||||
return result
|
||||
@@ -200,8 +198,8 @@ class TLArg:
|
||||
if self.is_generic:
|
||||
real_type = '!{}'.format(real_type)
|
||||
|
||||
if self.is_flag:
|
||||
real_type = 'flags.{}?{}'.format(self.flag_index, real_type)
|
||||
if self.flag:
|
||||
real_type = '{}.{}?{}'.format(self.flag, self.flag_index, real_type)
|
||||
|
||||
return real_type
|
||||
|
||||
@@ -244,5 +242,5 @@ class TLArg:
|
||||
self.cls[0].as_example(f, indent)
|
||||
|
||||
def omit_example(self):
|
||||
return (self.is_flag or self.can_be_inferred) \
|
||||
return (self.flag or self.can_be_inferred) \
|
||||
and self.name in OMITTED_EXAMPLES
|
||||
|
Reference in New Issue
Block a user