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
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
@ -42,7 +41,7 @@ def create_pipe_event(to_client: zulip.Client, from_bot: Dict[str, Any],
|
|||
"type": "stream",
|
||||
"to": to_bot["stream"],
|
||||
"subject": subject,
|
||||
"content": "**{0}**: {1}".format(msg["sender_full_name"], msg["content"]),
|
||||
"content": "**{}**: {}".format(msg["sender_full_name"], msg["content"]),
|
||||
"has_attachment": msg.get("has_attachment", False),
|
||||
"has_image": msg.get("has_image", False),
|
||||
"has_link": msg.get("has_link", False)
|
||||
|
|
|
@ -116,7 +116,7 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
|||
"to": self.stream,
|
||||
"subject": self.topic,
|
||||
"content": content,
|
||||
"content": "**{0}**: {1}".format(sender, content),
|
||||
"content": "**{}**: {}".format(sender, content),
|
||||
}))
|
||||
|
||||
def on_dccmsg(self, c, e):
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Change these values to configure authentication for your codebase account
|
||||
# Note that this is the Codebase API Username, found in the Settings page
|
||||
# for your account
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Zulip mirror of Codebase HQ activity
|
||||
# The "zulip_codebase_mirror" script is run continuously, possibly on a work
|
||||
|
@ -256,7 +255,7 @@ def run_mirror():
|
|||
since = default_since()
|
||||
else:
|
||||
since = datetime.fromtimestamp(float(timestamp), tz=pytz.utc)
|
||||
except (ValueError, IOError) as e:
|
||||
except (ValueError, OSError) as e:
|
||||
logging.warn("Could not open resume file: %s" % (str(e)))
|
||||
since = default_since()
|
||||
|
||||
|
@ -289,13 +288,13 @@ def check_permissions():
|
|||
if config.LOG_FILE:
|
||||
try:
|
||||
open(config.LOG_FILE, "w")
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
sys.stderr.write("Could not open up log for writing:")
|
||||
sys.stderr.write(str(e))
|
||||
# check that the resume file can be written (this creates if it doesn't exist)
|
||||
try:
|
||||
open(config.RESUME_FILE, "a+")
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
sys.stderr.write("Could not open up the file %s for reading and writing" % (config.RESUME_FILE,))
|
||||
sys.stderr.write(str(e))
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Zulip notification post-receive hook.
|
||||
#
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from typing import Dict, Text, Optional
|
||||
|
||||
|
@ -28,7 +27,7 @@ def commit_notice_destination(repo, branch, commit):
|
|||
# type: (Text, Text, Text) -> Optional[Dict[Text, Text]]
|
||||
if branch in ["master", "test-post-receive"]:
|
||||
return dict(stream = STREAM_NAME,
|
||||
subject = u"%s" % (branch,))
|
||||
subject = "%s" % (branch,))
|
||||
|
||||
# Return None for cases where you don't want a notice sent
|
||||
return None
|
||||
|
|
|
@ -100,7 +100,7 @@ def get_credentials():
|
|||
return credentials
|
||||
except client.Error:
|
||||
logging.exception('Error while trying to open the `google-credentials.json` file.')
|
||||
except IOError:
|
||||
except OSError:
|
||||
logging.error("Run the get-google-credentials script from this directory first.")
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Zulip hook for Mercurial changeset pushes.
|
||||
#
|
||||
|
@ -35,7 +34,7 @@ def format_summary_line(web_url, user, base, tip, branch, node):
|
|||
formatted_commit_count = "{revcount} commit{s}".format(
|
||||
revcount=revcount, s=plural)
|
||||
|
||||
return u"**{user}** pushed {commits} to **{branch}** (`{tip}:{node}`):\n\n".format(
|
||||
return "**{user}** pushed {commits} to **{branch}** (`{tip}:{node}`):\n\n".format(
|
||||
user=user, commits=formatted_commit_count, branch=branch, tip=tip,
|
||||
node=node[:12])
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ class JabberToZulipBot(ClientXMPP):
|
|||
|
||||
def private(self, msg):
|
||||
# type: (JabberMessage) -> None
|
||||
if options.mode == 'public' or msg['thread'] == u'\u1FFFE':
|
||||
if options.mode == 'public' or msg['thread'] == '\u1FFFE':
|
||||
return
|
||||
sender = jid_to_zulip(msg["from"])
|
||||
recipient = jid_to_zulip(msg["to"])
|
||||
|
@ -178,7 +178,7 @@ class JabberToZulipBot(ClientXMPP):
|
|||
|
||||
def group(self, msg):
|
||||
# type: (JabberMessage) -> None
|
||||
if options.mode == 'personal' or msg["thread"] == u'\u1FFFE':
|
||||
if options.mode == 'personal' or msg["thread"] == '\u1FFFE':
|
||||
return
|
||||
|
||||
subject = msg["subject"]
|
||||
|
@ -212,7 +212,7 @@ class JabberToZulipBot(ClientXMPP):
|
|||
else:
|
||||
return jid
|
||||
|
||||
class ZulipToJabberBot(object):
|
||||
class ZulipToJabberBot:
|
||||
def __init__(self, zulip_client):
|
||||
# type: (Client) -> None
|
||||
self.client = zulip_client
|
||||
|
@ -254,7 +254,7 @@ class ZulipToJabberBot(object):
|
|||
mto = jabber_recipient,
|
||||
mbody = msg['content'],
|
||||
mtype = 'groupchat')
|
||||
outgoing['thread'] = u'\u1FFFE'
|
||||
outgoing['thread'] = '\u1FFFE'
|
||||
outgoing.send()
|
||||
|
||||
def private_message(self, msg):
|
||||
|
@ -271,7 +271,7 @@ class ZulipToJabberBot(object):
|
|||
mto = jabber_recipient,
|
||||
mbody = msg['content'],
|
||||
mtype = 'chat')
|
||||
outgoing['thread'] = u'\u1FFFE'
|
||||
outgoing['thread'] = '\u1FFFE'
|
||||
outgoing.send()
|
||||
|
||||
def process_subscription(self, event):
|
||||
|
@ -415,9 +415,9 @@ option does not affect login credentials.'''.replace("\n", " "))
|
|||
|
||||
config = SafeConfigParser()
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
with open(config_file) as f:
|
||||
config.readfp(f, config_file)
|
||||
except IOError:
|
||||
except OSError:
|
||||
pass
|
||||
for option in ("jid", "jabber_password", "conference_domain", "mode", "zulip_email_suffix",
|
||||
"jabber_server_address", "jabber_server_port"):
|
||||
|
|
|
@ -112,8 +112,8 @@ if __name__ == "__main__":
|
|||
open(lock_path, "w").write("1")
|
||||
zulip_client = zulip.init_from_options(args)
|
||||
try:
|
||||
log_files = json.loads(open(args.control_path, "r").read())
|
||||
except (json.JSONDecodeError, IOError): # type: ignore # error: Cannot determine type of 'IOError'
|
||||
log_files = json.loads(open(args.control_path).read())
|
||||
except (json.JSONDecodeError, OSError): # type: ignore # error: Cannot determine type of 'IOError'
|
||||
print("Could not load control data from %s" % (args.control_path,))
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Zulip notification post-receive hook.
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# https://github.com/python/mypy/issues/1141
|
||||
from typing import Dict, Text, Optional
|
||||
|
||||
|
@ -25,7 +23,7 @@ def deployment_notice_destination(branch):
|
|||
# type: (str) -> Optional[Dict[str, Text]]
|
||||
if branch in ['master', 'test-post-receive']:
|
||||
return dict(stream = 'deployments',
|
||||
subject = u'%s' % (branch,))
|
||||
subject = '%s' % (branch,))
|
||||
|
||||
# Return None for cases where you don't want a notice sent
|
||||
return None
|
||||
|
|
|
@ -339,7 +339,7 @@ def setP4ExecBit(file, mode):
|
|||
if not isModeExec(mode):
|
||||
p4Type = getP4OpenedType(file)
|
||||
p4Type = re.sub('^([cku]?)x(.*)', '\\1\\2', p4Type)
|
||||
p4Type = re.sub('(.*?\+.*?)x(.*?)', '\\1\\2', p4Type)
|
||||
p4Type = re.sub(r'(.*?\+.*?)x(.*?)', '\\1\\2', p4Type)
|
||||
if p4Type[-1] == "+":
|
||||
p4Type = p4Type[0:-1]
|
||||
|
||||
|
@ -349,7 +349,7 @@ def getP4OpenedType(file):
|
|||
# Returns the perforce file type for the given file.
|
||||
|
||||
result = p4_read_pipe(["opened", wildcard_encode(file)])
|
||||
match = re.match(".*\((.+)\)\r?$", result)
|
||||
match = re.match(".*\\((.+)\\)\r?$", result)
|
||||
if match:
|
||||
return match.group(1)
|
||||
else:
|
||||
|
@ -378,7 +378,7 @@ def getGitTags():
|
|||
def diffTreePattern():
|
||||
# This is a simple generator for the diff tree regex pattern. This could be
|
||||
# a class variable if this and parseDiffTreeEntry were a part of a class.
|
||||
pattern = re.compile(':(\d+) (\d+) (\w+) (\w+) ([A-Z])(\d+)?\t(.*?)((\t(.*))|$)')
|
||||
pattern = re.compile(':(\\d+) (\\d+) (\\w+) (\\w+) ([A-Z])(\\d+)?\t(.*?)((\t(.*))|$)')
|
||||
while True:
|
||||
yield pattern
|
||||
|
||||
|
@ -820,13 +820,13 @@ def wildcard_present(path):
|
|||
m = re.search("[*#@%]", path)
|
||||
return m is not None
|
||||
|
||||
class Command(object):
|
||||
class Command:
|
||||
def __init__(self):
|
||||
self.usage = "usage: %prog [options]"
|
||||
self.needsGit = True
|
||||
self.verbose = False
|
||||
|
||||
class P4UserMap(object):
|
||||
class P4UserMap:
|
||||
def __init__(self):
|
||||
self.userMapFromPerforceServer = False
|
||||
self.myP4UserId = None
|
||||
|
@ -883,7 +883,7 @@ class P4UserMap(object):
|
|||
for line in lines:
|
||||
entry = line.strip().split("\t")
|
||||
self.users[entry[0]] = entry[1]
|
||||
except IOError:
|
||||
except OSError:
|
||||
self.getUserMapFromPerforceServer()
|
||||
|
||||
class P4Debug(Command):
|
||||
|
@ -1056,7 +1056,7 @@ class P4Submit(Command, P4UserMap):
|
|||
(handle, outFileName) = tempfile.mkstemp(dir='.')
|
||||
try:
|
||||
outFile = os.fdopen(handle, "w+")
|
||||
inFile = open(file, "r")
|
||||
inFile = open(file)
|
||||
regexp = re.compile(pattern, re.VERBOSE)
|
||||
for line in inFile.readlines():
|
||||
line = regexp.sub(r'$\1$', line)
|
||||
|
@ -1391,7 +1391,7 @@ class P4Submit(Command, P4UserMap):
|
|||
newdiff += "==== new file ====\n"
|
||||
newdiff += "--- /dev/null\n"
|
||||
newdiff += "+++ %s\n" % newFile
|
||||
f = open(newFile, "r")
|
||||
f = open(newFile)
|
||||
for line in f.readlines():
|
||||
newdiff += "+" + line
|
||||
f.close()
|
||||
|
@ -1773,7 +1773,7 @@ class P4Submit(Command, P4UserMap):
|
|||
|
||||
return True
|
||||
|
||||
class View(object):
|
||||
class View:
|
||||
"""Represent a p4 view ("p4 help views"), and map files in a
|
||||
repo according to the view."""
|
||||
|
||||
|
@ -2377,7 +2377,7 @@ class P4Sync(Command, P4UserMap):
|
|||
# find the corresponding git commit; take the oldest commit
|
||||
changelist = int(change['change'])
|
||||
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
|
||||
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist])
|
||||
"--reverse", r":/\[git-p4:.*change = %d\]" % changelist])
|
||||
if len(gitCommit) == 0:
|
||||
print("could not find git commit for changelist %d" % changelist)
|
||||
else:
|
||||
|
@ -2657,7 +2657,7 @@ class P4Sync(Command, P4UserMap):
|
|||
self.initialParent)
|
||||
# only needed once, to connect to the previous commit
|
||||
self.initialParent = ""
|
||||
except IOError:
|
||||
except OSError:
|
||||
print(self.gitError.read())
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -2712,7 +2712,7 @@ class P4Sync(Command, P4UserMap):
|
|||
self.updateOptionDict(details)
|
||||
try:
|
||||
self.commit(details, self.extractFilesFromCommit(details), self.branch)
|
||||
except IOError:
|
||||
except OSError:
|
||||
print("IO error with git fast-import. Is your git version recent enough?")
|
||||
print(self.gitError.read())
|
||||
|
||||
|
@ -2878,7 +2878,7 @@ class P4Sync(Command, P4UserMap):
|
|||
if len(self.changesFile) == 0:
|
||||
revision = "#head"
|
||||
|
||||
p = re.sub ("\.\.\.$", "", p)
|
||||
p = re.sub (r"\.\.\.$", "", p)
|
||||
if not p.endswith("/"):
|
||||
p += "/"
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
'''Zulip notification change-commit hook.
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Dict, Optional, Text
|
||||
|
||||
# Change these values to configure authentication for the plugin
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# RSS integration for Zulip
|
||||
#
|
||||
|
@ -174,9 +173,9 @@ def send_zulip(entry, feed_name):
|
|||
return client.send_message(message)
|
||||
|
||||
try:
|
||||
with open(opts.feed_file, "r") as f:
|
||||
with open(opts.feed_file) as f:
|
||||
feed_urls = [feed.strip() for feed in f.readlines()] # type: List[str]
|
||||
except IOError:
|
||||
except OSError:
|
||||
log_error_and_exit("Unable to read feed file at %s." % (opts.feed_file,))
|
||||
|
||||
client = zulip.Client(email=opts.zulip_email, api_key=opts.zulip_api_key,
|
||||
|
@ -189,9 +188,9 @@ for feed_url in feed_urls:
|
|||
feed_file = os.path.join(opts.data_dir, urllib.parse.urlparse(feed_url).netloc) # Type: str
|
||||
|
||||
try:
|
||||
with open(feed_file, "r") as f:
|
||||
old_feed_hashes = dict((line.strip(), True) for line in f.readlines()) # type: Dict[str, bool]
|
||||
except IOError:
|
||||
with open(feed_file) as f:
|
||||
old_feed_hashes = {line.strip(): True for line in f.readlines()} # type: Dict[str, bool]
|
||||
except OSError:
|
||||
old_feed_hashes = {}
|
||||
|
||||
new_hashes = [] # type: List[str]
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Zulip notification post-commit hook.
|
||||
#
|
||||
|
@ -39,7 +38,7 @@ path, rev = sys.argv[1:] # type: Tuple[Text, Text]
|
|||
path = "file://" + path
|
||||
|
||||
entry = svn.log(path, revision_end=pysvn.Revision(pysvn.opt_revision_kind.number, rev))[0] # type: Dict[Text, Any]
|
||||
message = "**{0}** committed revision r{1} to `{2}`.\n\n> {3}".format(
|
||||
message = "**{}** committed revision r{} to `{}`.\n\n> {}".format(
|
||||
entry['author'],
|
||||
rev,
|
||||
path.split('/')[-1],
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Dict, Optional, Text
|
||||
|
||||
# Change these values to configure authentication for the plugin
|
||||
|
@ -25,7 +23,7 @@ def commit_notice_destination(path, commit):
|
|||
repo = path.split('/')[-1]
|
||||
if repo not in ["evil-master-plan", "my-super-secret-repository"]:
|
||||
return dict(stream = "commits",
|
||||
subject = u"%s" % (repo,))
|
||||
subject = "%s" % (repo,))
|
||||
|
||||
# Return None for cases where you don't want a notice sent
|
||||
return None
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Zulip trac plugin -- sends zulips when tickets change.
|
||||
#
|
||||
# Install by copying this file and zulip_trac_config.py to the trac
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# See zulip_trac.py for installation and configuration instructions
|
||||
|
||||
# Change these constants to configure the plugin:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# An easy Trello integration for Zulip.
|
||||
|
||||
|
@ -39,7 +38,7 @@ def get_model_id(options):
|
|||
params=params
|
||||
)
|
||||
|
||||
if trello_response.status_code is not 200:
|
||||
if trello_response.status_code != 200:
|
||||
print('Error: Can\'t get the idModel. Please check the configuration')
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -77,7 +76,7 @@ def get_webhook_id(options, id_model):
|
|||
data=data
|
||||
)
|
||||
|
||||
if trello_response.status_code is not 200:
|
||||
if trello_response.status_code != 200:
|
||||
print('Error: Can\'t create the Webhook:', trello_response.text)
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Twitter integration for Zulip
|
||||
|
||||
|
|
|
@ -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("")
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
if False:
|
||||
from typing import Any, Dict, Generator, List, Tuple
|
||||
|
@ -9,7 +8,7 @@ import sys
|
|||
|
||||
import itertools
|
||||
|
||||
with open("README.md", "r") as fh:
|
||||
with open("README.md") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
def version():
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
|
@ -34,7 +32,7 @@ requests_json_is_function = callable(requests.Response.json)
|
|||
|
||||
API_VERSTRING = "v1/"
|
||||
|
||||
class CountingBackoff(object):
|
||||
class CountingBackoff:
|
||||
def __init__(self, maximum_retries=10, timeout_success_equivalent=None, delay_cap=90.0):
|
||||
# type: (int, Optional[float], float) -> None
|
||||
self.number_of_retries = 0
|
||||
|
@ -70,7 +68,7 @@ class CountingBackoff(object):
|
|||
class RandomExponentialBackoff(CountingBackoff):
|
||||
def fail(self):
|
||||
# type: () -> None
|
||||
super(RandomExponentialBackoff, self).fail()
|
||||
super().fail()
|
||||
# Exponential growth with ratio sqrt(2); compute random delay
|
||||
# between x and 2x where x is growing exponentially
|
||||
delay_scale = int(2 ** (self.number_of_retries / 2.0 - 1)) + 1
|
||||
|
@ -278,7 +276,7 @@ class MissingURLError(ZulipError):
|
|||
class UnrecoverableNetworkError(ZulipError):
|
||||
pass
|
||||
|
||||
class Client(object):
|
||||
class Client:
|
||||
def __init__(self, email=None, api_key=None, config_file=None,
|
||||
verbose=False, retry_on_errors=True,
|
||||
site=None, client=None,
|
||||
|
@ -324,7 +322,7 @@ class Client(object):
|
|||
|
||||
if config_file is not None and os.path.exists(config_file):
|
||||
config = SafeConfigParser()
|
||||
with open(config_file, 'r') as f:
|
||||
with open(config_file) as f:
|
||||
config.readfp(f, config_file)
|
||||
if api_key is None:
|
||||
api_key = config.get("api", "key")
|
||||
|
@ -438,7 +436,7 @@ class Client(object):
|
|||
try:
|
||||
vendor = platform.system()
|
||||
vendor_version = platform.release()
|
||||
except IOError:
|
||||
except OSError:
|
||||
# If the calling process is handling SIGCHLD, platform.system() can
|
||||
# fail with an IOError. See http://bugs.python.org/issue9127
|
||||
pass
|
||||
|
@ -1475,7 +1473,7 @@ class Client(object):
|
|||
request=request
|
||||
)
|
||||
|
||||
class ZulipStream(object):
|
||||
class ZulipStream:
|
||||
"""
|
||||
A Zulip stream-like object
|
||||
"""
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# zulip-send -- Sends a message to the specified recipients.
|
||||
|
||||
import sys
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue