Documented instance root

This commit is contained in:
Armin Ronacher 2011-08-10 13:55:57 +02:00
parent 153ecbc920
commit 187cb80dcc
4 changed files with 78 additions and 3 deletions

View file

@ -565,7 +565,7 @@ class _PackageBoundObject(object):
raise RuntimeError('No static folder for this object')
return send_from_directory(self.static_folder, filename)
def open_resource(self, resource):
def open_resource(self, resource, mode='rb'):
"""Opens a resource from the application's resource folder. To see
how this works, consider the following folder structure::
@ -587,4 +587,6 @@ class _PackageBoundObject(object):
:param resource: the name of the resource. To access resources within
subfolders use forward slashes as separator.
"""
return open(os.path.join(self.root_path, resource), 'rb')
if mode not in ('r', 'rb'):
raise ValueError('Resources can only be opened for reading')
return open(os.path.join(self.root_path, resource), mode)