# Path: wdom/options.py
# def level_to_int(level: Union[str, int]) -> int:
# def set_loglevel(level: Union[int, str, None] = None) -> None:
# def parse_command_line() -> Namespace:


import sys
import re
import copy
import pathlib
import webbrowser
from webbrowser import _browsers  # type: ignore
from typing import TYPE_CHECKING
from tornado import autoreload
from wdom.options import config
    from typing import List, Pattern  # noqa
_exclude_patterns_prev = []  # type: List[str]


def _compile_exclude_patterns() -> None:
    global _exclude_patterns_re, _exclude_patterns_prev
    if _exclude_patterns_prev == exclude_patterns:
        return
    else:
        _exclude_patterns_prev = copy.copy(exclude_patterns)
    for pat in exclude_patterns:
        _exclude_patterns_re.append(re.compile(pat))


def _is_exclude(name: str) -> bool:
    return any(pat.match(name) for pat in _exclude_patterns_re)


def _add_watch_path(path: pathlib.Path) -> None:
    if _is_exclude(path.name):
        return
    elif path.is_dir():
        for f in path.iterdir():
            _add_watch_path(f)
    elif path.is_file():
        autoreload.watch(str(path))


def watch_dir(path: str) -> None:
    """Add ``path`` to watch for autoreload."""
    _compile_exclude_patterns()

# Path: wdom/options.py
# def level_to_int(level: Union[str, int]) -> int:
# def set_loglevel(level: Union[int, str, None] = None) -> None:
# def parse_command_line() -> Namespace:


# Path: wdom/server/base.py
import sys
import re
import copy
import pathlib
import webbrowser
from webbrowser import _browsers  # type: ignore
from typing import TYPE_CHECKING
from tornado import autoreload
from wdom.options import config
    from typing import List, Pattern  # noqa

_exclude_patterns_prev = []  # type: List[str]


def _compile_exclude_patterns() -> None:
    global _exclude_patterns_re, _exclude_patterns_prev
    if _exclude_patterns_prev == exclude_patterns:
        return
    else:
        _exclude_patterns_prev = copy.copy(exclude_patterns)
    for pat in exclude_patterns:
        _exclude_patterns_re.append(re.compile(pat))


def _is_exclude(name: str) -> bool:
    return any(pat.match(name) for pat in _exclude_patterns_re)


def _add_watch_path(path: pathlib.Path) -> None:
    if _is_exclude(path.name):
        return
    elif path.is_dir():
        for f in path.iterdir():
            _add_watch_path(f)
    elif path.is_file():
        autoreload.watch(str(path))


def watch_dir(path: str) -> None:
    """Add ``path`` to watch for autoreload."""
    _compile_exclude_patterns()

    if config.autoreload or config.debug: