Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 302170 Details for
Bug 441917
Escape characters in bigboard mail widget
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
go through all the steps to undo gmail's weirdness
gmail-unscrewage.patch (text/plain), 5.29 KB, created by
Colin Walters
on 2008-04-11 20:57:38 UTC
(
hide
)
Description:
go through all the steps to undo gmail's weirdness
Filename:
MIME Type:
Creator:
Colin Walters
Created:
2008-04-11 20:57:38 UTC
Size:
5.29 KB
patch
obsolete
>Index: bigboard/stocks/mail/MailStock.py >=================================================================== >--- bigboard/stocks/mail/MailStock.py (revision 7291) >+++ bigboard/stocks/mail/MailStock.py (working copy) >@@ -1,8 +1,13 @@ >-import logging, re, htmlentitydefs, time, urllib2 >+import logging, re, time, urllib2 > > import gobject, gtk > import hippo >+import xml.dom.minidom >+from xml.dom.minidom import Node >+from StringIO import StringIO > >+import simplejson >+ > from bigboard.stock import Stock > from bigboard.slideout import ThemedSlideout > import bigboard.google as google >@@ -16,48 +21,39 @@ > > _logger = logging.getLogger('bigboard.stocks.MailStock') > >-def remove_strange_tags(s, markup=False): >- if "\\u003cb\\>" in s: >- if markup == True: >- b = "<b>" >- e = "</b>" >+def gmail_jshtml_str_parse(s, markup=False): >+ # Convert the current data back into an ECMAScript string >+ jsstr = '"' + s + '"' >+ # These escape sequences are not legal ECMAScript; strip them >+ jsstr = jsstr.replace(r'\>', '>') >+ jsstr = jsstr.replace(r'\<', '<') >+ # Use an actual ECMAScript parser to turn it safely back into >+ # a Python string. >+ parsed_jsstr = simplejson.loads(jsstr) >+ # At this point, we have a Python unicode string which *should* hold >+ # an XML fragment. Convert that fragment into a document string. >+ pystr = "<html>" + parsed_jsstr + "</html>" >+ # Parse that document string into a DOM. >+ dom = xml.dom.minidom.parseString(pystr) >+ textContent = StringIO() >+ # Now we parse the XML, only allowing the bold tag through, and eating everything else >+ def DomToText(node): >+ if node.nodeType == Node.TEXT_NODE: >+ textContent.write(node.data) >+ if markup and node.nodeType == Node.ELEMENT_NODE and node.nodeName == 'b': >+ in_bold = True >+ textContent.write('<b>') > else: >- b = "" >- e = "" >- s = s.replace("\\u003cb\\>", b) >- s = s.replace("\\u003c/b\\>", e) >- return s >+ in_bold = False >+ if node.hasChildNodes(): >+ for child in node.childNodes: >+ DomToText(child) >+ if in_bold: >+ textContent.write('</b>') >+ DomToText(dom.documentElement) >+ # Return the sanely filtered content >+ return textContent.getvalue() > >-_CONVERT_ENTITIES_RE = re.compile("&(?:(#[0-9]+)|(#x[0-9A-Fa-f]+)|([A-Za-z]+));") >- >-def _convert_entity(m): >- try: >- if m.group(1) is not None: >- return unichr(int(m.group(1)[1:])) >- elif m.group(2) is not None: >- return unichr(int(m.group(2)[2:], 16)) >- else: >- return unichr(htmlentitydefs.name2codepoint[m.group(3)]) >- except ValueError: >- return m.group(0) >- except KeyError: >- return m.group(0) >- except OverflowError: >- return m.group(0) >- >-def convert_entities(s): >- """Replace standard HTML entities and numeric character references in the string""" >- return _CONVERT_ENTITIES_RE.sub(_convert_entity, s) >- >-# assert convert_entities("&") == "&" >-# assert convert_entities("&foo<") == "&foo<" >-# assert convert_entities("A") == "A" >-# assert convert_entities("A") == "A" >-# assert convert_entities("&zzz_amp;") == "&zzz_amp;" # not something we parse as an entity >-# assert convert_entities("&zzzamp;") == "&zzzamp;" # unknown entity >-# assert convert_entities("�") == "�" # not a unicode character >-# assert convert_entities("�") == "�" # overflow >- > class LabelSlideout(ThemedSlideout): > __gsignals__ = { > 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )), >@@ -94,7 +90,7 @@ > self.__header = Header(topborder=False) > self.id = thread.id > >- subject = remove_strange_tags(thread.subject) >+ subject = gmail_jshtml_str_parse(thread.subject) > > subject_box = hippo.CanvasText(classes='header', text=subject) > self.__header.append(subject_box, hippo.PACK_EXPAND) >@@ -106,9 +102,8 @@ > if type(value) is list: > s = ", ".join(value) > if type(value) is str: >- s = remove_strange_tags(value) >- >- s = convert_entities(s) >+ s = gmail_jshtml_str_parse(value) >+ > box = hippo.CanvasText(text=s, xalign=hippo.ALIGNMENT_START) > vbox.append(box) > >@@ -189,7 +184,7 @@ > for thread in threads: > if i >= self.__display_limit: break > >- subject = remove_strange_tags(thread.subject, True) >+ subject = gmail_jshtml_str_parse(thread.subject, True) > > box = PrelightingCanvasBox() > box.connect("button-press-event", self.create_email_slideout, thread) >@@ -246,3 +241,10 @@ > > def __on_more_button(self): > libbig.show_url("http://mail.google.com/mail") >+ >+if __name__ == '__main__': >+ # We want to keep bold tags >+ assert gmail_jshtml_str_parse(r'test \u003cb\>hi\u003c/b\> moo', True) == 'test <b>hi</b> moo' >+ # Strip unknown tag "A" >+ assert gmail_jshtml_str_parse(r'test \u003ca\>hi\u003c/a\> moo', True) == 'test hi moo' >+ >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 441917
: 302170