FaviconController: Work without pkg_resources (fixes #4)
If the `pkg_resources` module is not available, the `FaviconController` will fall back to finding the default image in the same directory on the filesystem as the `milla` package.master
parent
94b98a0620
commit
922a82e4e8
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue