Compare commits
2 Commits
rust
...
fix-channe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51cbe87501 | ||
|
|
ef02b3a596 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -15,8 +15,3 @@ slixmpp.egg-info/
|
|||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
venv/
|
venv/
|
||||||
|
|
||||||
# Added by cargo
|
|
||||||
|
|
||||||
/target
|
|
||||||
/Cargo.lock
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
steps:
|
steps:
|
||||||
mypy:
|
mypy:
|
||||||
image: python:3
|
image: python:3
|
||||||
commands:
|
script:
|
||||||
- pip3 install mypy types-setuptools
|
- pip3 install mypy types-setuptools
|
||||||
- mypy slixmpp
|
- mypy slixmpp
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
steps:
|
steps:
|
||||||
test_integration:
|
test_integration:
|
||||||
image: "python:3.11"
|
image: "python:3.11"
|
||||||
secrets: [ci_account1, ci_account1_password, ci_account2, ci_account2_password, ci_muc_server]
|
secrets: [ci_account1, ci_account1_password, ci_account2, ci_account2_password]
|
||||||
commands:
|
commands:
|
||||||
- apt-get update
|
- apt-get update
|
||||||
- apt-get install -y python3-pip cython3 gpg idn libidn-dev
|
- apt-get install -y python3-pip cython3 gpg
|
||||||
- pip3 install emoji aiohttp aiodns
|
- pip3 install emoji aiohttp aiodns
|
||||||
- python3 setup.py build_ext --inplace
|
|
||||||
- ./run_integration_tests.py
|
- ./run_integration_tests.py
|
||||||
|
|||||||
13
Cargo.toml
13
Cargo.toml
@@ -1,13 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "slixmpp"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
jid = "0.10"
|
|
||||||
pyo3 = "0.21"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
7
doap.xml
7
doap.xml
@@ -1064,12 +1064,5 @@
|
|||||||
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.4.tar.gz"/>
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.4.tar.gz"/>
|
||||||
</Version>
|
</Version>
|
||||||
</release>
|
</release>
|
||||||
<release>
|
|
||||||
<Version>
|
|
||||||
<revision>1.8.5</revision>
|
|
||||||
<created>2024-02-02</created>
|
|
||||||
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.5.tar.gz"/>
|
|
||||||
</Version>
|
|
||||||
</release>
|
|
||||||
</Project>
|
</Project>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ UNIQUE = uuid4().hex
|
|||||||
class TestMUC(SlixIntegration):
|
class TestMUC(SlixIntegration):
|
||||||
|
|
||||||
async def asyncSetUp(self):
|
async def asyncSetUp(self):
|
||||||
self.mucserver = self.envjid('CI_MUC_SERVER', default='chat.jabberfr.org')
|
self.mucserver = self.envjid('CI_MUC_SERVER')
|
||||||
self.muc = JID('%s@%s' % (UNIQUE, self.mucserver))
|
self.muc = JID('%s@%s' % (UNIQUE, self.mucserver))
|
||||||
self.add_client(
|
self.add_client(
|
||||||
self.envjid('CI_ACCOUNT1'),
|
self.envjid('CI_ACCOUNT1'),
|
||||||
|
|||||||
@@ -95,9 +95,7 @@ class ComponentXMPP(BaseXMPP):
|
|||||||
for st in Message, Iq, Presence:
|
for st in Message, Iq, Presence:
|
||||||
register_stanza_plugin(st, Error)
|
register_stanza_plugin(st, Error)
|
||||||
|
|
||||||
def connect(self, host: Optional[str] = None, port: int = 0, use_ssl: Optional[bool] = None,
|
def connect(self, host: str = None, port: int = 0, use_ssl: Optional[bool] = None) -> None:
|
||||||
force_starttls: Optional[bool] = None,
|
|
||||||
disable_starttls: Optional[bool] = None) -> None:
|
|
||||||
"""Connect to the server.
|
"""Connect to the server.
|
||||||
|
|
||||||
|
|
||||||
@@ -107,8 +105,6 @@ class ComponentXMPP(BaseXMPP):
|
|||||||
Defauts to :attr:`server_port`.
|
Defauts to :attr:`server_port`.
|
||||||
:param use_ssl: Flag indicating if SSL should be used by connecting
|
:param use_ssl: Flag indicating if SSL should be used by connecting
|
||||||
directly to a port using SSL.
|
directly to a port using SSL.
|
||||||
:param force_starttls: UNUSED
|
|
||||||
:param disable_starttls: UNUSED
|
|
||||||
"""
|
"""
|
||||||
if host is not None:
|
if host is not None:
|
||||||
self.server_host = host
|
self.server_host = host
|
||||||
|
|||||||
446
slixmpp/jid.py
446
slixmpp/jid.py
@@ -1 +1,445 @@
|
|||||||
from libslixmpp import JID, InvalidJID
|
|
||||||
|
# slixmpp.jid
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# This module allows for working with Jabber IDs (JIDs).
|
||||||
|
# Part of Slixmpp: The Slick XMPP Library
|
||||||
|
# :copyright: (c) 2011 Nathanael C. Fritz
|
||||||
|
# :license: MIT, see LICENSE for more details
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
import socket
|
||||||
|
|
||||||
|
from functools import lru_cache
|
||||||
|
from typing import (
|
||||||
|
Optional,
|
||||||
|
Union,
|
||||||
|
)
|
||||||
|
|
||||||
|
from slixmpp.stringprep import nodeprep, resourceprep, idna, StringprepError
|
||||||
|
|
||||||
|
HAVE_INET_PTON = hasattr(socket, 'inet_pton')
|
||||||
|
|
||||||
|
#: The basic regex pattern that a JID must match in order to determine
|
||||||
|
#: the local, domain, and resource parts. This regex does NOT do any
|
||||||
|
#: validation, which requires application of nodeprep, resourceprep, etc.
|
||||||
|
JID_PATTERN = re.compile(
|
||||||
|
"^(?:([^\"&'/:<>@]{1,1023})@)?([^/@]{1,1023})(?:/(.{1,1023}))?$"
|
||||||
|
)
|
||||||
|
|
||||||
|
#: The set of escape sequences for the characters not allowed by nodeprep.
|
||||||
|
JID_ESCAPE_SEQUENCES = {'\\20', '\\22', '\\26', '\\27', '\\2f',
|
||||||
|
'\\3a', '\\3c', '\\3e', '\\40', '\\5c'}
|
||||||
|
|
||||||
|
#: The reverse mapping of escape sequences to their original forms.
|
||||||
|
JID_UNESCAPE_TRANSFORMATIONS = {'\\20': ' ',
|
||||||
|
'\\22': '"',
|
||||||
|
'\\26': '&',
|
||||||
|
'\\27': "'",
|
||||||
|
'\\2f': '/',
|
||||||
|
'\\3a': ':',
|
||||||
|
'\\3c': '<',
|
||||||
|
'\\3e': '>',
|
||||||
|
'\\40': '@',
|
||||||
|
'\\5c': '\\'}
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Find the best cache size for a standard usage.
|
||||||
|
@lru_cache(maxsize=1024)
|
||||||
|
def _parse_jid(data: str):
|
||||||
|
"""
|
||||||
|
Parse string data into the node, domain, and resource
|
||||||
|
components of a JID, if possible.
|
||||||
|
|
||||||
|
:param string data: A string that is potentially a JID.
|
||||||
|
|
||||||
|
:raises InvalidJID:
|
||||||
|
|
||||||
|
:returns: tuple of the validated local, domain, and resource strings
|
||||||
|
"""
|
||||||
|
match = JID_PATTERN.match(data)
|
||||||
|
if not match:
|
||||||
|
raise InvalidJID('JID could not be parsed')
|
||||||
|
|
||||||
|
(node, domain, resource) = match.groups()
|
||||||
|
|
||||||
|
node = _validate_node(node)
|
||||||
|
domain = _validate_domain(domain)
|
||||||
|
resource = _validate_resource(resource)
|
||||||
|
|
||||||
|
return node, domain, resource
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_node(node: Optional[str]):
|
||||||
|
"""Validate the local, or username, portion of a JID.
|
||||||
|
|
||||||
|
:raises InvalidJID:
|
||||||
|
|
||||||
|
:returns: The local portion of a JID, as validated by nodeprep.
|
||||||
|
"""
|
||||||
|
if node is None:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
node = nodeprep(node)
|
||||||
|
except StringprepError:
|
||||||
|
raise InvalidJID('Nodeprep failed')
|
||||||
|
|
||||||
|
if not node:
|
||||||
|
raise InvalidJID('Localpart must not be 0 bytes')
|
||||||
|
if len(node) > 1023:
|
||||||
|
raise InvalidJID('Localpart must be less than 1024 bytes')
|
||||||
|
return node
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_domain(domain: str):
|
||||||
|
"""Validate the domain portion of a JID.
|
||||||
|
|
||||||
|
IP literal addresses are left as-is, if valid. Domain names
|
||||||
|
are stripped of any trailing label separators (`.`), and are
|
||||||
|
checked with the nameprep profile of stringprep. If the given
|
||||||
|
domain is actually a punyencoded version of a domain name, it
|
||||||
|
is converted back into its original Unicode form. Domains must
|
||||||
|
also not start or end with a dash (`-`).
|
||||||
|
|
||||||
|
:raises InvalidJID:
|
||||||
|
|
||||||
|
:returns: The validated domain name
|
||||||
|
"""
|
||||||
|
ip_addr = False
|
||||||
|
|
||||||
|
# First, check if this is an IPv4 address
|
||||||
|
try:
|
||||||
|
socket.inet_aton(domain)
|
||||||
|
ip_addr = True
|
||||||
|
except socket.error:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Check if this is an IPv6 address
|
||||||
|
if not ip_addr and HAVE_INET_PTON and domain[0] == '[' and domain[-1] == ']':
|
||||||
|
try:
|
||||||
|
ip = domain[1:-1]
|
||||||
|
socket.inet_pton(socket.AF_INET6, ip)
|
||||||
|
ip_addr = True
|
||||||
|
except (socket.error, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not ip_addr:
|
||||||
|
# This is a domain name, which must be checked further
|
||||||
|
|
||||||
|
if domain and domain[-1] == '.':
|
||||||
|
domain = domain[:-1]
|
||||||
|
|
||||||
|
try:
|
||||||
|
domain = idna(domain)
|
||||||
|
except StringprepError:
|
||||||
|
raise InvalidJID(f'idna validation failed: {domain}')
|
||||||
|
|
||||||
|
if ':' in domain:
|
||||||
|
raise InvalidJID(f'Domain containing a port: {domain}')
|
||||||
|
for label in domain.split('.'):
|
||||||
|
if not label:
|
||||||
|
raise InvalidJID(f'Domain containing too many dots: {domain}')
|
||||||
|
if '-' in (label[0], label[-1]):
|
||||||
|
raise InvalidJID(f'Domain starting or ending with -: {domain}')
|
||||||
|
|
||||||
|
if not domain:
|
||||||
|
raise InvalidJID('Domain must not be 0 bytes')
|
||||||
|
if len(domain) > 1023:
|
||||||
|
raise InvalidJID('Domain must be less than 1024 bytes')
|
||||||
|
|
||||||
|
return domain
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_resource(resource: Optional[str]):
|
||||||
|
"""Validate the resource portion of a JID.
|
||||||
|
|
||||||
|
:raises InvalidJID:
|
||||||
|
|
||||||
|
:returns: The local portion of a JID, as validated by resourceprep.
|
||||||
|
"""
|
||||||
|
if resource is None:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
resource = resourceprep(resource)
|
||||||
|
except StringprepError:
|
||||||
|
raise InvalidJID('Resourceprep failed')
|
||||||
|
|
||||||
|
if not resource:
|
||||||
|
raise InvalidJID('Resource must not be 0 bytes')
|
||||||
|
if len(resource) > 1023:
|
||||||
|
raise InvalidJID('Resource must be less than 1024 bytes')
|
||||||
|
return resource
|
||||||
|
|
||||||
|
|
||||||
|
def _unescape_node(node: str):
|
||||||
|
"""Unescape a local portion of a JID.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
The unescaped local portion is meant ONLY for presentation,
|
||||||
|
and should not be used for other purposes.
|
||||||
|
"""
|
||||||
|
unescaped = []
|
||||||
|
seq = ''
|
||||||
|
for i, char in enumerate(node):
|
||||||
|
if char == '\\':
|
||||||
|
seq = node[i:i+3]
|
||||||
|
if seq not in JID_ESCAPE_SEQUENCES:
|
||||||
|
seq = ''
|
||||||
|
if seq:
|
||||||
|
if len(seq) == 3:
|
||||||
|
unescaped.append(JID_UNESCAPE_TRANSFORMATIONS.get(seq, char))
|
||||||
|
|
||||||
|
# Pop character off the escape sequence, and ignore it
|
||||||
|
seq = seq[1:]
|
||||||
|
else:
|
||||||
|
unescaped.append(char)
|
||||||
|
return ''.join(unescaped)
|
||||||
|
|
||||||
|
|
||||||
|
def _format_jid(
|
||||||
|
local: Optional[str] = None,
|
||||||
|
domain: Optional[str] = None,
|
||||||
|
resource: Optional[str] = None,
|
||||||
|
):
|
||||||
|
"""Format the given JID components into a full or bare JID.
|
||||||
|
|
||||||
|
:param string local: Optional. The local portion of the JID.
|
||||||
|
:param string domain: Required. The domain name portion of the JID.
|
||||||
|
:param strin resource: Optional. The resource portion of the JID.
|
||||||
|
|
||||||
|
:return: A full or bare JID string.
|
||||||
|
"""
|
||||||
|
if domain is None:
|
||||||
|
return ''
|
||||||
|
if local is not None:
|
||||||
|
result = local + '@' + domain
|
||||||
|
else:
|
||||||
|
result = domain
|
||||||
|
if resource is not None:
|
||||||
|
result += '/' + resource
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidJID(ValueError):
|
||||||
|
"""
|
||||||
|
Raised when attempting to create a JID that does not pass validation.
|
||||||
|
|
||||||
|
It can also be raised if modifying an existing JID in such a way as
|
||||||
|
to make it invalid, such trying to remove the domain from an existing
|
||||||
|
full JID while the local and resource portions still exist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# pylint: disable=R0903
|
||||||
|
class UnescapedJID:
|
||||||
|
|
||||||
|
"""
|
||||||
|
.. versionadded:: 1.1.10
|
||||||
|
"""
|
||||||
|
|
||||||
|
__slots__ = ('_node', '_domain', '_resource')
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
node: Optional[str],
|
||||||
|
domain: Optional[str],
|
||||||
|
resource: Optional[str],
|
||||||
|
):
|
||||||
|
self._node = node
|
||||||
|
self._domain = domain
|
||||||
|
self._resource = resource
|
||||||
|
|
||||||
|
def __getattribute__(self, name: str):
|
||||||
|
"""Retrieve the given JID component.
|
||||||
|
|
||||||
|
:param name: one of: user, server, domain, resource,
|
||||||
|
full, or bare.
|
||||||
|
"""
|
||||||
|
if name == 'resource':
|
||||||
|
return self._resource or ''
|
||||||
|
if name in ('user', 'username', 'local', 'node'):
|
||||||
|
return self._node or ''
|
||||||
|
if name in ('server', 'domain', 'host'):
|
||||||
|
return self._domain or ''
|
||||||
|
if name in ('full', 'jid'):
|
||||||
|
return _format_jid(self._node, self._domain, self._resource)
|
||||||
|
if name == 'bare':
|
||||||
|
return _format_jid(self._node, self._domain)
|
||||||
|
return object.__getattribute__(self, name)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Use the full JID as the string value."""
|
||||||
|
return _format_jid(self._node, self._domain, self._resource)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
"""Use the full JID as the representation."""
|
||||||
|
return _format_jid(self._node, self._domain, self._resource)
|
||||||
|
|
||||||
|
|
||||||
|
class JID:
|
||||||
|
|
||||||
|
"""
|
||||||
|
A representation of a Jabber ID, or JID.
|
||||||
|
|
||||||
|
Each JID may have three components: a user, a domain, and an optional
|
||||||
|
resource. For example: user@domain/resource
|
||||||
|
|
||||||
|
When a resource is not used, the JID is called a bare JID.
|
||||||
|
The JID is a full JID otherwise.
|
||||||
|
|
||||||
|
**JID Properties:**
|
||||||
|
:full: The string value of the full JID.
|
||||||
|
:jid: Alias for ``full``.
|
||||||
|
:bare: The string value of the bare JID.
|
||||||
|
:node: The node portion of the JID.
|
||||||
|
:user: Alias for ``node``.
|
||||||
|
:local: Alias for ``node``.
|
||||||
|
:username: Alias for ``node``.
|
||||||
|
:domain: The domain name portion of the JID.
|
||||||
|
:server: Alias for ``domain``.
|
||||||
|
:host: Alias for ``domain``.
|
||||||
|
:resource: The resource portion of the JID.
|
||||||
|
|
||||||
|
:param string jid:
|
||||||
|
A string of the form ``'[user@]domain[/resource]'``.
|
||||||
|
:param bool bare:
|
||||||
|
If present, discard the provided resource.
|
||||||
|
|
||||||
|
:raises InvalidJID:
|
||||||
|
"""
|
||||||
|
|
||||||
|
__slots__ = ('_node', '_domain', '_resource', '_bare', '_full')
|
||||||
|
|
||||||
|
def __init__(self, jid: Optional[Union[str, 'JID']] = None, bare: bool = False):
|
||||||
|
if not jid:
|
||||||
|
self._node = ''
|
||||||
|
self._domain = ''
|
||||||
|
self._resource = ''
|
||||||
|
self._bare = ''
|
||||||
|
self._full = ''
|
||||||
|
return
|
||||||
|
elif not isinstance(jid, JID):
|
||||||
|
node, domain, resource = _parse_jid(jid)
|
||||||
|
self._node = node
|
||||||
|
self._domain = domain
|
||||||
|
self._resource = resource if not bare else ''
|
||||||
|
else:
|
||||||
|
self._node = jid._node
|
||||||
|
self._domain = jid._domain
|
||||||
|
self._resource = jid._resource if not bare else ''
|
||||||
|
self._update_bare_full()
|
||||||
|
|
||||||
|
def unescape(self):
|
||||||
|
"""Return an unescaped JID object.
|
||||||
|
|
||||||
|
Using an unescaped JID is preferred for displaying JIDs
|
||||||
|
to humans, and they should NOT be used for any other
|
||||||
|
purposes than for presentation.
|
||||||
|
|
||||||
|
:return: :class:`UnescapedJID`
|
||||||
|
|
||||||
|
.. versionadded:: 1.1.10
|
||||||
|
"""
|
||||||
|
return UnescapedJID(_unescape_node(self._node),
|
||||||
|
self._domain,
|
||||||
|
self._resource)
|
||||||
|
|
||||||
|
def _update_bare_full(self):
|
||||||
|
"""Format the given JID into a bare and a full JID.
|
||||||
|
"""
|
||||||
|
self._bare = (self._node + '@' + self._domain
|
||||||
|
if self._node
|
||||||
|
else self._domain)
|
||||||
|
self._full = (self._bare + '/' + self._resource
|
||||||
|
if self._resource
|
||||||
|
else self._bare)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bare(self) -> str:
|
||||||
|
return self._bare
|
||||||
|
|
||||||
|
@bare.setter
|
||||||
|
def bare(self, value: str):
|
||||||
|
node, domain, resource = _parse_jid(value)
|
||||||
|
assert not resource
|
||||||
|
self._node = node
|
||||||
|
self._domain = domain
|
||||||
|
self._update_bare_full()
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node(self) -> str:
|
||||||
|
return self._node
|
||||||
|
|
||||||
|
@node.setter
|
||||||
|
def node(self, value: Optional[str]):
|
||||||
|
self._node = _validate_node(value)
|
||||||
|
self._update_bare_full()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def domain(self) -> str:
|
||||||
|
return self._domain
|
||||||
|
|
||||||
|
@domain.setter
|
||||||
|
def domain(self, value: str):
|
||||||
|
self._domain = _validate_domain(value)
|
||||||
|
self._update_bare_full()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def resource(self) -> str:
|
||||||
|
return self._resource
|
||||||
|
|
||||||
|
@resource.setter
|
||||||
|
def resource(self, value: Optional[str]):
|
||||||
|
self._resource = _validate_resource(value)
|
||||||
|
self._update_bare_full()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def full(self) -> str:
|
||||||
|
return self._full
|
||||||
|
|
||||||
|
@full.setter
|
||||||
|
def full(self, value: str):
|
||||||
|
self._node, self._domain, self._resource = _parse_jid(value)
|
||||||
|
self._update_bare_full()
|
||||||
|
|
||||||
|
user = node
|
||||||
|
local = node
|
||||||
|
username = node
|
||||||
|
|
||||||
|
server = domain
|
||||||
|
host = domain
|
||||||
|
|
||||||
|
jid = full
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Use the full JID as the string value."""
|
||||||
|
return self._full
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
"""Use the full JID as the representation."""
|
||||||
|
return self._full
|
||||||
|
|
||||||
|
# pylint: disable=W0212
|
||||||
|
def __eq__(self, other):
|
||||||
|
"""Two JIDs are equal if they have the same full JID value."""
|
||||||
|
if isinstance(other, UnescapedJID):
|
||||||
|
return False
|
||||||
|
if not isinstance(other, JID):
|
||||||
|
try:
|
||||||
|
other = JID(other)
|
||||||
|
except InvalidJID:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
return (self._node == other._node and
|
||||||
|
self._domain == other._domain and
|
||||||
|
self._resource == other._resource)
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
"""Two JIDs are considered unequal if they are not equal."""
|
||||||
|
return not self == other
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
"""Hash a JID based on the string version of its full JID."""
|
||||||
|
return hash(self._full)
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ PLUGINS = [
|
|||||||
'xep_0256', # Last Activity in Presence
|
'xep_0256', # Last Activity in Presence
|
||||||
'xep_0257', # Client Certificate Management for SASL EXTERNAL
|
'xep_0257', # Client Certificate Management for SASL EXTERNAL
|
||||||
'xep_0258', # Security Labels in XMPP
|
'xep_0258', # Security Labels in XMPP
|
||||||
'xep_0264', # Jingle Content Thumbnails
|
|
||||||
# 'xep_0270', # XMPP Compliance Suites 2010. Don’t automatically load
|
# 'xep_0270', # XMPP Compliance Suites 2010. Don’t automatically load
|
||||||
'xep_0279', # Server IP Check
|
'xep_0279', # Server IP Check
|
||||||
'xep_0280', # Message Carbons
|
'xep_0280', # Message Carbons
|
||||||
@@ -86,7 +85,6 @@ PLUGINS = [
|
|||||||
# 'xep_0302', # XMPP Compliance Suites 2012. Don’t automatically load
|
# 'xep_0302', # XMPP Compliance Suites 2012. Don’t automatically load
|
||||||
'xep_0308', # Last Message Correction
|
'xep_0308', # Last Message Correction
|
||||||
'xep_0313', # Message Archive Management
|
'xep_0313', # Message Archive Management
|
||||||
'xep_0317', # Hats
|
|
||||||
'xep_0319', # Last User Interaction in Presence
|
'xep_0319', # Last User Interaction in Presence
|
||||||
# 'xep_0323', # IoT Systems Sensor Data. Don’t automatically load
|
# 'xep_0323', # IoT Systems Sensor Data. Don’t automatically load
|
||||||
# 'xep_0325', # IoT Systems Control. Don’t automatically load
|
# 'xep_0325', # IoT Systems Control. Don’t automatically load
|
||||||
@@ -120,7 +118,6 @@ PLUGINS = [
|
|||||||
'xep_0444', # Message Reactions
|
'xep_0444', # Message Reactions
|
||||||
'xep_0447', # Stateless file sharing
|
'xep_0447', # Stateless file sharing
|
||||||
'xep_0461', # Message Replies
|
'xep_0461', # Message Replies
|
||||||
'xep_0469', # Bookmarks Pinning
|
|
||||||
# Meant to be imported by plugins
|
# Meant to be imported by plugins
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -137,14 +137,7 @@ class XEP_0199(BasePlugin):
|
|||||||
async def _keepalive(self, event=None):
|
async def _keepalive(self, event=None):
|
||||||
log.debug("Keepalive ping...")
|
log.debug("Keepalive ping...")
|
||||||
try:
|
try:
|
||||||
ifrom = None
|
rtt = await self.ping(self.xmpp.boundjid.host, timeout=self.timeout)
|
||||||
if self.xmpp.is_component:
|
|
||||||
ifrom = self.xmpp.boundjid
|
|
||||||
rtt = await self.ping(
|
|
||||||
self.xmpp.boundjid.host,
|
|
||||||
timeout=self.timeout,
|
|
||||||
ifrom=ifrom
|
|
||||||
)
|
|
||||||
except IqTimeout:
|
except IqTimeout:
|
||||||
log.debug("Did not receive ping back in time. " + \
|
log.debug("Did not receive ping back in time. " + \
|
||||||
"Requesting Reconnect.")
|
"Requesting Reconnect.")
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
from slixmpp.plugins.base import register_plugin
|
|
||||||
|
|
||||||
from .thumbnail import XEP_0264
|
|
||||||
|
|
||||||
register_plugin(XEP_0264)
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
from typing import Optional
|
|
||||||
|
|
||||||
from slixmpp import register_stanza_plugin
|
|
||||||
from slixmpp.plugins.xep_0234.stanza import File
|
|
||||||
from slixmpp.xmlstream import ElementBase
|
|
||||||
|
|
||||||
NS = "urn:xmpp:thumbs:1"
|
|
||||||
|
|
||||||
|
|
||||||
class Thumbnail(ElementBase):
|
|
||||||
name = plugin_attrib = "thumbnail"
|
|
||||||
namespace = NS
|
|
||||||
interfaces = {"uri", "media-type", "width", "height"}
|
|
||||||
|
|
||||||
def get_width(self) -> int:
|
|
||||||
return _int_or_none(self._get_attr("width"))
|
|
||||||
|
|
||||||
def get_height(self) -> int:
|
|
||||||
return _int_or_none(self._get_attr("height"))
|
|
||||||
|
|
||||||
def set_width(self, v: int) -> None:
|
|
||||||
self._set_attr("width", str(v))
|
|
||||||
|
|
||||||
def set_height(self, v: int) -> None:
|
|
||||||
self._set_attr("height", str(v))
|
|
||||||
|
|
||||||
|
|
||||||
def _int_or_none(v) -> Optional[int]:
|
|
||||||
try:
|
|
||||||
return int(v)
|
|
||||||
except ValueError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def register_plugin():
|
|
||||||
register_stanza_plugin(File, Thumbnail)
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
from slixmpp.plugins import BasePlugin
|
|
||||||
|
|
||||||
from . import stanza
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class XEP_0264(BasePlugin):
|
|
||||||
|
|
||||||
"""
|
|
||||||
XEP-0264: Jingle Content Thumbnails
|
|
||||||
|
|
||||||
Can also be used with 0385 (Stateless inline media sharing)
|
|
||||||
"""
|
|
||||||
|
|
||||||
name = "xep_0264"
|
|
||||||
description = "XEP-0264: Jingle Content Thumbnails"
|
|
||||||
dependencies = {"xep_0234"}
|
|
||||||
stanza = stanza
|
|
||||||
|
|
||||||
def plugin_init(self):
|
|
||||||
stanza.register_plugin()
|
|
||||||
@@ -52,10 +52,9 @@ class MAM(ElementBase):
|
|||||||
#: fetch, not relevant for the stanza itself.
|
#: fetch, not relevant for the stanza itself.
|
||||||
interfaces = {
|
interfaces = {
|
||||||
'queryid', 'start', 'end', 'with', 'results',
|
'queryid', 'start', 'end', 'with', 'results',
|
||||||
'before_id', 'after_id', 'ids', 'flip_page',
|
'before_id', 'after_id', 'ids',
|
||||||
}
|
}
|
||||||
sub_interfaces = {'start', 'end', 'with', 'before_id', 'after_id', 'ids',
|
sub_interfaces = {'start', 'end', 'with', 'before_id', 'after_id', 'ids'}
|
||||||
'flip_page'}
|
|
||||||
|
|
||||||
def setup(self, xml=None):
|
def setup(self, xml=None):
|
||||||
ElementBase.setup(self, xml)
|
ElementBase.setup(self, xml)
|
||||||
@@ -82,7 +81,7 @@ class MAM(ElementBase):
|
|||||||
def get_start(self) -> Optional[datetime]:
|
def get_start(self) -> Optional[datetime]:
|
||||||
fields = self.get_fields()
|
fields = self.get_fields()
|
||||||
field = fields.get('start')
|
field = fields.get('start')
|
||||||
if field and field["value"]:
|
if field:
|
||||||
return xep_0082.parse(field['value'])
|
return xep_0082.parse(field['value'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -95,7 +94,7 @@ class MAM(ElementBase):
|
|||||||
def get_end(self) -> Optional[datetime]:
|
def get_end(self) -> Optional[datetime]:
|
||||||
fields = self.get_fields()
|
fields = self.get_fields()
|
||||||
field = fields.get('end')
|
field = fields.get('end')
|
||||||
if field and field["value"]:
|
if field:
|
||||||
return xep_0082.parse(field['value'])
|
return xep_0082.parse(field['value'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -169,8 +168,6 @@ class MAM(ElementBase):
|
|||||||
def del_results(self):
|
def del_results(self):
|
||||||
self._results = []
|
self._results = []
|
||||||
|
|
||||||
def get_flip_page(self):
|
|
||||||
return self.xml.find(f'{{{self.namespace}}}flip-page') is not None
|
|
||||||
|
|
||||||
class Fin(ElementBase):
|
class Fin(ElementBase):
|
||||||
"""A MAM fin element (end of query).
|
"""A MAM fin element (end of query).
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
# Slixmpp: The Slick XMPP Library
|
|
||||||
# This file is part of Slixmpp.
|
|
||||||
# See the file LICENSE for copying permission.
|
|
||||||
from slixmpp.plugins import register_plugin
|
|
||||||
from slixmpp.plugins.xep_0317 import stanza
|
|
||||||
from slixmpp.plugins.xep_0317.hats import XEP_0317
|
|
||||||
from slixmpp.plugins.xep_0317.stanza import Hat, Hats
|
|
||||||
|
|
||||||
register_plugin(XEP_0317)
|
|
||||||
|
|
||||||
__all__ = ['stanza', 'XEP_317']
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
from slixmpp.plugins import BasePlugin
|
|
||||||
from . import stanza
|
|
||||||
|
|
||||||
|
|
||||||
class XEP_0317(BasePlugin):
|
|
||||||
"""
|
|
||||||
XEP-0317: Hats
|
|
||||||
"""
|
|
||||||
name = 'xep_0317'
|
|
||||||
description = 'XEP-0317: Hats'
|
|
||||||
dependencies = {'xep_0030', 'xep_0045', 'xep_0050'}
|
|
||||||
stanza = stanza
|
|
||||||
namespace = stanza.NS
|
|
||||||
|
|
||||||
def plugin_init(self):
|
|
||||||
stanza.register_plugin()
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
from slixmpp import Presence
|
|
||||||
from slixmpp.xmlstream import ElementBase, register_stanza_plugin
|
|
||||||
from typing import List, Tuple
|
|
||||||
|
|
||||||
NS = 'urn:xmpp:hats:0'
|
|
||||||
|
|
||||||
|
|
||||||
class Hats(ElementBase):
|
|
||||||
"""
|
|
||||||
Hats element, container for multiple hats:
|
|
||||||
|
|
||||||
.. code-block::xml
|
|
||||||
|
|
||||||
|
|
||||||
<hats xmlns='urn:xmpp:hats:0'>
|
|
||||||
<hat title='Host' uri='http://schemas.example.com/hats#host' xml:lang='en-us'>
|
|
||||||
<badge xmlns="urn:example:badges" fgcolor="#000000" bgcolor="#58C5BA"/>
|
|
||||||
</hat>
|
|
||||||
<hat title='Presenter' uri='http://schemas.example.com/hats#presenter' xml:lang='en-us'>
|
|
||||||
<badge xmlns="urn:example:badges" fgcolor="#000000" bgcolor="#EC0524"/>
|
|
||||||
</hat>
|
|
||||||
</hats>
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
name = 'hats'
|
|
||||||
namespace = NS
|
|
||||||
plugin_attrib = 'hats'
|
|
||||||
|
|
||||||
def add_hats(self, data: List[Tuple[str, str]]) -> None:
|
|
||||||
for uri, title in data:
|
|
||||||
hat = Hat()
|
|
||||||
hat["uri"] = uri
|
|
||||||
hat["title"] = title
|
|
||||||
self.append(hat)
|
|
||||||
|
|
||||||
|
|
||||||
class Hat(ElementBase):
|
|
||||||
"""
|
|
||||||
Hat element, has a title and url, may contain arbitrary sub-elements.
|
|
||||||
|
|
||||||
.. code-block::xml
|
|
||||||
|
|
||||||
<hat title='Host' uri='http://schemas.example.com/hats#host' xml:lang='en-us'>
|
|
||||||
<badge xmlns="urn:example:badges" fgcolor="#000000" bgcolor="#58C5BA"/>
|
|
||||||
</hat>
|
|
||||||
|
|
||||||
"""
|
|
||||||
name = 'hat'
|
|
||||||
plugin_attrib = 'hat'
|
|
||||||
namespace = NS
|
|
||||||
interfaces = {'title', 'uri'}
|
|
||||||
plugin_multi_attrib = "hats"
|
|
||||||
|
|
||||||
|
|
||||||
def register_plugin() -> None:
|
|
||||||
register_stanza_plugin(Hats, Hat, iterable=True)
|
|
||||||
register_stanza_plugin(Presence, Hats)
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
from slixmpp.plugins.base import register_plugin
|
|
||||||
|
|
||||||
from . import stanza
|
|
||||||
from .pinning import XEP_0469
|
|
||||||
|
|
||||||
register_plugin(XEP_0469)
|
|
||||||
|
|
||||||
__all__ = ['stanza', 'XEP_0469']
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
from slixmpp.plugins import BasePlugin
|
|
||||||
from . import stanza
|
|
||||||
|
|
||||||
|
|
||||||
class XEP_0469(BasePlugin):
|
|
||||||
|
|
||||||
"""
|
|
||||||
XEP-0469: Bookmark Pinning
|
|
||||||
"""
|
|
||||||
|
|
||||||
name = "xep_0469"
|
|
||||||
description = "XEP-0469: Bookmark Pinning"
|
|
||||||
dependencies = {"xep_0402"}
|
|
||||||
stanza = stanza
|
|
||||||
|
|
||||||
def plugin_init(self):
|
|
||||||
stanza.register_plugin()
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
from slixmpp import register_stanza_plugin
|
|
||||||
from slixmpp.plugins.xep_0402.stanza import Extensions
|
|
||||||
from slixmpp.xmlstream import ElementBase
|
|
||||||
|
|
||||||
NS = "urn:xmpp:bookmarks-pinning:0"
|
|
||||||
|
|
||||||
|
|
||||||
class Pinned(ElementBase):
|
|
||||||
"""
|
|
||||||
Pinned bookmark element
|
|
||||||
|
|
||||||
|
|
||||||
To enable it on a Conference element, use enable() like this:
|
|
||||||
|
|
||||||
.. code-block::python
|
|
||||||
|
|
||||||
# C being a Conference element
|
|
||||||
C['extensions'].enable('pinned')
|
|
||||||
|
|
||||||
Which will add the <pinned> element to the <extensions> element.
|
|
||||||
"""
|
|
||||||
namespace = NS
|
|
||||||
name = "pinned"
|
|
||||||
plugin_attrib = "pinned"
|
|
||||||
interfaces = {"pinned"}
|
|
||||||
bool_interfaces = {"pinned"}
|
|
||||||
is_extension = True
|
|
||||||
|
|
||||||
|
|
||||||
def register_plugin():
|
|
||||||
register_stanza_plugin(Extensions, Pinned)
|
|
||||||
@@ -69,14 +69,12 @@ from slixmpp.plugins.xep_0249 import XEP_0249
|
|||||||
from slixmpp.plugins.xep_0256 import XEP_0256
|
from slixmpp.plugins.xep_0256 import XEP_0256
|
||||||
from slixmpp.plugins.xep_0257 import XEP_0257
|
from slixmpp.plugins.xep_0257 import XEP_0257
|
||||||
from slixmpp.plugins.xep_0258 import XEP_0258
|
from slixmpp.plugins.xep_0258 import XEP_0258
|
||||||
from slixmpp.plugins.xep_0264 import XEP_0264
|
|
||||||
from slixmpp.plugins.xep_0279 import XEP_0279
|
from slixmpp.plugins.xep_0279 import XEP_0279
|
||||||
from slixmpp.plugins.xep_0280 import XEP_0280
|
from slixmpp.plugins.xep_0280 import XEP_0280
|
||||||
from slixmpp.plugins.xep_0297 import XEP_0297
|
from slixmpp.plugins.xep_0297 import XEP_0297
|
||||||
from slixmpp.plugins.xep_0300 import XEP_0300
|
from slixmpp.plugins.xep_0300 import XEP_0300
|
||||||
from slixmpp.plugins.xep_0308 import XEP_0308
|
from slixmpp.plugins.xep_0308 import XEP_0308
|
||||||
from slixmpp.plugins.xep_0313 import XEP_0313
|
from slixmpp.plugins.xep_0313 import XEP_0313
|
||||||
from slixmpp.plugins.xep_0317 import XEP_0317
|
|
||||||
from slixmpp.plugins.xep_0319 import XEP_0319
|
from slixmpp.plugins.xep_0319 import XEP_0319
|
||||||
from slixmpp.plugins.xep_0332 import XEP_0332
|
from slixmpp.plugins.xep_0332 import XEP_0332
|
||||||
from slixmpp.plugins.xep_0333 import XEP_0333
|
from slixmpp.plugins.xep_0333 import XEP_0333
|
||||||
@@ -102,7 +100,6 @@ from slixmpp.plugins.xep_0428 import XEP_0428
|
|||||||
from slixmpp.plugins.xep_0437 import XEP_0437
|
from slixmpp.plugins.xep_0437 import XEP_0437
|
||||||
from slixmpp.plugins.xep_0439 import XEP_0439
|
from slixmpp.plugins.xep_0439 import XEP_0439
|
||||||
from slixmpp.plugins.xep_0444 import XEP_0444
|
from slixmpp.plugins.xep_0444 import XEP_0444
|
||||||
from slixmpp.plugins.xep_0461 import XEP_0461
|
|
||||||
|
|
||||||
|
|
||||||
class PluginsDict(TypedDict):
|
class PluginsDict(TypedDict):
|
||||||
@@ -165,14 +162,12 @@ class PluginsDict(TypedDict):
|
|||||||
xep_0256: XEP_0256
|
xep_0256: XEP_0256
|
||||||
xep_0257: XEP_0257
|
xep_0257: XEP_0257
|
||||||
xep_0258: XEP_0258
|
xep_0258: XEP_0258
|
||||||
xep_0264: XEP_0264
|
|
||||||
xep_0279: XEP_0279
|
xep_0279: XEP_0279
|
||||||
xep_0280: XEP_0280
|
xep_0280: XEP_0280
|
||||||
xep_0297: XEP_0297
|
xep_0297: XEP_0297
|
||||||
xep_0300: XEP_0300
|
xep_0300: XEP_0300
|
||||||
xep_0308: XEP_0308
|
xep_0308: XEP_0308
|
||||||
xep_0313: XEP_0313
|
xep_0313: XEP_0313
|
||||||
xep_0317: XEP_0317
|
|
||||||
xep_0319: XEP_0319
|
xep_0319: XEP_0319
|
||||||
xep_0332: XEP_0332
|
xep_0332: XEP_0332
|
||||||
xep_0333: XEP_0333
|
xep_0333: XEP_0333
|
||||||
@@ -198,4 +193,3 @@ class PluginsDict(TypedDict):
|
|||||||
xep_0437: XEP_0437
|
xep_0437: XEP_0437
|
||||||
xep_0439: XEP_0439
|
xep_0439: XEP_0439
|
||||||
xep_0444: XEP_0444
|
xep_0444: XEP_0444
|
||||||
xep_0461: XEP_0461
|
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ class SlixIntegration(IsolatedAsyncioTestCase):
|
|||||||
self.clients = []
|
self.clients = []
|
||||||
self.addAsyncCleanup(self._destroy)
|
self.addAsyncCleanup(self._destroy)
|
||||||
|
|
||||||
def envjid(self, name: str, *, default: Optional[str] = None) -> JID:
|
def envjid(self, name):
|
||||||
"""Get a JID from an env var"""
|
"""Get a JID from an env var"""
|
||||||
value = os.getenv(name, default=default)
|
value = os.getenv(name)
|
||||||
return JID(value)
|
return JID(value)
|
||||||
|
|
||||||
def envstr(self, name):
|
def envstr(self, name):
|
||||||
|
|||||||
@@ -755,8 +755,5 @@ class SlixTest(unittest.TestCase):
|
|||||||
|
|
||||||
@atexit.register
|
@atexit.register
|
||||||
def cleanup():
|
def cleanup():
|
||||||
try:
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.close()
|
loop.close()
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|||||||
@@ -5,5 +5,5 @@
|
|||||||
# We don't want to have to import the entire library
|
# We don't want to have to import the entire library
|
||||||
# just to get the version info for setup.py
|
# just to get the version info for setup.py
|
||||||
|
|
||||||
__version__ = '1.8.5'
|
__version__ = '1.8.4'
|
||||||
__version_info__ = (1, 8, 5)
|
__version_info__ = (1, 8, 4)
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
else:
|
else:
|
||||||
self.loop.run_until_complete(self.disconnected)
|
self.loop.run_until_complete(self.disconnected)
|
||||||
else:
|
else:
|
||||||
tasks: List[Union[asyncio.Task, asyncio.Future]] = [asyncio.Task(asyncio.sleep(timeout))]
|
tasks: List[Awaitable] = [asyncio.sleep(timeout)]
|
||||||
if not forever:
|
if not forever:
|
||||||
tasks.append(self.disconnected)
|
tasks.append(self.disconnected)
|
||||||
self.loop.run_until_complete(asyncio.wait(tasks))
|
self.loop.run_until_complete(asyncio.wait(tasks))
|
||||||
@@ -850,8 +850,6 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
log.debug("Connection error:", exc_info=True)
|
log.debug("Connection error:", exc_info=True)
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
return False
|
return False
|
||||||
if transp is None:
|
|
||||||
raise Exception("Transport should not be none")
|
|
||||||
der_cert = transp.get_extra_info("ssl_object").getpeercert(True)
|
der_cert = transp.get_extra_info("ssl_object").getpeercert(True)
|
||||||
pem_cert = ssl.DER_cert_to_PEM_cert(der_cert)
|
pem_cert = ssl.DER_cert_to_PEM_cert(der_cert)
|
||||||
self.event('ssl_cert', pem_cert)
|
self.event('ssl_cert', pem_cert)
|
||||||
|
|||||||
278
src/lib.rs
278
src/lib.rs
@@ -1,278 +0,0 @@
|
|||||||
use pyo3::exceptions::{PyNotImplementedError, PyValueError};
|
|
||||||
use pyo3::prelude::*;
|
|
||||||
|
|
||||||
pyo3::create_exception!(py_jid, InvalidJID, PyValueError, "Raised when attempting to create a JID that does not pass validation.\n\nIt can also be raised if modifying an existing JID in such a way as\nto make it invalid, such trying to remove the domain from an existing\nfull JID while the local and resource portions still exist.");
|
|
||||||
|
|
||||||
fn to_exc(err: jid::Error) -> PyErr {
|
|
||||||
InvalidJID::new_err(err.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A representation of a Jabber ID, or JID.
|
|
||||||
///
|
|
||||||
/// Each JID may have three components: a user, a domain, and an optional resource. For example:
|
|
||||||
/// user@domain/resource
|
|
||||||
///
|
|
||||||
/// When a resource is not used, the JID is called a bare JID. The JID is a full JID otherwise.
|
|
||||||
///
|
|
||||||
/// Raises InvalidJID if the parser rejects it.
|
|
||||||
#[pyclass(name = "JID", module = "slixmpp.jid")]
|
|
||||||
struct PyJid {
|
|
||||||
jid: Option<jid::Jid>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pymethods]
|
|
||||||
impl PyJid {
|
|
||||||
#[new]
|
|
||||||
#[pyo3(signature = (jid=None, bare=false))]
|
|
||||||
fn new(jid: Option<&Bound<'_, PyAny>>, bare: bool) -> PyResult<Self> {
|
|
||||||
if let Some(jid) = jid {
|
|
||||||
if let Ok(py_jid) = jid.extract::<PyRef<PyJid>>() {
|
|
||||||
if bare {
|
|
||||||
if let Some(py_jid) = &(*py_jid).jid {
|
|
||||||
Ok(PyJid {
|
|
||||||
jid: Some(jid::Jid::Bare(py_jid.to_bare())),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Ok(PyJid { jid: None })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(PyJid {
|
|
||||||
jid: (*py_jid).jid.clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let jid: &str = jid.extract()?;
|
|
||||||
if jid.is_empty() {
|
|
||||||
Ok(PyJid { jid: None })
|
|
||||||
} else {
|
|
||||||
let mut jid = jid::Jid::new(jid).map_err(to_exc)?;
|
|
||||||
if bare {
|
|
||||||
jid = jid::Jid::Bare(jid.into_bare())
|
|
||||||
}
|
|
||||||
Ok(PyJid { jid: Some(jid) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(PyJid { jid: None })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO: implement or remove from the API
|
|
||||||
fn unescape() {
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_bare(&self) -> String {
|
|
||||||
match &self.jid {
|
|
||||||
None => String::new(),
|
|
||||||
Some(jid) => jid.to_bare().to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_bare(&mut self, bare: &str) -> PyResult<()> {
|
|
||||||
let bare = jid::BareJid::new(bare).map_err(to_exc)?;
|
|
||||||
self.jid = Some(match &self.jid {
|
|
||||||
Some(jid::Jid::Bare(_)) | None => jid::Jid::Bare(bare),
|
|
||||||
Some(jid::Jid::Full(jid)) => jid::Jid::Full(bare.with_resource(&jid.resource())),
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_full(&self) -> String {
|
|
||||||
match &self.jid {
|
|
||||||
None => String::new(),
|
|
||||||
Some(jid) => jid.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_full(&mut self, full: &str) -> PyResult<()> {
|
|
||||||
// JID.full = 'domain' is acceptable in slixmpp.
|
|
||||||
self.jid = Some(jid::Jid::new(full).map_err(to_exc)?);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_node(&self) -> String {
|
|
||||||
match &self.jid {
|
|
||||||
None => String::new(),
|
|
||||||
Some(jid) => jid
|
|
||||||
.node_str()
|
|
||||||
.map(ToString::to_string)
|
|
||||||
.unwrap_or_else(String::new),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_node(&mut self, node: &str) -> PyResult<()> {
|
|
||||||
let node = jid::NodePart::new(node).map_err(to_exc)?;
|
|
||||||
self.jid = Some(match &self.jid {
|
|
||||||
Some(jid::Jid::Bare(jid)) => {
|
|
||||||
jid::Jid::Bare(jid::BareJid::from_parts(Some(&node), &jid.domain()))
|
|
||||||
}
|
|
||||||
Some(jid::Jid::Full(jid)) => jid::Jid::Full(jid::FullJid::from_parts(
|
|
||||||
Some(&node),
|
|
||||||
&jid.domain(),
|
|
||||||
&jid.resource(),
|
|
||||||
)),
|
|
||||||
None => Err(InvalidJID::new_err("JID.node must apply to a proper JID"))?,
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_domain(&self) -> String {
|
|
||||||
match &self.jid {
|
|
||||||
None => String::new(),
|
|
||||||
Some(jid) => jid.domain_str().to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_domain(&mut self, domain: &str) -> PyResult<()> {
|
|
||||||
let domain = jid::DomainPart::new(domain).map_err(to_exc)?;
|
|
||||||
self.jid = Some(match &self.jid {
|
|
||||||
Some(jid::Jid::Bare(jid)) => {
|
|
||||||
jid::Jid::Bare(jid::BareJid::from_parts(jid.node().as_ref(), &domain))
|
|
||||||
}
|
|
||||||
Some(jid::Jid::Full(jid)) => jid::Jid::Full(jid::FullJid::from_parts(
|
|
||||||
jid.node().as_ref(),
|
|
||||||
&domain,
|
|
||||||
&jid.resource(),
|
|
||||||
)),
|
|
||||||
None => jid::Jid::Bare(jid::BareJid::from_parts(None, &domain)),
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_resource(&self) -> String {
|
|
||||||
match &self.jid {
|
|
||||||
None => String::new(),
|
|
||||||
Some(jid) => jid
|
|
||||||
.resource_str()
|
|
||||||
.map(ToString::to_string)
|
|
||||||
.unwrap_or_else(String::new),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_resource(&mut self, resource: &str) -> PyResult<()> {
|
|
||||||
let resource = jid::ResourcePart::new(resource).map_err(to_exc)?;
|
|
||||||
self.jid = Some(match &self.jid {
|
|
||||||
Some(jid::Jid::Bare(jid)) => jid::Jid::Full(jid.with_resource(&resource)),
|
|
||||||
Some(jid::Jid::Full(jid)) => jid::Jid::Full(jid::FullJid::from_parts(
|
|
||||||
jid.node().as_ref(),
|
|
||||||
&jid.domain(),
|
|
||||||
&resource,
|
|
||||||
)),
|
|
||||||
None => Err(InvalidJID::new_err(
|
|
||||||
"JID.resource must apply to a proper JID",
|
|
||||||
))?,
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Use the full JID as the string value.
|
|
||||||
fn __str__(&self) -> String {
|
|
||||||
match &self.jid {
|
|
||||||
None => String::new(),
|
|
||||||
Some(jid) => jid.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Use the full JID as the representation.
|
|
||||||
fn __repr__(&self) -> String {
|
|
||||||
match &self.jid {
|
|
||||||
None => String::new(),
|
|
||||||
Some(jid) => jid.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Two JIDs are equal if they have the same full JID value.
|
|
||||||
fn __richcmp__(&self, other: &Bound<'_, PyAny>, op: pyo3::basic::CompareOp) -> PyResult<bool> {
|
|
||||||
let other = if let Ok(other) = other.extract::<PyRef<PyJid>>() {
|
|
||||||
other
|
|
||||||
} else if other.is_none() {
|
|
||||||
Bound::new(other.py(), PyJid::new(None, false)?)?.borrow()
|
|
||||||
} else {
|
|
||||||
Bound::new(other.py(), PyJid::new(Some(other), false)?)?.borrow()
|
|
||||||
};
|
|
||||||
match (&self.jid, &other.jid) {
|
|
||||||
(None, None) => Ok(true),
|
|
||||||
(Some(jid), Some(other)) => match op {
|
|
||||||
pyo3::basic::CompareOp::Eq => Ok(jid == other),
|
|
||||||
pyo3::basic::CompareOp::Ne => Ok(jid != other),
|
|
||||||
_ => Err(PyNotImplementedError::new_err(
|
|
||||||
"Only == and != are implemented",
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
_ => Ok(false),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Hash a JID based on the string version of its full JID.
|
|
||||||
fn __hash__(&self) -> isize {
|
|
||||||
if let Some(jid) = &self.jid {
|
|
||||||
// Use the same algorithm as the Python JID.
|
|
||||||
let string = jid.to_string();
|
|
||||||
unsafe { pyo3::ffi::_Py_HashBytes(string.as_ptr() as *const _, string.len() as isize) }
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Aliases
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_user(&self) -> String {
|
|
||||||
self.get_node()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_user(&mut self, user: &str) -> PyResult<()> {
|
|
||||||
self.set_node(user)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_server(&self) -> String {
|
|
||||||
self.get_domain()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_server(&mut self, server: &str) -> PyResult<()> {
|
|
||||||
self.set_domain(server)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_host(&self) -> String {
|
|
||||||
self.get_domain()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_host(&mut self, host: &str) -> PyResult<()> {
|
|
||||||
self.set_domain(host)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[getter]
|
|
||||||
fn get_jid(&self) -> String {
|
|
||||||
self.get_full()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[setter]
|
|
||||||
fn set_jid(&mut self, jid: &str) -> PyResult<()> {
|
|
||||||
self.set_full(jid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pymodule]
|
|
||||||
#[pyo3(name = "libslixmpp")]
|
|
||||||
fn py_jid(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
||||||
m.add_class::<PyJid>()?;
|
|
||||||
m.add("InvalidJID", py.get_type_bound::<InvalidJID>())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||||||
import unittest
|
import unittest
|
||||||
from slixmpp.test import SlixTest
|
from slixmpp.test import SlixTest
|
||||||
from slixmpp import JID, InvalidJID
|
from slixmpp import JID, InvalidJID
|
||||||
|
from slixmpp.jid import nodeprep
|
||||||
|
|
||||||
|
|
||||||
class TestJIDClass(SlixTest):
|
class TestJIDClass(SlixTest):
|
||||||
@@ -191,12 +192,10 @@ class TestJIDClass(SlixTest):
|
|||||||
self.assertRaises(InvalidJID, JID, 'test.com/%s' % resource)
|
self.assertRaises(InvalidJID, JID, 'test.com/%s' % resource)
|
||||||
self.assertRaises(InvalidJID, JID, 'user@test.com/%s' % resource)
|
self.assertRaises(InvalidJID, JID, 'user@test.com/%s' % resource)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testTooLongDomainLabel(self):
|
def testTooLongDomainLabel(self):
|
||||||
domain = ('a' * 64) + '.com'
|
domain = ('a' * 64) + '.com'
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testDomainEmptyLabel(self):
|
def testDomainEmptyLabel(self):
|
||||||
domain = 'aaa..bbb.com'
|
domain = 'aaa..bbb.com'
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
@@ -217,7 +216,6 @@ class TestJIDClass(SlixTest):
|
|||||||
jid3 = JID('%s/resource' % domain)
|
jid3 = JID('%s/resource' % domain)
|
||||||
jid4 = JID('user@%s/resource' % domain)
|
jid4 = JID('user@%s/resource' % domain)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testDomainInvalidIPv6NoBrackets(self):
|
def testDomainInvalidIPv6NoBrackets(self):
|
||||||
domain = '::1'
|
domain = '::1'
|
||||||
|
|
||||||
@@ -226,7 +224,6 @@ class TestJIDClass(SlixTest):
|
|||||||
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testDomainInvalidIPv6MissingBracket(self):
|
def testDomainInvalidIPv6MissingBracket(self):
|
||||||
domain = '[::1'
|
domain = '[::1'
|
||||||
|
|
||||||
@@ -235,7 +232,6 @@ class TestJIDClass(SlixTest):
|
|||||||
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testDomainInvalidIPv6WrongBracket(self):
|
def testDomainInvalidIPv6WrongBracket(self):
|
||||||
domain = '[::]1]'
|
domain = '[::]1]'
|
||||||
|
|
||||||
@@ -244,7 +240,6 @@ class TestJIDClass(SlixTest):
|
|||||||
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testDomainWithPort(self):
|
def testDomainWithPort(self):
|
||||||
domain = 'example.com:5555'
|
domain = 'example.com:5555'
|
||||||
|
|
||||||
@@ -253,14 +248,12 @@ class TestJIDClass(SlixTest):
|
|||||||
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, '%s/resource' % domain)
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testDomainWithTrailingDot(self):
|
def testDomainWithTrailingDot(self):
|
||||||
domain = 'example.com.'
|
domain = 'example.com.'
|
||||||
jid = JID('user@%s/resource' % domain)
|
jid = JID('user@%s/resource' % domain)
|
||||||
|
|
||||||
self.assertEqual(jid.domain, 'example.com')
|
self.assertEqual(jid.domain, 'example.com')
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testDomainWithDashes(self):
|
def testDomainWithDashes(self):
|
||||||
domain = 'example.com-'
|
domain = 'example.com-'
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
@@ -268,13 +261,21 @@ class TestJIDClass(SlixTest):
|
|||||||
domain = '-example.com'
|
domain = '-example.com'
|
||||||
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
|
||||||
|
|
||||||
@unittest.skip('Rust')
|
|
||||||
def testACEDomain(self):
|
def testACEDomain(self):
|
||||||
domain = 'xn--bcher-kva.ch'
|
domain = 'xn--bcher-kva.ch'
|
||||||
jid = JID('user@%s/resource' % domain)
|
jid = JID('user@%s/resource' % domain)
|
||||||
|
|
||||||
self.assertEqual(jid.domain.encode('utf-8'), b'b\xc3\xbccher.ch')
|
self.assertEqual(jid.domain.encode('utf-8'), b'b\xc3\xbccher.ch')
|
||||||
|
|
||||||
|
def testJIDUnescape(self):
|
||||||
|
jid = JID('here\\27s_a_wild_\\26_\\2fcr%zy\\2f_\\40ddress\\20for\\3a\\3cwv\\3e(\\22IMPS\\22)\\5c@example.com')
|
||||||
|
ujid = jid.unescape()
|
||||||
|
self.assertEqual(ujid.local, 'here\'s_a_wild_&_/cr%zy/_@ddress for:<wv>("imps")\\')
|
||||||
|
|
||||||
|
jid = JID('blah\\5cfoo\\5c20bar@example.com')
|
||||||
|
ujid = jid.unescape()
|
||||||
|
self.assertEqual(ujid.local, 'blah\\foo\\20bar')
|
||||||
|
|
||||||
def testStartOrEndWithEscapedSpaces(self):
|
def testStartOrEndWithEscapedSpaces(self):
|
||||||
local = ' foo'
|
local = ' foo'
|
||||||
self.assertRaises(InvalidJID, JID, '%s@example.com' % local)
|
self.assertRaises(InvalidJID, JID, '%s@example.com' % local)
|
||||||
@@ -287,5 +288,9 @@ class TestJIDClass(SlixTest):
|
|||||||
#self.assertRaises(InvalidJID, JID, '%s@example.com' % '\\20foo2')
|
#self.assertRaises(InvalidJID, JID, '%s@example.com' % '\\20foo2')
|
||||||
#self.assertRaises(InvalidJID, JID, '%s@example.com' % 'bar2\\20')
|
#self.assertRaises(InvalidJID, JID, '%s@example.com' % 'bar2\\20')
|
||||||
|
|
||||||
|
def testNodePrepIdemptotent(self):
|
||||||
|
node = 'ᴹᴵᴷᴬᴱᴸ'
|
||||||
|
self.assertEqual(nodeprep(node), nodeprep(nodeprep(node)))
|
||||||
|
|
||||||
|
|
||||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestJIDClass)
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestJIDClass)
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
import unittest
|
|
||||||
from slixmpp import Presence
|
|
||||||
from slixmpp.test import SlixTest
|
|
||||||
import slixmpp.plugins.xep_0317 as xep_0317
|
|
||||||
from slixmpp.plugins.xep_0317 import stanza
|
|
||||||
|
|
||||||
|
|
||||||
class TestStanzaHats(SlixTest):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
stanza.register_plugin()
|
|
||||||
|
|
||||||
def test_create_hats(self):
|
|
||||||
raw_xml = """
|
|
||||||
<hats xmlns="urn:xmpp:hats:0">
|
|
||||||
<hat uri="http://example.com/hats#Teacher" title="Teacher"/>
|
|
||||||
</hats>
|
|
||||||
"""
|
|
||||||
|
|
||||||
hats = xep_0317.Hats()
|
|
||||||
|
|
||||||
hat = xep_0317.Hat()
|
|
||||||
hat['uri'] = 'http://example.com/hats#Teacher'
|
|
||||||
hat['title'] = 'Teacher'
|
|
||||||
hats.append(hat)
|
|
||||||
|
|
||||||
self.check(hats, raw_xml, use_values=False)
|
|
||||||
|
|
||||||
def test_set_single_hat(self):
|
|
||||||
presence = Presence()
|
|
||||||
presence["hats"]["hat"]["uri"] = "test-uri"
|
|
||||||
presence["hats"]["hat"]["title"] = "test-title"
|
|
||||||
self.check(
|
|
||||||
presence, # language=XML
|
|
||||||
"""
|
|
||||||
<presence>
|
|
||||||
<hats xmlns='urn:xmpp:hats:0'>
|
|
||||||
<hat uri='test-uri' title='test-title'/>
|
|
||||||
</hats>
|
|
||||||
</presence>
|
|
||||||
""",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_set_multi_hat(self):
|
|
||||||
presence = Presence()
|
|
||||||
presence["hats"].add_hats([("uri1", "title1"), ("uri2", "title2")])
|
|
||||||
self.check(
|
|
||||||
presence, # language=XML
|
|
||||||
"""
|
|
||||||
<presence>
|
|
||||||
<hats xmlns='urn:xmpp:hats:0'>
|
|
||||||
<hat uri='uri1' title='title1'/>
|
|
||||||
<hat uri='uri2' title='title2'/>
|
|
||||||
</hats>
|
|
||||||
</presence>
|
|
||||||
""",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_get_hats(self):
|
|
||||||
presence = Presence()
|
|
||||||
presence["hats"].add_hats([("uri1", "title1"), ("uri2", "title2")])
|
|
||||||
for i, hat in enumerate(presence["hats"]["hats"], start=1):
|
|
||||||
self.assertEqual(hat["uri"], f"uri{i}")
|
|
||||||
self.assertEqual(hat["title"], f"title{i}")
|
|
||||||
|
|
||||||
|
|
||||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestStanzaHats)
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import unittest
|
|
||||||
|
|
||||||
from slixmpp.test import SlixTest
|
|
||||||
from slixmpp.plugins.xep_0469 import stanza
|
|
||||||
from slixmpp.plugins.xep_0402 import stanza as b_stanza
|
|
||||||
|
|
||||||
|
|
||||||
class TestBookmarksPinning(SlixTest):
|
|
||||||
def setUp(self):
|
|
||||||
b_stanza.register_plugin()
|
|
||||||
stanza.register_plugin()
|
|
||||||
|
|
||||||
def test_pinned(self):
|
|
||||||
bookmark = b_stanza.Conference()
|
|
||||||
bookmark["password"] = "pass"
|
|
||||||
bookmark["nick"] = "nick"
|
|
||||||
bookmark["autojoin"] = False
|
|
||||||
bookmark["extensions"].enable("pinned")
|
|
||||||
self.check(
|
|
||||||
bookmark,
|
|
||||||
"""
|
|
||||||
<conference xmlns='urn:xmpp:bookmarks:1'
|
|
||||||
autojoin='false'>
|
|
||||||
<nick>nick</nick>
|
|
||||||
<password>pass</password>
|
|
||||||
<extensions>
|
|
||||||
<pinned xmlns="urn:xmpp:bookmarks-pinning:0" />
|
|
||||||
</extensions>
|
|
||||||
</conference>
|
|
||||||
""",
|
|
||||||
use_values=False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestBookmarksPinning)
|
|
||||||
Reference in New Issue
Block a user