From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id E5B2F138200 for ; Thu, 25 Apr 2013 16:44:25 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 99131E0B5D; Thu, 25 Apr 2013 16:44:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id EA5F8E0B5D for ; Thu, 25 Apr 2013 16:44:19 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BC78733DF46 for ; Thu, 25 Apr 2013 16:44:18 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 6396FE408C for ; Thu, 25 Apr 2013 16:44:17 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1363536382.4f5260ef21e696548fbf04a54bc67df21ff86aa7.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/strutil.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 4f5260ef21e696548fbf04a54bc67df21ff86aa7 X-VCS-Branch: master Date: Thu, 25 Apr 2013 16:44:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 630b2914-771d-4aa6-a62a-0cfca95ef146 X-Archives-Hash: d2a594f5d78e0cd887dc7b25d48d4e8b commit: 4f5260ef21e696548fbf04a54bc67df21ff86aa7 Author: André Erdmann mailerd de> AuthorDate: Sun Mar 17 11:54:34 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Sun Mar 17 16:06:22 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=4f5260ef strutil: add additional_filter to ascii_filter() The additional_filter arg should be None or a function Char -> Bool that can be used to filter out unwanted ascii chars without the need of an extra string iteration. --- roverlay/strutil.py | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) diff --git a/roverlay/strutil.py b/roverlay/strutil.py index f5ab8fd..f0d60df 100644 --- a/roverlay/strutil.py +++ b/roverlay/strutil.py @@ -52,9 +52,22 @@ def fix_ebuild_name ( name ): ) # --- end of fix_ebuild_name (...) --- -def ascii_filter ( _str ): - """Removes all non-ascii chars from a string and returns the result.""" - return ''.join ( c for c in _str if ord ( c ) < 128 ) +def ascii_filter ( _str, additional_filter=None ): + """Removes all non-ascii chars from a string and returns the result. + + arguments: + * _str -- string to be filtered + * additional_filter -- a function that is called for each ascii char + and returns true if the char is allowed (i.e., + should be kept in the resulting string), else False. + Defaults to None, which means "keep all". + """ + if additional_filter is None: + return ''.join ( c for c in _str if ord ( c ) < 128 ) + else: + return ''.join ( + c for c in _str if ord ( c ) < 128 and additional_filter ( c ) + ) # --- end of ascii_filter (...) --- def shorten_str ( s, maxlen, replace_end=None ):