def from_element(e): disco = SubscriptionsDiscovery(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for c in e.xml_children: if not isinstance(c, E): continue if c.xml_ns == XMPP_PUBSUB_NS and c.xml_name == 'pubsub': for p in c.xml_children: if not isinstance(p, E): continue if p.xml_ns == XMPP_PUBSUB_NS and p.xml_name == 'subscriptions': for s in p.xml_children: if not isinstance(s, E): continue jid = s.get_attribute_value('jid', None) if jid: JID.parse(jid) sub = Subscription(s.get_attribute_value('node'), jid, s.get_attribute_value('subscription')) disco.subscriptions.append(sub) elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': disco.error = Error.from_element(c) return disco
def from_element(e): disco = FeaturesDiscovery(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for c in e.xml_children: if not isinstance(c, E): continue if c.xml_ns in [XMPP_DISCO_INFO_NS, XMPP_DISCO_ITEMS_NS]: for i in c.xml_children: if i.xml_ns in [XMPP_DISCO_INFO_NS, XMPP_DISCO_ITEMS_NS]: if i.xml_name == 'identity': ident = Identity(i.get_attribute_value('name'), i.get_attribute_value('category'), i.get_attribute_value('type')) disco.identities.append(ident) elif i.xml_name == 'feature': feat = Feature(i.get_attribute_value('var')) disco.features.append(feat) elif i.xml_name == 'item': jid = JID.parse(unicode(i.get_attribute_value('jid'))) item = Item(jid, i.get_attribute_value('action'), i.get_attribute_value('name'), i.get_attribute_value('node')) disco.items.append(item) elif i.xml_ns == XMPP_DATA_FORM_NS: disco.x = Data.from_element(i) elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': disco.error = Error.from_element(c) return disco
def from_element(e): registration = Registration(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) error = e.get_child('error', XMPP_CLIENT_NS) if error: registration.error = Error.from_element(error) query = e.get_child('query', XMPP_IBR_NS) for c in query.xml_children: if not isinstance(c, E): continue if c.xml_ns == XMPP_DATA_FORM_NS: registration.x = Date.from_element(c) elif c.xml_ns == XMPP_IBR_NS: if c.xml_name == 'remove': registration.remove = True elif c.xml_name == 'registered': registration.registered = True else: registration.infos[c.xml_name] = c.xml_text return registration
def from_purge_element(e): node = Node(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for i in e.xml_children: if i.xml_ns in [XMPP_PUBSUB_OWNER_NS]: for p in i.xml_children: if p.xml_ns in [XMPP_PUBSUB_OWNER_NS]: if p.xml_name == 'purge': node.node_name = p.get_attribute_value('node') elif i.xml_ns == XMPP_CLIENT_NS and i.xml_name == 'error': node.error = Error.from_element(i) return node
def from_element(e): r = Roster(JID.parse(e.xml_parent.get_attribute_value('from')), JID.parse(e.xml_parent.get_attribute_value('to'))) for child in e.xml_children: if child.xml_name == 'item': jid = JID.parse(unicode(child.get_attribute('jid'))) nodeid = jid.nodeid() item = Item(jid) item.name = child.get_attribute_value('name') groups = child.get_children('group', ns=child.xml_ns) or [] for group in groups: if group.xml_text: item.groups.append(group.xml_text) item.subscription = child.get_attribute_value('subscription') r.items[nodeid] = item return r
def from_unsubscription_element(e): sub = Node(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for i in e.xml_children: if i.xml_ns in [XMPP_PUBSUB_NS]: for p in i.xml_children: if p.xml_ns in [XMPP_PUBSUB_NS]: if p.xml_name == 'subscribe': sub.node_name = p.get_attribute_value('node') sub.sub_jid = p.get_attribute_value('jid') elif i.xml_ns == XMPP_CLIENT_NS and i.xml_name == 'error': sub.error = Error.from_element(i) return sub
def from_element(e): activity = Activity( JID.parse(e.get_attribute_value("from")), JID.parse(e.get_attribute_value("to")), e.get_attribute_value("type"), e.get_attribute_value("id"), ) for child in e.xml_children: if not isinstance(child, E): continue if child.xml_ns == XMPP_LAST_NS: seconds = child.get_attribute_value("seconds") if seconds != None: activity.seconds = long(seconds) activity.message = child.xml_text return activity
def from_element(e): message = Message(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), e.get_attribute_value('type'), e.get_attribute_value('id'), e.get_attribute_value('lang')) for child in e.xml_children: if not isinstance(child, E): continue if child.xml_ns == XMPP_EVENT_NS: if child.has_child('offline', XMPP_EVENT_NS): message.event = Event.offline if child.has_child('composing', XMPP_EVENT_NS): message.event = Event.composing if child.has_child('delivered', XMPP_EVENT_NS): message.event = Event.delivered if child.has_child('displayed', XMPP_EVENT_NS): message.event = Event.displayed elif child.xml_ns == XMPP_CLIENT_NS: if child.xml_name == 'body': lang = child.get_attribute_value('lang') data = child.collapse(separator='') b = Body(unescape(data), lang=lang) message.bodies.append(b) elif child.xml_name == 'subject': lang = child.get_attribute_value('lang') data = child.xml_text or '' b = Subject(unescape(data), lang=lang) message.subjects.append(b) elif child.xml_name == 'thread': message.thread = child.xml_text if child.xml_name == 'html' and child.xml_ns == XMPP_XHTML_IM_N: b = XHTMLBody(child.xml_children.clone()) message.bodies.append(b) else: message.foreign.append(Foreign(child)) else: message.foreign.append(Foreign(child)) return message
def from_element(e): msg = Message(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to'))) for c in e.xml_children: if c.xml_ns == XMPP_PUBSUB_EVENT_NS: # x or event for i in c.xml_children: if i.xml_ns == XMPP_PUBSUB_EVENT_NS: # items msg.node_name = i.get_attribute_value('node') msg.event = i.xml_name if msg.event == 'items': for t in i.xml_children: # item payload = None if t.xml_children: payload = t.xml_children msg.items.append(Item(id=t.get_attribute_value('id'), payload=payload, eventType=t.xml_name)) return msg
def from_retract_element(e): node = Node(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for i in e.xml_children: if i.xml_ns in [XMPP_PUBSUB_NS]: for p in i.xml_children: if p.xml_ns in [XMPP_PUBSUB_NS]: if p.xml_name == 'retract': node.node_name = p.get_attribute_value('node') for q in p.xml_children: if q.xml_name == 'item': node.item = Item(q.get_attribute_value('id')) elif i.xml_ns == XMPP_CLIENT_NS and i.xml_name == 'error': node.error = Error.from_element(i) return node
def from_element(e): p = Presence(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), e.get_attribute_value('type', None)) for child in e.xml_children: if isinstance(child, unicode): continue if child.xml_ns == XMPP_CLIENT_NS: if child.xml_name == 'show': p.show = child.xml_text elif child.xml_name == 'status': p.status = child.xml_text elif child.xml_name == 'priority': p.priority = int(child.xml_text) else: p.foreign.append(Foreign(child)) return p
def from_element(e): p = Profile(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type', None), stanza_id=e.get_attribute_value('id')) error = e.get_child('error', XMPP_CLIENT_NS) if error: registration.error = Error.from_element(error) profile = e.get_child('profile', XMPP_USER_PROFILE_NS) for c in profile.xml_children: if not isinstance(c, E): continue if c.xml_ns == XMPP_DATA_FORM_NS: p.x = Date.from_element(c) return p
def from_publication_element(e): node = Node(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for i in e.xml_children: if i.xml_ns in [XMPP_PUBSUB_NS]: for p in i.xml_children: if p.xml_ns in [XMPP_PUBSUB_NS]: if p.xml_name == 'publish': node.node_name = p.get_attribute_value('node') for q in p.xml_children: if q.xml_name == 'item': payload = None if q.xml_children: payload = q.xml_children[0].clone() node.item = Item(q.get_attribute_value('id'), payload) elif i.xml_ns == XMPP_CLIENT_NS and i.xml_name == 'error': node.error = Error.from_element(i) return node
def _handle_jid(self, e): self.log(e) self.jid = JID.parse(e.xml_text) self.status = ACTIVE self.send(self.jid, 'jid') # Sends the initial presence information to the server self.propagate(element=Stanza.to_element(Stanza(u'presence'))) # Asks immediatly for the client's roster list iq = Iq.create_get_iq(from_jid=unicode(self.jid), stanza_id=generate_unique()) E(u'query', namespace=XMPP_ROSTER_NS, parent=iq) self.propagate(element=iq)
def from_element(e): disco = ItemsDiscovery(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for c in e.xml_children: if not isinstance(c, E): continue if c.xml_ns in [XMPP_DISCO_ITEMS_NS]: if c.xml_name == 'query': disco.node_name = c.get_attribute_value('node') for i in c.xml_children: if i.xml_name == 'item' and i.xml_ns in [XMPP_DISCO_ITEMS_NS]: jid = JID.parse(unicode(i.get_attribute_value('jid'))) item = Item(jid, i.get_attribute_value('action'), i.get_attribute_value('name'), disco.node_name) disco.items.append(item) elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': disco.error = Error.from_element(c) return disco
def __init__(self, username, password, domain, resource=u"headstock-client1", server=u'localhost', port=5222, usetls=False, register=False, log='/home/jason/chat.log'): super(Client, self).__init__() self.jid = JID(username, domain, resource) self.username = username self.password = password self.server = server self.port = port self.client = None self.graph = None self.domain = domain self.usetls = usetls self.register = register self.log_location = log
def from_element(e): disco = AffiliationsDiscovery(JID.parse(e.get_attribute_value('from')), JID.parse(e.get_attribute_value('to')), type=e.get_attribute_value('type'), stanza_id=e.get_attribute_value('id')) for c in e.xml_children: if not isinstance(c, E): continue if c.xml_ns == XMPP_PUBSUB_NS and c.xml_name == 'pubsub': for p in c.xml_children: if not isinstance(p, E): continue if p.xml_ns == XMPP_PUBSUB_NS and p.xml_name == 'affiliations': for s in p.xml_children: if not isinstance(s, E): continue aff = Affiliation(s.get_attribute_value('node'), s.get_attribute_value('affiliation')) disco.affiliations.append(aff) elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': disco.error = Error.from_element(c) return disco
def from_element(e): message = Message() from_jid = e.get_attribute_value('from') message.sender = JID.parse(from_jid) body = e.get_children('body', e.xml_ns) or [] for chunk in body: message.body.append(unicode(chunk)) subjects = e.get_children('subject', e.xml_ns) or [] for chunk in subjects: message.body.append(unicode(chunk)) return message