comparison frontends/src/jp/jp @ 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 beaf6bec2fcd
children 84a6e83157c2
comparison
equal deleted inserted replaced
600:c5451501465b 601:a4f6f78f0620
54 from os.path import abspath, basename, dirname 54 from os.path import abspath, basename, dirname
55 from optparse import OptionParser 55 from optparse import OptionParser
56 from sat.tools.jid import JID 56 from sat.tools.jid import JID
57 import gobject 57 import gobject
58 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService 58 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
59 from sat.tools.utils import clean_ustr
59 import tarfile 60 import tarfile
60 import tempfile 61 import tempfile
61 import shutil 62 import shutil
62 import unicodedata
63 try: 63 try:
64 from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed 64 from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed
65 except ImportError, e: 65 except ImportError, e:
66 info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar')) 66 info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
67 info (_('Progress bar deactivated\n--\n')) 67 info (_('Progress bar deactivated\n--\n'))
196 self.dest_jids[i] = expandJid(self.dest_jids[i]) 196 self.dest_jids[i] = expandJid(self.dest_jids[i])
197 check(self.dest_jids[i]) 197 check(self.dest_jids[i])
198 except AttributeError: 198 except AttributeError:
199 pass 199 pass
200 200
201 def clean_ustr(self, ustr):
202 """Clean unicode string
203 remove special characters from unicode string"""
204 def valid_chars(unicode_source):
205 for char in unicode_source:
206 if unicodedata.category(char) == 'Cc' and char!='\n':
207 continue
208 yield char
209 return ''.join(valid_chars(ustr))
210
211 201
212 def send_stdin(self): 202 def send_stdin(self):
213 """Send incomming data on stdin to jabber contact""" 203 """Send incomming data on stdin to jabber contact"""
214 header = "\n" if self.options.new_line else "" 204 header = "\n" if self.options.new_line else ""
215 205
216 if self.options.separate: #we send stdin in several messages 206 if self.options.separate: #we send stdin in several messages
217 if header: 207 if header:
218 self.bridge.sendMessage(self.dest_jid, header, profile_key=self.profile) 208 self.bridge.sendMessage(self.dest_jid, header, profile_key=self.profile)
219 while (True): 209 while (True):
220 line = self.clean_ustr(sys.stdin.readline().decode('utf-8','ignore')) 210 line = clean_ustr(sys.stdin.readline().decode('utf-8','ignore'))
221 if not line: 211 if not line:
222 break 212 break
223 self.bridge.sendMessage(self.dest_jid, line.replace("\n",""), profile_key=self.profile) 213 self.bridge.sendMessage(self.dest_jid, line.replace("\n",""), profile_key=self.profile)
224 else: 214 else:
225 self.bridge.sendMessage(self.dest_jid, header + self.clean_ustr(u"".join([stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()])), profile_key=self.profile) 215 self.bridge.sendMessage(self.dest_jid, header + clean_ustr(u"".join([stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()])), profile_key=self.profile)
226 216
227 217
228 def pipe_out(self): 218 def pipe_out(self):
229 """Create named pipe, and send stdin to it""" 219 """Create named pipe, and send stdin to it"""
230 tmp_dir = tempfile.mkdtemp() 220 tmp_dir = tempfile.mkdtemp()