# Path: wikked/utils.py
# class PageNotFoundError(Exception):
#     """ An error raised when no physical file
#        is found for a given URL.
#     """
#     def __init__(self, url, message=None, *args):
#         Exception.__init__(self, url, message, *args)
# 
#     @property
#     def url(self):
#         return self.args[0]
# 
#     def __str__(self):
#         url = self.args[0]
#         message = self.args[1]
#         res = "Can't find page '%s'." % url
#         if message:
#             res += ' ' + message
#         return res
# 
# class NamespaceNotFoundError(Exception):
#     """ An error raised when no physical directory is found
#         for a given URL.
#     """
#     pass
# 
# def split_page_url(url):
#     m = endpoint_regex.match(url)
#     if m is None:
#         return (None, url)
#     endpoint = m.group(1)
#     path = m.group(2)
#     return (endpoint, path)


import os
import os.path
import re
import codecs
import fnmatch
import logging
import itertools
from .utils import (PageNotFoundError, NamespaceNotFoundError,
                    split_page_url)
                    not valid_filename_pattern.match(url_path)):
                raise ValueError("Invalid URL: %s" % url_path)
            return os.path.join(root, url_path + '.' + self.default_extension)

        # Find the right file-system entry for this URL.
        url_path = os.path.join(root, url_path)
        if is_file:
            dirname, basename = os.path.split(url_path)
            if basename == '':
                raise ValueError("Invalid URL: %s" % url_path)
            if not os.path.isdir(dirname):
                self._throwNotFoundError(url, root, is_file)

            it = os.walk(dirname)
            # TODO: This is weird, `itertools.islice` seems useless here.
            for _, __, ___ in it:
                filenames = ___
                break
            for filename in filenames:
                name, ext = os.path.splitext(filename)
                if name == basename:
                    return os.path.join(dirname, filename)
            self._throwNotFoundError(url, root, is_file)
        else:
            if os.path.isdir(url_path):
                return url_path
            self._throwNotFoundError(url, root, is_file)

    def _throwNotFoundError(self, url, searched, is_file):
        if is_file:

# Path: wikked/utils.py
# class PageNotFoundError(Exception):
#     """ An error raised when no physical file
#        is found for a given URL.
#     """
#     def __init__(self, url, message=None, *args):
#         Exception.__init__(self, url, message, *args)
# 
#     @property
#     def url(self):
#         return self.args[0]
# 
#     def __str__(self):
#         url = self.args[0]
#         message = self.args[1]
#         res = "Can't find page '%s'." % url
#         if message:
#             res += ' ' + message
#         return res
# 
# class NamespaceNotFoundError(Exception):
#     """ An error raised when no physical directory is found
#         for a given URL.
#     """
#     pass
# 
# def split_page_url(url):
#     m = endpoint_regex.match(url)
#     if m is None:
#         return (None, url)
#     endpoint = m.group(1)
#     path = m.group(2)
#     return (endpoint, path)


# Path: wikked/fs.py
import os
import os.path
import re
import codecs
import fnmatch
import logging
import itertools
from .utils import (PageNotFoundError, NamespaceNotFoundError,
                    split_page_url)

                    not valid_filename_pattern.match(url_path)):
                raise ValueError("Invalid URL: %s" % url_path)
            return os.path.join(root, url_path + '.' + self.default_extension)

        # Find the right file-system entry for this URL.
        url_path = os.path.join(root, url_path)
        if is_file:
            dirname, basename = os.path.split(url_path)
            if basename == '':
                raise ValueError("Invalid URL: %s" % url_path)
            if not os.path.isdir(dirname):
                self._throwNotFoundError(url, root, is_file)

            it = os.walk(dirname)
            # TODO: This is weird, `itertools.islice` seems useless here.
            for _, __, ___ in it:
                filenames = ___
                break
            for filename in filenames:
                name, ext = os.path.splitext(filename)
                if name == basename:
                    return os.path.join(dirname, filename)
            self._throwNotFoundError(url, root, is_file)
        else:
            if os.path.isdir(url_path):
                return url_path
            self._throwNotFoundError(url, root, is_file)

    def _throwNotFoundError(self, url, searched, is_file):
        if is_file:

            raise PageNotFoundError("No such page '%s' in: %s" %