<commit_before># coding: utf-8
from __future__ import print_function

from watchdog import events
from watchdog.observers.polling import PollingObserver
from mkdocs.build import build
from mkdocs.compat import httpserver, socketserver, urlunquote
from mkdocs.config import load_config
import os
import posixpath
import shutil
import sys
import tempfile


class BuildEventHandler(events.FileSystemEventHandler):
    """
    Perform a rebuild when anything in the theme or docs directory changes.
    """
    def __init__(self, options):
        super(BuildEventHandler, self).__init__()
        self.options = options

    def on_any_event(self, event):
        if not isinstance(event, events.DirModifiedEvent):
            print('Rebuilding documentation...', end='')
            config = load_config(options=self.options)
            build(config, live_server=True)
            print(' done')


class ConfigEventHandler(BuildEventHandler):
    """
    Perform a rebuild when the config file changes.
    """
    def on_any_event(self, event):
        if os.path.basename(event.src_path) == 'mkdocs.yml':
            super(ConfigEventHandler, self).on_any_event(event)


class FixedDirectoryHandler(httpserver.SimpleHTTPRequestHandler):
    """<commit_msg>Catch errors in the Watchdog error handler<commit_after># coding: utf-8
from __future__ import print_function

from watchdog import events
from watchdog.observers.polling import PollingObserver
from mkdocs.build import build
from mkdocs.compat import httpserver, socketserver, urlunquote
from mkdocs.config import load_config
import os
import posixpath
import shutil
import sys
import tempfile


class BuildEventHandler(events.FileSystemEventHandler):
    """
    Perform a rebuild when anything in the theme or docs directory changes.
    """
    def __init__(self, options):
        super(BuildEventHandler, self).__init__()
        self.options = options

    def on_any_event(self, event):
        if not isinstance(event, events.DirModifiedEvent):
            print('Rebuilding documentation...', end='')
            config = load_config(options=self.options)
            build(config, live_server=True)
            print(' done')


class ConfigEventHandler(BuildEventHandler):
    """
    Perform a rebuild when the config file changes.
    """
    def on_any_event(self, event):
        try:
            if os.path.basename(event.src_path) == 'mkdocs.yml':
                super(ConfigEventHandler, self).on_any_event(event)
        except Exception as e:
            print(e)


class FixedDirectoryHandler(httpserver.SimpleHTTPRequestHandler):
    """
{'fraction_non_alphanumeric': 0.08333333333333333, 'fraction_numerical': 0.0007645259938837921, 'mean_word_length': 3.5198618307426597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4892309', 'n_tokens_mistral': 707, 'n_tokens_neox': 699, 'n_words': 204}