# 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/utils.py
# def ascii_lowercase(val):
#     return re.sub('[%s]' % string.ascii_uppercase, lambda m: m.group().lower(), val)


import os
import apsw
from collections import defaultdict
from PyQt6.QtCore import QUrl
from .constants import config_dir
from .utils import ascii_lowercase
    @property
    def conn(self):
        if self._conn is None:
            self._conn = apsw.Connection(self.path)
            c = self._conn.cursor()
            uv = next(c.execute('PRAGMA user_version'))[0]
            if uv == 0:
                c.execute(
                    'CREATE TABLE permissions (id INTEGER PRIMARY KEY, domain TEXT NOT NULL, type TEXT NOT NULL, UNIQUE(domain, type)); PRAGMA user_version=1;')
            c.close()
        return self._conn

    def has_permission(self, qurl_or_domain, permission_type):
        domain = qurl_or_domain
        if isinstance(domain, QUrl):
            domain = domain.host()
        domain = ascii_lowercase(domain)
        if permission_type in self.temporary[domain]:
            return True
        try:
            next(self.conn.cursor().execute('SELECT domain FROM permissions WHERE domain=? AND type=?', (domain, permission_type)))
            return True
        except StopIteration:
            pass
        return False

    def add_permission(self, qurl_or_domain, permission_type, permanent=True):
        domain = qurl_or_domain
        if isinstance(domain, QUrl):
            domain = domain.host()

# 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/utils.py
# def ascii_lowercase(val):
#     return re.sub('[%s]' % string.ascii_uppercase, lambda m: m.group().lower(), val)


# Path: vise/site_permissions.py
import os
import apsw
from collections import defaultdict
from PyQt6.QtCore import QUrl
from .constants import config_dir
from .utils import ascii_lowercase

    @property
    def conn(self):
        if self._conn is None:
            self._conn = apsw.Connection(self.path)
            c = self._conn.cursor()
            uv = next(c.execute('PRAGMA user_version'))[0]
            if uv == 0:
                c.execute(
                    'CREATE TABLE permissions (id INTEGER PRIMARY KEY, domain TEXT NOT NULL, type TEXT NOT NULL, UNIQUE(domain, type)); PRAGMA user_version=1;')
            c.close()
        return self._conn

    def has_permission(self, qurl_or_domain, permission_type):
        domain = qurl_or_domain
        if isinstance(domain, QUrl):
            domain = domain.host()
        domain = ascii_lowercase(domain)
        if permission_type in self.temporary[domain]:
            return True
        try:
            next(self.conn.cursor().execute('SELECT domain FROM permissions WHERE domain=? AND type=?', (domain, permission_type)))
            return True
        except StopIteration:
            pass
        return False

    def add_permission(self, qurl_or_domain, permission_type, permanent=True):
        domain = qurl_or_domain
        if isinstance(domain, QUrl):
            domain = domain.host()

        domain = ascii_lowercase(domain)