Package tdi :: Module filters
[frames] | no frames]

Source Code for Module tdi.filters

  1  # -*- coding: ascii -*- 
  2  # 
  3  # Copyright 2006 - 2013 
  4  # Andr\xe9 Malo or his licensors, as applicable 
  5  # 
  6  # Licensed under the Apache License, Version 2.0 (the "License"); 
  7  # you may not use this file except in compliance with the License. 
  8  # You may obtain a copy of the License at 
  9  # 
 10  #     http://www.apache.org/licenses/LICENSE-2.0 
 11  # 
 12  # Unless required by applicable law or agreed to in writing, software 
 13  # distributed under the License is distributed on an "AS IS" BASIS, 
 14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 15  # See the License for the specific language governing permissions and 
 16  # limitations under the License. 
 17  """ 
 18  ========================= 
 19   Template Filter Classes 
 20  ========================= 
 21   
 22  This module provides the base classes and concrete implementations for 
 23  filters. 
 24  """ 
 25  __author__ = u"Andr\xe9 Malo" 
 26  __docformat__ = "restructuredtext en" 
 27   
 28   
29 -class BaseStreamFilter(object):
30 """ 31 Base stream filter class, which actually passes everything unfiltered 32 33 :IVariables: 34 `_stream` : ``file`` 35 The decorated stream 36 """ 37
38 - def __init__(self, stream):
39 """ 40 Initialization 41 42 :Parameters: 43 `stream` : ``file`` 44 The stream to decorate 45 """ 46 self._stream = stream
47
48 - def __getattr__(self, name):
49 """ 50 Delegate unknown symbols to the next stream (downwards) 51 52 :Parameters: 53 `name` : ``str`` 54 The symbol to look up 55 56 :Return: The requested symbol 57 :Rtype: any 58 59 :Exceptions: 60 - `AttributeError` : The symbol was not found 61 """ 62 return getattr(self._stream, name)
63 64
65 -class StreamFilename(BaseStreamFilter):
66 """ 67 Provide filename for upchain stream filters 68 69 :IVariables: 70 `filename` : ``str`` 71 The provided filename 72 """ 73
74 - def __init__(self, stream, filename):
75 """ 76 Initialization 77 78 :Parameters: 79 `stream` : ``stream`` 80 The next stream layer 81 82 `filename` : ``str`` 83 The filename to provide 84 """ 85 super(StreamFilename, self).__init__(stream) 86 self.filename = filename
87 88
89 -class BaseEventFilter(object):
90 """ 91 Base event filter class, which actually passes everything unfiltered 92 93 Override the event handlers you need. 94 95 :See: `BuildingListenerInterface` 96 97 :IVariables: 98 `builder` : `BuildingListenerInterface` 99 The next level builder 100 """ 101 __slots__ = ('builder',) 102
103 - def __init__(self, builder):
104 """ 105 Store the next level builder 106 107 :Parameters: 108 `builder` : `BuildingListenerInterface` 109 The next level builder 110 """ 111 self.builder = builder
112
113 - def __getattr__(self, name):
114 """ 115 Delegate unknown symbols to the next level builder (upwards) 116 117 :Parameters: 118 `name` : ``str`` 119 The symbol to look up 120 121 :Return: The requested symbol 122 :Rtype: any 123 124 :Exceptions: 125 - `AttributeError` : The symbol was not found 126 """ 127 return getattr(self.builder, name)
128 129 130 from tdi import c 131 c = c.load('impl') 132 if c is not None: 133 BaseEventFilter = c.BaseEventFilter 134 del c 135 136
137 -class FilterFilename(BaseEventFilter):
138 """ 139 Provide the filename for down-chain filters 140 141 :IVariables: 142 `filename` : ``str`` 143 The provided filename 144 """ 145
146 - def __init__(self, builder, filename):
147 """ 148 Initialization 149 150 :Parameters: 151 `builder` : `BuildingListenerInterface` 152 The next level builder 153 154 `filename` : ``str`` 155 The filename to provide 156 """ 157 super(FilterFilename, self).__init__(builder) 158 self.filename = filename
159