# Path: vise/constants.py
# DOWNLOADS_URL = 'vise:downloads'
# WELCOME_URL = 'vise:welcome'
# STATUS_BAR_HEIGHT = 24
# FOLLOW_LINK_KEY_MAP = {getattr(Qt.Key, 'Key_' + x.upper()): x for x in string.ascii_lowercase + string.digits}
# VISE_SCHEME = 'vise'
# def _get_cache_dir():
# def _get_config_dir():
# def get_windows_username():
# def local_socket_address():
# 
# Path: vise/resources.py
# def get_data(name):
#     return get_data_as_file(name).read()


import os
import re
import math
import time
import unicodedata
import apsw
from collections import OrderedDict, namedtuple
from itertools import repeat
from PyQt6.QtWebEngineCore import QWebEnginePage
from .constants import config_dir
from .resources import get_data
            from .url_substitution import substitute as transform_func
    from glob import glob
            self._conn.close()
            self._conn = None

    def subsequence_matches(self, subsequence=None, limit=50):
        c = self.conn.cursor()
        if not subsequence:
            for url, title in c.execute('SELECT url, title FROM PLACES ORDER BY frecency DESC LIMIT ?', (limit,)):
                yield url, title
            return

        subsequence = normalize((subsequence or ''))[:20]
        like_expr = re.sub(r'([|%_])', r'|\1', subsequence.lower())
        like_expr = '%' + '%'.join(like_expr) + '%'

        for place_id, url, title in c.execute(
                'SELECT id, url, title FROM places WHERE url_lower LIKE ? ESCAPE "|" OR title_lower LIKE ? ESCAPE "|" ORDER BY frecency DESC LIMIT ?',
                (like_expr, like_expr, limit)):
            yield place_id, url, title

    def substring_matches(self, substrings=None, limit=50):
        c = self.conn.cursor()
        if not substrings:
            for url, title in c.execute('SELECT url, title FROM PLACES ORDER BY frecency DESC LIMIT ?', (limit,)):
                yield url, title
            return
        substrings = map(normalize, substrings)
        like_expressions = tuple('%' + re.sub(r'([|%_])', r'|\1', x.lower()) + '%' for x in substrings)
        where_clause = ' AND '.join(repeat('(url_lower LIKE ? OR title_lower LIKE ?)', len(like_expressions)))

        for place_id, url, title in c.execute(

# Path: vise/constants.py
# DOWNLOADS_URL = 'vise:downloads'
# WELCOME_URL = 'vise:welcome'
# STATUS_BAR_HEIGHT = 24
# FOLLOW_LINK_KEY_MAP = {getattr(Qt.Key, 'Key_' + x.upper()): x for x in string.ascii_lowercase + string.digits}
# VISE_SCHEME = 'vise'
# def _get_cache_dir():
# def _get_config_dir():
# def get_windows_username():
# def local_socket_address():
# 
# Path: vise/resources.py
# def get_data(name):
#     return get_data_as_file(name).read()


# Path: vise/places.py
import os
import re
import math
import time
import unicodedata
import apsw
from collections import OrderedDict, namedtuple
from itertools import repeat
from PyQt6.QtWebEngineCore import QWebEnginePage
from .constants import config_dir
from .resources import get_data
            from .url_substitution import substitute as transform_func
    from glob import glob

            self._conn.close()
            self._conn = None

    def subsequence_matches(self, subsequence=None, limit=50):
        c = self.conn.cursor()
        if not subsequence:
            for url, title in c.execute('SELECT url, title FROM PLACES ORDER BY frecency DESC LIMIT ?', (limit,)):
                yield url, title
            return

        subsequence = normalize((subsequence or ''))[:20]
        like_expr = re.sub(r'([|%_])', r'|\1', subsequence.lower())
        like_expr = '%' + '%'.join(like_expr) + '%'

        for place_id, url, title in c.execute(
                'SELECT id, url, title FROM places WHERE url_lower LIKE ? ESCAPE "|" OR title_lower LIKE ? ESCAPE "|" ORDER BY frecency DESC LIMIT ?',
                (like_expr, like_expr, limit)):
            yield place_id, url, title

    def substring_matches(self, substrings=None, limit=50):
        c = self.conn.cursor()
        if not substrings:
            for url, title in c.execute('SELECT url, title FROM PLACES ORDER BY frecency DESC LIMIT ?', (limit,)):
                yield url, title
            return
        substrings = map(normalize, substrings)
        like_expressions = tuple('%' + re.sub(r'([|%_])', r'|\1', x.lower()) + '%' for x in substrings)
        where_clause = ' AND '.join(repeat('(url_lower LIKE ? OR title_lower LIKE ?)', len(like_expressions)))

        for place_id, url, title in c.execute(

                'SELECT id, url, title FROM places WHERE %s ORDER BY frecency DESC LIMIT %d' % (where_clause, limit),