def send_message(self, to_jid_list, message, html_message=None, atom_message=None): if settings.IM_TEST_ONLY: to_jid_list = [x for x in to_jid_list if x.base() in settings.IM_TEST_JIDS] raw_xml = False message = encoding.smart_str(message) body = message if html_message or atom_message: raw_xml = True body_builder = ["<body>%s</body>" % (html.escape(body.strip())),] if html_message: html_message = encoding.smart_str(html_message) body_builder.append(html_message) if atom_message: atom_message = encoding.smart_str(atom_message) body_builder.append(atom_message) body = u'\n'.join([encoding.smart_unicode(x) for x in body_builder]) body = body.encode('ascii', 'xmlcharrefreplace') xmpp_service = component.best['xmpp_service'] xmpp_service.send_message([j.base() for j in to_jid_list], body, raw_xml=raw_xml)
def string_length(value, message="Must be between %(max)s and %(min)s characters", max_length=None, min_length=None): value = encoding.smart_unicode(value) value_length = len(value) message % {'max': max_length, 'min': min_length, 'length': value_length} if max_length is not None and value_length > max_length: raise exception.ValidationError(message) if min_length is not None and value_length < min_length: raise exception.ValidationError(message) return value
def nick(value, message='Invalid nick'): """ expects to get a nick in one of the following forms: popular #popular [email protected] #[email protected] """ value = encoding.smart_unicode(value) try: return user(value, message=message) except exception.ValidationError: return channel(value, message=message)
def user(value, message='Invalid nick'): """ expects to get a nick in one of the following forms: popular [email protected] """ value = encoding.smart_unicode(value) if not value.endswith('@%s' % settings.NS_DOMAIN): value = '%s@%s' % (value, settings.NS_DOMAIN) match = USER_COMPILED.match(value) if not match: raise exception.ValidationError(message) return value
def channel(value, message='Invalid channel name'): """ expects to get a channel in one of the following forms: popular #popular #[email protected] """ value = encoding.smart_unicode(value) if not value.startswith('#'): value = '#%s' % value if not value.endswith('@%s' % settings.NS_DOMAIN): value = '%s@%s' % (value, settings.NS_DOMAIN) match = channel_re.match(value) if not match: raise exception.ValidationError(message) return value