# Path: vise/config.py
# def color(key, default):
#     ans = colors().get(key)
#     if not ans or ans == 'default':
#         ans = default
#     return ans
# 
# @lru_cache()
# def font_sizes():
#     uff = (load_config(user=True).get('fonts') or {}).get('sizes') or {}
#     dff = load_config(user=False)['fonts']['sizes']
#     sizes = {}
# 
#     def conv(x):
#         if x == 'default':
#             return 0
#         try:
#             return int(x)
#         except Exception:
#             pass
# 
#     def get_ff(x):
#         if isinstance(x, dict):
#             return conv(x.get(hostname) or x.get('*'))
#         return conv(x)
# 
#     for ftype, val in uff.items():
#         val = get_ff(val)
#         if isinstance(val, int):
#             sizes[ftype] = val
# 
#     for ftype, val in dff.items():
#         if ftype not in sizes:
#             val = get_ff(val)
#             if isinstance(val, int):
#                 sizes[ftype] = val
# 
#     return sizes
# 
# 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_as_file(name):
#     return open(get_data_as_path(name), 'rb')


import glob
import json
import os
import apsw
from base64 import standard_b64decode, standard_b64encode
from binascii import hexlify
from collections import defaultdict
from functools import lru_cache
from PyQt6.QtGui import QKeySequence
from PyQt6.QtWebEngineCore import (QWebEngineProfile, QWebEngineScript,
                                   QWebEngineSettings)
from PyQt6.QtWidgets import QApplication
from .config import color, font_sizes
from .constants import (DOWNLOADS_URL, VISE_SCHEME, appname, cache_dir,
                        config_dir)
from .resources import get_data_as_file
    from .url_intercept import Interceptor
    from .vise_scheme import UrlSchemeHandler
        from .downloads import download_requested
    from .config import font_families, font_sizes
        from .downloads import download_requested
    from .utils import safe_disconnect
        from .utils import parse_url
        sc.insert(script)


def get_spell_langs():
    ans = getattr(get_spell_langs, 'ans', None)
    if ans is None:
        # To learn how to create bdic files, see https://doc.qt.io/qt-5/qtwebengine-webenginewidgets-spellchecker-example.html
        spell_dir = os.environ['QTWEBENGINE_DICTIONARIES_PATH']
        langs = []
        if os.path.exists(spell_dir):
            for dic in glob.glob(os.path.join(spell_dir, '*.bdic')):
                langs.append(os.path.basename(dic).rpartition('.')[0])
        get_spell_langs.ans = ans = langs
    return ans


private_profiles = []


def create_profile(parent=None, private=False):
    if parent is None:
        parent = QApplication.instance()
    if private:
        ans = QWebEngineProfile(parent)
        ans.downloadRequested.connect(download_requested)
        private_profiles.append(ans)
    else:
        ans = QWebEngineProfile(appname, parent)
        ans.setCachePath(os.path.join(cache_dir, appname, 'cache'))
        safe_makedirs(ans.cachePath())

# Path: vise/config.py
# def color(key, default):
#     ans = colors().get(key)
#     if not ans or ans == 'default':
#         ans = default
#     return ans
# 
# @lru_cache()
# def font_sizes():
#     uff = (load_config(user=True).get('fonts') or {}).get('sizes') or {}
#     dff = load_config(user=False)['fonts']['sizes']
#     sizes = {}
# 
#     def conv(x):
#         if x == 'default':
#             return 0
#         try:
#             return int(x)
#         except Exception:
#             pass
# 
#     def get_ff(x):
#         if isinstance(x, dict):
#             return conv(x.get(hostname) or x.get('*'))
#         return conv(x)
# 
#     for ftype, val in uff.items():
#         val = get_ff(val)
#         if isinstance(val, int):
#             sizes[ftype] = val
# 
#     for ftype, val in dff.items():
#         if ftype not in sizes:
#             val = get_ff(val)
#             if isinstance(val, int):
#                 sizes[ftype] = val
# 
#     return sizes
# 
# 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_as_file(name):
#     return open(get_data_as_path(name), 'rb')


# Path: vise/settings.py
import glob
import json
import os
import apsw
from base64 import standard_b64decode, standard_b64encode
from binascii import hexlify
from collections import defaultdict
from functools import lru_cache
from PyQt6.QtGui import QKeySequence
from PyQt6.QtWebEngineCore import (QWebEngineProfile, QWebEngineScript,
                                   QWebEngineSettings)
from PyQt6.QtWidgets import QApplication
from .config import color, font_sizes
from .constants import (DOWNLOADS_URL, VISE_SCHEME, appname, cache_dir,
                        config_dir)
from .resources import get_data_as_file
    from .url_intercept import Interceptor
    from .vise_scheme import UrlSchemeHandler
        from .downloads import download_requested
    from .config import font_families, font_sizes
        from .downloads import download_requested
    from .utils import safe_disconnect
        from .utils import parse_url

        sc.insert(script)


def get_spell_langs():
    ans = getattr(get_spell_langs, 'ans', None)
    if ans is None:
        # To learn how to create bdic files, see https://doc.qt.io/qt-5/qtwebengine-webenginewidgets-spellchecker-example.html
        spell_dir = os.environ['QTWEBENGINE_DICTIONARIES_PATH']
        langs = []
        if os.path.exists(spell_dir):
            for dic in glob.glob(os.path.join(spell_dir, '*.bdic')):
                langs.append(os.path.basename(dic).rpartition('.')[0])
        get_spell_langs.ans = ans = langs
    return ans


private_profiles = []


def create_profile(parent=None, private=False):
    if parent is None:
        parent = QApplication.instance()
    if private:
        ans = QWebEngineProfile(parent)
        ans.downloadRequested.connect(download_requested)
        private_profiles.append(ans)
    else:
        ans = QWebEngineProfile(appname, parent)
        ans.setCachePath(os.path.join(cache_dir, appname, 'cache'))
        safe_makedirs(ans.cachePath())

        ans.setPersistentStoragePath(os.path.join(cache_dir, appname, 'storage'))