# Path: cardinal/decorators.py
# def regex(expression):
#     if (not isinstance(expression, str) and
#             not isinstance(expression, _RETYPE)):
#         raise TypeError("Regular expression must be a string or regex type")
# 
#     def wrap(f):
#         f.regex = expression
#         return f
# 
#     return wrap


import re
import html
import logging
import unicodedata
from datetime import datetime
from urllib import request
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import regex
    """Timeout in seconds before bailing on loading page"""

    READ_BYTES = 524288
    """Bytes to read before bailing on loading page (512KB)"""

    LOOKUP_COOLOFF = 10
    """Timeout in seconds before looking up the same URL again"""

    def __init__(self, cardinal, config):
        # Initialize logger
        self.logger = logging.getLogger(__name__)

        # Holds the last URL looked up, for cooloff
        self.last_url = None

        # Holds time last URL was looked up, for cooloff
        self.last_url_at = None

        # If config doesn't exist, use an empty dict
        config = config or {}

        self.timeout = config.get('timeout', self.TIMEOUT)
        self.read_bytes = config.get('read_bytes', self.READ_BYTES)
        self.lookup_cooloff = config.get('lookup_cooloff', self.LOOKUP_COOLOFF)
        # Whether to attempt to grab a title if no other plugin handles it
        self.generic_handler_enabled = config.get(
            'handle_generic_urls', True)

        cardinal.event_manager.register('urls.detection', 2)


# Path: cardinal/decorators.py
# def regex(expression):
#     if (not isinstance(expression, str) and
#             not isinstance(expression, _RETYPE)):
#         raise TypeError("Regular expression must be a string or regex type")
# 
#     def wrap(f):
#         f.regex = expression
#         return f
# 
#     return wrap


# Path: plugins/urls/plugin.py
import re
import html
import logging
import unicodedata
from datetime import datetime
from urllib import request
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import regex

    """Timeout in seconds before bailing on loading page"""

    READ_BYTES = 524288
    """Bytes to read before bailing on loading page (512KB)"""

    LOOKUP_COOLOFF = 10
    """Timeout in seconds before looking up the same URL again"""

    def __init__(self, cardinal, config):
        # Initialize logger
        self.logger = logging.getLogger(__name__)

        # Holds the last URL looked up, for cooloff
        self.last_url = None

        # Holds time last URL was looked up, for cooloff
        self.last_url_at = None

        # If config doesn't exist, use an empty dict
        config = config or {}

        self.timeout = config.get('timeout', self.TIMEOUT)
        self.read_bytes = config.get('read_bytes', self.READ_BYTES)
        self.lookup_cooloff = config.get('lookup_cooloff', self.LOOKUP_COOLOFF)
        # Whether to attempt to grab a title if no other plugin handles it
        self.generic_handler_enabled = config.get(
            'handle_generic_urls', True)

        cardinal.event_manager.register('urls.detection', 2)


    @regex(URL_REGEX)