Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-mako
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-mako
Commits
565ea6c9
Commit
565ea6c9
authored
18 years ago
by
Mike Bayer
Browse files
Options
Downloads
Patches
Plain Diff
added lookup module
parent
355deb16
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/mako/lookup.py
+40
-0
40 additions, 0 deletions
lib/mako/lookup.py
with
40 additions
and
0 deletions
lib/mako/lookup.py
0 → 100644
+
40
−
0
View file @
565ea6c9
# lookup.py
# Copyright (C) 2006 Michael Bayer mike_mp@zzzcomputing.com
#
# This module is part of Mako and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import
posixpath
import
os
from
mako
import
exceptions
from
mako.template
import
Template
class
AbstractTemplateLookup
(
object
):
def
has_template
(
self
,
uri
):
try
:
self
.
get_template
(
uri
)
return
True
except
exceptions
.
TemplateLookupException
,
e
:
return
False
def
get_template
(
self
,
uri
):
raise
NotImplementedError
()
class
TemplateLookup
(
AbstractTemplateLookup
):
def
__init__
(
self
,
directories
=
None
,
module_directory
=
None
,
filesystem_checks
=
True
,
collection_size
=-
1
):
self
.
directories
=
directories
or
[]
self
.
module_directory
=
module_directory
self
.
filesystem_checks
=
filesystem_checks
self
.
collection_size
=
collection_size
self
.
_collection
=
{}
def
get_template
(
self
,
uri
):
try
:
return
self
.
_collection
[
uri
]
except
KeyError
:
for
dir
in
self
.
directories
:
srcfile
=
posixpath
.
join
(
dir
,
uri
)
if
os
.
access
(
srcfile
,
os
.
F_OK
):
self
.
_collection
[
uri
]
=
Template
(
file
(
srcfile
).
read
(),
lookup
=
self
)
return
self
.
_collection
[
uri
]
else
:
raise
exceptions
.
TemplateLookupException
(
"
Cant locate template for uri
'
%s
'"
%
uri
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment