Exemple #1
0
 def build_message(self, text):
     try:
         node = XML2Node(utf8(text))
         text_plain = xhtml2txt(text)
         logging.debug('Plain Text translation from XHTML-IM:\n%s' % text_plain)
         message = Message(body=utf8(text_plain))
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=utf8(text))
     return message
Exemple #2
0
    def build_text_html_message_pair(self, source):
        node = None
        text_plain = None

        try:
            node = XML2Node(utf8(source))
            text_plain = xhtml2txt(source)
        except ExpatError as ee:
            if source.strip(): # avoids keep alive pollution
                logging.debug('Could not parse [%s] as XHTML-IM, assume pure text Parsing error = [%s]' % (source, ee))
                text_plain = source
        return text_plain, node
Exemple #3
0
Fichier : base.py Projet : qznc/err
def build_text_html_message_pair(source):
    node = None
    text_plain = None

    try:
        node = ET.XML(source)
        text_plain = xhtml2txt(source)
    except ParseError as ee:
        if source.strip():  # avoids keep alive pollution
            logging.debug('Could not parse [%s] as XHTML-IM, assume pure text Parsing error = [%s]' % (source, ee))
            text_plain = source
    return text_plain, node
Exemple #4
0
 def build_message(self, text):
     try:
         node = XML2Node(utf8(text))
         text_plain = xhtml2txt(text)
         logging.debug('Plain Text translation from XHTML-IM:\n%s' %
                       text_plain)
         message = Message(body=utf8(text_plain))
     except ExpatError as ee:
         if text.strip():  # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' %
                           (text, ee))
         message = Message(body=utf8(text))
     return message
Exemple #5
0
def build_text_html_message_pair(source):
    node = None
    text_plain = None

    try:
        node = ET.XML(source)
        text_plain = xhtml2txt(source)
    except ParseError as ee:
        if source.strip():  # avoids keep alive pollution
            log.debug('Could not parse [%s] as XHTML-IM, assume pure text Parsing error = [%s]' % (source, ee))
            text_plain = source
    except UnicodeEncodeError:
        text_plain = source
    return text_plain, node
Exemple #6
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         node = XML2Node(text)
         # logging.debug('This message is XML : %s' % text)
         text_plain = xhtml2txt(text)
         logging.debug('Plain Text translation from XHTML-IM:\n%s' % text_plain)
         message = Message(body=text_plain)
         message.addChild(node = node)
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Exemple #7
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         node = XML2Node(text)
         # logging.debug('This message is XML : %s' % text)
         text_plain = xhtml2txt(text)
         logging.debug('Plain Text translation from XHTML-IM:\n%s' %
                       text_plain)
         message = Message(body=text_plain)
         message.addChild(node=node)
     except ExpatError as ee:
         if text.strip():  # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' %
                           (text, ee))
         message = Message(body=text)
     return message
Exemple #8
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         text = utf8(text)
         XML2Node(text) # test if is it xml
         # yes, ok epurate it for hipchat
         try:
             hipchat_html = xhtml2hipchat(text)
             node = XML2Node(hipchat_html)
             message = Message(body=xhtml2txt(text))
             message.addChild(node = node)
         except ExpatError as ee:
             logging.error('Error translating to hipchat [%s] Parsing error = [%s]' % (hipchat_html, ee))
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Exemple #9
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     message = None # keeps the compiler happy
     try:
         text = utf8(text)
         XML2Node(text) # test if is it xml
         # yes, ok epurate it for hipchat
         hipchat_html = xhtml2hipchat(text)
         try:
             node = XML2Node(hipchat_html)
             message = Message(body=xhtml2txt(text))
             message.addChild(node = node)
         except ExpatError as ee:
             logging.error('Error translating to hipchat [%s] Parsing error = [%s]' % (hipchat_html, ee))
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Exemple #10
0
Fichier : base.py Projet : edux/err
    def build_message(self, text):
        """ You might want to override this one depending on your backend """
        # the default implementation gets the text, check if it is parseable in
        # xhtml
        # if yes, tries to reconstruct a text version of it.

        node = None
        try:
            if PY2:
                node = ET.XML(text.encode('utf-8'))  # test if is it xml
            else:
                node = ET.XML(text)

            text = xhtml2txt(text)
        except ET.ParseError as ee:
            if text.strip():  # avoids keep alive pollution
                log.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))

        message = Message(body=text)
        if node:
            message.html = node
        return message