code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
self._logger.debug("incoming iq: %r", stanza_obj) if stanza_obj.type_.is_response: # iq response self._logger.debug("iq is response") keys = [(stanza_obj.from_, stanza_obj.id_)] if self._local_jid is not None: # needed for some ser...
def _process_incoming_iq(self, stanza_obj)
Process an incoming IQ stanza `stanza_obj`. Calls the response handler, spawns a request handler coroutine or drops the stanza while logging a warning if no handler can be found.
2.953916
2.887592
1.022969
self._logger.debug("incoming message: %r", stanza_obj) stanza_obj = self.service_inbound_message_filter.filter(stanza_obj) if stanza_obj is None: self._logger.debug("incoming message dropped by service " "filter chain") return ...
def _process_incoming_message(self, stanza_obj)
Process an incoming message stanza `stanza_obj`.
2.670051
2.619293
1.019379
self._logger.debug("incoming presence: %r", stanza_obj) stanza_obj = self.service_inbound_presence_filter.filter(stanza_obj) if stanza_obj is None: self._logger.debug("incoming presence dropped by service filter" " chain") return ...
def _process_incoming_presence(self, stanza_obj)
Process an incoming presence stanza `stanza_obj`.
2.88775
2.825488
1.022036
stanza_obj, exc = queue_entry # first, handle SM stream objects if isinstance(stanza_obj, nonza.SMAcknowledgement): self._logger.debug("received SM ack: %r", stanza_obj) if not self._sm_enabled: self._logger.warning("received SM ack, but SM not ...
def _process_incoming(self, xmlstream, queue_entry)
Dispatch to the different methods responsible for the different stanza types or handle a non-stanza stream-level element from `stanza_obj`, which has arrived over the given `xmlstream`.
2.823504
2.724807
1.036222
while True: try: stanza_obj = self._incoming_queue.get_nowait() except asyncio.QueueEmpty: break self._process_incoming(None, stanza_obj)
def flush_incoming(self)
Flush all incoming queues to the respective processing methods. The handlers are called as usual, thus it may require at least one iteration through the asyncio event loop before effects can be seen. The incoming queues are empty after a call to this method. It is legal (but pretty use...
4.30564
4.647993
0.926344
if token.state == StanzaState.ABORTED: return stanza_obj = token.stanza if isinstance(stanza_obj, stanza.Presence): stanza_obj = self.app_outbound_presence_filter.filter( stanza_obj ) if stanza_obj is not None: ...
def _send_stanza(self, xmlstream, token)
Send a stanza token `token` over the given `xmlstream`. Only sends if the `token` has not been aborted (see :meth:`StanzaToken.abort`). Sends the state of the token acoording to :attr:`sm_enabled`.
2.629092
2.504331
1.049818
self._send_stanza(xmlstream, token) # try to send a bulk while True: try: token = self._active_queue.get_nowait() except asyncio.QueueEmpty: break self._send_stanza(xmlstream, token) if self._sm_enabled: ...
def _process_outgoing(self, xmlstream, token)
Process the current outgoing stanza `token` and also any other outgoing stanza which is currently in the active queue. After all stanzas have been processed, use :meth:`_send_ping` to allow an opportunistic ping to be sent.
7.081892
6.154799
1.150629
self._iq_response_map.add_listener( (from_, id_), callbacks.OneshotAsyncTagListener(cb, loop=self._loop) ) self._logger.debug("iq response callback registered: from=%r, id=%r", from_, id_)
def register_iq_response_callback(self, from_, id_, cb)
Register a callback function `cb` to be called when a IQ stanza with type ``result`` or ``error`` is recieved from the :class:`~aioxmpp.JID` `from_` with the id `id_`. The callback is called at most once. .. note:: In contrast to :meth:`register_iq_response_future`, errors ...
6.818439
7.459357
0.914079
self._iq_response_map.add_listener( (from_, id_), StanzaErrorAwareListener( callbacks.FutureListener(fut) ) ) self._logger.debug("iq response future registered: from=%r, id=%r", from_, id_)
def register_iq_response_future(self, from_, id_, fut)
Register a future `fut` for an IQ stanza with type ``result`` or ``error`` from the :class:`~aioxmpp.JID` `from_` with the id `id_`. If the type of the IQ stanza is ``result``, the stanza is set as result to the future. If the type of the IQ stanza is ``error``, the stanzas erro...
7.854794
7.569354
1.03771
self._iq_response_map.remove_listener((from_, id_)) self._logger.debug("iq response unregistered: from=%r, id=%r", from_, id_)
def unregister_iq_response(self, from_, id_)
Unregister a registered callback or future for the IQ response identified by `from_` and `id_`. See :meth:`register_iq_response_future` or :meth:`register_iq_response_callback` for details on the arguments meanings and how to register futures and callbacks respectively. .. note:...
4.403216
5.609985
0.784889
warnings.warn( "register_iq_request_coro is a deprecated alias to " "register_iq_request_handler and will be removed in aioxmpp 1.0", DeprecationWarning, stacklevel=2) return self.register_iq_request_handler(type_, payload_cls, coro)
def register_iq_request_coro(self, type_, payload_cls, coro)
Alias of :meth:`register_iq_request_handler`. .. deprecated:: 0.10 This alias will be removed in version 1.0.
2.459217
2.409811
1.020502
type_ = self._coerce_enum(type_, structs.IQType) del self._iq_request_map[type_, payload_cls] self._logger.debug( "iq request coroutine unregistered: type=%r, payload=%r", type_, payload_cls)
def unregister_iq_request_handler(self, type_, payload_cls)
Unregister a coroutine previously registered with :meth:`register_iq_request_handler`. :param type_: IQ type to react to (must be a request type). :type type_: :class:`~structs.IQType` :param payload_cls: Payload class to react to (subclass of :class:`~xso.XSO`) :typ...
5.337592
5.089345
1.048778
if type_ is not None: type_ = self._coerce_enum(type_, structs.MessageType) warnings.warn( "register_message_callback is deprecated; use " "aioxmpp.dispatcher.SimpleMessageDispatcher instead", DeprecationWarning, stacklevel=2 )...
def register_message_callback(self, type_, from_, cb)
Register a callback to be called when a message is received. :param type_: Message type to listen for, or :data:`None` for a wildcard match. :type type_: :class:`~.MessageType` or :data:`None` :param from_: Sender JID to listen for, or :data:`None` for a wildcard ...
4.444929
3.775554
1.177292
if type_ is not None: type_ = self._coerce_enum(type_, structs.MessageType) warnings.warn( "unregister_message_callback is deprecated; use " "aioxmpp.dispatcher.SimpleMessageDispatcher instead", DeprecationWarning, stacklevel=2 ...
def unregister_message_callback(self, type_, from_)
Unregister a callback previously registered with :meth:`register_message_callback`. :param type_: Message type to listen for. :type type_: :class:`~.MessageType` or :data:`None` :param from_: Sender JID to listen for. :type from_: :class:`~aioxmpp.JID` or :data:`None` :r...
4.843685
3.993384
1.212928
type_ = self._coerce_enum(type_, structs.PresenceType) warnings.warn( "register_presence_callback is deprecated; use " "aioxmpp.dispatcher.SimplePresenceDispatcher or " "aioxmpp.PresenceClient instead", DeprecationWarning, stacklevel=2...
def register_presence_callback(self, type_, from_, cb)
Register a callback to be called when a presence stanza is received. :param type_: Presence type to listen for. :type type_: :class:`~.PresenceType` :param from_: Sender JID to listen for, or :data:`None` for a wildcard match. :type from_: :class:`~aioxmpp.JID` or ...
4.777293
4.195565
1.138653
type_ = self._coerce_enum(type_, structs.PresenceType) warnings.warn( "unregister_presence_callback is deprecated; use " "aioxmpp.dispatcher.SimplePresenceDispatcher or " "aioxmpp.PresenceClient instead", DeprecationWarning, stacklevel...
def unregister_presence_callback(self, type_, from_)
Unregister a callback previously registered with :meth:`register_presence_callback`. :param type_: Presence type to listen for. :type type_: :class:`~.PresenceType` :param from_: Sender JID to listen for, or :data:`None` for a wildcard match. :type from_: :...
5.17855
4.964123
1.043195
if self.running: raise RuntimeError("already started") self._start_prepare(xmlstream, self.recv_stanza) self._closed = False self._start_commit(xmlstream)
def start(self, xmlstream)
Start or resume the stanza stream on the given :class:`aioxmpp.protocol.XMLStream` `xmlstream`. This starts the main broker task, registers stanza classes at the `xmlstream` .
7.868005
7.723447
1.018717
if not self.running: return self._logger.debug("sending stop signal to task") self._task.cancel()
def stop(self)
Send a signal to the main broker task to terminate. You have to check :attr:`running` and possibly wait for it to become :data:`False` --- the task takes at least one loop through the event loop to terminate. It is guarenteed that the task will not attempt to send stanzas over the exist...
7.271867
6.095092
1.193069
if not self.running: return self.stop() try: yield from self._task except asyncio.CancelledError: pass
def wait_stop(self)
Stop the stream and wait for it to stop. See :meth:`stop` for the general stopping conditions. You can assume that :meth:`stop` is the first thing this coroutine calls.
5.792554
4.621554
1.253378
exc = DestructionRequested("close() called") if self.running: if self.sm_enabled: self._xmlstream.send_xso(nonza.SMAcknowledgement( counter=self._sm_inbound_ctr )) yield from self._xmlstream.close_and_wait() # does n...
def close(self)
Close the stream and the underlying XML stream (if any is connected). This is essentially a way of saying "I do not want to use this stream anymore" (until the next call to :meth:`start`). If the stream is currently running, the XML stream is closed gracefully (potentially sending an SM...
11.799036
8.320618
1.418048
self._logger.info("resuming SM stream with remote_ctr=%d", remote_ctr) # remove any acked stanzas self.sm_ack(remote_ctr) # reinsert the remaining stanzas for token in self._sm_unacked_list: self._active_queue.putleft_nowait(token) self._sm_unacked_li...
def _resume_sm(self, remote_ctr)
Version of :meth:`resume_sm` which can be used during slow start.
7.123336
6.780234
1.050603
if self.running: raise RuntimeError("Cannot resume Stream Management while" " StanzaStream is running") self._start_prepare(xmlstream, self.recv_stanza) try: response = yield from protocol.send_and_wait_for( xmlstr...
def resume_sm(self, xmlstream)
Resume an SM-enabled stream using the given `xmlstream`. If the server rejects the attempt to resume stream management, a :class:`.errors.StreamNegotiationFailure` is raised. The stream is then in stopped state and stream management has been stopped. .. warning:: This metho...
6.00512
5.060768
1.186603
if not self.sm_enabled: raise RuntimeError("Stream Management is not enabled") self._logger.info("stopping SM stream") self._sm_enabled = False del self._sm_outbound_base del self._sm_inbound_ctr self._clear_unacked(StanzaState.SENT_WITHOUT_SM) ...
def _stop_sm(self)
Version of :meth:`stop_sm` which can be called during startup.
10.087187
10.041049
1.004595
if not self._sm_enabled: raise RuntimeError("Stream Management is not enabled") self._logger.debug("sm_ack(%d)", remote_ctr) to_drop = (remote_ctr - self._sm_outbound_base) & 0xffffffff self._logger.debug("sm_ack: to drop %d, unacked: %d", ...
def sm_ack(self, remote_ctr)
Process the remote stanza counter `remote_ctr`. Any acked stanzas are dropped from :attr:`sm_unacked_list` and put into :attr:`StanzaState.ACKED` state and the counters are increased accordingly. If called with an erroneous remote stanza counter :class:`.errors.StreamNegotationF...
3.302067
2.517157
1.311824
warnings.warn( r"send_iq_and_wait_for_reply is deprecated and will be removed in" r" 1.0", DeprecationWarning, stacklevel=1, ) return (yield from self.send(iq, timeout=timeout))
def send_iq_and_wait_for_reply(self, iq, *, timeout=None)
Send an IQ stanza `iq` and wait for the response. If `timeout` is not :data:`None`, it must be the time in seconds for which to wait for a response. If the response is a ``"result"`` IQ, the value of the :attr:`~aioxmpp.IQ.payload` attribute is returned. Otherwise, the exception...
3.499982
3.093415
1.13143
warnings.warn( r"send_and_wait_for_sent is deprecated and will be removed in 1.0", DeprecationWarning, stacklevel=1, ) yield from self._enqueue(stanza)
def send_and_wait_for_sent(self, stanza)
Send the given `stanza` over the given :class:`StanzaStream` `stream`. .. deprecated:: 0.8 This method will be removed in 1.0. Use :meth:`send` instead.
4.253453
3.851065
1.104487
stanza.autoset_id() self._logger.debug("sending %r and waiting for it to be sent", stanza) if not isinstance(stanza, stanza_.IQ) or stanza.type_.is_response: if cb is not None: raise ValueError( "cb not supporte...
def _send_immediately(self, stanza, *, timeout=None, cb=None)
Send a stanza without waiting for the stream to be ready to send stanzas. This is only useful from within :class:`aioxmpp.node.Client` before the stream is fully established.
3.830621
3.806132
1.006434
parts = [ feature.encode("utf-8")+b"\x1f" for feature in features ] parts.sort() return b"".join(parts)+b"\x1c"
def _process_features(features)
Generate the `Features String` from an iterable of features. :param features: The features to generate the features string from. :type features: :class:`~collections.abc.Iterable` of :class:`str` :return: The `Features String` :rtype: :class:`bytes` Generate the `Features String` from the given `f...
4.803125
4.819849
0.99653
parts = [ _process_identity(identity) for identity in identities ] parts.sort() return b"".join(parts)+b"\x1c"
def _process_identities(identities)
Generate the `Identities String` from an iterable of identities. :param identities: The identities to generate the features string from. :type identities: :class:`~collections.abc.Iterable` of :class:`~.disco.xso.Identity` :return: The `Identities String` :rtype: :class:`bytes` Generate th...
6.086969
5.620315
1.08303
parts = [ _process_form(form) for form in exts ] parts.sort() return b"".join(parts)+b"\x1c"
def _process_extensions(exts)
Generate the `Extensions String` from an iterable of data forms. :param exts: The data forms to generate the extensions string from. :type exts: :class:`~collections.abc.Iterable` of :class:`~.forms.xso.Data` :return: The `Extensions String` :rtype: :class:`bytes` Generate the `Extensions ...
7.861825
6.660774
1.180317
if class_ is None: class_ = type(instance) self._toplevels[class_] = instance
def set_toplevel_object(self, instance, class_=None)
Set the toplevel object to return from :meth:`get_toplevel_object` when asked for `class_` to `instance`. If `class_` is :data:`None`, the :func:`type` of the `instance` is used.
3.433911
4.59158
0.747871
result = expr.eval(self) iterator = iter(result) try: next(iterator) except StopIteration: return False else: return True finally: if hasattr(iterator, "close"): iterator.close()
def eval_bool(self, expr)
Evaluate the expression `expr` and return the truthness of its result. A result of an expression is said to be true if it contains at least one value. It has the same semantics as :func:`bool` on sequences.s
3.087175
2.948435
1.047055
if new_state > self._state: raise ValueError("cannot forward using rewind " "({} > {})".format(new_state, self._state)) self._state = new_state
def rewind(self, new_state)
Rewind can be used as an exceptional way to roll back the state of a :class:`OrderedStateMachine`. Rewinding is not the usual use case for an :class:`OrderedStateMachine`. Usually, if the current state `A` is greater than any given state `B`, it is assumed that state `B` cannot ...
4.628192
4.721847
0.980166
if self._state == new_state: return if self._state > new_state: raise OrderedStateSkipped(new_state) fut = asyncio.Future(loop=self.loop) self._exact_waiters.append((new_state, fut)) yield from fut
def wait_for(self, new_state)
Wait for an exact state `new_state` to be reached by the state machine. If the state is skipped, that is, if a state which is greater than `new_state` is written to :attr:`state`, the coroutine raises :class:`OrderedStateSkipped` exception as it is not possible anymore that it c...
4.982695
3.523314
1.414207
if not (self._state < new_state): return fut = asyncio.Future(loop=self.loop) self._least_waiters.append((new_state, fut)) yield from fut
def wait_for_at_least(self, new_state)
Wait for a state to be entered which is greater than or equal to `new_state` and return.
6.006816
5.549409
1.082424
Item.register_child( Item.registered_payload, cls, ) EventItem.register_child( EventItem.registered_payload, cls, ) return cls
def as_payload_class(cls)
Register the given class `cls` as Publish-Subscribe payload on both :class:`Item` and :class:`EventItem`. Return the class, to allow this to be used as decorator.
7.464141
4.846298
1.540174
presences = sorted( self.get_peer_resources(peer_jid).items(), key=lambda item: aioxmpp.structs.PresenceState.from_stanza(item[1]) ) if not presences: return None return presences[-1][1]
def get_most_available_stanza(self, peer_jid)
Obtain the stanza describing the most-available presence of the contact. :param peer_jid: Bare JID of the contact. :type peer_jid: :class:`aioxmpp.JID` :rtype: :class:`aioxmpp.Presence` or :data:`None` :return: The presence stanza of the most available resource or ...
4.766711
4.19465
1.136379
try: d = dict(self._presences[peer_jid]) d.pop(None, None) return d except KeyError: return {}
def get_peer_resources(self, peer_jid)
Return a dict mapping resources of the given bare `peer_jid` to the presence state last received for that resource. Unavailable presence states are not included. If the bare JID is in a error state (i.e. an error presence stanza has been received), the returned mapping is empty.
5.197275
4.250421
1.222767
try: return self._presences[peer_jid.bare()][peer_jid.resource] except KeyError: pass try: return self._presences[peer_jid.bare()][None] except KeyError: pass
def get_stanza(self, peer_jid)
Return the last presence recieved for the given bare or full `peer_jid`. If the last presence was unavailable, the return value is :data:`None`, as if no presence was ever received. If no presence was ever received for the given bare JID, :data:`None` is returned.
2.925603
2.877553
1.016698
stanza = aioxmpp.Presence() self._state.apply_to_stanza(stanza) stanza.status.update(self._status) return stanza
def make_stanza(self)
Create and return a presence stanza with the current settings. :return: Presence stanza :rtype: :class:`aioxmpp.Presence`
7.006313
5.696356
1.229964
if not isinstance(priority, numbers.Integral): raise TypeError( "invalid priority: got {}, expected integer".format( type(priority) ) ) if not isinstance(state, aioxmpp.PresenceState): raise TypeError( ...
def set_presence(self, state, status={}, priority=0)
Change the presence broadcast by the client. :param state: New presence state to broadcast :type state: :class:`aioxmpp.PresenceState` :param status: New status information to broadcast :type status: :class:`dict` or :class:`str` :param priority: New priority for the resource ...
2.556511
2.386725
1.071138
if self.client.established: return self.client.enqueue(self.make_stanza())
def resend_presence(self)
Re-send the currently configured presence. :return: Stanza token of the presence stanza or :data:`None` if the stream is not established. :rtype: :class:`~.stream.StanzaToken` .. note:: :meth:`set_presence` automatically broadcasts the new presence if an...
14.351249
12.564834
1.142176
result = { "subject": ( (("commonName", x509.get_subject().commonName),), ) } for ext_idx in range(x509.get_extension_count()): ext = x509.get_extension(ext_idx) sn = ext.get_short_name() if sn != b"subjectAltName": continue data...
def extract_python_dict_from_x509(x509)
Extract a python dictionary similar to the return value of :meth:`ssl.SSLSocket.getpeercert` from the given :class:`OpenSSL.crypto.X509` `x509` object. Note that by far not all attributes are included; only those required to use :func:`ssl.match_hostname` are extracted and put in the result. In th...
2.710394
2.750087
0.985566
return pyasn1.codec.der.decoder.decode( blob, asn1Spec=pyasn1_modules.rfc2459.Certificate() )[0]
def blob_to_pyasn1(blob)
Convert an ASN.1 encoded certificate (such as obtained from :func:`extract_blob`) to a :mod:`pyasn1` structure and return the result.
3.066635
2.939644
1.043199
pk = pyasn1_struct.getComponentByName( "tbsCertificate" ).getComponentByName( "subjectPublicKeyInfo" ) return pyasn1.codec.der.encoder.encode(pk)
def extract_pk_blob_from_pyasn1(pyasn1_struct)
Extract an ASN.1 encoded public key blob from the given :mod:`pyasn1` structure (which must represent a certificate).
3.346926
3.08438
1.085121
cert_structure = extract_python_dict_from_x509(x509) try: ssl.match_hostname(cert_structure, hostname) except ssl.CertificateError: return False return True
def check_x509_hostname(x509, hostname)
Check whether the given :class:`OpenSSL.crypto.X509` certificate `x509` matches the given `hostname`. Return :data:`True` if the name matches and :data:`False` otherwise. This uses :func:`ssl.match_hostname` and :func:`extract_python_dict_from_x509`.
4.243701
2.652637
1.599805
ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) ctx.set_options(OpenSSL.SSL.OP_NO_SSLv2 | OpenSSL.SSL.OP_NO_SSLv3) ctx.set_verify(OpenSSL.SSL.VERIFY_PEER, default_verify_callback) return ctx
def default_ssl_context()
Return a sensibly configured :class:`OpenSSL.SSL.Context` context. The context has SSLv2 and SSLv3 disabled, and supports TLS 1.0+ (depending on the version of the SSL library). Tries to negotiate an XMPP c2s connection via ALPN (:rfc:`7301`).
1.900849
1.773227
1.071972
if not transport.get_extra_info("sslcontext"): transport = None last_auth_error = None for sasl_provider in sasl_providers: try: result = yield from sasl_provider.execute( jid, features, xmlstream, transport) except ValueError as err: ra...
def negotiate_sasl(transport, xmlstream, sasl_providers, negotiation_timeout, jid, features)
Perform SASL authentication on the given :class:`.protocol.XMLStream` `stream`. `transport` must be the :class:`asyncio.Transport` over which the `stream` runs. It is used to detect whether TLS is used and may be required by some SASL mechanisms. `sasl_providers` must be an iterable of :class:`SASLProv...
4.11834
3.329257
1.237015
sasl_providers = tuple(sasl_providers) if not sasl_providers: raise ValueError("At least one SASL provider must be given.") for sasl_provider in sasl_providers: sasl_provider.execute # check that sasl_provider has execute method result = SecurityLayer( tls_provider.ssl_c...
def security_layer(tls_provider, sasl_providers)
.. deprecated:: 0.6 Replaced by :class:`SecurityLayer`. Return a configured :class:`SecurityLayer`. `tls_provider` must be a :class:`STARTTLSProvider`. The return value can be passed to the constructor of :class:`~.node.Client`. Some very basic checking on the input is also performed.
3.748642
3.747392
1.000334
tls_kwargs = {} if certificate_verifier_factory is not None: tls_kwargs["certificate_verifier_factory"] = \ certificate_verifier_factory return SecurityLayer( ssl_context_factory, certificate_verifier_factory, True, ( PasswordSASLProvide...
def tls_with_password_based_authentication( password_provider, ssl_context_factory=default_ssl_context, max_auth_attempts=3, certificate_verifier_factory=PKIXCertificateVerifier)
Produce a commonly used :class:`SecurityLayer`, which uses TLS and password-based SASL authentication. If `ssl_context_factory` is not provided, an SSL context with TLSv1+ is used. `password_provider` must be a coroutine which is called with the jid as first and the number of attempt as second argument...
3.67453
3.799212
0.967182
key = self._x509_key(x509) self._storage.setdefault(hostname, set()).add(key)
def pin(self, hostname, x509)
Pin an :class:`OpenSSL.crypto.X509` object `x509` for use with the given `hostname`. Which information exactly is used to identify the certificate depends :meth:`_x509_key`.
5.794683
3.90324
1.484583
key = self._x509_key(x509) try: pins = self._storage[hostname] except KeyError: return None if key in pins: return True return None
def query(self, hostname, x509)
Return true if the given :class:`OpenSSL.crypto.X509` object `x509` has previously been pinned for use with the given `hostname` and :data:`None` otherwise. Returning :data:`None` allows this method to be used with :class:`PinningPKIXCertificateVerifier`.
4.754226
3.829011
1.241633
return { hostname: sorted(self._encode_key(key) for key in pins) for hostname, pins in self._storage.items() }
def export_to_json(self)
Return a JSON dictionary which contains all the pins stored in this store.
13.682096
7.723949
1.771386
if override: self._storage = { hostname: set(self._decode_key(key) for key in pins) for hostname, pins in data.items() } return for hostname, pins in data.items(): existing_pins = self._storage.setdefault(hostname...
def import_from_json(self, data, *, override=False)
Import a JSON dictionary which must have the same format as exported by :meth:`export`. If *override* is true, the existing data in the pin store will be overriden with the data from `data`. Otherwise, the `data` will be merged into the store.
3.132041
3.153871
0.993078
try: mechanisms = features[SASLMechanisms] except KeyError: logger.error("No sasl mechanisms: %r", list(features)) raise errors.SASLUnavailable( "Remote side does not support SASL") from None remote_mechanism_list = mechanisms.get_me...
def _find_supported(self, features, mechanism_classes)
Find the first mechansim class which supports a mechanism announced in the given stream features. :param features: Current XMPP stream features :type features: :class:`~.nonza.StreamFeatures` :param mechanism_classes: SASL mechanism classes to use :type mechanism_classes: iterab...
4.929173
3.694458
1.334208
sm = aiosasl.SASLStateMachine(intf) try: yield from mechanism.authenticate(sm, token) return True except aiosasl.SASLFailure as err: if err.opaque_error in self.AUTHENTICATION_FAILURES: raise aiosasl.AuthenticationFailure( ...
def _execute(self, intf, mechanism, token)
Execute a SASL authentication process. :param intf: SASL interface to use :type intf: :class:`~.sasl.SASLXMPPInterface` :param mechanism: SASL mechanism to use :type mechanism: :class:`aiosasl.SASLMechanism` :param token: The opaque token argument for the mechanism :type...
4.940531
3.37153
1.465368
features_future = asyncio.Future(loop=loop) stream = protocol.XMLStream( to=domain, features_future=features_future, base_logger=base_logger, ) if base_logger is not None: logger = base_logger.getChild(type(self).__name__) ...
def connect(self, loop, metadata, domain: str, host, port, negotiation_timeout, base_logger=None)
.. seealso:: :meth:`BaseConnector.connect` For general information on the :meth:`connect` method. Connect to `host` at TCP port number `port`. The :class:`aioxmpp.security_layer.SecurityLayer` object `metadata` is used to determine the parameters of the TLS connection....
4.0748
3.529445
1.154516
features_future = asyncio.Future(loop=loop) stream = protocol.XMLStream( to=domain, features_future=features_future, base_logger=base_logger, ) if base_logger is not None: logger = base_logger.getChild(type(self).__name__) ...
def connect(self, loop, metadata, domain, host, port, negotiation_timeout, base_logger=None)
.. seealso:: :meth:`BaseConnector.connect` For general information on the :meth:`connect` method. Connect to `host` at TCP port number `port`. The :class:`aioxmpp.security_layer.SecurityLayer` object `metadata` is used to determine the parameters of the TLS connection....
4.406449
3.848299
1.145038
if isinstance(tag, str): namespace_uri, sep, localname = tag.partition("}") if sep: if not namespace_uri.startswith("{"): raise ValueError("not a valid etree-format tag") namespace_uri = namespace_uri[1:] else: localname = namespace_ur...
def normalize_tag(tag)
Normalize an XML element tree `tag` into the tuple format. The following input formats are accepted: * ElementTree namespaced string, e.g. ``{uri:bar}foo`` * Unnamespaced tags, e.g. ``foo`` * Two-tuples consisting of `namespace_uri` and `localpart`; `namespace_uri` may be :data:`None` if the tag ...
3.073649
3.027082
1.015383
token, tracker = self.send_message_tracked(body) tracker.cancel() return token
def send_message(self, body)
Send a message to the conversation. :param msg: The message to send. :type msg: :class:`aioxmpp.Message` :return: The stanza token obtained from sending. :rtype: :class:`~aioxmpp.stream.StanzaToken` The default implementation simply calls :meth:`send_message_tracked` an...
19.872051
9.48411
2.0953
raise self._not_implemented_error("inviting entities")
def invite(self, address, text=None, *, mode=InviteMode.DIRECT, allow_upgrade=False)
Invite another entity to the conversation. :param address: The address of the entity to invite. :type address: :class:`aioxmpp.JID` :param text: A reason/accompanying text for the invitation. :param mode: The invitation mode to use. :type mode: :class:`~.im.InviteMode` :...
36.90168
60.720695
0.607728
if sys.stdout.seekable(): # it’s a file return sys.stdout.buffer.raw if os.isatty(sys.stdin.fileno()): # it’s a tty, use fd 0 fd_to_use = 0 else: fd_to_use = 1 twrite, pwrite = await loop.connect_write_pipe( asyncio.streams.FlowControlMixin, ...
async def stdout_writer()
This is a bit complex, as stdout can be a pipe or a file. If it is a file, we cannot use :meth:`asycnio.BaseEventLoop.connect_write_pipe`.
3.751824
3.506458
1.069975
try: enabled, (fun_name, fun_args, fun_kwargs) = _HASH_ALGO_MAP[algo] except KeyError: raise NotImplementedError( "hash algorithm {!r} unknown".format(algo) ) from None if not enabled: raise ValueError( "support of {} in XMPP is forbidden".forma...
def hash_from_algo(algo)
Return a :mod:`hashlib` hash given the :xep:`300` `algo`. :param algo: The algorithm identifier as defined in :xep:`300`. :type algo: :class:`str` :raises NotImplementedError: if the hash algortihm is not supported by :mod:`hashlib`. :raises ValueError: if the hash algorithm MUST NOT be support...
3.681801
3.316121
1.110273
try: enabled, algo = _HASH_ALGO_REVERSE_MAP[h.name] except KeyError: pass else: if not enabled: raise ValueError("support of {} in XMPP is forbidden".format( algo )) return algo if h.name == "blake2b": return "blake2b-...
def algo_of_hash(h)
Return a :xep:`300` `algo` from a given :mod:`hashlib` hash. :param h: Hash object from :mod:`hashlib`. :raises ValueError: if `h` does not have a defined `algo` value. :raises ValueError: if the hash function MUST NOT be supported. :return: The `algo` value for the given hash. :rtype: :class:`str`...
4.719816
3.95676
1.192849
disco_info = yield from self._disco_client.query_info(other_entity) intersection = disco_info.features & SUPPORTED_HASH_FEATURES if (not intersection and namespaces.xep0300_hashes2 not in disco_info.features): raise RuntimeError( "Remote does ...
def select_common_hashes(self, other_entity)
Return the list of algos supported by us and `other_entity`. The algorithms are represented by their :xep:`300` URNs (`urn:xmpp:hash-function-text-names:...`). :param other_entity: the address of another entity :type other_entity: :class:`aioxmpp.JID` :returns: the identifiers o...
11.555995
5.808732
1.989418
fut = asyncio.Future() for signal in signals: signal.connect(fut, signal.AUTO_FUTURE) return fut
def first_signal(*signals)
Connect to multiple signals and wait for the first to emit. :param signals: Signals to connect to. :type signals: :class:`AdHocSignal` :return: An awaitable for the first signal to emit. The awaitable returns the first argument passed to the signal. If the first argument is an exception, the excep...
9.539585
5.834167
1.635124
mode = mode or self.STRONG self.logger.debug("connecting %r with mode %r", f, mode) return self._connect(mode(f))
def connect(self, f, mode=None)
Connect an object `f` to the signal. The type the object needs to have depends on `mode`, but usually it needs to be a callable. :meth:`connect` returns an opaque token which can be used with :meth:`disconnect` to disconnect the object from the signal. The default value for `mode` is :...
7.965405
6.497786
1.225865
for token, wrapper in list(self._connections.items()): try: keep = wrapper(args, kwargs) except Exception: self.logger.exception("listener attached to signal raised") keep = False if not keep: del self._...
def fire(self, *args, **kwargs)
Emit the signal, calling all connected objects in-line with the given arguments and in the order they were registered. :class:`AdHocSignal` provides full isolation with respect to exceptions. If a connected listener raises an exception, the other listeners are executed as normal, but th...
7.380926
6.511399
1.133539
fut = asyncio.Future() self.connect(fut, self.AUTO_FUTURE) return fut
def future(self)
Return a :class:`asyncio.Future` which has been :meth:`connect`\\ -ed using :attr:`AUTO_FUTURE`. The token returned by :meth:`connect` is not returned; to remove the future from the signal, just cancel it.
11.344247
5.556413
2.041649
self.logger.debug("connecting %r", coro) return self._connect(coro)
def connect(self, coro)
The coroutine `coro` is connected to the signal. The coroutine must return a true value, unless it wants to be disconnected from the signal. .. note:: This is different from the return value convention with :attr:`AdHocSignal.STRONG` and :attr:`AdHocSignal.WEAK`. ...
5.575232
7.138677
0.780989
for token, coro in list(self._connections.items()): keep = yield from coro(*args, **kwargs) if not keep: del self._connections[token]
def fire(self, *args, **kwargs)
Emit the signal, calling all coroutines in-line with the given arguments and in the order they were registered. This is obviously a coroutine. Instead of calling :meth:`fire` explicitly, the ad-hoc signal object itself can be called, too.
6.038152
5.689381
1.061302
token = self.Token() self._filter_order.append((order, token, func)) self._filter_order.sort(key=lambda x: x[0]) return token
def register(self, func, order)
Add a function to the filter chain. :param func: A callable which is to be added to the filter chain. :param order: An object indicating the ordering of the function relative to the others. :return: Token representing the registration. Register the function `func`...
4.824193
5.436595
0.887356
for _, _, func in self._filter_order: obj = func(obj, *args, **kwargs) if obj is None: return None return obj
def filter(self, obj, *args, **kwargs)
Filter the given object through the filter chain. :param obj: The object to filter :param args: Additional arguments to pass to each filter function. :param kwargs: Additional keyword arguments to pass to each filter function. :return: The filtered object or :data...
4.122118
4.489673
0.918133
for i, (_, token, _) in enumerate(self._filter_order): if token == token_to_remove: break else: raise ValueError("unregistered token: {!r}".format( token_to_remove)) del self._filter_order[i]
def unregister(self, token_to_remove)
Unregister a filter function. :param token_to_remove: The token as returned by :meth:`register`. Unregister a function from the filter chain using the token returned by :meth:`register`.
3.680784
3.313857
1.110725
token = self.register(func, *args) try: yield finally: self.unregister(token)
def context_register(self, func, *args)
:term:`Context manager <context manager>` which temporarily registers a filter function. :param func: The filter function to register. :param order: The sorting key for the filter function. :rtype: :term:`context manager` :return: Context manager which temporarily registers the ...
4.581184
6.205893
0.738199
loop = asyncio.get_event_loop() if isinstance(timeout, timedelta): timeout = timeout.total_seconds() loop.call_later(timeout, self.close)
def set_timeout(self, timeout)
Automatically close the tracker after `timeout` has elapsed. :param timeout: The timeout after which the tracker is closed automatically. :type timeout: :class:`numbers.Real` or :class:`datetime.timedelta` If the `timeout` is not a :class:`datetime.timedelta` instance, ...
3.049834
3.908183
0.780371
if self._closed: raise RuntimeError("message tracker is closed") # reject some transitions as documented if (self._state == MessageState.ABORTED or new_state == MessageState.IN_TRANSIT or (self._state == MessageState.ERROR and ...
def _set_state(self, new_state, response=None)
Set the state of the tracker. :param new_state: The new state of the tracker. :type new_state: :class:`~.MessageState` member :param response: A stanza related to the new state. :type response: :class:`~.StanzaBase` or :data:`None` :raise ValueError: if a forbidden state transit...
2.3595
1.785826
1.321237
token = self.client.enqueue(stanza) self.attach_tracker(stanza, tracker, token) return token
def send_tracked(self, stanza, tracker)
Send a message stanza with tracking. :param stanza: Message stanza to send. :type stanza: :class:`aioxmpp.Message` :param tracker: Message tracker to use. :type tracker: :class:`~.MessageTracker` :rtype: :class:`~.StanzaToken` :return: The token used to send the stanza. ...
8.978313
11.570053
0.775996
if tracker is None: tracker = MessageTracker() stanza.autoset_id() key = stanza.to.bare(), stanza.id_ self._trackers[key] = tracker tracker.on_closed.connect( functools.partial(self._tracker_closed, key) ) if token is not None: ...
def attach_tracker(self, stanza, tracker=None, token=None)
Configure tracking for a stanza without sending it. :param stanza: Message stanza to send. :type stanza: :class:`aioxmpp.Message` :param tracker: Message tracker to use. :type tracker: :class:`~.MessageTracker` or :data:`None` :param token: Optional stanza token for more fine-gr...
4.477367
4.082073
1.096837
self.stop() self._task = asyncio.ensure_future(self._pinger(), loop=self._loop)
def start(self)
Start the pinging coroutine using the client and event loop which was passed to the constructor. :meth:`start` always behaves as if :meth:`stop` was called right before it.
5.813272
4.736115
1.227435
if task.exception() is None: self._on_fresh() return exc = task.exception() if isinstance(exc, aioxmpp.errors.XMPPError): if exc.condition in [ aioxmpp.errors.ErrorCondition.SERVICE_UNAVAILABLE, aioxmpp.errors....
def _interpret_result(self, task)
Interpret the result of a ping. :param task: The pinger task. The result or exception of the `task` is interpreted as follows: * :data:`None` result: *positive* * :class:`aioxmpp.errors.XMPPError`, ``service-unavailable``: *positive* * :class:`aioxmpp.errors.XMPPErro...
3.227417
2.665186
1.210954
self._monitor.notify_received() self._pinger.stop() self._mark_fresh()
def reset(self)
Reset the monitor. Reset the aliveness timeouts. Clear the stale state. Cancel and stop pinging. Call `on_fresh` if the stale state was set.
25.194536
13.764102
1.830453
if message.type_ == aioxmpp.MessageType.ERROR: raise ValueError("receipts cannot be generated for error messages") if message.xep0184_received: raise ValueError("receipts cannot be generated for receipts") if message.id_ is None: raise ValueError("receipts cannot be generated f...
def compose_receipt(message)
Compose a :xep:`184` delivery receipt for a :class:`~aioxmpp.Message`. :param message: The message to compose the receipt for. :type message: :class:`~aioxmpp.Message` :raises ValueError: if the input message is of type :attr:`~aioxmpp.MessageType.ERROR` :raises ValueError: if the input message...
5.291995
3.874257
1.365938
if stanza.xep0184_received is not None: raise ValueError( "requesting delivery receipts for delivery receipts is not " "allowed" ) if stanza.type_ == aioxmpp.MessageType.ERROR: raise ValueError( "requesting deli...
def attach_tracker(self, stanza, tracker=None)
Return a new tracker or modify one to track the stanza. :param stanza: Stanza to track. :type stanza: :class:`aioxmpp.Message` :param tracker: Existing tracker to attach to. :type tracker: :class:`.tracking.MessageTracker` :raises ValueError: if the stanza is of type ...
5.618946
4.635147
1.212248
iq = aioxmpp.IQ( type_=aioxmpp.IQType.GET, payload=private_xml_xso.Query(query_xso) ) return (yield from self.client.send(iq))
def get_private_xml(self, query_xso)
Get the private XML data for the element `query_xso` from the server. :param query_xso: the object to retrieve. :returns: the stored private XML data. `query_xso` *must* serialize to an empty XML node of the wanted namespace and type and *must* be registered as private ...
7.29904
5.049274
1.445562
iq = aioxmpp.IQ( type_=aioxmpp.IQType.SET, payload=private_xml_xso.Query(xso) ) yield from self.client.send(iq)
def set_private_xml(self, xso)
Store the serialization of `xso` on the server as the private XML data for the namespace of `xso`. :param xso: the XSO whose serialization is send as private XML data.
10.59125
9.309352
1.1377
todo = [asyncio.ensure_future(fut_or_coro) for fut_or_coro in fut_or_coros] if not todo: return [] yield from asyncio.wait(todo) results = [] exceptions = [] for fut in todo: if fut.exception() is not None: exceptions.append(fut.exception()) else: ...
def gather_reraise_multi(*fut_or_coros, message="gather_reraise_multi")
Wrap all the arguments `fut_or_coros` in futures with :func:`asyncio.ensure_future` and wait until all of them are finish or fail. :param fut_or_coros: the futures or coroutines to wait for :type fut_or_coros: future or coroutine :param message: the message included with the raised :class:`...
2.43234
2.434556
0.99909
if isinstance(rand_token, int): rand_token = rand_token.to_bytes( (rand_token.bit_length() + 7) // 8, "little" ) e = base64.urlsafe_b64encode(rand_token).rstrip(b"=").decode("ascii") return ":" + e if isinstance(rand_token, bytes): e = base6...
def to_nmtoken(rand_token)
Convert a (random) token given as raw :class:`bytes` or :class:`int` to a valid NMTOKEN <https://www.w3.org/TR/xml/#NT-Nmtoken>. The encoding as a valid nmtoken is injective, ensuring that two different inputs cannot yield the same token. Nevertheless, it is recommended to only use one kind of inpu...
2.396914
2.31334
1.036127
return self.localizable_string.localize( formatter, translator, *self.args, **self.kwargs )
def localize(self, formatter, translator)
Return a localized version of the `localizable_string` passed to the consturctor. It is formatted using the `formatter` with the `args` and `kwargs` passed to the constructor of :class:`UserError`.
4.90948
3.033066
1.618653
res = yield from self._private_xml.get_private_xml( bookmark_xso.Storage() ) return res.registered_payload.bookmarks
def _get_bookmarks(self)
Get the stored bookmarks from the server. :returns: a list of bookmarks
43.368954
43.282703
1.001993
storage = bookmark_xso.Storage() storage.bookmarks[:] = bookmarks yield from self._private_xml.set_private_xml(storage)
def _set_bookmarks(self, bookmarks)
Set the bookmarks stored on the server.
25.435946
21.795998
1.167001
self.logger.debug("diffing %s, %s", self._bookmark_cache, new_bookmarks) def subdivide(level, old, new): if len(old) == len(new) == 1: old_entry = old.pop() new_entry = new.pop() if old_entry ==...
def _diff_emit_update(self, new_bookmarks)
Diff the bookmark cache and the new bookmark state, emit signals as needed and set the bookmark cache to the new data.
2.79608
2.761167
1.012644
with (yield from self._lock): bookmarks = yield from self._get_bookmarks() self._diff_emit_update(bookmarks) return bookmarks
def get_bookmarks(self)
Get the stored bookmarks from the server. Causes signals to be fired to reflect the changes. :returns: a list of bookmarks
9.319599
12.63365
0.737681
with (yield from self._lock): yield from self._set_bookmarks(bookmarks) self._diff_emit_update(bookmarks)
def set_bookmarks(self, bookmarks)
Store the sequence of bookmarks `bookmarks`. Causes signals to be fired to reflect the changes. .. note:: This should normally not be used. It does not mitigate the race condition between clients concurrently modifying the bookmarks and may lead to ...
11.640615
11.982989
0.971428
with (yield from self._lock): bookmarks = yield from self._get_bookmarks() try: modified_bookmarks = list(bookmarks) if new_bookmark not in bookmarks: modified_bookmarks.append(new_bookmark) yield from self._se...
def add_bookmark(self, new_bookmark, *, max_retries=3)
Add a bookmark and check whether it was successfully added to the bookmark list. Already existant bookmarks are not added twice. :param new_bookmark: the bookmark to add :type new_bookmark: an instance of :class:`~bookmark_xso.Bookmark` :param max_retries: the number of retries if setti...
2.260977
2.39847
0.942675
with (yield from self._lock): bookmarks = yield from self._get_bookmarks() occurences = bookmarks.count(bookmark_to_remove) try: if not occurences: return modified_bookmarks = list(bookmarks) modif...
def discard_bookmark(self, bookmark_to_remove, *, max_retries=3)
Remove a bookmark and check it has been removed. :param bookmark_to_remove: the bookmark to remove :type bookmark_to_remove: a :class:`~bookmark_xso.Bookmark` subclass. :param max_retries: the number of retries of removing the bookmark fails. :type max_retrie...
2.102671
2.17794
0.965441
def replace_bookmark(bookmarks, old, new): modified_bookmarks = list(bookmarks) try: i = bookmarks.index(old) modified_bookmarks[i] = new except ValueError: modified_bookmarks.append(new) return modified_boo...
def update_bookmark(self, old, new, *, max_retries=3)
Update a bookmark and check it was successful. The bookmark matches an existing bookmark `old` according to bookmark equalitiy and replaces it by `new`. The bookmark `new` is added if no bookmark matching `old` exists. :param old: the bookmark to replace :type bookmark_to_remov...
2.672424
2.598312
1.028523
for (category, type_), names in self._identities.items(): for lang, name in names.items(): yield category, type_, lang, name if not names: yield category, type_, None, None
def iter_identities(self, stanza=None)
Return an iterator of tuples describing the identities of the node. :param stanza: The IQ request stanza :type stanza: :class:`~aioxmpp.IQ` or :data:`None` :rtype: iterable of (:class:`str`, :class:`str`, :class:`str` or :data:`None`, :class:`str` or :data:`None`) tuples :re...
5.522493
3.604571
1.532081
return itertools.chain( iter(self.STATIC_FEATURES), iter(self._features) )
def iter_features(self, stanza=None)
Return an iterator which yields the features of the node. :param stanza: The IQ request stanza :type stanza: :class:`~aioxmpp.IQ` :rtype: iterable of :class:`str` :return: :xep:`30` features of this node `stanza` is the :class:`aioxmpp.IQ` stanza of the request. This can be ...
11.290795
15.399117
0.733211
if var in self._features or var in self.STATIC_FEATURES: raise ValueError("feature already claimed: {!r}".format(var)) self._features.add(var) self.on_info_changed()
def register_feature(self, var)
Register a feature with the namespace variable `var`. If the feature is already registered or part of the default :xep:`30` features, a :class:`ValueError` is raised.
6.200716
6.228513
0.995537