cleanup: Move line breaks before binary operators.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
6f40bcf745
commit
17cf26aa1f
12 changed files with 152 additions and 77 deletions
|
@ -75,8 +75,10 @@ def matrix_to_zulip(
|
|||
zulip_bot_user = ('@%s:matrix.org' % matrix_config['username'])
|
||||
# We do this to identify the messages generated from Zulip -> Matrix
|
||||
# and we make sure we don't forward it again to the Zulip stream.
|
||||
not_from_zulip_bot = ('body' not in event['content'] or
|
||||
event['sender'] != zulip_bot_user)
|
||||
not_from_zulip_bot = (
|
||||
'body' not in event['content']
|
||||
or event['sender'] != zulip_bot_user
|
||||
)
|
||||
|
||||
if not_from_zulip_bot and content:
|
||||
try:
|
||||
|
|
|
@ -59,8 +59,10 @@ def send_bot_message(oldrev: str, newrev: str, refname: str) -> None:
|
|||
new_head = newrev[:12]
|
||||
old_head = oldrev[:12]
|
||||
|
||||
if (oldrev == '0000000000000000000000000000000000000000' or
|
||||
newrev == '0000000000000000000000000000000000000000'):
|
||||
if (
|
||||
oldrev == '0000000000000000000000000000000000000000'
|
||||
or newrev == '0000000000000000000000000000000000000000'
|
||||
):
|
||||
# New branch pushed or old branch removed
|
||||
added = ''
|
||||
removed = ''
|
||||
|
|
|
@ -66,9 +66,11 @@ def jid_to_zulip(jid: JID) -> str:
|
|||
|
||||
def zulip_to_jid(email: str, jabber_domain: str) -> JID:
|
||||
jid = JID(email, domain=jabber_domain)
|
||||
if (options.zulip_email_suffix and
|
||||
options.zulip_email_suffix in jid.username and
|
||||
not jid.username.endswith("-bot")):
|
||||
if (
|
||||
options.zulip_email_suffix
|
||||
and options.zulip_email_suffix in jid.username
|
||||
and not jid.username.endswith("-bot")
|
||||
):
|
||||
jid.username = jid.username.rpartition(options.zulip_email_suffix)[0]
|
||||
return jid
|
||||
|
||||
|
@ -393,8 +395,10 @@ option does not affect login credentials.'''.replace("\n", " "))
|
|||
pass
|
||||
for option in ("jid", "jabber_password", "conference_domain", "mode", "zulip_email_suffix",
|
||||
"jabber_server_address", "jabber_server_port"):
|
||||
if (getattr(options, option) is None and
|
||||
config.has_option("jabber_mirror", option)):
|
||||
if (
|
||||
getattr(options, option) is None
|
||||
and config.has_option("jabber_mirror", option)
|
||||
):
|
||||
setattr(options, option, config.get("jabber_mirror", option))
|
||||
|
||||
for option in ("no_use_tls",):
|
||||
|
|
|
@ -74,8 +74,10 @@ class ZulipPlugin(Component):
|
|||
`old_values` is a dictionary containing the previous values of the
|
||||
fields that have changed.
|
||||
"""
|
||||
if not (set(old_values.keys()).intersection(set(config.TRAC_NOTIFY_FIELDS)) or
|
||||
(comment and "comment" in set(config.TRAC_NOTIFY_FIELDS))):
|
||||
if not (
|
||||
set(old_values.keys()).intersection(set(config.TRAC_NOTIFY_FIELDS))
|
||||
or (comment and "comment" in set(config.TRAC_NOTIFY_FIELDS))
|
||||
):
|
||||
return
|
||||
|
||||
content = "%s updated %s" % (author, markdown_ticket_url(ticket))
|
||||
|
|
|
@ -61,9 +61,11 @@ def to_zephyr_username(zulip_username: str) -> str:
|
|||
# line.
|
||||
def different_paragraph(line: str, next_line: str) -> bool:
|
||||
words = next_line.split()
|
||||
return (len(line + " " + words[0]) < len(next_line) * 0.8 or
|
||||
len(line + " " + words[0]) < 50 or
|
||||
len(line) < len(words[0]))
|
||||
return (
|
||||
len(line + " " + words[0]) < len(next_line) * 0.8
|
||||
or len(line + " " + words[0]) < 50
|
||||
or len(line) < len(words[0])
|
||||
)
|
||||
|
||||
# Linewrapping algorithm based on:
|
||||
# http://gcbenison.wordpress.com/2011/07/03/a-program-to-intelligently-remove-carriage-returns-so-you-can-paste-text-without-having-it-look-awful/ #ignorelongline
|
||||
|
@ -73,13 +75,17 @@ def unwrap_lines(body: str) -> str:
|
|||
previous_line = lines[0]
|
||||
for line in lines[1:]:
|
||||
line = line.rstrip()
|
||||
if (re.match(r'^\W', line, flags=re.UNICODE) and
|
||||
re.match(r'^\W', previous_line, flags=re.UNICODE)):
|
||||
if (
|
||||
re.match(r'^\W', line, flags=re.UNICODE)
|
||||
and re.match(r'^\W', previous_line, flags=re.UNICODE)
|
||||
):
|
||||
result += previous_line + "\n"
|
||||
elif (line == "" or
|
||||
previous_line == "" or
|
||||
re.match(r'^\W', line, flags=re.UNICODE) or
|
||||
different_paragraph(previous_line, line)):
|
||||
elif (
|
||||
line == ""
|
||||
or previous_line == ""
|
||||
or re.match(r'^\W', line, flags=re.UNICODE)
|
||||
or different_paragraph(previous_line, line)
|
||||
):
|
||||
# Use 2 newlines to separate sections so that we
|
||||
# trigger proper Markdown processing on things like
|
||||
# bulleted lists
|
||||
|
@ -178,8 +184,10 @@ def update_subscriptions() -> None:
|
|||
classes_to_subscribe = set()
|
||||
for stream in public_streams:
|
||||
zephyr_class = stream.encode("utf-8")
|
||||
if (options.shard is not None and
|
||||
not hashlib.sha1(zephyr_class).hexdigest().startswith(options.shard)):
|
||||
if (
|
||||
options.shard is not None
|
||||
and not hashlib.sha1(zephyr_class).hexdigest().startswith(options.shard)
|
||||
):
|
||||
# This stream is being handled by a different zephyr_mirror job.
|
||||
continue
|
||||
if zephyr_class in current_zephyr_subs:
|
||||
|
@ -198,9 +206,10 @@ def maybe_kill_child() -> None:
|
|||
logger.exception("")
|
||||
|
||||
def maybe_restart_mirroring_script() -> None:
|
||||
if os.stat(os.path.join(options.stamp_path, "stamps", "restart_stamp")).st_mtime > start_time or \
|
||||
((options.user == "tabbott" or options.user == "tabbott/extra") and
|
||||
os.stat(os.path.join(options.stamp_path, "stamps", "tabbott_stamp")).st_mtime > start_time):
|
||||
if os.stat(os.path.join(options.stamp_path, "stamps", "restart_stamp")).st_mtime > start_time or (
|
||||
(options.user == "tabbott" or options.user == "tabbott/extra")
|
||||
and os.stat(os.path.join(options.stamp_path, "stamps", "tabbott_stamp")).st_mtime > start_time
|
||||
):
|
||||
logger.warning("")
|
||||
logger.warning("zephyr mirroring script has been updated; restarting...")
|
||||
maybe_kill_child()
|
||||
|
@ -258,8 +267,10 @@ def process_loop(log: Optional[IO[Any]]) -> None:
|
|||
def parse_zephyr_body(zephyr_data: str, notice_format: str) -> Tuple[str, str]:
|
||||
try:
|
||||
(zsig, body) = zephyr_data.split("\x00", 1)
|
||||
if (notice_format == 'New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4' or
|
||||
notice_format == 'New transaction [$1] entered in $2\nFrom: $3\nSubject: $4'):
|
||||
if (
|
||||
notice_format == 'New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4'
|
||||
or notice_format == 'New transaction [$1] entered in $2\nFrom: $3\nSubject: $4'
|
||||
):
|
||||
# Logic based off of owl_zephyr_get_message in barnowl
|
||||
fields = body.split('\x00')
|
||||
if len(fields) == 5:
|
||||
|
@ -351,8 +362,12 @@ def process_notice(notice: Any, log: Optional[IO[Any]]) -> None:
|
|||
if notice.format.startswith("Zephyr error: See") or notice.format.endswith("@(@color(blue))"):
|
||||
logger.debug("Skipping message we got from Zulip!")
|
||||
return
|
||||
if (zephyr_class == "mail" and notice.instance.lower() == "inbox" and is_personal and
|
||||
not options.forward_mail_zephyrs):
|
||||
if (
|
||||
zephyr_class == "mail"
|
||||
and notice.instance.lower() == "inbox"
|
||||
and is_personal
|
||||
and not options.forward_mail_zephyrs
|
||||
):
|
||||
# Only forward mail zephyrs if forwarding them is enabled.
|
||||
return
|
||||
|
||||
|
@ -606,8 +621,10 @@ Feedback button or at support@zulipchat.com."""
|
|||
# Forward messages sent to '(instance "WHITESPACE")' back to the
|
||||
# appropriate WHITESPACE instance for bidirectional mirroring
|
||||
instance = match_whitespace_instance.group(1)
|
||||
elif (instance == "instance %s" % (zephyr_class,) or
|
||||
instance == "test instance %s" % (zephyr_class,)):
|
||||
elif (
|
||||
instance == "instance %s" % (zephyr_class,)
|
||||
or instance == "test instance %s" % (zephyr_class,)
|
||||
):
|
||||
# Forward messages to e.g. -c -i white-magic back from the
|
||||
# place we forward them to
|
||||
if instance.startswith("test"):
|
||||
|
@ -675,8 +692,10 @@ returned the following warning:
|
|||
|
||||
%s""" % (support_heading, stderr, support_closing))
|
||||
return
|
||||
elif code != 0 and (stderr.startswith("zwrite: Ticket expired while sending notice to ") or
|
||||
stderr.startswith("zwrite: No credentials cache found while sending notice to ")):
|
||||
elif code != 0 and (
|
||||
stderr.startswith("zwrite: Ticket expired while sending notice to ")
|
||||
or stderr.startswith("zwrite: No credentials cache found while sending notice to ")
|
||||
):
|
||||
# Retry sending the message unauthenticated; if that works,
|
||||
# just notify the user that they need to renew their tickets
|
||||
(code, stderr) = send_unauthed_zephyr(zwrite_args, wrapped_content)
|
||||
|
@ -711,10 +730,17 @@ received it, Zephyr users did not. The error message from zwrite was:
|
|||
def maybe_forward_to_zephyr(message: Dict[str, Any]) -> None:
|
||||
# The key string can be used to direct any type of text.
|
||||
if (message["sender_email"] == zulip_account_email):
|
||||
if not ((message["type"] == "stream") or
|
||||
(message["type"] == "private" and
|
||||
False not in [u["email"].lower().endswith("mit.edu") for u in
|
||||
message["display_recipient"]])):
|
||||
if not (
|
||||
(message["type"] == "stream")
|
||||
or (
|
||||
message["type"] == "private"
|
||||
and False
|
||||
not in [
|
||||
u["email"].lower().endswith("mit.edu")
|
||||
for u in message["display_recipient"]
|
||||
]
|
||||
)
|
||||
):
|
||||
# Don't try forward private messages with non-MIT users
|
||||
# to MIT Zephyr.
|
||||
return
|
||||
|
|
|
@ -55,9 +55,11 @@ class CountingBackoff:
|
|||
self.last_attempt_time = time.time()
|
||||
|
||||
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):
|
||||
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):
|
||||
|
@ -236,8 +238,10 @@ def get_default_config_filename() -> Optional[str]:
|
|||
return None
|
||||
|
||||
config_file = os.path.join(os.environ["HOME"], ".zuliprc")
|
||||
if (not os.path.exists(config_file) and
|
||||
os.path.exists(os.path.join(os.environ["HOME"], ".humbugrc"))):
|
||||
if (
|
||||
not os.path.exists(config_file)
|
||||
and os.path.exists(os.path.join(os.environ["HOME"], ".humbugrc"))
|
||||
):
|
||||
raise ZulipError("The Zulip API configuration file is now ~/.zuliprc; please run:\n\n"
|
||||
" mv ~/.humbugrc ~/.zuliprc\n")
|
||||
return config_file
|
||||
|
@ -530,8 +534,10 @@ class Client:
|
|||
# Timeouts are either a Timeout or an SSLError; we
|
||||
# want the later exception handlers to deal with any
|
||||
# non-timeout other SSLErrors
|
||||
if (isinstance(e, requests.exceptions.SSLError) and
|
||||
str(e) != "The read operation timed out"):
|
||||
if (
|
||||
isinstance(e, requests.exceptions.SSLError)
|
||||
and str(e) != "The read operation timed out"
|
||||
):
|
||||
raise UnrecoverableNetworkError('SSL Error')
|
||||
if longpolling:
|
||||
# When longpolling, we expect the timeout to fire,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue