Back to index

obnam  1.1
Public Member Functions | Public Attributes | Static Public Attributes
obnamlib.hooks.FilterHook Class Reference
Inheritance diagram for obnamlib.hooks.FilterHook:
Inheritance graph
[legend]
Collaboration diagram for obnamlib.hooks.FilterHook:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def add_callback
def remove_callback
def call_callbacks
def run_filter_read
def run_filter_write
def call_callbacks

Public Attributes

 bytag
 callbacks
 priorities

Static Public Attributes

int EARLY_PRIORITY = 250
int DEFAULT_PRIORITY = 500
int LATE_PRIORITY = 750

Detailed Description

A hook which filters data through callbacks.

Every hook of this type accepts a piece of data as its first argument
Each callback gets the return value of the previous one as its
argument. The caller gets the value of the final callback.

Other arguments (with or without keywords) are passed as-is to
each callback.

Definition at line 85 of file hooks.py.


Constructor & Destructor Documentation

Reimplemented from obnamlib.hooks.Hook.

Definition at line 98 of file hooks.py.

00098 
00099     def __init__(self):
00100         Hook.__init__(self)
00101         self.bytag = {}


Member Function Documentation

def obnamlib.hooks.FilterHook.add_callback (   self,
  callback,
  priority = Hook.DEFAULT_PRIORITY 
)
Add a callback to this hook.

Return an identifier that can be used to remove this callback.

Reimplemented from obnamlib.hooks.Hook.

Definition at line 102 of file hooks.py.

00102 
00103     def add_callback(self, callback, priority=Hook.DEFAULT_PRIORITY):
00104         assert(hasattr(callback, "tag"))
00105         assert(hasattr(callback, "filter_read"))
00106         assert(hasattr(callback, "filter_write"))
00107         self.bytag[callback.tag] = callback
00108         return Hook.add_callback(self, callback, priority)

def obnamlib.hooks.Hook.call_callbacks (   self,
  args,
  kwargs 
) [inherited]
Call all callbacks with the given arguments.

Definition at line 62 of file hooks.py.

00062 
00063     def call_callbacks(self, *args, **kwargs):
00064         '''Call all callbacks with the given arguments.'''
00065         for callback in self.callbacks:
00066             callback(*args, **kwargs)
        
def obnamlib.hooks.FilterHook.call_callbacks (   self,
  data,
  args,
  kwargs 
)

Definition at line 113 of file hooks.py.

00113 
00114     def call_callbacks(self, data, *args, **kwargs):
00115         raise NotImplementedError()
        
def obnamlib.hooks.FilterHook.remove_callback (   self,
  callback_id 
)
Remove a specific callback.

Reimplemented from obnamlib.hooks.Hook.

Definition at line 109 of file hooks.py.

00109 
00110     def remove_callback(self, callback_id):
00111         Hook.remove_callback(self, callback_id)
00112         del self.bytag[callback_id.tag]

def obnamlib.hooks.FilterHook.run_filter_read (   self,
  data,
  args,
  kwargs 
)

Definition at line 116 of file hooks.py.

00116 
00117     def run_filter_read(self, data, *args, **kwargs):
00118         tag, content = data.split("\0", 1)
00119         while tag != "":
00120             if tag not in self.bytag:
00121                 raise MissingFilterError(tag)
00122             data = self.bytag[tag].filter_read(content, *args, **kwargs)
00123             tag, content = data.split("\0", 1)
00124         return content

def obnamlib.hooks.FilterHook.run_filter_write (   self,
  data,
  args,
  kwargs 
)

Definition at line 125 of file hooks.py.

00125 
00126     def run_filter_write(self, data, *args, **kwargs):
00127         tracing.trace('called')
00128         data = "\0" + data
00129         for filt in self.callbacks:
00130             tracing.trace('calling %s' % filt)
00131             new_data = filt.filter_write(data, *args, **kwargs)
00132             assert new_data is not None, \
00133                    filt.tag + ": Returned None from filter_write()"
00134             if data != new_data:
00135                 tracing.trace('filt.tag=%s' % filt.tag)
00136                 data = filt.tag + "\0" + new_data
00137         tracing.trace('done')
00138         return data
00139 


Member Data Documentation

Definition at line 100 of file hooks.py.

Definition at line 44 of file hooks.py.

int obnamlib.hooks.Hook.DEFAULT_PRIORITY = 500 [static, inherited]

Definition at line 40 of file hooks.py.

int obnamlib.hooks.Hook.EARLY_PRIORITY = 250 [static, inherited]

Definition at line 39 of file hooks.py.

int obnamlib.hooks.Hook.LATE_PRIORITY = 750 [static, inherited]

Definition at line 41 of file hooks.py.

Definition at line 45 of file hooks.py.


The documentation for this class was generated from the following file: