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
def send_message(self, mess): if self.connected: m = utf8(mess.getBody()) if m[-1] != '\n': m+='\n' self.msg(mess.getTo().node, m) else: logging.debug("Zapped message because the backend is not connected yet %s" % mess.getBody())
def send_message(self, mess): if self.connected: m = utf8(mess.getBody()) if m[-1] != '\n': m += '\n' self.msg(mess.getTo().node, m) else: logging.debug( "Zapped message because the backend is not connected yet %s" % mess.getBody())
def send_api_message(self, room_id, fr, message, message_format='html'): base = {'format': 'json', 'auth_token': self.token} red_data = { 'room_id': room_id, 'from': fr, 'message': utf8(message), 'message_format': message_format } req = Request(url=HIPCHAT_MESSAGE_URL + '?' + urlencode(base), data=urlencode(red_data)) return json.load(urlopen(req))
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
def send_message(self, mess): global irc_message_lock if self.connected: m = utf8(mess.getBody()) if m[-1] != '\n': m += '\n' with irc_message_lock: if mess.typ == 'chat' and mess.getTo().resource: # if this is a response in private of a public message take the recipient in the resource instead of the incoming chatroom to = mess.getTo().resource else: to = mess.getTo().node self.lineRate = self.channel_rate if to.startswith('#') else self.private_rate self.msg(to, m) else: logging.debug("Zapped message because the backend is not connected yet %s" % mess.getBody())
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
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
def build_message(text, message_class, conversion_function=None): """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) text = text.replace('', '*') # there is a weird chr IRC is sending that we need to filter out XML2Node(text) # test if is it xml edulcorated_html = conversion_function(text) if conversion_function else text try: text_plain, node = build_text_html_message_pair(edulcorated_html) message = message_class(body=text_plain) message.addChild(node=node) except ExpatError as ee: logging.error('Error translating to hipchat [%s] Parsing error = [%s]' % (edulcorated_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_class(body=text) return message
def build_message(self, text): txt, node = build_text_html_message_pair(utf8(text)) msg = Message(txt, html=node) if node else Message(txt) msg.setFrom(self.jid) return msg # rebuild a pure html snippet to include directly in the console html
def send_api_message(self, room_id, fr, message, message_format='html'): base = {'format': 'json', 'auth_token': self.token} red_data = {'room_id': room_id, 'from': fr, 'message': utf8(message), 'message_format': message_format} req = Request(url=HIPCHAT_MESSAGE_URL + '?' + urlencode(base), data=urlencode(red_data)) return json.load(urlopen(req))
def send_message(self, mess): if self.connected: self.msg(mess.getTo(), utf8(mess.getBody())) else: logging.debug("Zapped message because the backend is not connected yet %s" % mess.getBody())