Compare commits
15 Commits
slix-1.8.5
...
test-ci
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcaf812a28 | ||
|
|
ae4de043d2 | ||
|
|
998bbb80ad | ||
|
|
5a5b36ab39 | ||
|
|
f151f0a7ab | ||
|
|
2424a3b36f | ||
|
|
1c4bbbce8e | ||
|
|
66d552d057 | ||
|
|
b8205a9ae4 | ||
|
|
85b7210115 | ||
|
|
909c865524 | ||
|
|
586d2f5107 | ||
|
|
9f7260747f | ||
|
|
c41209510a | ||
|
|
9266486f46 |
@@ -1,6 +1,6 @@
|
|||||||
steps:
|
steps:
|
||||||
mypy:
|
mypy:
|
||||||
image: python:3
|
image: python:3
|
||||||
script:
|
commands:
|
||||||
- pip3 install mypy types-setuptools
|
- pip3 install mypy types-setuptools
|
||||||
- mypy slixmpp
|
- mypy slixmpp
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
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]
|
secrets: [ci_account1, ci_account1_password, ci_account2, ci_account2_password, ci_muc_server]
|
||||||
commands:
|
commands:
|
||||||
- apt-get update
|
- apt-get update
|
||||||
- apt-get install -y python3-pip cython3 gpg
|
- apt-get install -y python3-pip cython3 gpg idn libidn-dev
|
||||||
- pip3 install emoji aiohttp aiodns
|
- pip3 install emoji aiohttp aiodns
|
||||||
|
- python3 setup.py build_ext --inplace
|
||||||
- ./run_integration_tests.py
|
- ./run_integration_tests.py
|
||||||
|
|||||||
@@ -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')
|
self.mucserver = self.envjid('CI_MUC_SERVER', default='chat.jabberfr.org')
|
||||||
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,7 +95,9 @@ 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: str = None, port: int = 0, use_ssl: Optional[bool] = None) -> None:
|
def connect(self, host: Optional[str] = None, port: int = 0, use_ssl: Optional[bool] = None,
|
||||||
|
force_starttls: Optional[bool] = None,
|
||||||
|
disable_starttls: Optional[bool] = None) -> None:
|
||||||
"""Connect to the server.
|
"""Connect to the server.
|
||||||
|
|
||||||
|
|
||||||
@@ -105,6 +107,8 @@ 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
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ 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
|
||||||
@@ -85,6 +86,7 @@ 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
|
||||||
@@ -118,6 +120,7 @@ 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
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
5
slixmpp/plugins/xep_0264/__init__.py
Normal file
5
slixmpp/plugins/xep_0264/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from .thumbnail import XEP_0264
|
||||||
|
|
||||||
|
register_plugin(XEP_0264)
|
||||||
36
slixmpp/plugins/xep_0264/stanza.py
Normal file
36
slixmpp/plugins/xep_0264/stanza.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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)
|
||||||
24
slixmpp/plugins/xep_0264/thumbnail.py
Normal file
24
slixmpp/plugins/xep_0264/thumbnail.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
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,9 +52,10 @@ 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',
|
'before_id', 'after_id', 'ids', 'flip_page',
|
||||||
}
|
}
|
||||||
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)
|
||||||
@@ -81,7 +82,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:
|
if field and field["value"]:
|
||||||
return xep_0082.parse(field['value'])
|
return xep_0082.parse(field['value'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -94,7 +95,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:
|
if field and field["value"]:
|
||||||
return xep_0082.parse(field['value'])
|
return xep_0082.parse(field['value'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -168,6 +169,8 @@ 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).
|
||||||
|
|||||||
11
slixmpp/plugins/xep_0317/__init__.py
Normal file
11
slixmpp/plugins/xep_0317/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# 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']
|
||||||
16
slixmpp/plugins/xep_0317/hats.py
Normal file
16
slixmpp/plugins/xep_0317/hats.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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()
|
||||||
58
slixmpp/plugins/xep_0317/stanza.py
Normal file
58
slixmpp/plugins/xep_0317/stanza.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
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)
|
||||||
8
slixmpp/plugins/xep_0469/__init__.py
Normal file
8
slixmpp/plugins/xep_0469/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from .pinning import XEP_0469
|
||||||
|
|
||||||
|
register_plugin(XEP_0469)
|
||||||
|
|
||||||
|
__all__ = ['stanza', 'XEP_0469']
|
||||||
17
slixmpp/plugins/xep_0469/pinning.py
Normal file
17
slixmpp/plugins/xep_0469/pinning.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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()
|
||||||
31
slixmpp/plugins/xep_0469/stanza.py
Normal file
31
slixmpp/plugins/xep_0469/stanza.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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,12 +69,14 @@ 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
|
||||||
@@ -100,6 +102,7 @@ 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):
|
||||||
@@ -162,12 +165,14 @@ 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
|
||||||
@@ -193,3 +198,4 @@ 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):
|
def envjid(self, name: str, *, default: Optional[str] = None) -> JID:
|
||||||
"""Get a JID from an env var"""
|
"""Get a JID from an env var"""
|
||||||
value = os.getenv(name)
|
value = os.getenv(name, default=default)
|
||||||
return JID(value)
|
return JID(value)
|
||||||
|
|
||||||
def envstr(self, name):
|
def envstr(self, name):
|
||||||
|
|||||||
@@ -755,5 +755,8 @@ 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
|
||||||
|
|||||||
@@ -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[Awaitable] = [asyncio.Task(asyncio.sleep(timeout))]
|
tasks: List[Union[asyncio.Task, asyncio.Future]] = [asyncio.Task(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,6 +850,8 @@ 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)
|
||||||
|
|||||||
67
tests/test_stanza_xep_0317.py
Normal file
67
tests/test_stanza_xep_0317.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
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)
|
||||||
36
tests/test_stanza_xep_0469.py
Normal file
36
tests/test_stanza_xep_0469.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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