1
2 r"""
3 :Copyright:
4
5 Copyright 2006 - 2015
6 Andr\xe9 Malo or his licensors, as applicable
7
8 :License:
9
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21
22 =================
23 Factory Caching
24 =================
25
26 Factory Caching.
27 """
28 if __doc__:
29
30 __doc__ = __doc__.encode('ascii').decode('unicode_escape')
31 __author__ = r"Andr\xe9 Malo".encode('ascii').decode('unicode_escape')
32 __docformat__ = "restructuredtext en"
33
34
36 """
37 Copy docstring
38
39 :Parameters:
40 `func` : ``callable``
41 The method's function
42 """
43 from . import factory as _factory
44 method = getattr(_factory.Factory, func.__name__, None)
45 if method is not None:
46 func.__doc__ = method.__doc__
47
48
50 """
51 Wrapper for providing template factory memoization keys
52
53 :IVariables:
54 `_factory` : `tdi.factory.Factory`
55 Factory
56 """
57
59 """
60 Initialization
61
62 :Parameters:
63 `factory` : `tdi.factory.Factory`
64 Factory
65 """
66 self._factory = factory
67
68 - def replace(self, autoupdate=None, eventfilters=None, streamfilters=None,
69 default_eventfilters=None, default_streamfilters=None,
70 overlay_eventfilters=None, overlay_streamfilters=None,
71 overlay_default_eventfilters=None,
72 overlay_default_streamfilters=None, default_encoding=None,
73 memoizer=None):
74 """ Create factory with replaced parameters """
75
76
77 return self.__class__(self._factory.replace(
78 autoupdate=autoupdate,
79 eventfilters=eventfilters,
80 streamfilters=streamfilters,
81 default_eventfilters=default_eventfilters,
82 default_streamfilters=default_streamfilters,
83 overlay_eventfilters=overlay_eventfilters,
84 overlay_streamfilters=overlay_streamfilters,
85 overlay_default_eventfilters=overlay_default_eventfilters,
86 overlay_default_streamfilters=overlay_default_streamfilters,
87 default_encoding=default_encoding,
88 memoizer=memoizer,
89 ))
90 _copy_doc(replace)
91
92 - def from_file(self, filename, encoding=None, key=None):
99 _copy_doc(from_file)
100
101 - def from_stream(self, stream, encoding=None, filename=None, mtime=None,
102 opener=None, key=None):
114 _copy_doc(from_stream)
115
116 - def from_opener(self, opener, filename, encoding=None, key=None):
123 _copy_doc(from_opener)
124
125 - def from_string(self, data, encoding=None, filename=None, mtime=None,
126 key=None):
137 _copy_doc(from_string)
138
139 - def from_files(self, names, encoding=None, basedir=None, key=None):
140 """ Load templates from files and overlay them """
141 if key is None:
142 key = (basedir,) + tuple(names)
143 return self._factory.from_files(
144 names,
145 encoding=encoding,
146 basedir=basedir,
147 key=key,
148 )
149 _copy_doc(from_files)
150
151 - def from_streams(self, streams, encoding=None, streamopen=None,
152 key=None):
153 """ Load templates from streams and overlay them """
154 if key is None:
155 key = tuple(streams)
156 try:
157 hash(key)
158 except TypeError:
159 key = None
160 return self._factory.from_streams(
161 streams,
162 encoding=encoding,
163 streamopen=streamopen,
164 key=key,
165 )
166 _copy_doc(from_streams)
167