/usr/lib/python2.7/dist-packages/stetl/filters/stringfilter.py is in python-stetl 1.0.9+ds-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | # -*- coding: utf-8 -*-
#
# String filtering.
#
# Author:Just van den Broecke
from stetl.util import Util
from stetl.filter import Filter
from stetl.packet import FORMAT
log = Util.get_log("stringfilter")
class StringFilter(Filter):
"""
Base class for any string filtering
"""
# Constructor
def __init__(self, configdict, section, consumes, produces):
Filter.__init__(self, configdict, section, consumes, produces)
def invoke(self, packet):
if packet.data is None:
return packet
return self.filter_string(packet)
def filter_string(self, packet):
pass
class StringSubstitutionFilter(StringFilter):
"""
String filtering using Python advanced String formatting.
String should have substitutable values like {schema} {foo}
format_args should be of the form format_args = schema:test foo:bar ...
consumes=FORMAT.string, produces=FORMAT.string
"""
# Constructor
def __init__(self, configdict, section):
StringFilter.__init__(self, configdict, section, consumes=FORMAT.string, produces=FORMAT.string)
# Formatting of content according to Python String.format()
# String should have substitutable values like {schema} {foo}
# format_args should be of the form format_args = schema:test foo:bar ...
self.format_args = self.cfg.get('format_args')
# Convert string to dict: http://stackoverflow.com/a/1248990
self.format_args_dict = Util.string_to_dict(self.format_args, ':')
def filter_string(self, packet):
# String substitution based on Python String.format()
packet.data = packet.data.format(**self.format_args_dict)
return packet
|