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

Source Code for Module tdi.filters

  1  # -*- coding: ascii -*- 
  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   Template Filter Classes 
 24  ========================= 
 25   
 26  This module provides the base classes and concrete implementations for 
 27  filters. 
 28  """ 
 29  if __doc__: 
 30      # pylint: disable = redefined-builtin 
 31      __doc__ = __doc__.encode('ascii').decode('unicode_escape') 
 32  __author__ = r"Andr\xe9 Malo".encode('ascii').decode('unicode_escape') 
 33  __docformat__ = "restructuredtext en" 
 34   
 35   
36 -class BaseStreamFilter(object):
37 """ 38 Base stream filter class, which actually passes everything unfiltered 39 40 :IVariables: 41 `_stream` : ``file`` 42 The decorated stream 43 """ 44
45 - def __init__(self, stream):
46 """ 47 Initialization 48 49 :Parameters: 50 `stream` : ``file`` 51 The stream to decorate 52 """ 53 self._stream = stream
54
55 - def __getattr__(self, name):
56 """ 57 Delegate unknown symbols to the next stream (downwards) 58 59 :Parameters: 60 `name` : ``str`` 61 The symbol to look up 62 63 :Return: The requested symbol 64 :Rtype: any 65 66 :Exceptions: 67 - `AttributeError` : The symbol was not found 68 """ 69 return getattr(self._stream, name)
70 71
72 -class StreamFilename(BaseStreamFilter):
73 """ 74 Provide filename for upchain stream filters 75 76 :IVariables: 77 `filename` : ``str`` 78 The provided filename 79 """ 80
81 - def __init__(self, stream, filename):
82 """ 83 Initialization 84 85 :Parameters: 86 `stream` : ``stream`` 87 The next stream layer 88 89 `filename` : ``str`` 90 The filename to provide 91 """ 92 super(StreamFilename, self).__init__(stream) 93 self.filename = filename
94 95
96 -class BaseEventFilter(object):
97 """ 98 Base event filter class, which actually passes everything unfiltered 99 100 Override the event handlers you need. 101 102 :See: `BuildingListenerInterface` 103 104 :IVariables: 105 `builder` : `BuildingListenerInterface` 106 The next level builder 107 """ 108 __slots__ = ('builder',) 109
110 - def __init__(self, builder):
111 """ 112 Store the next level builder 113 114 :Parameters: 115 `builder` : `BuildingListenerInterface` 116 The next level builder 117 """ 118 self.builder = builder
119
120 - def __getattr__(self, name):
121 """ 122 Delegate unknown symbols to the next level builder (upwards) 123 124 :Parameters: 125 `name` : ``str`` 126 The symbol to look up 127 128 :Return: The requested symbol 129 :Rtype: any 130 131 :Exceptions: 132 - `AttributeError` : The symbol was not found 133 """ 134 return getattr(self.builder, name)
135 136 137 from . import c 138 c = c.load('impl') 139 if c is not None: 140 BaseEventFilter = c.BaseEventFilter # noqa 141 del c 142 143
144 -class FilterFilename(BaseEventFilter):
145 """ 146 Provide the filename for down-chain filters 147 148 :IVariables: 149 `filename` : ``str`` 150 The provided filename 151 """ 152
153 - def __init__(self, builder, filename):
154 """ 155 Initialization 156 157 :Parameters: 158 `builder` : `BuildingListenerInterface` 159 The next level builder 160 161 `filename` : ``str`` 162 The filename to provide 163 """ 164 super(FilterFilename, self).__init__(builder) 165 self.filename = filename
166