Modernize legacy Python 2 syntax with pyupgrade.
Generated by `pyupgrade --py3-plus --keep-percent-format` followed by manual indentation fixes. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
543eb396b9
commit
e30b3b094b
107 changed files with 192 additions and 244 deletions
|
@ -155,7 +155,7 @@ for tries in range(10):
|
|||
if missing == 0:
|
||||
actually_subscribed = True
|
||||
break
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
if "SERVNAK received" in e: # type: ignore # https://github.com/python/mypy/issues/2118
|
||||
logger.error("SERVNAK repeatedly received, punting rest of test")
|
||||
else:
|
||||
|
@ -283,8 +283,8 @@ def process_keys(content_list):
|
|||
key_counts[key] = 0
|
||||
for key in content_keys:
|
||||
key_counts[key] += 1
|
||||
z_missing = set(key for key in zhkeys.keys() if key_counts[key] == 0)
|
||||
h_missing = set(key for key in hzkeys.keys() if key_counts[key] == 0)
|
||||
z_missing = {key for key in zhkeys.keys() if key_counts[key] == 0}
|
||||
h_missing = {key for key in hzkeys.keys() if key_counts[key] == 0}
|
||||
duplicates = any(val > 1 for val in key_counts.values())
|
||||
success = all(val == 1 for val in key_counts.values())
|
||||
return key_counts, z_missing, h_missing, duplicates, success
|
||||
|
|
|
@ -26,7 +26,7 @@ session_path = "/home/zulip/zephyr_sessions/%s" % (program_name,)
|
|||
# Preserve mail zephyrs forwarding setting across rewriting the config file
|
||||
|
||||
try:
|
||||
if "--forward-mail-zephyrs" in open(supervisor_path, "r").read():
|
||||
if "--forward-mail-zephyrs" in open(supervisor_path).read():
|
||||
template_data = template_data.replace("--use-sessions", "--use-sessions --forward-mail-zephyrs")
|
||||
except Exception:
|
||||
pass
|
||||
|
|
|
@ -20,7 +20,7 @@ import select
|
|||
|
||||
DEFAULT_SITE = "https://api.zulip.com"
|
||||
|
||||
class States(object):
|
||||
class States:
|
||||
Startup, ZulipToZephyr, ZephyrToZulip, ChildSending = list(range(4))
|
||||
CURRENT_STATE = States.Startup
|
||||
|
||||
|
@ -142,7 +142,7 @@ def zephyr_bulk_subscribe(subs):
|
|||
# type: (List[Tuple[str, str, str]]) -> None
|
||||
try:
|
||||
zephyr._z.subAll(subs)
|
||||
except IOError:
|
||||
except OSError:
|
||||
# Since we haven't added the subscription to
|
||||
# current_zephyr_subs yet, we can just return (so that we'll
|
||||
# continue processing normal messages) and we'll end up
|
||||
|
@ -153,7 +153,7 @@ def zephyr_bulk_subscribe(subs):
|
|||
return
|
||||
try:
|
||||
actual_zephyr_subs = [cls for (cls, _, _) in zephyr._z.getSubscriptions()]
|
||||
except IOError:
|
||||
except OSError:
|
||||
logger.exception("Error getting current Zephyr subscriptions")
|
||||
# Don't add anything to current_zephyr_subs so that we'll
|
||||
# retry the next time we check for streams to subscribe to
|
||||
|
@ -169,7 +169,7 @@ def zephyr_bulk_subscribe(subs):
|
|||
# missing 15 seconds of messages on the affected
|
||||
# classes
|
||||
zephyr._z.sub(cls, instance, recipient)
|
||||
except IOError:
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
current_zephyr_subs.add(cls)
|
||||
|
@ -177,7 +177,7 @@ def zephyr_bulk_subscribe(subs):
|
|||
def update_subscriptions():
|
||||
# type: () -> None
|
||||
try:
|
||||
f = open(options.stream_file_path, "r")
|
||||
f = open(options.stream_file_path)
|
||||
public_streams = json.loads(f.read())
|
||||
f.close()
|
||||
except Exception:
|
||||
|
@ -217,7 +217,7 @@ def maybe_restart_mirroring_script():
|
|||
maybe_kill_child()
|
||||
try:
|
||||
zephyr._z.cancelSubs()
|
||||
except IOError:
|
||||
except OSError:
|
||||
# We don't care whether we failed to cancel subs properly, but we should log it
|
||||
logger.exception("")
|
||||
while True:
|
||||
|
@ -288,14 +288,14 @@ def parse_crypt_table(zephyr_class, instance):
|
|||
# type: (Text, str) -> Optional[str]
|
||||
try:
|
||||
crypt_table = open(os.path.join(os.environ["HOME"], ".crypt-table"))
|
||||
except IOError:
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
for line in crypt_table.readlines():
|
||||
if line.strip() == "":
|
||||
# Ignore blank lines
|
||||
continue
|
||||
match = re.match("^crypt-(?P<class>\S+):\s+((?P<algorithm>(AES|DES)):\s+)?(?P<keypath>\S+)$", line)
|
||||
match = re.match(r"^crypt-(?P<class>\S+):\s+((?P<algorithm>(AES|DES)):\s+)?(?P<keypath>\S+)$", line)
|
||||
if match is None:
|
||||
# Malformed crypt_table line
|
||||
logger.debug("Invalid crypt_table line!")
|
||||
|
@ -464,7 +464,7 @@ def zephyr_init_autoretry():
|
|||
zephyr.init()
|
||||
backoff.succeed()
|
||||
return
|
||||
except IOError:
|
||||
except OSError:
|
||||
logger.exception("Error initializing Zephyr library (retrying). Traceback:")
|
||||
backoff.fail()
|
||||
|
||||
|
@ -475,12 +475,12 @@ def zephyr_load_session_autoretry(session_path):
|
|||
backoff = zulip.RandomExponentialBackoff()
|
||||
while backoff.keep_going():
|
||||
try:
|
||||
session = open(session_path, "r").read()
|
||||
session = open(session_path).read()
|
||||
zephyr._z.initialize()
|
||||
zephyr._z.load_session(session)
|
||||
zephyr.__inited = True
|
||||
return
|
||||
except IOError:
|
||||
except OSError:
|
||||
logger.exception("Error loading saved Zephyr session (retrying). Traceback:")
|
||||
backoff.fail()
|
||||
|
||||
|
@ -494,7 +494,7 @@ def zephyr_subscribe_autoretry(sub):
|
|||
zephyr.Subscriptions().add(sub)
|
||||
backoff.succeed()
|
||||
return
|
||||
except IOError:
|
||||
except OSError:
|
||||
# Probably a SERVNAK from the zephyr server, but log the
|
||||
# traceback just in case it's something else
|
||||
logger.exception("Error subscribing to personals (retrying). Traceback:")
|
||||
|
@ -522,7 +522,7 @@ def zephyr_to_zulip(options):
|
|||
open(options.session_path, "w").write(zephyr._z.dump_session())
|
||||
|
||||
if options.logs_to_resend is not None:
|
||||
with open(options.logs_to_resend, 'r') as log:
|
||||
with open(options.logs_to_resend) as log:
|
||||
for ln in log:
|
||||
try:
|
||||
zeph = json.loads(ln)
|
||||
|
@ -884,7 +884,7 @@ def parse_zephyr_subs(verbose=False):
|
|||
logger.error("Couldn't find ~/.zephyr.subs!")
|
||||
return zephyr_subscriptions
|
||||
|
||||
for line in open(subs_file, "r").readlines():
|
||||
for line in open(subs_file).readlines():
|
||||
line = line.strip()
|
||||
if len(line) == 0:
|
||||
continue
|
||||
|
@ -1039,7 +1039,7 @@ def die_gracefully(signal, frame):
|
|||
try:
|
||||
# zephyr=>zulip processes may have added subs, so run cancelSubs
|
||||
zephyr._z.cancelSubs()
|
||||
except IOError:
|
||||
except OSError:
|
||||
# We don't care whether we failed to cancel subs properly, but we should log it
|
||||
logger.exception("")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue