Skip to content

Commit

Permalink
squashme: conditional typing imports, suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
half-duplex committed May 25, 2022
1 parent 5fa96f9 commit 9aabcf7
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions sopel/modules/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
from ipaddress import ip_address
import logging
import re
from typing import Generator, List, Optional, Tuple
from typing import TYPE_CHECKING
from urllib.parse import urlparse

import dns.resolver
import requests
from urllib3.exceptions import LocationValueError # type: ignore[import]

from sopel import plugin, tools
from sopel.bot import Sopel, SopelWrapper
from sopel.config import Config, types
from sopel.config import types
from sopel.tools import web
from sopel.trigger import Trigger

if TYPE_CHECKING:
from typing import Generator, List, Optional, Tuple

from sopel.bot import Sopel, SopelWrapper
from sopel.config import Config
from sopel.trigger import Trigger

LOGGER = logging.getLogger(__name__)
USER_AGENT = (
Expand Down Expand Up @@ -320,6 +324,11 @@ def process_urls(
"""
For each URL in the list, ensure it should be titled, and do so.
:param bot: Sopel instance
:param trigger: The trigger object for this event
:param urls: The URLs detected in the triggering message
:param requested: Whether the title was explicitly requested (vs automatic)
See if it's handled by another plugin. If not, find where it redirects to,
if anywhere. If that redirected URL should be handled by another plugin,
dispatch the callback for it. Return a list of
Expand All @@ -329,11 +338,6 @@ def process_urls(
For titles explicitly requested by the user, exclusion_char and excludes
are skipped.
:param bot: Sopel instance
:param trigger: The trigger object for this event
:param urls: The URLs detected in the triggering message
:param requested: Whether the title was explicitly requested (vs automatic)
"""
shorten_url_length = bot.config.url.shorten_url_length
for url in urls:
Expand Down Expand Up @@ -406,9 +410,9 @@ def check_callbacks(bot: SopelWrapper, url: str, use_excludes: bool = True) -> b
"""
# Check if it matches the exclusion list first
excluded = False
if use_excludes:
excluded = any(regex.search(url) for regex in bot.memory["url_exclude"])
excluded = use_excludes and any(
regex.search(url) for regex in bot.memory["url_exclude"]
)
return (
excluded or
any(bot.search_url_callbacks(url)) or
Expand Down

0 comments on commit 9aabcf7

Please sign in to comment.