ruff: Fix SIM108 Use ternary operator instead of if
-else
-block.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
2aa36f90fb
commit
b009dcd7d3
9 changed files with 30 additions and 77 deletions
10
tools/deploy
10
tools/deploy
|
@ -181,10 +181,7 @@ def prepare(options: argparse.Namespace) -> None:
|
||||||
def log(options: argparse.Namespace) -> None:
|
def log(options: argparse.Namespace) -> None:
|
||||||
check_common_options(options)
|
check_common_options(options)
|
||||||
headers = {"key": options.token}
|
headers = {"key": options.token}
|
||||||
if options.lines:
|
lines = options.lines
|
||||||
lines = options.lines
|
|
||||||
else:
|
|
||||||
lines = None
|
|
||||||
payload = {"name": options.botname, "lines": lines}
|
payload = {"name": options.botname, "lines": lines}
|
||||||
url = urllib.parse.urljoin(options.server, "bots/logs/" + options.botname)
|
url = urllib.parse.urljoin(options.server, "bots/logs/" + options.botname)
|
||||||
response = requests.get(url, json=payload, headers=headers)
|
response = requests.get(url, json=payload, headers=headers)
|
||||||
|
@ -209,10 +206,7 @@ def delete(options: argparse.Namespace) -> None:
|
||||||
def list_bots(options: argparse.Namespace) -> None:
|
def list_bots(options: argparse.Namespace) -> None:
|
||||||
check_common_options(options)
|
check_common_options(options)
|
||||||
headers = {"key": options.token}
|
headers = {"key": options.token}
|
||||||
if options.format:
|
pretty_print = options.format
|
||||||
pretty_print = True
|
|
||||||
else:
|
|
||||||
pretty_print = False
|
|
||||||
url = urllib.parse.urljoin(options.server, "bots/list")
|
url = urllib.parse.urljoin(options.server, "bots/list")
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
result = handle_common_response(
|
result = handle_common_response(
|
||||||
|
|
|
@ -77,13 +77,10 @@ the Python version this command is executed with."""
|
||||||
else:
|
else:
|
||||||
print("Virtualenv already exists.")
|
print("Virtualenv already exists.")
|
||||||
|
|
||||||
if os.path.isdir(os.path.join(venv_dir, "Scripts")):
|
# POSIX compatibility layer and Linux environment emulation for Windows
|
||||||
# POSIX compatibility layer and Linux environment emulation for Windows
|
# venv uses /Scripts instead of /bin on Windows cmd and Power Shell.
|
||||||
# venv uses /Scripts instead of /bin on Windows cmd and Power Shell.
|
# Read https://docs.python.org/3/library/venv.html
|
||||||
# Read https://docs.python.org/3/library/venv.html
|
venv_exec_dir = "Scripts" if os.path.isdir(os.path.join(venv_dir, "Scripts")) else "bin"
|
||||||
venv_exec_dir = "Scripts"
|
|
||||||
else:
|
|
||||||
venv_exec_dir = "bin"
|
|
||||||
|
|
||||||
# On OS X, ensure we use the virtualenv version of the python binary for
|
# On OS X, ensure we use the virtualenv version of the python binary for
|
||||||
# future subprocesses instead of the version that this script was launched with. See
|
# future subprocesses instead of the version that this script was launched with. See
|
||||||
|
|
|
@ -452,10 +452,7 @@ option does not affect login credentials.""".replace("\n", " "),
|
||||||
zulipToJabber.set_jabber_client(xmpp)
|
zulipToJabber.set_jabber_client(xmpp)
|
||||||
|
|
||||||
xmpp.process(block=False)
|
xmpp.process(block=False)
|
||||||
if options.mode == "public":
|
event_types = ["stream"] if options.mode == "public" else ["message", "subscription"]
|
||||||
event_types = ["stream"]
|
|
||||||
else:
|
|
||||||
event_types = ["message", "subscription"]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.info("Connecting to Zulip.")
|
logging.info("Connecting to Zulip.")
|
||||||
|
|
|
@ -31,11 +31,8 @@ P4_WEB: Optional[str] = None
|
||||||
# * subject "change_root"
|
# * subject "change_root"
|
||||||
def commit_notice_destination(path: str, changelist: int) -> Optional[Dict[str, str]]:
|
def commit_notice_destination(path: str, changelist: int) -> Optional[Dict[str, str]]:
|
||||||
dirs = path.split("/")
|
dirs = path.split("/")
|
||||||
if len(dirs) >= 4 and dirs[3] not in ("*", "..."):
|
# If no subdirectory, just use "depot"
|
||||||
directory = dirs[3]
|
directory = dirs[3] if len(dirs) >= 4 and dirs[3] not in ("*", "...") else dirs[2]
|
||||||
else:
|
|
||||||
# No subdirectory, so just use "depot"
|
|
||||||
directory = dirs[2]
|
|
||||||
|
|
||||||
if directory not in ["evil-master-plan", "my-super-secret-repository"]:
|
if directory not in ["evil-master-plan", "my-super-secret-repository"]:
|
||||||
return dict(stream=f"{directory}-commits", subject=path)
|
return dict(stream=f"{directory}-commits", subject=path)
|
||||||
|
|
|
@ -181,15 +181,9 @@ elif opts.twitter_name:
|
||||||
else:
|
else:
|
||||||
statuses = api.GetUserTimeline(screen_name=opts.twitter_name, since_id=since_id)
|
statuses = api.GetUserTimeline(screen_name=opts.twitter_name, since_id=since_id)
|
||||||
|
|
||||||
if opts.excluded_terms:
|
excluded_terms = opts.excluded_terms.split(",") if opts.excluded_terms else []
|
||||||
excluded_terms = opts.excluded_terms.split(",")
|
|
||||||
else:
|
|
||||||
excluded_terms = []
|
|
||||||
|
|
||||||
if opts.excluded_users:
|
excluded_users = opts.excluded_users.split(",") if opts.excluded_users else []
|
||||||
excluded_users = opts.excluded_users.split(",")
|
|
||||||
else:
|
|
||||||
excluded_users = []
|
|
||||||
|
|
||||||
for status in statuses[::-1][: opts.limit_tweets]:
|
for status in statuses[::-1][: opts.limit_tweets]:
|
||||||
# Check if the tweet is from an excluded user
|
# Check if the tweet is from an excluded user
|
||||||
|
|
|
@ -36,9 +36,6 @@ assert sys.version_info >= (3, 6)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# In newer versions, the 'json' attribute is a function, not a property
|
|
||||||
requests_json_is_function = callable(requests.Response.json)
|
|
||||||
|
|
||||||
API_VERSTRING = "v1/"
|
API_VERSTRING = "v1/"
|
||||||
|
|
||||||
# An optional parameter to `move_topic` and `update_message` actions
|
# An optional parameter to `move_topic` and `update_message` actions
|
||||||
|
@ -571,14 +568,11 @@ class Client:
|
||||||
if files is None:
|
if files is None:
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
if longpolling:
|
# When long-polling, set timeout to 90 sec as a balance
|
||||||
# When long-polling, set timeout to 90 sec as a balance
|
# between a low traffic rate and a still reasonable latency
|
||||||
# between a low traffic rate and a still reasonable latency
|
# time in case of a connection failure.
|
||||||
# time in case of a connection failure.
|
# Otherwise, 15s should be plenty of time.
|
||||||
request_timeout = 90.0
|
request_timeout = 90.0 if longpolling else timeout or 15.0
|
||||||
else:
|
|
||||||
# Otherwise, 15s should be plenty of time.
|
|
||||||
request_timeout = 15.0 if not timeout else timeout
|
|
||||||
|
|
||||||
request = {}
|
request = {}
|
||||||
req_files = []
|
req_files = []
|
||||||
|
@ -630,10 +624,7 @@ class Client:
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if method == "GET":
|
kwarg = "params" if method == "GET" else "data"
|
||||||
kwarg = "params"
|
|
||||||
else:
|
|
||||||
kwarg = "data"
|
|
||||||
|
|
||||||
kwargs = {kwarg: query_state["request"]}
|
kwargs = {kwarg: query_state["request"]}
|
||||||
|
|
||||||
|
@ -689,22 +680,17 @@ class Client:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if requests_json_is_function:
|
json_result = res.json()
|
||||||
json_result = res.json()
|
|
||||||
else:
|
|
||||||
json_result = res.json
|
|
||||||
except Exception:
|
except Exception:
|
||||||
json_result = None
|
end_error_retry(False)
|
||||||
|
return {
|
||||||
|
"msg": "Unexpected error from the server",
|
||||||
|
"result": "http-error",
|
||||||
|
"status_code": res.status_code,
|
||||||
|
}
|
||||||
|
|
||||||
if json_result is not None:
|
end_error_retry(True)
|
||||||
end_error_retry(True)
|
return json_result
|
||||||
return json_result
|
|
||||||
end_error_retry(False)
|
|
||||||
return {
|
|
||||||
"msg": "Unexpected error from the server",
|
|
||||||
"result": "http-error",
|
|
||||||
"status_code": res.status_code,
|
|
||||||
}
|
|
||||||
|
|
||||||
def call_endpoint(
|
def call_endpoint(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -113,10 +113,7 @@ def syntax_help(cmd_name: str) -> str:
|
||||||
commands = get_commands()
|
commands = get_commands()
|
||||||
f, arg_names = commands[cmd_name]
|
f, arg_names = commands[cmd_name]
|
||||||
arg_syntax = " ".join("<" + a + ">" for a in arg_names)
|
arg_syntax = " ".join("<" + a + ">" for a in arg_names)
|
||||||
if arg_syntax:
|
cmd = cmd_name + " " + arg_syntax if arg_syntax else cmd_name
|
||||||
cmd = cmd_name + " " + arg_syntax
|
|
||||||
else:
|
|
||||||
cmd = cmd_name
|
|
||||||
return f"syntax: {cmd}"
|
return f"syntax: {cmd}"
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,10 +204,7 @@ def dbx_read(client: Any, fn: str) -> str:
|
||||||
|
|
||||||
|
|
||||||
def dbx_search(client: Any, query: str, folder: str, max_results: str) -> str:
|
def dbx_search(client: Any, query: str, folder: str, max_results: str) -> str:
|
||||||
if folder is None:
|
folder = "" if folder is None else "/" + folder
|
||||||
folder = ""
|
|
||||||
else:
|
|
||||||
folder = "/" + folder
|
|
||||||
if max_results is None:
|
if max_results is None:
|
||||||
max_results = "20"
|
max_results = "20"
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -303,10 +303,7 @@ def display_game(topic_name, merels_storage):
|
||||||
|
|
||||||
response = ""
|
response = ""
|
||||||
|
|
||||||
if data.take_mode == 1:
|
take = "Yes" if data.take_mode == 1 else "No"
|
||||||
take = "Yes"
|
|
||||||
else:
|
|
||||||
take = "No"
|
|
||||||
|
|
||||||
response += interface.graph_grid(data.grid()) + "\n"
|
response += interface.graph_grid(data.grid()) + "\n"
|
||||||
response += f"""Phase {data.get_phase()}. Take mode: {take}.
|
response += f"""Phase {data.get_phase()}. Take mode: {take}.
|
||||||
|
|
|
@ -166,10 +166,7 @@ def syntax_help(cmd_name: str) -> str:
|
||||||
commands = get_commands()
|
commands = get_commands()
|
||||||
f, arg_names = commands[cmd_name]
|
f, arg_names = commands[cmd_name]
|
||||||
arg_syntax = " ".join("<" + a + ">" for a in arg_names)
|
arg_syntax = " ".join("<" + a + ">" for a in arg_names)
|
||||||
if arg_syntax:
|
cmd = cmd_name + " " + arg_syntax if arg_syntax else cmd_name
|
||||||
cmd = cmd_name + " " + arg_syntax
|
|
||||||
else:
|
|
||||||
cmd = cmd_name
|
|
||||||
return f"syntax: {cmd}"
|
return f"syntax: {cmd}"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue