typing: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting assignment type annotations, which require Python 3.6), followed by some manual whitespace adjustment, and two fixes for use-before-define issues: - def set_zulip_client(self, zulipToJabberClient: ZulipToJabberBot) -> None: + def set_zulip_client(self, zulipToJabberClient: 'ZulipToJabberBot') -> None: -def init_from_options(options: Any, client: Optional[str] = None) -> Client: +def init_from_options(options: Any, client: Optional[str] = None) -> 'Client': Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
7c5f73dce9
commit
5428c5f296
42 changed files with 311 additions and 577 deletions
|
@ -33,41 +33,35 @@ requests_json_is_function = callable(requests.Response.json)
|
|||
API_VERSTRING = "v1/"
|
||||
|
||||
class CountingBackoff:
|
||||
def __init__(self, maximum_retries=10, timeout_success_equivalent=None, delay_cap=90.0):
|
||||
# type: (int, Optional[float], float) -> None
|
||||
def __init__(self, maximum_retries: int = 10, timeout_success_equivalent: Optional[float] = None, delay_cap: float = 90.0) -> None:
|
||||
self.number_of_retries = 0
|
||||
self.maximum_retries = maximum_retries
|
||||
self.timeout_success_equivalent = timeout_success_equivalent
|
||||
self.last_attempt_time = 0.0
|
||||
self.delay_cap = delay_cap
|
||||
|
||||
def keep_going(self):
|
||||
# type: () -> bool
|
||||
def keep_going(self) -> bool:
|
||||
self._check_success_timeout()
|
||||
return self.number_of_retries < self.maximum_retries
|
||||
|
||||
def succeed(self):
|
||||
# type: () -> None
|
||||
def succeed(self) -> None:
|
||||
self.number_of_retries = 0
|
||||
self.last_attempt_time = time.time()
|
||||
|
||||
def fail(self):
|
||||
# type: () -> None
|
||||
def fail(self) -> None:
|
||||
self._check_success_timeout()
|
||||
self.number_of_retries = min(self.number_of_retries + 1,
|
||||
self.maximum_retries)
|
||||
self.last_attempt_time = time.time()
|
||||
|
||||
def _check_success_timeout(self):
|
||||
# type: () -> None
|
||||
def _check_success_timeout(self) -> None:
|
||||
if (self.timeout_success_equivalent is not None and
|
||||
self.last_attempt_time != 0 and
|
||||
time.time() - self.last_attempt_time > self.timeout_success_equivalent):
|
||||
self.number_of_retries = 0
|
||||
|
||||
class RandomExponentialBackoff(CountingBackoff):
|
||||
def fail(self):
|
||||
# type: () -> None
|
||||
def fail(self) -> None:
|
||||
super().fail()
|
||||
# Exponential growth with ratio sqrt(2); compute random delay
|
||||
# between x and 2x where x is growing exponentially
|
||||
|
@ -80,16 +74,17 @@ class RandomExponentialBackoff(CountingBackoff):
|
|||
print(message)
|
||||
time.sleep(delay)
|
||||
|
||||
def _default_client():
|
||||
# type: () -> str
|
||||
def _default_client() -> str:
|
||||
return "ZulipPython/" + __version__
|
||||
|
||||
def add_default_arguments(parser, patch_error_handling=True, allow_provisioning=False):
|
||||
# type: (argparse.ArgumentParser, bool, bool) -> argparse.ArgumentParser
|
||||
def add_default_arguments(
|
||||
parser: argparse.ArgumentParser,
|
||||
patch_error_handling: bool = True,
|
||||
allow_provisioning: bool = False,
|
||||
) -> argparse.ArgumentParser:
|
||||
|
||||
if patch_error_handling:
|
||||
def custom_error_handling(self, message):
|
||||
# type: (argparse.ArgumentParser, str) -> None
|
||||
def custom_error_handling(self: argparse.ArgumentParser, message: str) -> None:
|
||||
self.print_help(sys.stderr)
|
||||
self.exit(2, '{}: error: {}\n'.format(self.prog, message))
|
||||
parser.error = types.MethodType(custom_error_handling, parser) # type: ignore # patching function
|
||||
|
@ -154,8 +149,7 @@ def add_default_arguments(parser, patch_error_handling=True, allow_provisioning=
|
|||
# except for the fact that is uses the deprecated `optparse` module.
|
||||
# We still keep it for legacy support of out-of-tree bots and integrations
|
||||
# depending on it.
|
||||
def generate_option_group(parser, prefix=''):
|
||||
# type: (optparse.OptionParser, str) -> optparse.OptionGroup
|
||||
def generate_option_group(parser: optparse.OptionParser, prefix: str = '') -> optparse.OptionGroup:
|
||||
logging.warning("""zulip.generate_option_group is based on optparse, which
|
||||
is now deprecated. We recommend migrating to argparse and
|
||||
using zulip.add_default_arguments instead.""")
|
||||
|
@ -209,8 +203,7 @@ def generate_option_group(parser, prefix=''):
|
|||
file).''')
|
||||
return group
|
||||
|
||||
def init_from_options(options, client=None):
|
||||
# type: (Any, Optional[str]) -> Client
|
||||
def init_from_options(options: Any, client: Optional[str] = None) -> 'Client':
|
||||
|
||||
if getattr(options, 'provision', False):
|
||||
requirements_path = os.path.abspath(os.path.join(sys.path[0], 'requirements.txt'))
|
||||
|
@ -238,8 +231,7 @@ def init_from_options(options, client=None):
|
|||
client_cert=options.client_cert,
|
||||
client_cert_key=options.client_cert_key)
|
||||
|
||||
def get_default_config_filename():
|
||||
# type: () -> Optional[str]
|
||||
def get_default_config_filename() -> Optional[str]:
|
||||
if os.environ.get("HOME") is None:
|
||||
return None
|
||||
|
||||
|
@ -250,8 +242,7 @@ def get_default_config_filename():
|
|||
" mv ~/.humbugrc ~/.zuliprc\n")
|
||||
return config_file
|
||||
|
||||
def validate_boolean_field(field):
|
||||
# type: (Optional[Text]) -> Union[bool, None]
|
||||
def validate_boolean_field(field: Optional[Text]) -> Union[bool, None]:
|
||||
if not isinstance(field, str):
|
||||
return None
|
||||
|
||||
|
@ -277,12 +268,11 @@ class UnrecoverableNetworkError(ZulipError):
|
|||
pass
|
||||
|
||||
class Client:
|
||||
def __init__(self, email=None, api_key=None, config_file=None,
|
||||
verbose=False, retry_on_errors=True,
|
||||
site=None, client=None,
|
||||
cert_bundle=None, insecure=None,
|
||||
client_cert=None, client_cert_key=None):
|
||||
# type: (Optional[str], Optional[str], Optional[str], bool, bool, Optional[str], Optional[str], Optional[str], Optional[bool], Optional[str], Optional[str]) -> None
|
||||
def __init__(self, email: Optional[str] = None, api_key: Optional[str] = None, config_file: Optional[str] = None,
|
||||
verbose: bool = False, retry_on_errors: bool = True,
|
||||
site: Optional[str] = None, client: Optional[str] = None,
|
||||
cert_bundle: Optional[str] = None, insecure: Optional[bool] = None,
|
||||
client_cert: Optional[str] = None, client_cert_key: Optional[str] = None) -> None:
|
||||
if client is None:
|
||||
client = _default_client()
|
||||
|
||||
|
@ -406,8 +396,7 @@ class Client:
|
|||
|
||||
self.has_connected = False
|
||||
|
||||
def ensure_session(self):
|
||||
# type: () -> None
|
||||
def ensure_session(self) -> None:
|
||||
|
||||
# Check if the session has been created already, and return
|
||||
# immediately if so.
|
||||
|
@ -429,8 +418,7 @@ class Client:
|
|||
session.headers.update({"User-agent": self.get_user_agent()})
|
||||
self.session = session
|
||||
|
||||
def get_user_agent(self):
|
||||
# type: () -> str
|
||||
def get_user_agent(self) -> str:
|
||||
vendor = ''
|
||||
vendor_version = ''
|
||||
try:
|
||||
|
@ -454,9 +442,8 @@ class Client:
|
|||
vendor_version=vendor_version,
|
||||
)
|
||||
|
||||
def do_api_query(self, orig_request, url, method="POST",
|
||||
longpolling=False, files=None, timeout=None):
|
||||
# type: (Mapping[str, Any], str, str, bool, Optional[List[IO[Any]]], Optional[float]) -> Dict[str, Any]
|
||||
def do_api_query(self, orig_request: Mapping[str, Any], url: str, method: str = "POST",
|
||||
longpolling: bool = False, files: Optional[List[IO[Any]]] = None, timeout: Optional[float] = None) -> Dict[str, Any]:
|
||||
if files is None:
|
||||
files = []
|
||||
|
||||
|
@ -490,8 +477,7 @@ class Client:
|
|||
'failures': 0,
|
||||
} # type: Dict[str, Any]
|
||||
|
||||
def error_retry(error_string):
|
||||
# type: (str) -> bool
|
||||
def error_retry(error_string: str) -> bool:
|
||||
if not self.retry_on_errors or query_state["failures"] >= 10:
|
||||
return False
|
||||
if self.verbose:
|
||||
|
@ -507,8 +493,7 @@ class Client:
|
|||
query_state["failures"] += 1
|
||||
return True
|
||||
|
||||
def end_error_retry(succeeded):
|
||||
# type: (bool) -> None
|
||||
def end_error_retry(succeeded: bool) -> None:
|
||||
if query_state["had_error_retry"] and self.verbose:
|
||||
if succeeded:
|
||||
print("Success!")
|
||||
|
@ -589,9 +574,8 @@ class Client:
|
|||
return {'msg': "Unexpected error from the server", "result": "http-error",
|
||||
"status_code": res.status_code}
|
||||
|
||||
def call_endpoint(self, url=None, method="POST", request=None,
|
||||
longpolling=False, files=None, timeout=None):
|
||||
# type: (Optional[str], str, Optional[Dict[str, Any]], bool, Optional[List[IO[Any]]], Optional[float]) -> Dict[str, Any]
|
||||
def call_endpoint(self, url: Optional[str] = None, method: str = "POST", request: Optional[Dict[str, Any]] = None,
|
||||
longpolling: bool = False, files: Optional[List[IO[Any]]] = None, timeout: Optional[float] = None) -> Dict[str, Any]:
|
||||
if request is None:
|
||||
request = dict()
|
||||
marshalled_request = {}
|
||||
|
@ -602,13 +586,16 @@ class Client:
|
|||
return self.do_api_query(marshalled_request, versioned_url, method=method,
|
||||
longpolling=longpolling, files=files, timeout=timeout)
|
||||
|
||||
def call_on_each_event(self, callback, event_types=None, narrow=None):
|
||||
# type: (Callable[[Dict[str, Any]], None], Optional[List[str]], Optional[List[List[str]]]) -> None
|
||||
def call_on_each_event(
|
||||
self,
|
||||
callback: Callable[[Dict[str, Any]], None],
|
||||
event_types: Optional[List[str]] = None,
|
||||
narrow: Optional[List[List[str]]] = None,
|
||||
) -> None:
|
||||
if narrow is None:
|
||||
narrow = []
|
||||
|
||||
def do_register():
|
||||
# type: () -> Tuple[str, int]
|
||||
def do_register() -> Tuple[str, int]:
|
||||
while True:
|
||||
if event_types is None:
|
||||
res = self.register()
|
||||
|
@ -666,16 +653,13 @@ class Client:
|
|||
last_event_id = max(last_event_id, int(event['id']))
|
||||
callback(event)
|
||||
|
||||
def call_on_each_message(self, callback):
|
||||
# type: (Callable[[Dict[str, Any]], None]) -> None
|
||||
def event_callback(event):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
def call_on_each_message(self, callback: Callable[[Dict[str, Any]], None]) -> None:
|
||||
def event_callback(event: Dict[str, Any]) -> None:
|
||||
if event['type'] == 'message':
|
||||
callback(event['message'])
|
||||
self.call_on_each_event(event_callback, ['message'])
|
||||
|
||||
def get_messages(self, message_filters):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def get_messages(self, message_filters: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/get-messages for example usage
|
||||
'''
|
||||
|
@ -685,8 +669,7 @@ class Client:
|
|||
request=message_filters
|
||||
)
|
||||
|
||||
def check_messages_match_narrow(self, **request):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def check_messages_match_narrow(self, **request: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
'''
|
||||
Example usage:
|
||||
|
@ -702,8 +685,7 @@ class Client:
|
|||
request=request
|
||||
)
|
||||
|
||||
def get_raw_message(self, message_id):
|
||||
# type: (int) -> Dict[str, str]
|
||||
def get_raw_message(self, message_id: int) -> Dict[str, str]:
|
||||
'''
|
||||
See examples/get-raw-message for example usage
|
||||
'''
|
||||
|
@ -712,8 +694,7 @@ class Client:
|
|||
method='GET'
|
||||
)
|
||||
|
||||
def send_message(self, message_data):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def send_message(self, message_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/send-message for example usage.
|
||||
'''
|
||||
|
@ -722,8 +703,7 @@ class Client:
|
|||
request=message_data,
|
||||
)
|
||||
|
||||
def upload_file(self, file):
|
||||
# type: (IO[Any]) -> Dict[str, Any]
|
||||
def upload_file(self, file: IO[Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/upload-file for example usage.
|
||||
'''
|
||||
|
@ -732,8 +712,7 @@ class Client:
|
|||
files=[file]
|
||||
)
|
||||
|
||||
def get_attachments(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def get_attachments(self) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -745,8 +724,7 @@ class Client:
|
|||
method='GET'
|
||||
)
|
||||
|
||||
def update_message(self, message_data):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_message(self, message_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/edit-message for example usage.
|
||||
'''
|
||||
|
@ -756,8 +734,7 @@ class Client:
|
|||
request=message_data,
|
||||
)
|
||||
|
||||
def delete_message(self, message_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def delete_message(self, message_id: int) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/delete-message for example usage.
|
||||
'''
|
||||
|
@ -766,8 +743,7 @@ class Client:
|
|||
method='DELETE'
|
||||
)
|
||||
|
||||
def update_message_flags(self, update_data):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_message_flags(self, update_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/update-flags for example usage.
|
||||
'''
|
||||
|
@ -777,8 +753,7 @@ class Client:
|
|||
request=update_data
|
||||
)
|
||||
|
||||
def mark_all_as_read(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def mark_all_as_read(self) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -790,8 +765,7 @@ class Client:
|
|||
method='POST',
|
||||
)
|
||||
|
||||
def mark_stream_as_read(self, stream_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def mark_stream_as_read(self, stream_id: int) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -804,8 +778,7 @@ class Client:
|
|||
request={'stream_id': stream_id},
|
||||
)
|
||||
|
||||
def mark_topic_as_read(self, stream_id, topic_name):
|
||||
# type: (int, str) -> Dict[str, Any]
|
||||
def mark_topic_as_read(self, stream_id: int, topic_name: str) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -821,8 +794,7 @@ class Client:
|
|||
},
|
||||
)
|
||||
|
||||
def get_message_history(self, message_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def get_message_history(self, message_id: int) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/message-history for example usage.
|
||||
'''
|
||||
|
@ -831,8 +803,7 @@ class Client:
|
|||
method='GET'
|
||||
)
|
||||
|
||||
def add_reaction(self, reaction_data):
|
||||
# type: (Dict[str, str]) -> Dict[str, Any]
|
||||
def add_reaction(self, reaction_data: Dict[str, str]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -850,8 +821,7 @@ class Client:
|
|||
request=reaction_data,
|
||||
)
|
||||
|
||||
def remove_reaction(self, reaction_data):
|
||||
# type: (Dict[str, str]) -> Dict[str, Any]
|
||||
def remove_reaction(self, reaction_data: Dict[str, str]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -869,8 +839,7 @@ class Client:
|
|||
request=reaction_data,
|
||||
)
|
||||
|
||||
def get_realm_emoji(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def get_realm_emoji(self) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/realm-emoji for example usage.
|
||||
'''
|
||||
|
@ -879,8 +848,7 @@ class Client:
|
|||
method='GET'
|
||||
)
|
||||
|
||||
def upload_custom_emoji(self, emoji_name, file_obj):
|
||||
# type: (str, IO[Any]) -> Dict[str, Any]
|
||||
def upload_custom_emoji(self, emoji_name: str, file_obj: IO[Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -893,8 +861,7 @@ class Client:
|
|||
files=[file_obj]
|
||||
)
|
||||
|
||||
def get_realm_filters(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def get_realm_filters(self) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -906,8 +873,7 @@ class Client:
|
|||
method='GET',
|
||||
)
|
||||
|
||||
def add_realm_filter(self, pattern, url_format_string):
|
||||
# type: (str, str) -> Dict[str, Any]
|
||||
def add_realm_filter(self, pattern: str, url_format_string: str) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -923,8 +889,7 @@ class Client:
|
|||
},
|
||||
)
|
||||
|
||||
def remove_realm_filter(self, filter_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def remove_realm_filter(self, filter_id: int) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -936,8 +901,7 @@ class Client:
|
|||
method='DELETE',
|
||||
)
|
||||
|
||||
def get_server_settings(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def get_server_settings(self) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -949,8 +913,7 @@ class Client:
|
|||
method='GET',
|
||||
)
|
||||
|
||||
def get_events(self, **request):
|
||||
# type: (**Any) -> Dict[str, Any]
|
||||
def get_events(self, **request: Any) -> Dict[str, Any]:
|
||||
'''
|
||||
See the register() method for example usage.
|
||||
'''
|
||||
|
@ -961,8 +924,12 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def register(self, event_types=None, narrow=None, **kwargs):
|
||||
# type: (Optional[Iterable[str]], Optional[List[List[str]]], **Any) -> Dict[str, Any]
|
||||
def register(
|
||||
self,
|
||||
event_types: Optional[Iterable[str]] = None,
|
||||
narrow: Optional[List[List[str]]] = None,
|
||||
**kwargs: Any
|
||||
) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -986,8 +953,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def deregister(self, queue_id, timeout=None):
|
||||
# type: (str, Optional[float]) -> Dict[str, Any]
|
||||
def deregister(self, queue_id: str, timeout: Optional[float] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1005,8 +971,7 @@ class Client:
|
|||
timeout=timeout,
|
||||
)
|
||||
|
||||
def get_profile(self, request=None):
|
||||
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
|
||||
def get_profile(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1019,8 +984,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def get_user_presence(self, email):
|
||||
# type: (str) -> Dict[str, Any]
|
||||
def get_user_presence(self, email: str) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1032,8 +996,7 @@ class Client:
|
|||
method='GET',
|
||||
)
|
||||
|
||||
def get_realm_presence(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def get_realm_presence(self) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1045,8 +1008,7 @@ class Client:
|
|||
method='GET',
|
||||
)
|
||||
|
||||
def update_presence(self, request):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_presence(self, request: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1063,8 +1025,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def get_streams(self, **request):
|
||||
# type: (**Any) -> Dict[str, Any]
|
||||
def get_streams(self, **request: Any) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/get-public-streams for example usage.
|
||||
'''
|
||||
|
@ -1074,8 +1035,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def update_stream(self, stream_data):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_stream(self, stream_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/edit-stream for example usage.
|
||||
'''
|
||||
|
@ -1086,8 +1046,7 @@ class Client:
|
|||
request=stream_data,
|
||||
)
|
||||
|
||||
def delete_stream(self, stream_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def delete_stream(self, stream_id: int) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/delete-stream for example usage.
|
||||
'''
|
||||
|
@ -1096,8 +1055,7 @@ class Client:
|
|||
method='DELETE',
|
||||
)
|
||||
|
||||
def add_default_stream(self, stream_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def add_default_stream(self, stream_id: int) -> Dict[str, Any]:
|
||||
|
||||
'''
|
||||
Example usage:
|
||||
|
@ -1111,8 +1069,7 @@ class Client:
|
|||
request={'stream_id': stream_id},
|
||||
)
|
||||
|
||||
def get_user_by_id(self, user_id, **request):
|
||||
# type: (int, **Any) -> Dict[str, Any]
|
||||
def get_user_by_id(self, user_id: int, **request: Any) -> Dict[str, Any]:
|
||||
|
||||
'''
|
||||
Example usage:
|
||||
|
@ -1126,8 +1083,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def deactivate_user_by_id(self, user_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def deactivate_user_by_id(self, user_id: int) -> Dict[str, Any]:
|
||||
|
||||
'''
|
||||
Example usage:
|
||||
|
@ -1140,8 +1096,7 @@ class Client:
|
|||
method='DELETE',
|
||||
)
|
||||
|
||||
def reactivate_user_by_id(self, user_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def reactivate_user_by_id(self, user_id: int) -> Dict[str, Any]:
|
||||
|
||||
'''
|
||||
Example usage:
|
||||
|
@ -1154,8 +1109,7 @@ class Client:
|
|||
method='POST',
|
||||
)
|
||||
|
||||
def update_user_by_id(self, user_id, **request):
|
||||
# type: (int, **Any) -> Dict[str, Any]
|
||||
def update_user_by_id(self, user_id: int, **request: Any) -> Dict[str, Any]:
|
||||
|
||||
'''
|
||||
Example usage:
|
||||
|
@ -1173,8 +1127,7 @@ class Client:
|
|||
request=request
|
||||
)
|
||||
|
||||
def get_members(self, request=None):
|
||||
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
|
||||
def get_members(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/list-members for example usage.
|
||||
'''
|
||||
|
@ -1184,8 +1137,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def get_alert_words(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def get_alert_words(self) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/alert-words for example usage.
|
||||
'''
|
||||
|
@ -1194,8 +1146,7 @@ class Client:
|
|||
method='GET'
|
||||
)
|
||||
|
||||
def add_alert_words(self, alert_words):
|
||||
# type: (List[str]) -> Dict[str, Any]
|
||||
def add_alert_words(self, alert_words: List[str]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/alert-words for example usage.
|
||||
'''
|
||||
|
@ -1207,8 +1158,7 @@ class Client:
|
|||
}
|
||||
)
|
||||
|
||||
def remove_alert_words(self, alert_words):
|
||||
# type: (List[str]) -> Dict[str, Any]
|
||||
def remove_alert_words(self, alert_words: List[str]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/alert-words for example usage.
|
||||
'''
|
||||
|
@ -1220,8 +1170,7 @@ class Client:
|
|||
}
|
||||
)
|
||||
|
||||
def list_subscriptions(self, request=None):
|
||||
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
|
||||
def list_subscriptions(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/list-subscriptions for example usage.
|
||||
'''
|
||||
|
@ -1231,8 +1180,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def add_subscriptions(self, streams, **kwargs):
|
||||
# type: (Iterable[Dict[str, Any]], **Any) -> Dict[str, Any]
|
||||
def add_subscriptions(self, streams: Iterable[Dict[str, Any]], **kwargs: Any) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/subscribe for example usage.
|
||||
'''
|
||||
|
@ -1246,8 +1194,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def remove_subscriptions(self, streams, principals=None):
|
||||
# type: (Iterable[str], Optional[Iterable[str]]) -> Dict[str, Any]
|
||||
def remove_subscriptions(self, streams: Iterable[str], principals: Optional[Iterable[str]] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/unsubscribe for example usage.
|
||||
'''
|
||||
|
@ -1264,8 +1211,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def mute_topic(self, request):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def mute_topic(self, request: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/mute-topic for example usage.
|
||||
'''
|
||||
|
@ -1275,8 +1221,7 @@ class Client:
|
|||
request=request
|
||||
)
|
||||
|
||||
def update_subscription_settings(self, subscription_data):
|
||||
# type: (List[Dict[str, Any]]) -> Dict[str, Any]
|
||||
def update_subscription_settings(self, subscription_data: List[Dict[str, Any]]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1298,8 +1243,7 @@ class Client:
|
|||
request={'subscription_data': subscription_data}
|
||||
)
|
||||
|
||||
def update_notification_settings(self, notification_settings):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_notification_settings(self, notification_settings: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1315,8 +1259,7 @@ class Client:
|
|||
request=notification_settings,
|
||||
)
|
||||
|
||||
def get_stream_id(self, stream):
|
||||
# type: (str) -> Dict[str, Any]
|
||||
def get_stream_id(self, stream: str) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage: client.get_stream_id('devel')
|
||||
'''
|
||||
|
@ -1328,8 +1271,7 @@ class Client:
|
|||
request=None,
|
||||
)
|
||||
|
||||
def get_stream_topics(self, stream_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def get_stream_topics(self, stream_id: int) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/get-stream-topics for example usage.
|
||||
'''
|
||||
|
@ -1338,8 +1280,7 @@ class Client:
|
|||
method='GET'
|
||||
)
|
||||
|
||||
def get_user_groups(self):
|
||||
# type: () -> Dict[str, Any]
|
||||
def get_user_groups(self) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
>>> client.get_user_groups()
|
||||
|
@ -1350,8 +1291,7 @@ class Client:
|
|||
method='GET',
|
||||
)
|
||||
|
||||
def create_user_group(self, group_data):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def create_user_group(self, group_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
>>> client.create_user_group({
|
||||
|
@ -1367,8 +1307,7 @@ class Client:
|
|||
request=group_data,
|
||||
)
|
||||
|
||||
def update_user_group(self, group_data):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_user_group(self, group_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1385,8 +1324,7 @@ class Client:
|
|||
request=group_data,
|
||||
)
|
||||
|
||||
def remove_user_group(self, group_id):
|
||||
# type: (int) -> Dict[str, Any]
|
||||
def remove_user_group(self, group_id: int) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1398,8 +1336,7 @@ class Client:
|
|||
method='DELETE',
|
||||
)
|
||||
|
||||
def update_user_group_members(self, group_data):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_user_group_members(self, group_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1415,8 +1352,7 @@ class Client:
|
|||
request=group_data,
|
||||
)
|
||||
|
||||
def get_subscribers(self, **request):
|
||||
# type: (**Any) -> Dict[str, Any]
|
||||
def get_subscribers(self, **request: Any) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage: client.get_subscribers(stream='devel')
|
||||
'''
|
||||
|
@ -1432,8 +1368,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def render_message(self, request=None):
|
||||
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
|
||||
def render_message(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1446,8 +1381,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def create_user(self, request=None):
|
||||
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
|
||||
def create_user(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
See examples/create-user for example usage.
|
||||
'''
|
||||
|
@ -1457,8 +1391,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def update_storage(self, request):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def update_storage(self, request: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1472,8 +1405,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def get_storage(self, request=None):
|
||||
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
|
||||
def get_storage(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
|
@ -1489,8 +1421,7 @@ class Client:
|
|||
request=request,
|
||||
)
|
||||
|
||||
def set_typing_status(self, request):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
def set_typing_status(self, request: Dict[str, Any]) -> Dict[str, Any]:
|
||||
'''
|
||||
Example usage:
|
||||
>>> client.set_typing_status({
|
||||
|
@ -1510,21 +1441,18 @@ class ZulipStream:
|
|||
A Zulip stream-like object
|
||||
"""
|
||||
|
||||
def __init__(self, type, to, subject, **kwargs):
|
||||
# type: (str, str, str, **Any) -> None
|
||||
def __init__(self, type: str, to: str, subject: str, **kwargs: Any) -> None:
|
||||
self.client = Client(**kwargs)
|
||||
self.type = type
|
||||
self.to = to
|
||||
self.subject = subject
|
||||
|
||||
def write(self, content):
|
||||
# type: (str) -> None
|
||||
def write(self, content: str) -> None:
|
||||
message = {"type": self.type,
|
||||
"to": self.to,
|
||||
"subject": self.subject,
|
||||
"content": content}
|
||||
self.client.send_message(message)
|
||||
|
||||
def flush(self):
|
||||
# type: () -> None
|
||||
def flush(self) -> None:
|
||||
pass
|
||||
|
|
|
@ -4,8 +4,7 @@ import zulip
|
|||
|
||||
import argparse
|
||||
|
||||
def main():
|
||||
# type: () -> None
|
||||
def main() -> None:
|
||||
usage = """zulip-api-examples [script_name]
|
||||
|
||||
Prints the path to the Zulip API example scripts."""
|
||||
|
|
|
@ -14,8 +14,7 @@ Example: edit-stream --stream-id=3 --history-public-to-subscribers
|
|||
"""
|
||||
|
||||
|
||||
def quote(string):
|
||||
# type: (str) -> str
|
||||
def quote(string: str) -> str:
|
||||
return '"{}"'.format(string)
|
||||
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
def print_event(event):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
def print_event(event: Dict[str, Any]) -> None:
|
||||
print(event)
|
||||
|
||||
# This is a blocking call, and will continuously poll for new events
|
||||
|
|
|
@ -20,8 +20,7 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
def print_message(message):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
def print_message(message: Dict[str, Any]) -> None:
|
||||
print(message)
|
||||
|
||||
# This is a blocking call, and will continuously poll for new messages
|
||||
|
|
|
@ -51,17 +51,14 @@ streams_to_watch = ['new members']
|
|||
# These streams will cause anyone who sends a message there to be removed from the watchlist
|
||||
streams_to_cancel = ['development help']
|
||||
|
||||
def get_watchlist():
|
||||
# type: () -> List[Any]
|
||||
def get_watchlist() -> List[Any]:
|
||||
storage = client.get_storage()
|
||||
return list(storage['storage'].values())
|
||||
|
||||
def set_watchlist(watchlist):
|
||||
# type: (List[str]) -> None
|
||||
def set_watchlist(watchlist: List[str]) -> None:
|
||||
client.update_storage({'storage': dict(enumerate(watchlist))})
|
||||
|
||||
def handle_event(event):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
def handle_event(event: Dict[str, Any]) -> None:
|
||||
try:
|
||||
if event['type'] == 'realm_user' and event['op'] == 'add':
|
||||
watchlist = get_watchlist()
|
||||
|
@ -87,8 +84,7 @@ def handle_event(event):
|
|||
print(err)
|
||||
|
||||
|
||||
def start_event_handler():
|
||||
# type: () -> None
|
||||
def start_event_handler() -> None:
|
||||
print("Starting event handler...")
|
||||
client.call_on_each_event(handle_event, event_types=['realm_user', 'message'])
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ logging.basicConfig()
|
|||
|
||||
log = logging.getLogger('zulip-send')
|
||||
|
||||
def do_send_message(client, message_data):
|
||||
# type: (zulip.Client, Dict[str, Any]) -> bool
|
||||
def do_send_message(client: zulip.Client, message_data: Dict[str, Any]) -> bool:
|
||||
'''Sends a message and optionally prints status about the same.'''
|
||||
|
||||
if message_data['type'] == 'stream':
|
||||
|
@ -30,8 +29,7 @@ def do_send_message(client, message_data):
|
|||
log.error(response['msg'])
|
||||
return False
|
||||
|
||||
def main():
|
||||
# type: () -> int
|
||||
def main() -> int:
|
||||
usage = """zulip-send [options] [recipient...]
|
||||
|
||||
Sends a message to specified recipients.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue