Skip to content

Commit

Permalink
Clean up a bunch of SyntaxWarning messages
Browse files Browse the repository at this point in the history
Add r prefix to a bunch of regex strings
  • Loading branch information
mrphlip committed Sep 7, 2024
1 parent 60835bd commit e94f9b1
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build_carddb_keyforge.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def main():
processed_cards.add(filteredname)
conn.commit()

re_429_detail = re.compile("This endpoint is currently disabled due to too many requests\\. Please, try again in (\d+) seconds\\.")
re_429_detail = re.compile(r"This endpoint is currently disabled due to too many requests\. Please, try again in (\d+) seconds\.")
def getpage(page):
fn = f"{CACHE_DIR}/{page}.json"
if os.path.exists(fn):
Expand Down
4 changes: 2 additions & 2 deletions common/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def get_timezone(tz):
else:
raise

re_timefmt1 = re.compile("^\s*(?:\s*(\d*)\s*d)?(?:\s*(\d*)\s*h)?(?:\s*(\d*)\s*m)?(?:\s*(\d*)\s*s?)?\s*$")
re_timefmt2 = re.compile("^(?:(?:(?:\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*$")
re_timefmt1 = re.compile(r"^\s*(?:\s*(\d*)\s*d)?(?:\s*(\d*)\s*h)?(?:\s*(\d*)\s*m)?(?:\s*(\d*)\s*s?)?\s*$")
re_timefmt2 = re.compile(r"^(?:(?:(?:\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*$")
def parsetime(s):
"""
Parse user-supplied times in one of two formats:
Expand Down
4 changes: 2 additions & 2 deletions common/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async def url_regex():
# For example: if 'co' is before 'com', 'example.com/path' is matched as 'example.co'.
tlds = sorted((await get_tlds()), key=lambda e: len(e), reverse=True)
re_tld = "(?:" + "|".join(map(re.escape, tlds)) + ")"
re_hostname = "(?:(?:(?:[\w-]+\.)+" + re_tld + "\.?)|(?:\d{,3}(?:\.\d{,3}){3})|(?:\[[0-9a-fA-F:.]+\]))"
re_url = "((?:https?://)?" + re_hostname + "(?::\d+)?(?:/[\x5E\s\u200b]*)?)"
re_hostname = r"(?:(?:(?:[\w-]+\.)+%s\.?)|(?:\d{,3}(?:\.\d{,3}){3})|(?:\[[0-9a-fA-F:.]+\]))" % re_tld
re_url = r"((?:https?://)?%s(?::\d+)?(?:/[\x5E\s\u200b]*)?)" % re_hostname
re_url = re_url + "|" + "|".join(map(lambda parens: re.escape(parens[0]) + re_url + re.escape(parens[1]), parens))
return re.compile(re_url, re.IGNORECASE)

Expand Down
2 changes: 1 addition & 1 deletion lrrbot/chatlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ async def get_display_name(nick):
except Exception:
return nick

re_just_words = re.compile("^\w+$")
re_just_words = re.compile(r"^\w+$")
@utils.cache(CACHE_EXPIRY)
async def get_twitch_emotes():
"""
Expand Down
10 changes: 5 additions & 5 deletions lrrbot/commands/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

blueprint = Blueprint()

@blueprint.command("cardview (yt )?(on|off)")
@blueprint.command(r"cardview (yt )?(on|off)")
@lrrbot.decorators.mod_only
def set_cardview(bot, conn, event, respond_to, youtube, setting):
"""
Expand All @@ -26,7 +26,7 @@ def set_cardview(bot, conn, event, respond_to, youtube, setting):

conn.privmsg(respond_to, "Card viewer %s" % ("enabled" if bot.cardview else "disabled"))

@blueprint.command("(?:card|mtg) (.+)")
@blueprint.command(r"(?:card|mtg) (.+)")
@lrrbot.decorators.throttle(60, count=3)
def mtg_card_lookup(bot, conn, event, respond_to, search):
"""
Expand All @@ -38,7 +38,7 @@ def mtg_card_lookup(bot, conn, event, respond_to, search):
"""
real_card_lookup(bot, conn, event, respond_to, search, game=CARD_GAME_MTG)

@blueprint.command("(?:kf|keyforge) (.+)")
@blueprint.command(r"(?:kf|keyforge) (.+)")
@lrrbot.decorators.throttle(60, count=3)
def keyforge_card_lookup(lrrbot, conn, event, respond_to, search):
"""
Expand All @@ -50,7 +50,7 @@ def keyforge_card_lookup(lrrbot, conn, event, respond_to, search):
"""
real_card_lookup(lrrbot, conn, event, respond_to, search, game=CARD_GAME_KEYFORGE)

@blueprint.command("(?:pok[eé]mon|pok[eé]|pkmn|ptcg) (.+)")
@blueprint.command(r"(?:pok[eé]mon|pok[eé]|pkmn|ptcg) (.+)")
@lrrbot.decorators.throttle(60, count=3)
def pokemon_card_lookup(lrrbot, conn, event, respond_to, search):
"""
Expand All @@ -62,7 +62,7 @@ def pokemon_card_lookup(lrrbot, conn, event, respond_to, search):
"""
real_card_lookup(lrrbot, conn, event, respond_to, search, game=CARD_GAME_PTCG)

@blueprint.command("(?:lorcana) (.+)")
@blueprint.command(r"(?:lorcana) (.+)")
@lrrbot.decorators.throttle(60, count=3)
def lorcana_card_lookup(bot, conn, event, respond_to, search):
"""
Expand Down
8 changes: 4 additions & 4 deletions lrrbot/commands/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

blueprint = Blueprint()

@blueprint.command("game")
@blueprint.command(r"game")
@lrrbot.decorators.throttle()
async def current_game(bot, conn, event, respond_to):
"""
Expand Down Expand Up @@ -39,7 +39,7 @@ async def current_game(bot, conn, event, respond_to):
" (overridden)" if bot.game_override is not None else ""
))

@blueprint.command("game display (.*?)")
@blueprint.command(r"game display (.*?)")
@lrrbot.decorators.mod_only
async def set_game_name(bot, conn, event, respond_to, name):
"""
Expand Down Expand Up @@ -78,7 +78,7 @@ async def set_game_name(bot, conn, event, respond_to, name):

conn.privmsg(respond_to, "OK, I'll start calling %s \"%s\"" % (real_name, name))

@blueprint.command("game override (.*?)")
@blueprint.command(r"game override (.*?)")
@lrrbot.decorators.mod_only
async def override_game(bot, conn, event, respond_to, game):
"""
Expand Down Expand Up @@ -123,7 +123,7 @@ async def override_game(bot, conn, event, respond_to, game):
message += "Currently playing: %s" % name
conn.privmsg(respond_to, message)

@blueprint.command("game refresh")
@blueprint.command(r"game refresh")
@lrrbot.decorators.mod_only
async def refresh(bot, conn, event, respond_to):
"""
Expand Down
10 changes: 5 additions & 5 deletions lrrbot/commands/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

blueprint = Blueprint()

@blueprint.command("live")
@blueprint.command(r"live")
@lrrbot.decorators.throttle()
@lrrbot.decorators.private_reply_when_live
async def live(bot, conn, event, respond_to):
Expand Down Expand Up @@ -55,7 +55,7 @@ async def live(bot, conn, event, respond_to):
])
return conn.privmsg(respond_to, utils.trim_length(message))

@blueprint.command("live register")
@blueprint.command(r"live register")
async def register_self(bot, conn, event, respond_to):
"""
Command: !live register
Expand All @@ -64,7 +64,7 @@ async def register_self(bot, conn, event, respond_to):
"""
conn.privmsg(respond_to, "Currently the fanlist cannot be edited. Contact mrphlip if you want to be added.")

@blueprint.command("live unregister")
@blueprint.command(r"live unregister")
async def unregister_self(bot, conn, event, respond_to):
"""
Command: !live unregister
Expand All @@ -73,7 +73,7 @@ async def unregister_self(bot, conn, event, respond_to):
"""
conn.privmsg(respond_to, "Currently the fanlist cannot be edited. Contact mrphlip if you want to be removed.")

@blueprint.command("live register (.*)")
@blueprint.command(r"live register (.*)")
@lrrbot.decorators.mod_only
async def register(bot, conn, event, respond_to, channel):
"""
Expand All @@ -83,7 +83,7 @@ async def register(bot, conn, event, respond_to, channel):
"""
conn.privmsg(respond_to, "Currently the fanlist cannot be edited.")

@blueprint.command("live unregister (.*)")
@blueprint.command(r"live unregister (.*)")
@lrrbot.decorators.mod_only
async def unregister(bot, conn, event, respond_to, channel):
"""
Expand Down
4 changes: 2 additions & 2 deletions lrrbot/commands/lockdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

blueprint = Blueprint()

@blueprint.command("(mod|sub)only")
@blueprint.command(r"(mod|sub)only")
@lrrbot.decorators.mod_only
def mod_only(bot, conn, event, respond_to, level):
"""
Expand All @@ -16,7 +16,7 @@ def mod_only(bot, conn, event, respond_to, level):
bot.access = level
conn.privmsg(respond_to, "Commands from non-%ss are now ignored." % level)

@blueprint.command("(?:mod|sub)only off")
@blueprint.command(r"(?:mod|sub)only off")
@lrrbot.decorators.mod_only
def mod_only_off(bot, conn, event, respond_to):
"""
Expand Down
28 changes: 14 additions & 14 deletions lrrbot/commands/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
blueprint = Blueprint()
log = logging.getLogger('misc')

@blueprint.command("test")
@blueprint.command(r"test")
@lrrbot.decorators.mod_only
def test(bot, conn, event, respond_to):
conn.privmsg(respond_to, "Test")

@blueprint.command("storm(?:counts?)?")
@blueprint.command(r"storm(?:counts?)?")
@lrrbot.decorators.throttle()
def stormcount(bot, conn, event, respond_to):
"""
Expand Down Expand Up @@ -62,7 +62,7 @@ def stormcount(bot, conn, event, respond_to):
youtube_super_sticker,
))

@blueprint.command("spam(?:count)?")
@blueprint.command(r"spam(?:count)?")
@lrrbot.decorators.throttle()
def spamcount(bot, conn, event, respond_to):
"""
Expand All @@ -87,7 +87,7 @@ def spamcount(bot, conn, event, respond_to):
# When !desertbus should stop claiming the run is still active
DESERTBUS_END = DESERTBUS_START + datetime.timedelta(days=6) # Six days of plugs should be long enough

@blueprint.command("next( .*)?")
@blueprint.command(r"next( .*)?")
@lrrbot.decorators.throttle()
async def next(bot, conn, event, respond_to, timezone):
"""
Expand All @@ -107,7 +107,7 @@ async def next(bot, conn, event, respond_to, timezone):
else:
conn.privmsg(respond_to, message)

@blueprint.command("(?:db ?count(?: |-)?down|db ?next|next ?db)( .*)?")
@blueprint.command(r"(?:db ?count(?: |-)?down|db ?next|next ?db)( .*)?")
@lrrbot.decorators.throttle()
def desertbus(bot, conn, event, respond_to, timezone):
"""
Expand Down Expand Up @@ -138,7 +138,7 @@ def desertbus(bot, conn, event, respond_to, timezone):
else:
conn.privmsg(respond_to, "Desert Bus for Hope will return next year, start saving your donation money now!")

@blueprint.command("nextfan( .*)?")
@blueprint.command(r"nextfan( .*)?")
@lrrbot.decorators.throttle()
@lrrbot.decorators.private_reply_when_live
async def nextfan(bot, conn, event, respond_to, timezone):
Expand All @@ -151,7 +151,7 @@ async def nextfan(bot, conn, event, respond_to, timezone):
message, _ = await googlecalendar.get_next_event_text(googlecalendar.CALENDAR_FAN, tz=timezone, include_current=True)
conn.privmsg(respond_to, message)

@blueprint.command("time")
@blueprint.command(r"time")
@lrrbot.decorators.throttle()
def time(bot, conn, event, respond_to):
"""
Expand All @@ -163,7 +163,7 @@ def time(bot, conn, event, respond_to):
now = datetime.datetime.now(config["timezone"])
conn.privmsg(respond_to, "Current moonbase time: %s" % now.strftime("%l:%M %p"))

@blueprint.command("time 24")
@blueprint.command(r"time 24")
@lrrbot.decorators.throttle()
def time24(bot, conn, event, respond_to):
"""
Expand All @@ -175,7 +175,7 @@ def time24(bot, conn, event, respond_to):
now = datetime.datetime.now(config["timezone"])
conn.privmsg(respond_to, "Current moonbase time: %s" % now.strftime("%H:%M"))

@blueprint.command("viewers")
@blueprint.command(r"viewers")
@lrrbot.decorators.throttle()
async def viewers(bot, conn, event, respond_to):
"""
Expand Down Expand Up @@ -220,7 +220,7 @@ async def uptime_msg(stream_info=None, factor=1):
else:
return "The stream is not live."

@blueprint.command("uptime")
@blueprint.command(r"uptime")
@lrrbot.decorators.throttle()
async def uptime(bot, conn, event, respond_to):
"""
Expand All @@ -231,7 +231,7 @@ async def uptime(bot, conn, event, respond_to):
"""
conn.privmsg(respond_to, await uptime_msg())

@blueprint.command("updog")
@blueprint.command(r"updog")
@lrrbot.decorators.throttle()
async def updog(bot, conn, event, respond_to):
# intentionally not in help
Expand Down Expand Up @@ -284,7 +284,7 @@ async def get_status_msg(bot):
async def send_status(bot, conn, target):
conn.privmsg(target, await get_status_msg(bot))

@blueprint.command("status")
@blueprint.command(r"status")
async def status(bot, conn, event, respond_to):
"""
Command: !status
Expand All @@ -297,7 +297,7 @@ async def status(bot, conn, event, respond_to):
source = irc.client.NickMask(event.source)
await send_status(bot, conn, source.nick)

@blueprint.command("auto(?: |-)?status")
@blueprint.command(r"auto(?: |-)?status")
def autostatus_check(bot, conn, event, respond_to):
"""
Command: !autostatus
Expand All @@ -318,7 +318,7 @@ def autostatus_check(bot, conn, event, respond_to):
else:
conn.privmsg(source.nick, "Auto-status is disabled. Enable it with: !autostatus on")

@blueprint.command("auto(?: |-)?status (on|off)")
@blueprint.command(r"auto(?: |-)?status (on|off)")
def autostatus_set(bot, conn, event, respond_to, enable):
"""
Command: !autostatus on
Expand Down
10 changes: 5 additions & 5 deletions lrrbot/commands/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def format_quote(tag, qid, quote, name, date, context):
quote_msg += " [{date!s}]".format(date=date)
return quote_msg

@blueprint.command("quote(?: (?:(game|show) (.+)|(?:(\d+)|(.+))))?")
@blueprint.command(r"quote(?: (?:(game|show) (.+)|(?:(\d+)|(.+))))?")
@lrrbot.decorators.sub_only
@lrrbot.decorators.throttle(60, count=2)
def quote(bot, conn, event, respond_to, meta_param, meta_value, qid, attrib):
Expand Down Expand Up @@ -84,7 +84,7 @@ def quote(bot, conn, event, respond_to, meta_param, meta_value, qid, attrib):
qid, quote, name, date, context = row
conn.privmsg(respond_to, format_quote("Quote", qid, quote, name, date, context))

@blueprint.command("addquote(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?")
@blueprint.command(r"addquote(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?")
@lrrbot.decorators.mod_only
async def addquote(bot, conn, event, respond_to, name, date, quote, context):
"""
Expand Down Expand Up @@ -118,7 +118,7 @@ async def addquote(bot, conn, event, respond_to, name, date, quote, context):

conn.privmsg(respond_to, format_quote("New quote", qid, quote, name, date, context))

@blueprint.command("modquote (\d+)(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?")
@blueprint.command(r"modquote (\d+)(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?")
@lrrbot.decorators.mod_only
def modquote(bot, conn, event, respond_to, qid, name, date, quote, context):
"""
Expand Down Expand Up @@ -151,7 +151,7 @@ def modquote(bot, conn, event, respond_to, qid, name, date, quote, context):
else:
conn.privmsg(respond_to, "Could not modify quote.")

@blueprint.command("delquote (\d+)")
@blueprint.command(r"delquote (\d+)")
@lrrbot.decorators.mod_only
def delquote(bot, conn, event, respond_to, qid):
"""
Expand All @@ -170,7 +170,7 @@ def delquote(bot, conn, event, respond_to, qid):
else:
conn.privmsg(respond_to, "Could not find quote #{qid}.".format(qid=qid))

@blueprint.command("findquote (.*)")
@blueprint.command(r"findquote (.*)")
@lrrbot.decorators.sub_only
@lrrbot.decorators.throttle(60, count=2)
def findquote(bot, conn, event, respond_to, query):
Expand Down
4 changes: 2 additions & 2 deletions lrrbot/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def set_show(bot, show):
bot.set_show(show.lower())
bot.get_game_id.reset_throttle()

@blueprint.command("show")
@blueprint.command(r"show")
@lrrbot.decorators.throttle()
def get_show(bot, conn, event, respond_to):
"""
Expand All @@ -32,7 +32,7 @@ def print_show(bot, conn, respond_to):
conn.privmsg(respond_to, "Currently live: %s%s" % (name, " (overriden)" if bot.show_override is not None else ""))


@blueprint.command("show override (.*?)")
@blueprint.command(r"show override (.*?)")
@lrrbot.decorators.mod_only
def show_override(bot, conn, event, respond_to, show):
"""
Expand Down
4 changes: 2 additions & 2 deletions www/spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ async def test(session):

check = do_check_links if link_spam else do_check

re_twitchchat = re.compile("^\w*:\s*(.*)$")
re_irc = re.compile("<[^<>]*>\s*(.*)$")
re_twitchchat = re.compile(r"^\w*:\s*(.*)$")
re_irc = re.compile(r"<[^<>]*>\s*(.*)$")
lines = message.split('\n')
for line in lines:
res = await check(line, rules)
Expand Down

0 comments on commit e94f9b1

Please sign in to comment.