0002-factor-out-function-to-clean-text-for-open-document-.patch
wcs/qommon/ods.py | ||
---|---|---|
39 | 39 |
ET.register_namespace(prefix, uri) |
40 | 40 | |
41 | 41 | |
42 |
def clean_text(value): |
|
43 |
for i in range(0x20): # remove control characters |
|
44 |
char = chr(i) |
|
45 |
if char in ('\t', '\r', '\n'): |
|
46 |
# only allow tab, carriage return and line feed. |
|
47 |
continue |
|
48 |
value = value.replace(char, '') |
|
49 |
# fffe and ffff are also invalid characters |
|
50 |
return value.replace('\ufffe', '').replace('\uffff', '') |
|
51 | ||
52 | ||
42 | 53 |
def is_number(value): |
43 | 54 |
if value and (value.startswith('0') or value.startswith('+')): |
44 | 55 |
return False |
... | ... | |
167 | 178 | |
168 | 179 |
class WorkCell(object): |
169 | 180 |
def __init__(self, worksheet, value, formdata=None, data_field=None, native_value=None): |
181 |
self.worksheet = worksheet |
|
170 | 182 |
if value is None: |
171 | 183 |
value = '' |
172 |
value = force_text(value, 'utf-8') |
|
173 |
self.worksheet = worksheet |
|
174 |
for i in range(0x20): # remove control characters |
|
175 |
char = chr(i) |
|
176 |
if char in ('\t', '\r', '\n'): |
|
177 |
# only allow tab, carriage return and line feed. |
|
178 |
continue |
|
179 |
value = value.replace(char, '') |
|
180 |
# fffe and ffff are also invalid characters |
|
181 |
value = value.replace('\ufffe', '').replace('\uffff', '') |
|
182 |
self.value = value |
|
184 |
self.value = clean_text(force_text(value, 'utf-8')) |
|
183 | 185 |
self.formdata = formdata |
184 | 186 |
self.data_field = data_field |
185 | 187 |
self.native_value = native_value |
186 |
- |