/usr/lib/python2.7/dist-packages/gnatpython/stringutils.py is in python-gnatpython 54-3build1.
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | ############################################################################
# #
# STRINGUTILS.PY #
# #
# Copyright (C) 2008 - 2010 Ada Core Technologies, Inc. #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/> #
# #
############################################################################
"""This module provides various function to process/handle strings
"""
import re
class Filter (object):
"""Class that provide an easy way to apply several filters at the same time
on a string or a list of strings.
??? we should use tuple instead of list
ATTRIBUTES
filters: list of filters to apply. each element of filters is either a
function or a list of the form [ pattern, sub ] where pattern and sub
string representing regexp
"""
def __init__(self):
"""Filter constructor
PARAMETERS
None
RETURN VALUE
An instanciation of Filter
"""
self.filters = []
def process(self, item):
"""Apply the filters on the item
PARAMETERS
item: this is either a string or a list of strings
RETURN VALUE
return the filtered string or list
"""
def run_aux(line):
"""Apply the filters on a string"""
result = line
for p in self.filters:
if isinstance(p, list):
result = re.sub(p[0], p[1], result)
else:
result = p(result)
return result
if isinstance(item, list):
return [run_aux(k) for k in item]
else:
return run_aux(item)
def append(self, pattern):
"""Add a filter
PARAMETERS
pattern: eitheir a function of a list containing the matching pattern
and the sub pattern.
RETURN VALUE
None
"""
self.filters.append(pattern)
|