[kupfer: 14/23] plugin.thunderbird: fix unescaping and reading text cells
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 14/23] plugin.thunderbird: fix unescaping and reading text cells
- Date: Sat, 2 Jan 2010 23:11:28 +0000 (UTC)
commit e9b25cf103a9c3fa506ec678f924867fcfbc41f3
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date: Sun Dec 13 12:22:35 2009 +0100
plugin.thunderbird: fix unescaping and reading text cells
kupfer/plugin/thunderbird_support.py | 51 ++++++++++++++++++++++-----------
1 files changed, 34 insertions(+), 17 deletions(-)
---
diff --git a/kupfer/plugin/thunderbird_support.py b/kupfer/plugin/thunderbird_support.py
index b26b5a1..5ace41d 100644
--- a/kupfer/plugin/thunderbird_support.py
+++ b/kupfer/plugin/thunderbird_support.py
@@ -25,8 +25,8 @@ RE_ATOM = re.compile(r'<\s*(\(.+?\))\s*>')
RE_TABLE = re.compile(
r'\{-?(\d+):\^(..)\s*\{\(k\^(..):c\)\(s=9u?\)\s*(.*?)\}\s*(.+?)\}')
RE_ROW = re.compile(r'(-?)\s*\[(.+?)((\(.+?\)\s*)*)\]')
-RE_CELL_TEXT = re.compile(r'\^(.+?)[=^](.*)')
-RE_ESCAPED = re.compile(r'((\\[\$\0abtnvfr])|(\$..))')
+RE_CELL_TEXT = re.compile(r'\^(.+?)=(.*)')
+RE_CELL_OID = re.compile(r'\^(.+?)\^(.+)')
COLS_TO_KEEP = (
'DisplayName',
@@ -53,20 +53,24 @@ class _Table(object):
SPECIAL_CHARS = (
('\\\\', '\\'),
('\\$', '$'),
- ('\\0', chr(0)),
- ('\\a', chr(7)),
- ('\\b', chr(8)),
('\\t', chr(9)),
('\\n', chr(10)),
- ('\\v', chr(11)),
- ('\\f', chr(12)),
- ('\\r', chr(13)),
)
+RE_ESCAPED = re.compile(r'(\$[a-f0-9]{2})', re.IGNORECASE)
+
+def _unescape_character(match):
+ value = match.group()
+ try:
+ return chr(int(value[1:], 16))
+ except ValueError:
+ return value
+
+
def _unescape_data(instr):
for src, dst in SPECIAL_CHARS:
instr = instr.replace(src, dst)
- return RE_ESCAPED.sub(lambda x:chr(int(x.group()[1:], 16)), instr)
+ return RE_ESCAPED.sub(_unescape_character, instr)
def _read_mork(filename):
@@ -143,13 +147,19 @@ def _read_mork(filename):
rowdata = row[2:]
for rowcell in rowdata:
for cell in RE_CELL.findall(rowcell):
+ atom, col = None, None
match = RE_CELL_TEXT.match(cell)
if match:
col = cells.get(match.group(1))
- atom = atoms.get(match.group(2))
- if col and atom:
- table.add_cell(rowid, col, atom)
- continue
+ atom = match.group(2)
+ else:
+ match = RE_CELL_OID.match(cell)
+ if match:
+ col = cells.get(match.group(1))
+ atom = atoms.get(match.group(2))
+
+ if col and atom:
+ table.add_cell(rowid, col, atom)
pos = match.span()[1]
continue
@@ -164,13 +174,20 @@ def _read_mork(filename):
table = tables.get('1:80')
for rowcell in rowdata:
for cell in RE_CELL.findall(rowcell):
+ atom, col = None, None
match = RE_CELL_TEXT.match(cell)
if match:
col = cells.get(match.group(1))
- atom = atoms.get(match.group(2))
- if col and atom:
- table.add_cell(rowid, col, atom)
- continue
+ atom = match.group(2)
+ else:
+ match = RE_CELL_OID.match(cell)
+ if match:
+ col = cells.get(match.group(1))
+ atom = atoms.get(match.group(2))
+
+ if col and atom:
+ table.add_cell(rowid, col, atom)
+
pos = match.span()[1]
continue
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]