summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-30 01:55:23 +0200
committermathieui <mathieui@mathieui.net>2014-04-30 01:55:23 +0200
commit4e4ab569cf07fabf76339eeace1f6694f3414eff (patch)
treea74007d58875c36aa2bb965bb63c155e7588ea88 /src
parentc3dd20fc745b0f4c8fa402052182b5383afbb7f8 (diff)
downloadpoezio-4e4ab569cf07fabf76339eeace1f6694f3414eff.tar.gz
poezio-4e4ab569cf07fabf76339eeace1f6694f3414eff.tar.bz2
poezio-4e4ab569cf07fabf76339eeace1f6694f3414eff.tar.xz
poezio-4e4ab569cf07fabf76339eeace1f6694f3414eff.zip
Fix #2447 (OTR & HTML) -- partial WONTFIX
- Guess-parse the OTR messages in search for xhtml upon arrival - add a configurable option to decode it or not - We have XHTML-IM for a reason, and therefore we will *not* implement a full html parser for clients that dump whatever formatting inside the OTR payload (looking at you, pidgin)
Diffstat (limited to 'src')
-rw-r--r--src/xhtml.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/xhtml.py b/src/xhtml.py
index 33a89b5e..48664311 100644
--- a/src/xhtml.py
+++ b/src/xhtml.py
@@ -281,13 +281,15 @@ def trim(string):
return re.sub(whitespace_re, ' ', string)
class XHTMLHandler(sax.ContentHandler):
- def __init__(self):
+ def __init__(self, force_ns=False):
self.builder = []
self.formatting = []
self.attrs = []
self.list_state = []
self.is_pre = False
self.a_start = 0
+ # do not care about xhtml-in namespace
+ self.force_ns = force_ns
@property
def result(self):
@@ -305,7 +307,7 @@ class XHTMLHandler(sax.ContentHandler):
self.builder.append(characters if self.is_pre else trim(characters))
def startElementNS(self, name, _, attrs):
- if name[0] != XHTML_NS:
+ if name[0] != XHTML_NS and not self.force_ns:
return
builder = self.builder
@@ -356,7 +358,7 @@ class XHTMLHandler(sax.ContentHandler):
self.append_formatting('\x19b')
def endElementNS(self, name, _):
- if name[0] != XHTML_NS:
+ if name[0] != XHTML_NS and not self.force_ns:
return
builder = self.builder
@@ -387,13 +389,13 @@ class XHTMLHandler(sax.ContentHandler):
if 'title' in attrs:
builder.append(' [' + attrs['title'] + ']')
-def xhtml_to_poezio_colors(xml):
+def xhtml_to_poezio_colors(xml, force=False):
if isinstance(xml, str):
xml = xml.encode('utf8')
elif not isinstance(xml, bytes):
xml = ET.tostring(xml)
- handler = XHTMLHandler()
+ handler = XHTMLHandler(force_ns=force)
parser = sax.make_parser()
parser.setFeature(sax.handler.feature_namespaces, True)
parser.setContentHandler(handler)