diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..3ab3f39 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include src/milla/milla.ico diff --git a/milla.svg b/milla.svg new file mode 100755 index 0000000..3332376 --- /dev/null +++ b/milla.svg @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/src/milla/app.py b/src/milla/app.py index 30a575a..2a54876 100644 --- a/src/milla/app.py +++ b/src/milla/app.py @@ -7,6 +7,7 @@ Please give me a docstring! :Updated: $Date$ :Updater: $Author$ ''' +from milla.controllers import FaviconController from webob.exc import HTTPNotFound, WSGIHTTPException import milla.dispatch import webob @@ -34,14 +35,29 @@ class Application(object): def __init__(self, dispatcher): self.dispatcher = dispatcher - self.config = {} + self.config = {'milla.favicon': True} def __call__(self, environ, start_response): path_info = environ['PATH_INFO'] try: func = self.dispatcher.resolve(path_info) except milla.dispatch.UnresolvedPath: - return HTTPNotFound()(environ, start_response) + def asbool(val): + if not val: + return False + try: + val = val.lower() + except AttributeError: + pass + if val in ('false', 'no', 'f', 'n', 'off'): + return False + return True + + if asbool(self.config.get('milla.favicon')) and \ + path_info == '/favicon.ico': + func = FaviconController() + else: + return HTTPNotFound()(environ, start_response) request = webob.Request(environ) request.config = self.config.copy() diff --git a/src/milla/controllers.py b/src/milla/controllers.py index 796233d..5f8cd9b 100644 --- a/src/milla/controllers.py +++ b/src/milla/controllers.py @@ -9,6 +9,11 @@ from one or more of these classes can make things significantly easier. :Updated: $Date$ :Updater: $Author$ ''' +import milla +import os + +__all__ = ['Controller', 'FaviconController'] + class Controller(object): '''The base controller class @@ -21,3 +26,29 @@ class Controller(object): def __after__(self, request): pass + +class FaviconController(Controller): + '''A controller for the "favicon" + + This controller is specifically suited to serve a site "favicon" or + bookmark icon. By default, it will serve the *Milla* icon, but you + can pass an alternate file time to the constructor. + + :param icon: Path to an icon to serve + ''' + + def __init__(self, icon=None): + if not icon: + icon = os.path.join(os.path.dirname(milla.__file__), 'milla.ico') + try: + self.icon = open(icon) + except (IOError, OSError): + self.icon = None + + def __call__(self, request): + if not self.icon: + raise milla.HTTPNotFound + response = milla.Response() + response.app_iter = self.icon + response.headers['Content-Type'] = 'image/x-icon' + return response diff --git a/src/milla/milla.ico b/src/milla/milla.ico new file mode 100755 index 0000000..5e6fe35 Binary files /dev/null and b/src/milla/milla.ico differ