comparison src/plugins/plugin_xep_0234.py @ 1575:833bdb227b16

plugins XEP-0234, file: moved human file size conversion to file plugi
author Goffi <goffi@goffi.org>
date Wed, 11 Nov 2015 18:19:49 +0100
parents babd97d80049
children 846a39900fa6
comparison
equal deleted inserted replaced
1574:babd97d80049 1575:833bdb227b16
112 file_data[name] = unicode(file_elt.elements(NS_JINGLE_FT, name).next()) 112 file_data[name] = unicode(file_elt.elements(NS_JINGLE_FT, name).next())
113 except StopIteration: 113 except StopIteration:
114 file_data[name] = '' 114 file_data[name] = ''
115 115
116 try: 116 try:
117 size = file_data['size'] = int(file_data['size']) 117 file_data['size'] = int(file_data['size'])
118 except ValueError: 118 except ValueError:
119 raise failure.Failure(exceptions.DataError) 119 raise failure.Failure(exceptions.DataError)
120 else:
121 # human readable size
122 file_data['size_human'] = u'{:.6n} Mio'.format(float(size)/(1024**2))
123 120
124 name = file_data['name'] 121 name = file_data['name']
125 if '/' in name or '\\' in name: 122 if '/' in name or '\\' in name:
126 log.warning(u"File name contain path characters, we replace them: {}".format(name)) 123 log.warning(u"File name contain path characters, we replace them: {}".format(name))
127 file_data['name'] = name.replace('/', '_').replace('\\', '_') 124 file_data['name'] = name.replace('/', '_').replace('\\', '_')