def msg(self, channel, message): """ Send a message over XMPP to the specified channel. Channels prefixed with '#' are assumed to be multi user chat rooms, otherwise, they are assumed to be individual users. :param channel: The XMPP channel to send the message to. A channel not prefixed by a '#' will be sent as a private message to a user with that nick. :param message: The message to send """ logger.debug('[-->] %s - %s', channel, message) is_public = self.is_public_channel(channel) if is_public: resp_host = self.conference_host resp_type = 'groupchat' else: resp_host = self.jid.host resp_type = 'chat' resp_channel = '{user}@{host}'.format(user=channel, host=resp_host).lstrip('#') # Create the response <message/> element element = domish.Element(('jabber:client', 'message'), attribs={ 'to': resp_channel, 'from': self.jid.full(), 'type': resp_type, }) element.addElement('body', content=encodings.to_unicode(message)) self.stream.send(element)
def jira_match(client, channel, nick, message, matches): jira_url = to_unicode(settings.JIRA_URL) full_urls = dict(map(lambda s: (s, jira_url.format(ticket=s)), matches)) if not getattr(settings, 'JIRA_SHOW_FULL_DESCRIPTION', True): return u'{0} might be talking about JIRA ticket: {1}'.format(nick, ', '.join(full_urls.values())) # Otherwise, do the fetching with a deferred reactor.callLater(0, jira_full_descriptions, client, channel, full_urls) raise ResponseNotReady
def jira_match(client, channel, nick, message, matches): jira_url = to_unicode(settings.JIRA_URL) full_urls = dict(map(lambda s: (s, jira_url.format(ticket=s)), matches)) if not getattr(settings, 'JIRA_SHOW_FULL_DESCRIPTION', True): return u'{0} might be talking about JIRA ticket: {1}'.format( nick, ', '.join(full_urls.values())) # Otherwise, do the fetching with a deferred reactor.callLater(0, jira_full_descriptions, client, channel, full_urls) raise ResponseNotReady
def _rest_desc(ticket, url, auth=None): api_url = to_unicode(settings.JIRA_REST_API) resp = requests.get(api_url.format(ticket=ticket), auth=auth) try: resp.raise_for_status() except: logger.error('Error getting JIRA ticket %s. Status %s', ticket, resp.status_code) return try: return u'[{0}] {1} ({2})'.format(ticket.upper(), resp.json()['fields']['summary'], url) except: return u'[{0}] {1}'.format(ticket.upper(), url)
def test_to_unicode_with_unicode_string(): snowman = u'☃' retval = to_unicode(snowman) assert snowman == retval assert isinstance(retval, unicode)
def test_to_unicode_with_byte_string(): snowman = u'☃' bytes = '\xe2\x98\x83' retval = to_unicode(bytes) assert snowman == retval assert isinstance(retval, unicode)