Search is not available for this dataset
text
stringlengths
75
104k
def __get_reported(self, xmlnode): """Parse the <reported/> element of the form. :Parameters: - `xmlnode`: the element to parse. :Types: - `xmlnode`: `libxml2.xmlNode`""" child = xmlnode.children while child: if child.type != "element" or chil...
def register_disco_cache_fetchers(cache_suite,stream): """Register Service Discovery cache fetchers into given cache suite and using the stream provided. :Parameters: - `cache_suite`: the cache suite where the fetchers are to be registered. - `stream`: the stream to be used by the...
def remove(self): """Remove `self` from the containing `DiscoItems` object.""" if self.disco is None: return self.xmlnode.unlinkNode() oldns=self.xmlnode.ns() ns=self.xmlnode.newNs(oldns.getContent(),None) self.xmlnode.replaceNs(oldns,ns) common_root.a...
def set_name(self, name): """Set the name of the item. :Parameters: - `name`: the new name or `None`. :Types: - `name`: `unicode` """ if name is None: if self.xmlnode.hasProp("name"): self.xmlnode.unsetProp("name") return ...
def set_node(self,node): """Set the node of the item. :Parameters: - `node`: the new node or `None`. :Types: - `node`: `unicode` """ if node is None: if self.xmlnode.hasProp("node"): self.xmlnode.unsetProp("node") r...
def set_action(self,action): """Set the action of the item. :Parameters: - `action`: the new action or `None`. :Types: - `action`: `unicode` """ if action is None: if self.xmlnode.hasProp("action"): self.xmlnode.unsetProp("acti...
def get_name(self): """Get the name of the item. :return: the name of the item or `None`. :returntype: `unicode`""" var = self.xmlnode.prop("name") if not var: var = "" return var.decode("utf-8")
def set_name(self,name): """Set the name of the item. :Parameters: - `name`: the new name or `None`. :Types: - `name`: `unicode` """ if not name: raise ValueError("name is required in DiscoIdentity") name = unicode(name) self.xmlnode.s...
def get_category(self): """Get the category of the item. :return: the category of the item. :returntype: `unicode`""" var = self.xmlnode.prop("category") if not var: var = "?" return var.decode("utf-8")
def set_category(self, category): """Set the category of the item. :Parameters: - `category`: the new category. :Types: - `category`: `unicode` """ if not category: raise ValueError("Category is required in DiscoIdentity") category = unicode(c...
def get_type(self): """Get the type of the item. :return: the type of the item. :returntype: `unicode`""" item_type = self.xmlnode.prop("type") if not item_type: item_type = "?" return item_type.decode("utf-8")
def set_type(self, item_type): """Set the type of the item. :Parameters: - `item_type`: the new type. :Types: - `item_type`: `unicode` """ if not item_type: raise ValueError("Type is required in DiscoIdentity") item_type = unicode(item_type) ...
def get_items(self): """Get the items contained in `self`. :return: the items contained. :returntype: `list` of `DiscoItem`""" ret=[] l=self.xpath_ctxt.xpathEval("d:item") if l is not None: for i in l: ret.append(DiscoItem(self, i)) re...
def set_items(self, item_list): """Set items in the disco#items object. All previous items are removed. :Parameters: - `item_list`: list of items or item properties (jid,node,name,action). :Types: - `item_list`: sequence of `DiscoItem` or sequence ...
def add_item(self,jid,node=None,name=None,action=None): """Add a new item to the `DiscoItems` object. :Parameters: - `jid`: item JID. - `node`: item node name. - `name`: item name. - `action`: action for a "disco push". :Types: - `jid`...
def has_item(self,jid,node=None): """Check if `self` contains an item. :Parameters: - `jid`: JID of the item. - `node`: node name of the item. :Types: - `jid`: `JID` - `node`: `libxml2.xmlNode` :return: `True` if the item is found in `sel...
def get_features(self): """Get the features contained in `self`. :return: the list of features. :returntype: `list` of `unicode`""" l = self.xpath_ctxt.xpathEval("d:feature") ret = [] for f in l: if f.hasProp("var"): ret.append( f.prop("var")....
def set_features(self, features): """Set features in the disco#info object. All existing features are removed from `self`. :Parameters: - `features`: list of features. :Types: - `features`: sequence of `unicode` """ for var in self.features: ...
def has_feature(self,var): """Check if `self` contains the named feature. :Parameters: - `var`: the feature name. :Types: - `var`: `unicode` :return: `True` if the feature is found in `self`. :returntype: `bool`""" if not var: raise V...
def add_feature(self,var): """Add a feature to `self`. :Parameters: - `var`: the feature name. :Types: - `var`: `unicode`""" if self.has_feature(var): return n=self.xmlnode.newChild(None, "feature", None) n.setProp("var", to_utf8(var))
def remove_feature(self,var): """Remove a feature from `self`. :Parameters: - `var`: the feature name. :Types: - `var`: `unicode`""" if not var: raise ValueError("var is None") if '"' not in var: expr='d:feature[@var="%s"]' % (var,...
def get_identities(self): """List the identity objects contained in `self`. :return: the list of identities. :returntype: `list` of `DiscoIdentity`""" ret=[] l=self.xpath_ctxt.xpathEval("d:identity") if l is not None: for i in l: ret.append(Di...
def set_identities(self,identities): """Set identities in the disco#info object. Remove all existing identities from `self`. :Parameters: - `identities`: list of identities or identity properties (jid,node,category,type,name). :Types: - `identities...
def identity_is(self,item_category,item_type=None): """Check if the item described by `self` belongs to the given category and type. :Parameters: - `item_category`: the category name. - `item_type`: the type name. If `None` then only the category is checked...
def add_identity(self,item_name,item_category=None,item_type=None): """Add an identity to the `DiscoInfo` object. :Parameters: - `item_name`: name of the item. - `item_category`: category of the item. - `item_type`: type of the item. :Types: - `it...
def fetch(self): """Initialize the Service Discovery process.""" from ..iq import Iq jid,node = self.address iq = Iq(to_jid = jid, stanza_type = "get") disco = self.disco_class(node) iq.add_content(disco.xmlnode) self.stream.set_response_handlers(iq,self.__respons...
def __response(self,stanza): """Handle successful disco response. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `pyxmpp.stanza.Stanza`""" try: d=self.disco_class(stanza.get_query()) self.got_it(d) except ValueEr...
def __error(self,stanza): """Handle disco error response. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `pyxmpp.stanza.Stanza`""" try: self.error(stanza.get_error()) except ProtocolError: from ..error import Sta...
def make_error_response(self, cond): """Create error response for the a "get" or "set" iq stanza. :Parameters: - `cond`: error condition name, as defined in XMPP specification. :return: new `Iq` object with the same "id" as self, "from" and "to" attributes swapped, type...
def make_result_response(self): """Create result response for the a "get" or "set" iq stanza. :return: new `Iq` object with the same "id" as self, "from" and "to" attributes replaced and type="result". :returntype: `Iq`""" if self.stanza_type not in ("set", "get"): ...
def add_payload(self, payload): """Add new the stanza payload. Fails if there is already some payload element attached (<iq/> stanza can contain only one payload element) Marks the stanza dirty. :Parameters: - `payload`: XML element or stanza payload object to add ...
def make_stream_tls_features(self, stream, features): """Update the <features/> element with StartTLS feature. [receving entity only] :Parameters: - `features`: the <features/> element of the stream. :Types: - `features`: :etree:`ElementTree.Element` :r...
def handle_stream_features(self, stream, features): """Process incoming StartTLS related element of <stream:features/>. [initiating entity only] """ if self.stream and stream is not self.stream: raise ValueError("Single StreamTLSHandler instance can handle" ...
def _request_tls(self): """Request a TLS-encrypted connection. [initiating entity only]""" self.requested = True element = ElementTree.Element(STARTTLS_TAG) self.stream.write_element(element)
def _process_tls_proceed(self, stream, element): """Handle the <proceed /> element. """ # pylint: disable-msg=W0613 if not self.requested: logger.debug("Unexpected TLS element: {0!r}".format(element)) return False logger.debug(" tls: <proceed/> received") ...
def _make_tls_connection(self): """Initiate TLS connection. [initiating entity only] """ logger.debug("Preparing TLS connection") if self.settings["tls_verify_peer"]: cert_reqs = ssl.CERT_REQUIRED else: cert_reqs = ssl.CERT_NONE self.strea...
def handle_tls_connected_event(self, event): """Verify the peer certificate on the `TLSConnectedEvent`. """ if self.settings["tls_verify_peer"]: valid = self.settings["tls_verify_callback"](event.stream, event.peer_certificate) ...
def is_certificate_valid(stream, cert): """Default certificate verification callback for TLS connections. :Parameters: - `cert`: certificate information :Types: - `cert`: `CertificateData` :return: computed verification result. """ try: ...
def main(): """Parse the command-line arguments and run the tool.""" parser = argparse.ArgumentParser(description = 'XMPP version checker', parents = [XMPPSettings.get_arg_parser()]) parser.add_argument('source', metavar = 'SOURCE', ...
def handle_authorized(self, event): """Send the initial presence after log-in.""" request_software_version(self.client, self.target_jid, self.success, self.failure)
def set_item(self, key, value, timeout = None, timeout_callback = None): """Set item of the dictionary. :Parameters: - `key`: the key. - `value`: the object to store. - `timeout`: timeout value for the object (in seconds from now). - `timeout_callback`: f...
def expire(self): """Do the expiration of dictionary items. Remove items that expired by now from the dictionary. :Return: time, in seconds, when the next item expires or `None` :returntype: `float` """ with self._lock: logger.debug("expdict.expire. timeouts...
def _expire_item(self, key): """Do the expiration of a dictionary item. Remove the item if it has expired by now. :Parameters: - `key`: key to the object. :Types: - `key`: any hashable value """ (timeout, callback) = self._timeouts[key] n...
def _decode_attributes(self): """Decode attributes of the stanza XML element and put them into the stanza properties.""" try: from_jid = self._element.get('from') if from_jid: self._from_jid = JID(from_jid) to_jid = self._element.get('to') ...
def _decode_error(self): """Decode error element of the stanza.""" error_qname = self._ns_prefix + "error" for child in self._element: if child.tag == error_qname: self._error = StanzaErrorElement(child) return raise BadRequestProtocolError("Er...
def copy(self): """Create a deep copy of the stanza. :returntype: `Stanza`""" result = Stanza(self.element_name, self.from_jid, self.to_jid, self.stanza_type, self.stanza_id, self.error, self._return_path()) if self._payload is None: ...
def as_xml(self): """Return the XML stanza representation. Always return an independent copy of the stanza XML representation, which can be freely modified without affecting the stanza. :returntype: :etree:`ElementTree.Element`""" attrs = {} if self._from_jid: ...
def get_xml(self): """Return the XML stanza representation. This returns the original or cached XML representation, which may be much more efficient than `as_xml`. Result of this function should never be modified. :returntype: :etree:`ElementTree.Element`""" if not sel...
def decode_payload(self, specialize = False): """Decode payload from the element passed to the stanza constructor. Iterates over stanza children and creates StanzaPayload objects for them. Called automatically by `get_payload()` and other methods that access the payload. For th...
def set_payload(self, payload): """Set stanza payload to a single item. All current stanza content of will be dropped. Marks the stanza dirty. :Parameters: - `payload`: XML element or stanza payload object to use :Types: - `payload`: :etree:`ElementTree....
def add_payload(self, payload): """Add new the stanza payload. Marks the stanza dirty. :Parameters: - `payload`: XML element or stanza payload object to add :Types: - `payload`: :etree:`ElementTree.Element` or `StanzaPayload` """ if self._payload...
def get_all_payload(self, specialize = False): """Return list of stanza payload objects. :Parameters: - `specialize`: If `True`, then return objects of specialized `StanzaPayload` classes whenever possible, otherwise the representation already available will be u...
def get_payload(self, payload_class, payload_key = None, specialize = False): """Get the first payload item matching the given class and optional key. Payloads may be addressed using a specific payload class or via the generic `XML...
def element_to_unicode(element): """Serialize an XML element into a unicode string. This should work the same on Python2 and Python3 and with all :etree:`ElementTree` implementations. :Parameters: - `element`: the XML element to serialize :Types: - `element`: :etree:`ElementTree.El...
def make_stream_features(self, stream, features): """Add resource binding feature to the <features/> element of the stream. [receving entity only] :returns: update <features/> element. """ self.stream = stream if stream.peer_authenticated and not stream.peer.res...
def handle_stream_features(self, stream, features): """Process incoming <stream:features/> element. [initiating entity only] The received features element is available in `features`. """ logger.debug(u"Handling stream features: {0}".format( ...
def bind(self, stream, resource): """Bind to a resource. [initiating entity only] :Parameters: - `resource`: the resource name to bind to. :Types: - `resource`: `unicode` XMPP stream is authenticated for bare JID only. To use the full JID it mus...
def _bind_success(self, stanza): """Handle resource binding success. [initiating entity only] :Parameters: - `stanza`: <iq type="result"/> stanza received. Set `streambase.StreamBase.me` to the full JID negotiated.""" # pylint: disable-msg=R0201 payload = s...
def handle_bind_iq_set(self, stanza): """Handler <iq type="set"/> for resource binding.""" # pylint: disable-msg=R0201 if not self.stream: logger.error("Got bind stanza before stream feature has been set") return False if self.stream.initiator: return ...
def serialize(element): """Serialize an XMPP element. Utility function for debugging or logging. :Parameters: - `element`: the element to serialize :Types: - `element`: :etree:`ElementTree.Element` :Return: serialized element :Returntype: `unicode` ...
def add_prefix(self, namespace, prefix): """Add a new namespace prefix. If the root element has not yet been emitted the prefix will be declared there, otherwise the prefix will be declared on the top-most element using this namespace in every stanza. :Parameters: -...
def emit_head(self, stream_from, stream_to, stream_id = None, version = u'1.0', language = None): """Return the opening tag of the stream root element. :Parameters: - `stream_from`: the 'from' attribute of the stream. May be `None`. - ...
def _split_qname(self, name, is_element): """Split an element of attribute qname into namespace and local name. :Parameters: - `name`: element or attribute QName - `is_element`: `True` for an element, `False` for an attribute :Types: - `name`: `unicod...
def _make_prefix(self, declared_prefixes): """Make up a new namespace prefix, which won't conflict with `_prefixes` and prefixes declared in the current scope. :Parameters: - `declared_prefixes`: namespace to prefix mapping for the current scope :Types: ...
def _make_prefixed(self, name, is_element, declared_prefixes, declarations): """Return namespace-prefixed tag or attribute name. Add appropriate declaration to `declarations` when neccessary. If no prefix for an element namespace is defined, make the elements namespace default (no pref...
def _make_ns_declarations(declarations, declared_prefixes): """Build namespace declarations and remove obsoleted mappings from `declared_prefixes`. :Parameters: - `declarations`: namespace to prefix mapping of the new declarations - `declared_prefixes`: nam...
def _emit_element(self, element, level, declared_prefixes): """"Recursive XML element serializer. :Parameters: - `element`: the element to serialize - `level`: nest level (0 - root element, 1 - stanzas, etc.) - `declared_prefixes`: namespace to prefix mapping of alre...
def emit_stanza(self, element): """"Serialize a stanza. Must be called after `emit_head`. :Parameters: - `element`: the element to serialize :Types: - `element`: :etree:`ElementTree.Element` :Return: serialized element :Returntype: `unicode` ...
def filter_mechanism_list(mechanisms, properties, allow_insecure = False, server_side = False): """Filter a mechanisms list only to include those mechanisms that cans succeed with the provided properties and are secure enough. :Parameters: - `mechanisms`: list of the mec...
def error(self,stanza): """ Called when an error stanza is received. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `pyxmpp.stanza.Stanza` """ err=stanza.get_error() self.__logger.debug("Error from: %r Condition: %r" ...
def update_presence(self,presence): """ Update user information. :Parameters: - `presence`: a presence stanza with user information update. :Types: - `presence`: `MucPresence` """ self.presence=MucPresence(presence) t=presence.get_type() ...
def get_user(self,nick_or_jid,create=False): """ Get a room user with given nick or JID. :Parameters: - `nick_or_jid`: the nickname or room JID of the user requested. - `create`: if `True` and `nick_or_jid` is a JID, then a new user object will be created i...
def set_stream(self,stream): """ Called when current stream changes. Mark the room not joined and inform `self.handler` that it was left. :Parameters: - `stream`: the new stream. :Types: - `stream`: `pyxmpp.stream.Stream` """ _unused = st...
def join(self, password=None, history_maxchars = None, history_maxstanzas = None, history_seconds = None, history_since = None): """ Send a join request for the room. :Parameters: - `password`: password to the room. - `history_maxchars`: limit of the total nu...
def leave(self): """ Send a leave request for the room. """ if self.joined: p=MucPresence(to_jid=self.room_jid,stanza_type="unavailable") self.manager.stream.send(p)
def send_message(self,body): """ Send a message to the room. :Parameters: - `body`: the message body. :Types: - `body`: `unicode` """ m=Message(to_jid=self.room_jid.bare(),stanza_type="groupchat",body=body) self.manager.stream.send(m)
def set_subject(self,subject): """ Send a subject change request to the room. :Parameters: - `subject`: the new subject. :Types: - `subject`: `unicode` """ m=Message(to_jid=self.room_jid.bare(),stanza_type="groupchat",subject=subject) self...
def change_nick(self,new_nick): """ Send a nick change request to the room. :Parameters: - `new_nick`: the new nickname requested. :Types: - `new_nick`: `unicode` """ new_room_jid=JID(self.room_jid.node,self.room_jid.domain,new_nick) p=Pre...
def get_room_jid(self,nick=None): """ Get own room JID or a room JID for given `nick`. :Parameters: - `nick`: a nick for which the room JID is requested. :Types: - `nick`: `unicode` :return: the room JID. :returntype: `JID` """ if...
def process_available_presence(self,stanza): """ Process <presence/> received from the room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `MucPresence` """ fr=stanza.get_from() if not fr.resource: return ...
def process_unavailable_presence(self,stanza): """ Process <presence type="unavailable"/> received from the room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `MucPresence` """ fr=stanza.get_from() if not fr.resource: ...
def process_groupchat_message(self,stanza): """ Process <message type="groupchat"/> received from the room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Message` """ fr=stanza.get_from() user=self.get_user(fr,True) ...
def process_configuration_form_success(self, stanza): """ Process successful result of a room configuration form request. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Presence` """ if stanza.get_query_ns() != MUC_OWNER_NS: ...
def request_configuration_form(self): """ Request a configuration form for the room. When the form is received `self.handler.configuration_form_received` will be called. When an error response is received then `self.handler.error` will be called. :return: id of the request stan...
def process_configuration_success(self, stanza): """ Process success response for a room configuration request. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Presence` """ _unused = stanza self.configured = True ...
def configure_room(self, form): """ Configure the room using the provided data. Do nothing if the provided form is of type 'cancel'. :Parameters: - `form`: the configuration parameters. Should be a 'submit' form made by filling-in the configuration form retirev...
def request_instant_room(self): """ Request an "instant room" -- the default configuration for a MUC room. :return: id of the request stanza. :returntype: `unicode` """ if self.configured: raise RuntimeError("Instant room may be requested for unconfigured roo...
def set_stream(self,stream): """ Change the stream assigned to `self`. :Parameters: - `stream`: the new stream to be assigned to `self`. :Types: - `stream`: `pyxmpp.stream.Stream` """ self.jid=stream.me self.stream=stream for r in ...
def set_handlers(self,priority=10): """ Assign MUC stanza handlers to the `self.stream`. :Parameters: - `priority`: priority for the handlers. :Types: - `priority`: `int` """ self.stream.set_message_handler("groupchat",self.__groupchat_message,Non...
def join(self, room, nick, handler, password = None, history_maxchars = None, history_maxstanzas = None, history_seconds = None, history_since = None): """ Create and return a new room state object and request joining to a MUC room. :Parameters: - `room`: the nam...
def forget(self,rs): """ Remove a room from the list of managed rooms. :Parameters: - `rs`: the state object of the room. :Types: - `rs`: `MucRoomState` """ try: del self.rooms[rs.room_jid.bare().as_unicode()] except KeyError: ...
def __groupchat_message(self,stanza): """Process a groupchat message from a MUC room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Message` :return: `True` if the message was properly recognized as directed to one of the managed...
def __error_message(self,stanza): """Process an error message from a MUC room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Message` :return: `True` if the message was properly recognized as directed to one of the managed rooms,...
def __presence_error(self,stanza): """Process an presence error from a MUC room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Presence` :return: `True` if the stanza was properly recognized as generated by one of the managed roo...
def __presence_available(self,stanza): """Process an available presence from a MUC room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Presence` :return: `True` if the stanza was properly recognized as generated by one of the man...
def __presence_unavailable(self,stanza): """Process an unavailable presence from a MUC room. :Parameters: - `stanza`: the stanza received. :Types: - `stanza`: `Presence` :return: `True` if the stanza was properly recognized as generated by one of the...
def get(self, key, local_default = None, required = False): """Get a parameter value. If parameter is not set, return `local_default` if it is not `None` or the PyXMPP global default otherwise. :Raise `KeyError`: if parameter has no value and no global default :Return: paramet...
def load_arguments(self, args): """Load settings from :std:`ArgumentParser` output. :Parameters: - `args`: output of argument parsed based on the one returned by `get_arg_parser()` """ for name, setting in self._defs.items(): if sys.version_info.maj...
def add_setting(cls, name, type = unicode, default = None, factory = None, cache = False, default_d = None, doc = None, cmdline_help = None, validator = None, basic = False): """Add a new setting definition. :Parameters: - `name`: setting name...
def validate_string_list(value): """Validator for string lists to be used with `add_setting`.""" try: if sys.version_info.major < 3: # pylint: disable-msg=W0404 from locale import getpreferredencoding encoding = getpreferredencoding() ...