diff --git a/src/milla/controllers.py b/src/milla/controllers.py index 7e59fa0..1384552 100644 --- a/src/milla/controllers.py +++ b/src/milla/controllers.py @@ -19,13 +19,15 @@ from one or more of these classes can make things significantly easier. :Created: Mar 27, 2011 :Author: dustin -:Updated: $Date$ -:Updater: $Author$ ''' import datetime import milla.util -import pkg_resources +import os +try: + import pkg_resources +except ImportError: + pkg_resources = None class Controller(object): @@ -58,17 +60,23 @@ class FaviconController(Controller): EXPIRY_DAYS = 365 def __init__(self, icon=None, content_type='image/x-icon'): - if icon: - try: - self.icon = open(icon) - except (IOError, OSError): - self.icon = None - else: - try: + try: + if icon: + self.icon = open(icon, 'rb') + self.content_type = content_type + elif pkg_resources: self.icon = pkg_resources.resource_stream('milla', 'milla.ico') - except IOError: - self.icon = None - self.content_type = content_type + self.content_type = 'image/x-icon' + else: + icon = os.path.join( + os.path.dirname(milla.__file__), + 'milla.ico' + ) + self.icon = open(icon, 'rb') + self.content_type = 'image/x-icon' + except (IOError, OSError): + self.icon = self.content_type = None + def __call__(self, request): if not self.icon: