comparison src/tools/utils.py @ 601:a4f6f78f0620

jp, core: jp's clean_ustr moved to a new general utils module
author Goffi <goffi@goffi.org>
date Fri, 22 Feb 2013 00:11:47 +0100
parents
children 84a6e83157c2
comparison
equal deleted inserted replaced
600:c5451501465b 601:a4f6f78f0620
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 SAT: a jabber client
6 Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22 """ various useful methods """
23
24 import unicodedata
25
26
27 def clean_ustr(ustr):
28 """Clean unicode string
29 remove special characters from unicode string"""
30 def valid_chars(unicode_source):
31 for char in unicode_source:
32 if unicodedata.category(char) == 'Cc' and char!='\n':
33 continue
34 yield char
35 return ''.join(valid_chars(ustr))
36