Commit 3f119240 by Chris Jerdonek

Reordered and renamed some methods in locator.Locator.

parent 9202ce23
...@@ -30,20 +30,6 @@ class Locator(object): ...@@ -30,20 +30,6 @@ class Locator(object):
self.template_extension = extension self.template_extension = extension
def _find_path(self, file_name, search_dirs):
"""
Search for the given file, and return the path.
Returns None if the file is not found.
"""
for dir_path in search_dirs:
file_path = os.path.join(dir_path, file_name)
if os.path.exists(file_path):
return file_path
return None
def get_object_directory(self, obj): def get_object_directory(self, obj):
""" """
Return the directory containing an object's defining class. Return the directory containing an object's defining class.
...@@ -66,13 +52,6 @@ class Locator(object): ...@@ -66,13 +52,6 @@ class Locator(object):
return os.path.dirname(path) return os.path.dirname(path)
def make_file_name(self, template_name):
file_name = template_name
if self.template_extension is not False:
file_name += os.path.extsep + self.template_extension
return file_name
def make_template_name(self, obj): def make_template_name(self, obj):
""" """
Return the canonical template name for an object instance. Return the canonical template name for an object instance.
...@@ -97,12 +76,33 @@ class Locator(object): ...@@ -97,12 +76,33 @@ class Locator(object):
return re.sub('[A-Z]', repl, template_name)[1:] return re.sub('[A-Z]', repl, template_name)[1:]
def _find_path_by_file_name(self, search_dirs, file_name): def make_file_name(self, template_name):
file_name = template_name
if self.template_extension is not False:
file_name += os.path.extsep + self.template_extension
return file_name
def _find_path(self, search_dirs, file_name):
"""
Search for the given file, and return the path.
Returns None if the file is not found.
"""
for dir_path in search_dirs:
file_path = os.path.join(dir_path, file_name)
if os.path.exists(file_path):
return file_path
return None
def _find_path_required(self, search_dirs, file_name):
""" """
Return the path to a template with the given file name. Return the path to a template with the given file name.
""" """
path = self._find_path(file_name, search_dirs) path = self._find_path(search_dirs, file_name)
if path is None: if path is None:
# TODO: we should probably raise an exception of our own type. # TODO: we should probably raise an exception of our own type.
...@@ -118,7 +118,7 @@ class Locator(object): ...@@ -118,7 +118,7 @@ class Locator(object):
""" """
file_name = self.make_file_name(template_name) file_name = self.make_file_name(template_name)
return self._find_path_by_file_name(search_dirs, file_name) return self._find_path_required(search_dirs, file_name)
def find_path_by_object(self, search_dirs, obj, file_name=None): def find_path_by_object(self, search_dirs, obj, file_name=None):
""" """
...@@ -135,6 +135,6 @@ class Locator(object): ...@@ -135,6 +135,6 @@ class Locator(object):
if dir_path is not None: if dir_path is not None:
search_dirs = [dir_path] + search_dirs search_dirs = [dir_path] + search_dirs
path = self._find_path_by_file_name(search_dirs, file_name) path = self._find_path_required(search_dirs, file_name)
return path return path
...@@ -150,6 +150,10 @@ class Locator(object): ...@@ -150,6 +150,10 @@ class Locator(object):
return path return path
def get_template(self, view): def get_template(self, view):
"""
Return the unicode template string associated with a view.
"""
if view.template is not None: if view.template is not None:
return view.template return view.template
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment