Compare commits
99 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a30f76892b | ||
![]() |
3de8ee97b5 | ||
![]() |
0de9df92c4 | ||
![]() |
04d5c43853 | ||
![]() |
0707786057 | ||
![]() |
1c762c6b25 | ||
![]() |
f94a4f2dbd | ||
![]() |
75ea0bf039 | ||
![]() |
4cf1286332 | ||
![]() |
8a127f61d0 | ||
![]() |
1f14fb54c2 | ||
![]() |
651e0ea593 | ||
![]() |
4ac41a5250 | ||
![]() |
e03b7661c1 | ||
![]() |
e955cd308a | ||
![]() |
2db5e0199c | ||
![]() |
bf2e006f88 | ||
![]() |
8c8bb5da8b | ||
![]() |
bd638f1b39 | ||
![]() |
0ff9e3661d | ||
![]() |
5ec378cccd | ||
![]() |
a9fc955eda | ||
![]() |
05860f71ac | ||
![]() |
1482bcc395 | ||
![]() |
2e736bc715 | ||
![]() |
8d984cd8a1 | ||
![]() |
100014651c | ||
![]() |
f9a9a0dcb7 | ||
![]() |
c585ec5983 | ||
![]() |
27bbb1ef95 | ||
![]() |
5dfc622539 | ||
![]() |
2ab9b5a05c | ||
![]() |
09d9320b91 | ||
![]() |
fbf298c36d | ||
![]() |
7153d79006 | ||
![]() |
1d3e03a923 | ||
![]() |
3d0b09e2e2 | ||
![]() |
23544731ef | ||
![]() |
a18a6c4eb8 | ||
![]() |
dd903b1792 | ||
![]() |
cf3b30120e | ||
![]() |
d86dccaf85 | ||
![]() |
075812adf3 | ||
![]() |
8955ece461 | ||
![]() |
5051c60262 | ||
![]() |
c495eb73fc | ||
![]() |
12c516d365 | ||
![]() |
d9b0b6dfe6 | ||
![]() |
7979e3b603 | ||
![]() |
f24a7679e5 | ||
![]() |
df0ecfc142 | ||
![]() |
e79b98b266 | ||
![]() |
5ed5e60b20 | ||
![]() |
e5fe53ef45 | ||
![]() |
93608bd2f4 | ||
![]() |
3b2386ee2f | ||
![]() |
b94c6716f7 | ||
![]() |
db8ce9187c | ||
![]() |
7f926a944a | ||
![]() |
e96f8e1ed0 | ||
![]() |
c8c0bb9134 | ||
![]() |
825c51b87d | ||
![]() |
7c79f28587 | ||
![]() |
dcaf812a28 | ||
![]() |
ae4de043d2 | ||
![]() |
998bbb80ad | ||
![]() |
5a5b36ab39 | ||
![]() |
f151f0a7ab | ||
![]() |
2424a3b36f | ||
![]() |
1c4bbbce8e | ||
![]() |
66d552d057 | ||
![]() |
b8205a9ae4 | ||
![]() |
85b7210115 | ||
![]() |
909c865524 | ||
![]() |
586d2f5107 | ||
![]() |
9f7260747f | ||
![]() |
c41209510a | ||
![]() |
9266486f46 | ||
![]() |
5226858e0c | ||
![]() |
7128ea249b | ||
![]() |
992d80dd09 | ||
![]() |
c25305e80f | ||
![]() |
6765f84133 | ||
![]() |
31fe7f7e06 | ||
![]() |
84a7ac020f | ||
![]() |
331c1c1e21 | ||
![]() |
28a60c22e2 | ||
![]() |
af934b5bdf | ||
![]() |
897f876504 | ||
![]() |
2888be17ab | ||
![]() |
975e31229c | ||
![]() |
6e9e66139d | ||
![]() |
380ac04d52 | ||
![]() |
9e5b530607 | ||
![]() |
71de274fab | ||
![]() |
5a0b02378d | ||
![]() |
9fc82e9e6f | ||
![]() |
ca90d3908e | ||
![]() |
7de5cbcf33 |
13
.github/pull_request_template.md
vendored
13
.github/pull_request_template.md
vendored
@ -1,13 +0,0 @@
|
|||||||
################ Please use Gitlab instead of Github ###################################
|
|
||||||
|
|
||||||
Hello, thank you for contributing to slixmpp!
|
|
||||||
|
|
||||||
You’re about to open a pull request on github. However this github repository is not the official place for contributions on slixmpp.
|
|
||||||
|
|
||||||
Please open your merge request on https://lab.louiz.org/poezio/slixmpp/
|
|
||||||
|
|
||||||
You should be able to log in there with your github credentials, clone the slixmpp repository in your namespace, push your existing pull request into a new branch, and then open a merge request with one click, within 3 minutes.
|
|
||||||
|
|
||||||
This will help us review your contribution, avoid spreading things everywhere and it will even run the tests automatically with your changes.
|
|
||||||
|
|
||||||
Thank you.
|
|
@ -1,81 +0,0 @@
|
|||||||
stages:
|
|
||||||
- lint
|
|
||||||
- test
|
|
||||||
- trigger
|
|
||||||
|
|
||||||
mypy:
|
|
||||||
stage: lint
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3
|
|
||||||
script:
|
|
||||||
- pip3 install mypy
|
|
||||||
- mypy slixmpp
|
|
||||||
|
|
||||||
test-3.7:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3.7
|
|
||||||
script:
|
|
||||||
- apt-get update
|
|
||||||
- apt-get install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp cryptography
|
|
||||||
- ./run_tests.py
|
|
||||||
|
|
||||||
test-3.10:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3.10
|
|
||||||
script:
|
|
||||||
- apt update
|
|
||||||
- apt-get install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp cryptography
|
|
||||||
- ./run_tests.py
|
|
||||||
|
|
||||||
test-3.11:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3.11
|
|
||||||
script:
|
|
||||||
- apt-get update
|
|
||||||
- apt-get install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp cryptography
|
|
||||||
- ./run_tests.py
|
|
||||||
|
|
||||||
test-3.12:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3.12-rc
|
|
||||||
allow_failure: true
|
|
||||||
script:
|
|
||||||
- apt-get update
|
|
||||||
- apt-get install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp cryptography
|
|
||||||
- ./run_tests.py
|
|
||||||
|
|
||||||
test_integration:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3
|
|
||||||
only:
|
|
||||||
variables:
|
|
||||||
- $CI_ACCOUNT1
|
|
||||||
- $CI_ACCOUNT2
|
|
||||||
script:
|
|
||||||
- apt-get update
|
|
||||||
- apt-get install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp aiodns
|
|
||||||
- ./run_integration_tests.py
|
|
||||||
|
|
||||||
trigger_poezio:
|
|
||||||
stage: trigger
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: curlimages/curl:7.79.1
|
|
||||||
script:
|
|
||||||
- curl --request POST -F token="$SLIXMPP_TRIGGER_TOKEN" -F ref=master https://lab.louiz.org/api/v4/projects/18/trigger/pipeline
|
|
@ -1,7 +0,0 @@
|
|||||||
language: python
|
|
||||||
python:
|
|
||||||
- "3.7"
|
|
||||||
- "3.8-dev"
|
|
||||||
install:
|
|
||||||
- "pip install ."
|
|
||||||
script: testall.py
|
|
9
.woodpecker/lint.yml
Normal file
9
.woodpecker/lint.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
when:
|
||||||
|
event: [ push, pull_request ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
mypy:
|
||||||
|
image: python:3
|
||||||
|
commands:
|
||||||
|
- pip3 install mypy types-setuptools
|
||||||
|
- mypy slixmpp
|
23
.woodpecker/test-integration.yml
Normal file
23
.woodpecker/test-integration.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
when:
|
||||||
|
event: [ push, pull_request ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
test_integration:
|
||||||
|
image: "python:3.11"
|
||||||
|
environment:
|
||||||
|
CI_ACCOUNT1:
|
||||||
|
from_secret: ci_account1
|
||||||
|
CI_ACCOUNT1_PASSWORD:
|
||||||
|
from_secret: ci_account1_password
|
||||||
|
CI_ACCOUNT2:
|
||||||
|
from_secret: ci_account2
|
||||||
|
CI_ACCOUNT2_PASSWORD:
|
||||||
|
from_secret: ci_account2_password
|
||||||
|
CI_MUC_SERVER:
|
||||||
|
from_secret: ci_muc_server
|
||||||
|
commands:
|
||||||
|
- apt-get update
|
||||||
|
- apt-get install -y python3-pip cython3 gpg idn libidn-dev
|
||||||
|
- pip3 install emoji aiohttp aiodns
|
||||||
|
- python3 setup.py build_ext --inplace
|
||||||
|
- ./run_integration_tests.py
|
19
.woodpecker/test.yml
Normal file
19
.woodpecker/test.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
when:
|
||||||
|
event: [ push, pull_request ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
unit_tests:
|
||||||
|
image: "python:${TAG}"
|
||||||
|
commands:
|
||||||
|
- apt-get update
|
||||||
|
- apt-get install -y python3 python3-pip cython3 gpg
|
||||||
|
- pip3 install emoji aiohttp cryptography setuptools
|
||||||
|
- ./run_tests.py
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
TAG:
|
||||||
|
- "3.9"
|
||||||
|
- "3.10"
|
||||||
|
- "3.11"
|
||||||
|
- "3.12"
|
||||||
|
- "3.13"
|
76
doap.xml
76
doap.xml
@ -616,6 +616,14 @@
|
|||||||
<xmpp:since>1.0</xmpp:since>
|
<xmpp:since>1.0</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0264.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>0.4.2</xmpp:version>
|
||||||
|
<xmpp:since>1.8.6</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
<implements>
|
<implements>
|
||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0270.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0270.html"/>
|
||||||
@ -682,6 +690,14 @@
|
|||||||
<xmpp:since>1.0</xmpp:since>
|
<xmpp:since>1.0</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0317.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>1.8.6</xmpp:version>
|
||||||
|
<xmpp:since>0.2</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
<implements>
|
<implements>
|
||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0319.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0319.html"/>
|
||||||
@ -856,7 +872,7 @@
|
|||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0424.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0424.html"/>
|
||||||
<xmpp:status>complete</xmpp:status>
|
<xmpp:status>complete</xmpp:status>
|
||||||
<xmpp:version>0.3.0</xmpp:version>
|
<xmpp:version>0.4.0</xmpp:version>
|
||||||
<xmpp:since>1.6.0</xmpp:since>
|
<xmpp:since>1.6.0</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
@ -864,7 +880,7 @@
|
|||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0425.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0425.html"/>
|
||||||
<xmpp:status>complete</xmpp:status>
|
<xmpp:status>complete</xmpp:status>
|
||||||
<xmpp:version>0.2.1</xmpp:version>
|
<xmpp:version>0.3.0</xmpp:version>
|
||||||
<xmpp:since>1.6.0</xmpp:since>
|
<xmpp:since>1.6.0</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
@ -900,13 +916,53 @@
|
|||||||
<xmpp:since>1.6.0</xmpp:since>
|
<xmpp:since>1.6.0</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0446.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>0.2.0</xmpp:version>
|
||||||
|
<xmpp:since>1.8.7</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
<implements>
|
<implements>
|
||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0454.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0454.html"/>
|
||||||
<xmpp:status>partial</xmpp:status>
|
<xmpp:status>partial</xmpp:status>
|
||||||
<xmpp:version>0.1.0</xmpp:version>
|
<xmpp:version>0.1.0</xmpp:version>
|
||||||
<xmpp:since>1.8.1</xmpp:since>
|
<xmpp:since>1.8.1</xmpp:since>
|
||||||
<xmpp:note>no thumbnail support</xmpp:note>
|
<xmpp:note>no thumbnail support</xmpp:note>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0469.html"/>
|
||||||
|
<xmpp:status>partial</xmpp:status>
|
||||||
|
<xmpp:version>0.1.0</xmpp:version>
|
||||||
|
<xmpp:since>1.8.6</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0482.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>0.1.0</xmpp:version>
|
||||||
|
<xmpp:since>1.8.7</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0490.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>0.1.0</xmpp:version>
|
||||||
|
<xmpp:since>1.8.6</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0492.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>0.1.0</xmpp:version>
|
||||||
|
<xmpp:since>1.8.7</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
|
|
||||||
@ -1064,5 +1120,19 @@
|
|||||||
<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>
|
||||||
|
<release>
|
||||||
|
<Version>
|
||||||
|
<revision>1.8.6</revision>
|
||||||
|
<created>2024-12-26</created>
|
||||||
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.6.tar.gz"/>
|
||||||
|
</Version>
|
||||||
|
</release>
|
||||||
</Project>
|
</Project>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
@ -17,6 +17,7 @@ Plugin index
|
|||||||
xep_0049
|
xep_0049
|
||||||
xep_0050
|
xep_0050
|
||||||
xep_0054
|
xep_0054
|
||||||
|
xep_0055
|
||||||
xep_0059
|
xep_0059
|
||||||
xep_0060
|
xep_0060
|
||||||
xep_0065
|
xep_0065
|
||||||
@ -31,6 +32,7 @@ Plugin index
|
|||||||
xep_0085
|
xep_0085
|
||||||
xep_0086
|
xep_0086
|
||||||
xep_0092
|
xep_0092
|
||||||
|
xep_0100
|
||||||
xep_0106
|
xep_0106
|
||||||
xep_0107
|
xep_0107
|
||||||
xep_0108
|
xep_0108
|
||||||
@ -62,12 +64,15 @@ Plugin index
|
|||||||
xep_0256
|
xep_0256
|
||||||
xep_0257
|
xep_0257
|
||||||
xep_0258
|
xep_0258
|
||||||
|
xep_0264
|
||||||
xep_0279
|
xep_0279
|
||||||
xep_0280
|
xep_0280
|
||||||
|
xep_0292
|
||||||
xep_0297
|
xep_0297
|
||||||
xep_0300
|
xep_0300
|
||||||
xep_0308
|
xep_0308
|
||||||
xep_0313
|
xep_0313
|
||||||
|
xep_0317
|
||||||
xep_0319
|
xep_0319
|
||||||
xep_0332
|
xep_0332
|
||||||
xep_0333
|
xep_0333
|
||||||
@ -79,9 +84,13 @@ Plugin index
|
|||||||
xep_0359
|
xep_0359
|
||||||
xep_0363
|
xep_0363
|
||||||
xep_0369
|
xep_0369
|
||||||
|
xep_0372
|
||||||
xep_0377
|
xep_0377
|
||||||
xep_0380
|
xep_0380
|
||||||
|
xep_0382
|
||||||
|
xep_0385
|
||||||
xep_0394
|
xep_0394
|
||||||
|
xep_0402
|
||||||
xep_0403
|
xep_0403
|
||||||
xep_0404
|
xep_0404
|
||||||
xep_0405
|
xep_0405
|
||||||
@ -94,3 +103,9 @@ Plugin index
|
|||||||
xep_0439
|
xep_0439
|
||||||
xep_0441
|
xep_0441
|
||||||
xep_0444
|
xep_0444
|
||||||
|
xep_0446
|
||||||
|
xep_0447
|
||||||
|
xep_0461
|
||||||
|
xep_0469
|
||||||
|
xep_0490
|
||||||
|
xep_0492
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
XEP-0106: Gateway interaction
|
XEP-0100: Gateway interaction
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
.. module:: slixmpp.plugins.xep_0100
|
.. module:: slixmpp.plugins.xep_0100
|
||||||
|
18
docs/api/plugins/xep_0264.rst
Normal file
18
docs/api/plugins/xep_0264.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0264: Jingle Content Thumbnails
|
||||||
|
===================================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0264
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0264
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0264.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0317.rst
Normal file
18
docs/api/plugins/xep_0317.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0317: Hats
|
||||||
|
==============
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0317
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0317
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0317.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0372.rst
Normal file
18
docs/api/plugins/xep_0372.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0372: References
|
||||||
|
====================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0372
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0372
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0372.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0382.rst
Normal file
18
docs/api/plugins/xep_0382.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0382: Spoiler Messages
|
||||||
|
==========================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0382
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0382
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0382.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0385.rst
Normal file
18
docs/api/plugins/xep_0385.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0385: Stateless Inline Media Sharing (SIMS)
|
||||||
|
===============================================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0385
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0385
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0385.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0402.rst
Normal file
18
docs/api/plugins/xep_0402.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0402: PEP Native Bookmarks
|
||||||
|
==============================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0402
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0402
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0402.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0446.rst
Normal file
18
docs/api/plugins/xep_0446.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0446: File metadata element
|
||||||
|
===============================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0446
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0446
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0446.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0447.rst
Normal file
18
docs/api/plugins/xep_0447.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0447: Stateless File Sharing
|
||||||
|
================================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0447
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0447
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0447.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0461.rst
Normal file
18
docs/api/plugins/xep_0461.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0461: Message Replies
|
||||||
|
=========================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0461
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0461
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0461.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
17
docs/api/plugins/xep_0469.rst
Normal file
17
docs/api/plugins/xep_0469.rst
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
XEP-0469: Bookmark Pinning
|
||||||
|
==========================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0469
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0469
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0469.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0490.rst
Normal file
18
docs/api/plugins/xep_0490.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0490: Message Displayed Synchronization
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0490
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0490
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0490.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
18
docs/api/plugins/xep_0492.rst
Normal file
18
docs/api/plugins/xep_0492.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0492: Chat Notification Settings
|
||||||
|
====================================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0492
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0492
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0492.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
@ -167,8 +167,9 @@ processing the same stanza twice.
|
|||||||
- **Data:** :py:class:`~.Message`
|
- **Data:** :py:class:`~.Message`
|
||||||
- **Source:** :py:class:`BaseXMPP <.BaseXMPP>`
|
- **Source:** :py:class:`BaseXMPP <.BaseXMPP>`
|
||||||
|
|
||||||
Makes the contents of message stanzas available whenever one is received. Be
|
Makes the contents of message stanzas that include <body> tags available
|
||||||
sure to check the message type in order to handle error messages.
|
whenever one is received.
|
||||||
|
Be sure to check the message type to handle error messages appropriately.
|
||||||
|
|
||||||
message_error
|
message_error
|
||||||
- **Data:** :py:class:`~.Message`
|
- **Data:** :py:class:`~.Message`
|
||||||
|
100
docs/projects.rst
Normal file
100
docs/projects.rst
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
Projects Using Slixmpp
|
||||||
|
======================
|
||||||
|
|
||||||
|
This page enumerates software in the form of applications, bots and gateways utilizing the XMPP protocols with slixmpp.
|
||||||
|
|
||||||
|
Applications
|
||||||
|
------------
|
||||||
|
|
||||||
|
sendxmpp-py
|
||||||
|
~~~~~~~~~~~
|
||||||
|
sendxmpp is a command line program and is the XMPP equivalent of sendmail. It is a Python version of the original sendxmpp which is written in Perl.
|
||||||
|
|
||||||
|
- `Source <https://code.moparisthebest.com/moparisthebest/sendxmpp-py>`__
|
||||||
|
- `Groupchat <xmpp:xmpp-ircd@chatrooms.hackerposse.com?join>`__
|
||||||
|
|
||||||
|
Bots
|
||||||
|
----
|
||||||
|
|
||||||
|
BotLogMauve
|
||||||
|
~~~~~~~~~~~
|
||||||
|
XMPP bot which logs groupchat messages. Logs are in text format, with one file per day and per groupchat.
|
||||||
|
|
||||||
|
- `Source <https://git.khaganat.net/khaganat/BotLogMauve>`__
|
||||||
|
|
||||||
|
BukuBot
|
||||||
|
~~~~~~~
|
||||||
|
BukuBot makes it possible to manage and search your bookmarks from your chat.
|
||||||
|
|
||||||
|
- `Source <https://codeberg.org/sch/BukuBot>`__
|
||||||
|
|
||||||
|
LinkBot
|
||||||
|
~~~~~~~
|
||||||
|
This bot reveals the title of any shared link in a groupchat for quick content insight.
|
||||||
|
|
||||||
|
- `Source <https://git.xmpp-it.net/mario/XMPPBot>`__
|
||||||
|
|
||||||
|
llama-bot
|
||||||
|
~~~~~~~~~
|
||||||
|
Llama-bot enables engaging communication with the LLM (large language model) of llama.cpp, providing seamless and dynamic conversation with it.
|
||||||
|
|
||||||
|
- `Source <https://github.com/decent-im/llama-bot>`__
|
||||||
|
- `Demo <xmpp:llama@decent.im?message>`__
|
||||||
|
|
||||||
|
Morbot
|
||||||
|
~~~~~~
|
||||||
|
Morbot is a simple Slixmpp bot that will take new articles from listed RSS feeds and send them to assigned XMPP MUCs.
|
||||||
|
|
||||||
|
- `Source <https://codeberg.org/TheCoffeMaker/Morbot>`__
|
||||||
|
|
||||||
|
Slixfeed
|
||||||
|
~~~~~~~~
|
||||||
|
Slixfeed aims to be an easy to use and fully-featured news aggregator bot for XMPP. It provides a convenient access to Blogs, Fediverse and News websites along with filtering functionality.
|
||||||
|
|
||||||
|
- `Groupchat <xmpp:slixfeed@chat.woodpeckersnest.space?join>`__
|
||||||
|
- `Source <https://gitgud.io/sjehuda/slixfeed>`__
|
||||||
|
|
||||||
|
sms4you
|
||||||
|
~~~~~~~
|
||||||
|
sms4you forwards messages from and to SMS and connects either with sms4you-xmpp or sms4you-email to choose the other mean of communication. Nice for receiving or sending SMS, independently from carrying a SIM card.
|
||||||
|
|
||||||
|
- `Homepage <https://sms4you-team.pages.debian.net/sms4you/>`__
|
||||||
|
- `Source <https://salsa.debian.org/sms4you-team/sms4you>`__
|
||||||
|
|
||||||
|
Stable Diffusion
|
||||||
|
~~~~~~~~~~~~~~~~
|
||||||
|
XMPP bot that generates digital images from textual descriptions.
|
||||||
|
|
||||||
|
- `Groupchat <xmpp:slidge@conference.nicoco.fr?join>`__
|
||||||
|
- `Source <https://www.nicoco.fr/blog/2022/08/31/xmpp-bot-stable-diffusion/>`__
|
||||||
|
|
||||||
|
WhisperBot
|
||||||
|
~~~~~~~~~~
|
||||||
|
XMPP bot that transliterates audio messages using OpenAI's Whisper libraries.
|
||||||
|
|
||||||
|
- `Source <https://codeberg.org/TheCoffeMaker/WhisperBot>`__
|
||||||
|
|
||||||
|
XMPP MUC Message Gateway
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
A multipurpose JSON forwarder microservice from HTTP POST to XMPP MUC room over TLSv1.2 with SliXMPP.
|
||||||
|
|
||||||
|
- `Source <https://github.com/immanuelfodor/xmpp-muc-message-gateway>`__
|
||||||
|
|
||||||
|
Services
|
||||||
|
--------
|
||||||
|
|
||||||
|
AtomToPubsub
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
AtomToPubsub is a simple Python script that parses Atom + RSS feeds and pushes the entries to a designated XMPP Pubsub Node.
|
||||||
|
|
||||||
|
- `Groupchat <xmpp:movim@conference.movim.eu?join>`__
|
||||||
|
- `Source <https://github.com/imattau/atomtopubsub>`__
|
||||||
|
|
||||||
|
Slidge
|
||||||
|
~~~~~~
|
||||||
|
|
||||||
|
Slidge is a general purpose XMPP gateway framework in Python.
|
||||||
|
|
||||||
|
- `Groupchat <xmpp:slidge@conference.nicoco.fr?join>`__
|
||||||
|
- `Homepage <https://slidge.im/core/>`__
|
||||||
|
- `Source <https://sr.ht/~nicoco/slidge>`__
|
@ -50,10 +50,39 @@ Running the event loop
|
|||||||
only run for this amount of time, and if ``forever`` is False it will
|
only run for this amount of time, and if ``forever`` is False it will
|
||||||
run until disconnection).
|
run until disconnection).
|
||||||
|
|
||||||
|
This wrapper should be removed in slixmpp 1.9.0.
|
||||||
|
|
||||||
Therefore you can handle the event loop in any way you like
|
Therefore you can handle the event loop in any way you like
|
||||||
instead of using ``process()``.
|
instead of using ``process()``.
|
||||||
|
|
||||||
|
|
||||||
|
Using connect()
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
:meth:`.XMLStream.connect` schedules a lot of things in the background, but that
|
||||||
|
only holds true if the event loop is running!
|
||||||
|
|
||||||
|
That is why in all examples we usually call connect() right before calling
|
||||||
|
a `loop.run_…` function, or the deprecated `process()` function.
|
||||||
|
|
||||||
|
Using a different event loop
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Immediately upon XMPP object creation (`ClientXMPP` / `ComponentXMPP`) you
|
||||||
|
should sets its `loop` attribute to whatever you want, and ideally this
|
||||||
|
should work. This path is less tested, so it may break, if that is the case
|
||||||
|
please report a bug.
|
||||||
|
|
||||||
|
Any access to the `loop` attribute if not user-initialized will set it
|
||||||
|
to the default asyncio event loop by default.
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
If the loop attribute is modified at runtime, the application will probably
|
||||||
|
end up in an hybrid state and asyncio may complain loudly that things bound
|
||||||
|
to an event loop are being ran in another. Try to avoid that situation.
|
||||||
|
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
@ -73,10 +102,11 @@ callbacks while everything is not ready.
|
|||||||
callback = lambda _: client.connected_event.set()
|
callback = lambda _: client.connected_event.set()
|
||||||
client.add_event_handler('session_start', callback)
|
client.add_event_handler('session_start', callback)
|
||||||
client.connect()
|
client.connect()
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(event.wait())
|
loop.run_until_complete(event.wait())
|
||||||
# do some other stuff before running the event loop, e.g.
|
# do some other stuff before running the event loop, e.g.
|
||||||
# loop.run_until_complete(httpserver.init())
|
# loop.run_until_complete(httpserver.init())
|
||||||
client.process()
|
loop.run_forever()
|
||||||
|
|
||||||
|
|
||||||
Use with other asyncio-based libraries
|
Use with other asyncio-based libraries
|
||||||
@ -106,7 +136,7 @@ a simple <message>.
|
|||||||
client.add_event_handler('session_start', get_pythonorg)
|
client.add_event_handler('session_start', get_pythonorg)
|
||||||
client.add_event_handler('session_start', get_asyncioorg)
|
client.add_event_handler('session_start', get_asyncioorg)
|
||||||
client.connect()
|
client.connect()
|
||||||
client.process()
|
client.loop.run_until_complete(client.disconnected)
|
||||||
|
|
||||||
|
|
||||||
Blocking Iq
|
Blocking Iq
|
||||||
@ -136,6 +166,6 @@ JID indicating its findings.
|
|||||||
|
|
||||||
client = ExampleClient('jid@example', 'password')
|
client = ExampleClient('jid@example', 'password')
|
||||||
client.connect()
|
client.connect()
|
||||||
client.process()
|
client.loop.run_until_complete(client.disconnected)
|
||||||
|
|
||||||
|
|
||||||
|
184
examples/imghdr.py
Normal file
184
examples/imghdr.py
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
"""
|
||||||
|
Recognize image file formats based on their first few bytes.
|
||||||
|
|
||||||
|
|
||||||
|
Taken from cpython 3.11 source code before the removal in 3.13.
|
||||||
|
|
||||||
|
Licensed under Zero-Clause BSD
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from os import PathLike
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
__all__ = ["what"]
|
||||||
|
|
||||||
|
|
||||||
|
warnings._deprecated(__name__, remove=(3, 13))
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------#
|
||||||
|
# Recognize image headers #
|
||||||
|
#-------------------------#
|
||||||
|
|
||||||
|
def what(file, h=None):
|
||||||
|
f = None
|
||||||
|
try:
|
||||||
|
if h is None:
|
||||||
|
if isinstance(file, (str, PathLike)):
|
||||||
|
f = open(file, 'rb')
|
||||||
|
h = f.read(32)
|
||||||
|
else:
|
||||||
|
location = file.tell()
|
||||||
|
h = file.read(32)
|
||||||
|
file.seek(location)
|
||||||
|
for tf in tests:
|
||||||
|
res = tf(h, f)
|
||||||
|
if res:
|
||||||
|
return res
|
||||||
|
finally:
|
||||||
|
if f: f.close()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------#
|
||||||
|
# Subroutines per image file type #
|
||||||
|
#---------------------------------#
|
||||||
|
|
||||||
|
tests = []
|
||||||
|
|
||||||
|
def test_jpeg(h, f):
|
||||||
|
"""JPEG data with JFIF or Exif markers; and raw JPEG"""
|
||||||
|
if h[6:10] in (b'JFIF', b'Exif'):
|
||||||
|
return 'jpeg'
|
||||||
|
elif h[:4] == b'\xff\xd8\xff\xdb':
|
||||||
|
return 'jpeg'
|
||||||
|
|
||||||
|
tests.append(test_jpeg)
|
||||||
|
|
||||||
|
def test_png(h, f):
|
||||||
|
if h.startswith(b'\211PNG\r\n\032\n'):
|
||||||
|
return 'png'
|
||||||
|
|
||||||
|
tests.append(test_png)
|
||||||
|
|
||||||
|
def test_gif(h, f):
|
||||||
|
"""GIF ('87 and '89 variants)"""
|
||||||
|
if h[:6] in (b'GIF87a', b'GIF89a'):
|
||||||
|
return 'gif'
|
||||||
|
|
||||||
|
tests.append(test_gif)
|
||||||
|
|
||||||
|
def test_tiff(h, f):
|
||||||
|
"""TIFF (can be in Motorola or Intel byte order)"""
|
||||||
|
if h[:2] in (b'MM', b'II'):
|
||||||
|
return 'tiff'
|
||||||
|
|
||||||
|
tests.append(test_tiff)
|
||||||
|
|
||||||
|
def test_rgb(h, f):
|
||||||
|
"""SGI image library"""
|
||||||
|
if h.startswith(b'\001\332'):
|
||||||
|
return 'rgb'
|
||||||
|
|
||||||
|
tests.append(test_rgb)
|
||||||
|
|
||||||
|
def test_pbm(h, f):
|
||||||
|
"""PBM (portable bitmap)"""
|
||||||
|
if len(h) >= 3 and \
|
||||||
|
h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r':
|
||||||
|
return 'pbm'
|
||||||
|
|
||||||
|
tests.append(test_pbm)
|
||||||
|
|
||||||
|
def test_pgm(h, f):
|
||||||
|
"""PGM (portable graymap)"""
|
||||||
|
if len(h) >= 3 and \
|
||||||
|
h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r':
|
||||||
|
return 'pgm'
|
||||||
|
|
||||||
|
tests.append(test_pgm)
|
||||||
|
|
||||||
|
def test_ppm(h, f):
|
||||||
|
"""PPM (portable pixmap)"""
|
||||||
|
if len(h) >= 3 and \
|
||||||
|
h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r':
|
||||||
|
return 'ppm'
|
||||||
|
|
||||||
|
tests.append(test_ppm)
|
||||||
|
|
||||||
|
def test_rast(h, f):
|
||||||
|
"""Sun raster file"""
|
||||||
|
if h.startswith(b'\x59\xA6\x6A\x95'):
|
||||||
|
return 'rast'
|
||||||
|
|
||||||
|
tests.append(test_rast)
|
||||||
|
|
||||||
|
def test_xbm(h, f):
|
||||||
|
"""X bitmap (X10 or X11)"""
|
||||||
|
if h.startswith(b'#define '):
|
||||||
|
return 'xbm'
|
||||||
|
|
||||||
|
tests.append(test_xbm)
|
||||||
|
|
||||||
|
def test_bmp(h, f):
|
||||||
|
if h.startswith(b'BM'):
|
||||||
|
return 'bmp'
|
||||||
|
|
||||||
|
tests.append(test_bmp)
|
||||||
|
|
||||||
|
def test_webp(h, f):
|
||||||
|
if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
|
||||||
|
return 'webp'
|
||||||
|
|
||||||
|
tests.append(test_webp)
|
||||||
|
|
||||||
|
def test_exr(h, f):
|
||||||
|
if h.startswith(b'\x76\x2f\x31\x01'):
|
||||||
|
return 'exr'
|
||||||
|
|
||||||
|
tests.append(test_exr)
|
||||||
|
|
||||||
|
#--------------------#
|
||||||
|
# Small test program #
|
||||||
|
#--------------------#
|
||||||
|
|
||||||
|
def test():
|
||||||
|
import sys
|
||||||
|
recursive = 0
|
||||||
|
if sys.argv[1:] and sys.argv[1] == '-r':
|
||||||
|
del sys.argv[1:2]
|
||||||
|
recursive = 1
|
||||||
|
try:
|
||||||
|
if sys.argv[1:]:
|
||||||
|
testall(sys.argv[1:], recursive, 1)
|
||||||
|
else:
|
||||||
|
testall(['.'], recursive, 1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
sys.stderr.write('\n[Interrupted]\n')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def testall(list, recursive, toplevel):
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
for filename in list:
|
||||||
|
if os.path.isdir(filename):
|
||||||
|
print(filename + '/:', end=' ')
|
||||||
|
if recursive or toplevel:
|
||||||
|
print('recursing down:')
|
||||||
|
import glob
|
||||||
|
names = glob.glob(os.path.join(glob.escape(filename), '*'))
|
||||||
|
testall(names, recursive, 0)
|
||||||
|
else:
|
||||||
|
print('*** directory (use -r) ***')
|
||||||
|
else:
|
||||||
|
print(filename + ':', end=' ')
|
||||||
|
sys.stdout.flush()
|
||||||
|
try:
|
||||||
|
print(what(filename))
|
||||||
|
except OSError:
|
||||||
|
print('*** not found ***')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test()
|
||||||
|
|
184
itests/imghdr.py
Normal file
184
itests/imghdr.py
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
"""
|
||||||
|
Recognize image file formats based on their first few bytes.
|
||||||
|
|
||||||
|
|
||||||
|
Taken from cpython 3.11 source code before the removal in 3.13.
|
||||||
|
|
||||||
|
Licensed under Zero-Clause BSD
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from os import PathLike
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
__all__ = ["what"]
|
||||||
|
|
||||||
|
|
||||||
|
warnings._deprecated(__name__, remove=(3, 13))
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------#
|
||||||
|
# Recognize image headers #
|
||||||
|
#-------------------------#
|
||||||
|
|
||||||
|
def what(file, h=None):
|
||||||
|
f = None
|
||||||
|
try:
|
||||||
|
if h is None:
|
||||||
|
if isinstance(file, (str, PathLike)):
|
||||||
|
f = open(file, 'rb')
|
||||||
|
h = f.read(32)
|
||||||
|
else:
|
||||||
|
location = file.tell()
|
||||||
|
h = file.read(32)
|
||||||
|
file.seek(location)
|
||||||
|
for tf in tests:
|
||||||
|
res = tf(h, f)
|
||||||
|
if res:
|
||||||
|
return res
|
||||||
|
finally:
|
||||||
|
if f: f.close()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------#
|
||||||
|
# Subroutines per image file type #
|
||||||
|
#---------------------------------#
|
||||||
|
|
||||||
|
tests = []
|
||||||
|
|
||||||
|
def test_jpeg(h, f):
|
||||||
|
"""JPEG data with JFIF or Exif markers; and raw JPEG"""
|
||||||
|
if h[6:10] in (b'JFIF', b'Exif'):
|
||||||
|
return 'jpeg'
|
||||||
|
elif h[:4] == b'\xff\xd8\xff\xdb':
|
||||||
|
return 'jpeg'
|
||||||
|
|
||||||
|
tests.append(test_jpeg)
|
||||||
|
|
||||||
|
def test_png(h, f):
|
||||||
|
if h.startswith(b'\211PNG\r\n\032\n'):
|
||||||
|
return 'png'
|
||||||
|
|
||||||
|
tests.append(test_png)
|
||||||
|
|
||||||
|
def test_gif(h, f):
|
||||||
|
"""GIF ('87 and '89 variants)"""
|
||||||
|
if h[:6] in (b'GIF87a', b'GIF89a'):
|
||||||
|
return 'gif'
|
||||||
|
|
||||||
|
tests.append(test_gif)
|
||||||
|
|
||||||
|
def test_tiff(h, f):
|
||||||
|
"""TIFF (can be in Motorola or Intel byte order)"""
|
||||||
|
if h[:2] in (b'MM', b'II'):
|
||||||
|
return 'tiff'
|
||||||
|
|
||||||
|
tests.append(test_tiff)
|
||||||
|
|
||||||
|
def test_rgb(h, f):
|
||||||
|
"""SGI image library"""
|
||||||
|
if h.startswith(b'\001\332'):
|
||||||
|
return 'rgb'
|
||||||
|
|
||||||
|
tests.append(test_rgb)
|
||||||
|
|
||||||
|
def test_pbm(h, f):
|
||||||
|
"""PBM (portable bitmap)"""
|
||||||
|
if len(h) >= 3 and \
|
||||||
|
h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r':
|
||||||
|
return 'pbm'
|
||||||
|
|
||||||
|
tests.append(test_pbm)
|
||||||
|
|
||||||
|
def test_pgm(h, f):
|
||||||
|
"""PGM (portable graymap)"""
|
||||||
|
if len(h) >= 3 and \
|
||||||
|
h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r':
|
||||||
|
return 'pgm'
|
||||||
|
|
||||||
|
tests.append(test_pgm)
|
||||||
|
|
||||||
|
def test_ppm(h, f):
|
||||||
|
"""PPM (portable pixmap)"""
|
||||||
|
if len(h) >= 3 and \
|
||||||
|
h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r':
|
||||||
|
return 'ppm'
|
||||||
|
|
||||||
|
tests.append(test_ppm)
|
||||||
|
|
||||||
|
def test_rast(h, f):
|
||||||
|
"""Sun raster file"""
|
||||||
|
if h.startswith(b'\x59\xA6\x6A\x95'):
|
||||||
|
return 'rast'
|
||||||
|
|
||||||
|
tests.append(test_rast)
|
||||||
|
|
||||||
|
def test_xbm(h, f):
|
||||||
|
"""X bitmap (X10 or X11)"""
|
||||||
|
if h.startswith(b'#define '):
|
||||||
|
return 'xbm'
|
||||||
|
|
||||||
|
tests.append(test_xbm)
|
||||||
|
|
||||||
|
def test_bmp(h, f):
|
||||||
|
if h.startswith(b'BM'):
|
||||||
|
return 'bmp'
|
||||||
|
|
||||||
|
tests.append(test_bmp)
|
||||||
|
|
||||||
|
def test_webp(h, f):
|
||||||
|
if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
|
||||||
|
return 'webp'
|
||||||
|
|
||||||
|
tests.append(test_webp)
|
||||||
|
|
||||||
|
def test_exr(h, f):
|
||||||
|
if h.startswith(b'\x76\x2f\x31\x01'):
|
||||||
|
return 'exr'
|
||||||
|
|
||||||
|
tests.append(test_exr)
|
||||||
|
|
||||||
|
#--------------------#
|
||||||
|
# Small test program #
|
||||||
|
#--------------------#
|
||||||
|
|
||||||
|
def test():
|
||||||
|
import sys
|
||||||
|
recursive = 0
|
||||||
|
if sys.argv[1:] and sys.argv[1] == '-r':
|
||||||
|
del sys.argv[1:2]
|
||||||
|
recursive = 1
|
||||||
|
try:
|
||||||
|
if sys.argv[1:]:
|
||||||
|
testall(sys.argv[1:], recursive, 1)
|
||||||
|
else:
|
||||||
|
testall(['.'], recursive, 1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
sys.stderr.write('\n[Interrupted]\n')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def testall(list, recursive, toplevel):
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
for filename in list:
|
||||||
|
if os.path.isdir(filename):
|
||||||
|
print(filename + '/:', end=' ')
|
||||||
|
if recursive or toplevel:
|
||||||
|
print('recursing down:')
|
||||||
|
import glob
|
||||||
|
names = glob.glob(os.path.join(glob.escape(filename), '*'))
|
||||||
|
testall(names, recursive, 0)
|
||||||
|
else:
|
||||||
|
print('*** directory (use -r) ***')
|
||||||
|
else:
|
||||||
|
print(filename + ':', end=' ')
|
||||||
|
sys.stdout.flush()
|
||||||
|
try:
|
||||||
|
print(what(filename))
|
||||||
|
except OSError:
|
||||||
|
print('*** not found ***')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test()
|
||||||
|
|
@ -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'),
|
||||||
|
@ -23,7 +23,6 @@ class TestRetract(SlixIntegration):
|
|||||||
fallback_text='Twas a mistake',
|
fallback_text='Twas a mistake',
|
||||||
)
|
)
|
||||||
msg = await self.clients[1].wait_until('message_retract')
|
msg = await self.clients[1].wait_until('message_retract')
|
||||||
self.assertEqual(msg['apply_to']['id'], 'toto')
|
self.assertEqual(msg['retract']['id'], 'toto')
|
||||||
self.assertTrue(msg['apply_to']['retract'])
|
|
||||||
|
|
||||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestRetract)
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestRetract)
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from distutils.core import Command
|
from setuptools import Command
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from distutils.core import Command
|
from setuptools import Command
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
8
setup.py
8
setup.py
@ -33,12 +33,17 @@ CLASSIFIERS = [
|
|||||||
'Programming Language :: Python :: 3.7',
|
'Programming Language :: Python :: 3.7',
|
||||||
'Programming Language :: Python :: 3.8',
|
'Programming Language :: Python :: 3.8',
|
||||||
'Programming Language :: Python :: 3.9',
|
'Programming Language :: Python :: 3.9',
|
||||||
|
'Programming Language :: Python :: 3.10',
|
||||||
|
'Programming Language :: Python :: 3.11',
|
||||||
|
'Programming Language :: Python :: 3.12',
|
||||||
|
'Programming Language :: Python :: 3.13',
|
||||||
'Topic :: Internet :: XMPP',
|
'Topic :: Internet :: XMPP',
|
||||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||||
]
|
]
|
||||||
|
|
||||||
packages = [str(mod.parent) for mod in Path('slixmpp').rglob('__init__.py')]
|
packages = [str(mod.parent) for mod in Path('slixmpp').rglob('__init__.py')]
|
||||||
|
|
||||||
|
|
||||||
def check_include(library_name, header):
|
def check_include(library_name, header):
|
||||||
command = [os.environ.get('PKG_CONFIG', 'pkg-config'), '--cflags', library_name]
|
command = [os.environ.get('PKG_CONFIG', 'pkg-config'), '--cflags', library_name]
|
||||||
try:
|
try:
|
||||||
@ -59,6 +64,7 @@ def check_include(library_name, header):
|
|||||||
print('%s headers not found.' % library_name)
|
print('%s headers not found.' % library_name)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
HAS_PYTHON_HEADERS = check_include('python3', 'Python.h')
|
HAS_PYTHON_HEADERS = check_include('python3', 'Python.h')
|
||||||
HAS_STRINGPREP_HEADERS = check_include('libidn', 'stringprep.h')
|
HAS_STRINGPREP_HEADERS = check_include('libidn', 'stringprep.h')
|
||||||
|
|
||||||
@ -87,7 +93,7 @@ setup(
|
|||||||
packages=packages,
|
packages=packages,
|
||||||
ext_modules=ext_modules,
|
ext_modules=ext_modules,
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'aiodns>=1.0',
|
'aiodns >= 1.0; sys_platform=="linux" or sys_platform=="darwin"',
|
||||||
'pyasn1',
|
'pyasn1',
|
||||||
'pyasn1_modules',
|
'pyasn1_modules',
|
||||||
'typing_extensions; python_version < "3.8.0"',
|
'typing_extensions; python_version < "3.8.0"',
|
||||||
|
@ -27,3 +27,9 @@ from slixmpp.clientxmpp import ClientXMPP
|
|||||||
from slixmpp.componentxmpp import ComponentXMPP
|
from slixmpp.componentxmpp import ComponentXMPP
|
||||||
|
|
||||||
from slixmpp.version import __version__, __version_info__
|
from slixmpp.version import __version__, __version_info__
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'Message', 'Presence', 'Iq', 'JID', 'InvalidJID', 'ET', 'ElementBase',
|
||||||
|
'register_stanza_plugin', 'XMLStream', 'BaseXMPP', 'ClientXMPP', 'ComponentXMPP',
|
||||||
|
'__version__', '__version_info__'
|
||||||
|
]
|
||||||
|
@ -315,13 +315,12 @@ class BaseXMPP(XMLStream):
|
|||||||
pres['lang'] = self.default_lang
|
pres['lang'] = self.default_lang
|
||||||
return pres
|
return pres
|
||||||
|
|
||||||
def make_iq(self, id: str = "0", ifrom: OptJidStr = None,
|
def make_iq(self, id: Optional[str] = None, ifrom: OptJidStr = None,
|
||||||
ito: OptJidStr = None, itype: Optional[IqTypes] = None,
|
ito: OptJidStr = None, itype: Optional[IqTypes] = None,
|
||||||
iquery: Optional[str] = None) -> stanza.Iq:
|
iquery: Optional[str] = None) -> stanza.Iq:
|
||||||
"""Create a new :class:`~.Iq` stanza with a given Id and from JID.
|
"""Create a new :class:`~.Iq` stanza with a given Id and from JID.
|
||||||
|
|
||||||
:param id: An ideally unique ID value for this stanza thread.
|
:param id: An ideally unique ID value for this stanza thread.
|
||||||
Defaults to 0.
|
|
||||||
:param ifrom: The from :class:`~.JID`
|
:param ifrom: The from :class:`~.JID`
|
||||||
to use for this stanza.
|
to use for this stanza.
|
||||||
:param ito: The destination :class:`~.JID`
|
:param ito: The destination :class:`~.JID`
|
||||||
@ -332,7 +331,8 @@ class BaseXMPP(XMLStream):
|
|||||||
:param iquery: Optional namespace for adding a query element.
|
:param iquery: Optional namespace for adding a query element.
|
||||||
"""
|
"""
|
||||||
iq = self.Iq()
|
iq = self.Iq()
|
||||||
iq['id'] = str(id)
|
if id is not None:
|
||||||
|
iq['id'] = str(id)
|
||||||
iq['to'] = ito
|
iq['to'] = ito
|
||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
iq['type'] = itype
|
iq['type'] = itype
|
||||||
|
@ -138,8 +138,8 @@ class ClientXMPP(BaseXMPP):
|
|||||||
self.credentials['password'] = value
|
self.credentials['password'] = value
|
||||||
|
|
||||||
def connect(self, address: Optional[Tuple[str, int]] = None, # type: ignore
|
def connect(self, address: Optional[Tuple[str, int]] = None, # type: ignore
|
||||||
use_ssl: bool = False, force_starttls: bool = True,
|
use_ssl: Optional[bool] = None, force_starttls: Optional[bool] = None,
|
||||||
disable_starttls: bool = False) -> None:
|
disable_starttls: Optional[bool] = None) -> asyncio.Future:
|
||||||
"""Connect to the XMPP server.
|
"""Connect to the XMPP server.
|
||||||
|
|
||||||
When no address is given, a SRV lookup for the server will
|
When no address is given, a SRV lookup for the server will
|
||||||
@ -167,7 +167,8 @@ class ClientXMPP(BaseXMPP):
|
|||||||
self.dns_service = 'xmpp-client'
|
self.dns_service = 'xmpp-client'
|
||||||
|
|
||||||
return XMLStream.connect(self, host, port, use_ssl=use_ssl,
|
return XMLStream.connect(self, host, port, use_ssl=use_ssl,
|
||||||
force_starttls=force_starttls, disable_starttls=disable_starttls)
|
force_starttls=force_starttls,
|
||||||
|
disable_starttls=disable_starttls)
|
||||||
|
|
||||||
def register_feature(self, name: str, handler: Callable, restart: bool = False, order: int = 5000) -> None:
|
def register_feature(self, name: str, handler: Callable, restart: bool = False, order: int = 5000) -> None:
|
||||||
"""Register a stream feature handler.
|
"""Register a stream feature handler.
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
from asyncio import Future
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from slixmpp import Message, Iq, Presence
|
from slixmpp import Message, Iq, Presence
|
||||||
from slixmpp.basexmpp import BaseXMPP
|
from slixmpp.basexmpp import BaseXMPP
|
||||||
from slixmpp.stanza import Handshake
|
from slixmpp.stanza import Handshake
|
||||||
@ -93,7 +96,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=None, port=None, use_ssl=False):
|
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) -> Future:
|
||||||
"""Connect to the server.
|
"""Connect to the server.
|
||||||
|
|
||||||
|
|
||||||
@ -103,17 +108,18 @@ 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 None:
|
if host is not None:
|
||||||
host = self.server_host
|
self.server_host = host
|
||||||
if port is None:
|
if port:
|
||||||
port = self.server_port
|
self.server_port = port
|
||||||
|
|
||||||
self.server_name = self.boundjid.host
|
self.server_name = self.boundjid.host
|
||||||
|
|
||||||
log.debug("Connecting to %s:%s", host, port)
|
log.debug("Connecting to %s:%s", host, port)
|
||||||
return XMLStream.connect(self, host=host, port=port,
|
return XMLStream.connect(self, host=self.server_host, port=self.server_port, use_ssl=use_ssl)
|
||||||
use_ssl=use_ssl)
|
|
||||||
|
|
||||||
def incoming_filter(self, xml):
|
def incoming_filter(self, xml):
|
||||||
"""
|
"""
|
||||||
|
@ -135,6 +135,7 @@ _DEFAULT_ERROR_TYPES: Dict[ErrorConditions, ErrorTypes] = {
|
|||||||
"not-allowed": "cancel",
|
"not-allowed": "cancel",
|
||||||
"not-authorized": "auth",
|
"not-authorized": "auth",
|
||||||
"payment-required": "auth",
|
"payment-required": "auth",
|
||||||
|
"policy-violation": "modify",
|
||||||
"recipient-unavailable": "wait",
|
"recipient-unavailable": "wait",
|
||||||
"redirect": "modify",
|
"redirect": "modify",
|
||||||
"registration-required": "auth",
|
"registration-required": "auth",
|
||||||
|
@ -37,7 +37,8 @@ class FeatureMechanisms(BasePlugin):
|
|||||||
'unencrypted_digest': False,
|
'unencrypted_digest': False,
|
||||||
'unencrypted_cram': False,
|
'unencrypted_cram': False,
|
||||||
'unencrypted_scram': True,
|
'unencrypted_scram': True,
|
||||||
'order': 100
|
'order': 100,
|
||||||
|
'tls_version': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
@ -96,7 +97,20 @@ class FeatureMechanisms(BasePlugin):
|
|||||||
result[value] = creds.get('email', jid)
|
result[value] = creds.get('email', jid)
|
||||||
elif value == 'channel_binding':
|
elif value == 'channel_binding':
|
||||||
if isinstance(self.xmpp.socket, (ssl.SSLSocket, ssl.SSLObject)):
|
if isinstance(self.xmpp.socket, (ssl.SSLSocket, ssl.SSLObject)):
|
||||||
result[value] = self.xmpp.socket.get_channel_binding()
|
version = self.xmpp.socket.version()
|
||||||
|
# As of now, python does not implement anything else
|
||||||
|
# than tls-unique, which is forbidden on TLSv1.3
|
||||||
|
# see https://github.com/python/cpython/issues/95341
|
||||||
|
if version != 'TLSv1.3':
|
||||||
|
result[value] = self.xmpp.socket.get_channel_binding(
|
||||||
|
cb_type="tls-unique"
|
||||||
|
)
|
||||||
|
elif 'tls-exporter' in ssl.CHANNEL_BINDING_TYPES:
|
||||||
|
result[value] = self.xmpp.socket.get_channel_binding(
|
||||||
|
cb_type="tls-exporter"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
result[value] = None
|
||||||
else:
|
else:
|
||||||
result[value] = None
|
result[value] = None
|
||||||
elif value == 'host':
|
elif value == 'host':
|
||||||
@ -121,6 +135,11 @@ class FeatureMechanisms(BasePlugin):
|
|||||||
result[value] = True
|
result[value] = True
|
||||||
else:
|
else:
|
||||||
result[value] = False
|
result[value] = False
|
||||||
|
elif value == 'tls_version':
|
||||||
|
if isinstance(self.xmpp.socket, (ssl.SSLSocket, ssl.SSLObject)):
|
||||||
|
result[value] = self.xmpp.socket.version()
|
||||||
|
elif value == 'binding_proposed':
|
||||||
|
result[value] = any(x for x in self.mech_list if x.endswith('-PLUS'))
|
||||||
else:
|
else:
|
||||||
result[value] = self.config.get(value, False)
|
result[value] = self.config.get(value, False)
|
||||||
return result
|
return result
|
||||||
|
@ -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
|
||||||
@ -110,14 +112,19 @@ PLUGINS = [
|
|||||||
'xep_0421', # Anonymous unique occupant identifiers for MUCs
|
'xep_0421', # Anonymous unique occupant identifiers for MUCs
|
||||||
'xep_0422', # Message Fastening
|
'xep_0422', # Message Fastening
|
||||||
'xep_0424', # Message Retraction
|
'xep_0424', # Message Retraction
|
||||||
'xep_0425', # Message Moderation
|
'xep_0425', # Moderated Message Retraction
|
||||||
'xep_0428', # Message Fallback
|
'xep_0428', # Message Fallback
|
||||||
'xep_0437', # Room Activity Indicators
|
'xep_0437', # Room Activity Indicators
|
||||||
'xep_0439', # Quick Response
|
'xep_0439', # Quick Response
|
||||||
'xep_0441', # Message Archive Management Preferences
|
'xep_0441', # Message Archive Management Preferences
|
||||||
'xep_0444', # Message Reactions
|
'xep_0444', # Message Reactions
|
||||||
|
'xep_0446', # File metadata element
|
||||||
'xep_0447', # Stateless file sharing
|
'xep_0447', # Stateless file sharing
|
||||||
'xep_0461', # Message Replies
|
'xep_0461', # Message Replies
|
||||||
|
'xep_0469', # Bookmarks Pinning
|
||||||
|
'xep_0482', # Call Invites
|
||||||
|
'xep_0490', # Message Displayed Synchronization
|
||||||
|
'xep_0492', # Chat Notification Settings
|
||||||
# Meant to be imported by plugins
|
# Meant to be imported by plugins
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -6,14 +6,18 @@
|
|||||||
# Part of Slixmpp: The Slick XMPP Library
|
# Part of Slixmpp: The Slick XMPP Library
|
||||||
# :copyright: (c) 2012 Nathanael C. Fritz
|
# :copyright: (c) 2012 Nathanael C. Fritz
|
||||||
# :license: MIT, see LICENSE for more details
|
# :license: MIT, see LICENSE for more details
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from typing import Any, Dict, Set, ClassVar
|
from typing import Any, Dict, Set, ClassVar, Union, TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from slixmpp.clientxmpp import ClientXMPP
|
||||||
|
from slixmpp.componentxmpp import ComponentXMPP
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -272,7 +276,7 @@ class BasePlugin(object):
|
|||||||
#: `plugin.config['foo']`.
|
#: `plugin.config['foo']`.
|
||||||
default_config: ClassVar[Dict[str, Any]] = {}
|
default_config: ClassVar[Dict[str, Any]] = {}
|
||||||
|
|
||||||
def __init__(self, xmpp, config=None):
|
def __init__(self, xmpp: Union[ClientXMPP,ComponentXMPP], config=None):
|
||||||
self.xmpp = xmpp
|
self.xmpp = xmpp
|
||||||
if self.xmpp:
|
if self.xmpp:
|
||||||
self.api = self.xmpp.api.wrap(self.name)
|
self.api = self.xmpp.api.wrap(self.name)
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
|
||||||
# Slixmpp: The Slick XMPP Library
|
# Slixmpp: The Slick XMPP Library
|
||||||
# Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
|
# Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
|
||||||
# This file is part of Slixmpp.
|
# This file is part of Slixmpp.
|
||||||
# See the file LICENSE for copying permission.
|
# See the file LICENSE for copying permission.
|
||||||
|
import logging
|
||||||
|
|
||||||
from slixmpp.xmlstream import ElementBase, ET
|
from slixmpp.xmlstream import ElementBase, ET
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +79,14 @@ class FormField(ElementBase):
|
|||||||
reqXML = self.xml.find('{%s}required' % self.namespace)
|
reqXML = self.xml.find('{%s}required' % self.namespace)
|
||||||
return reqXML is not None
|
return reqXML is not None
|
||||||
|
|
||||||
def get_value(self, convert=True):
|
def get_value(self, convert=True, convert_list=False):
|
||||||
|
"""
|
||||||
|
Gets the value for this field
|
||||||
|
|
||||||
|
:param convert: Convert truthy values to boolean
|
||||||
|
:param convert_list: Convert text-multi fields to a string with
|
||||||
|
\n as separator for values
|
||||||
|
"""
|
||||||
valsXML = self.xml.findall('{%s}value' % self.namespace)
|
valsXML = self.xml.findall('{%s}value' % self.namespace)
|
||||||
if len(valsXML) == 0:
|
if len(valsXML) == 0:
|
||||||
return None
|
return None
|
||||||
@ -92,7 +100,7 @@ class FormField(ElementBase):
|
|||||||
if valXML.text is None:
|
if valXML.text is None:
|
||||||
valXML.text = ''
|
valXML.text = ''
|
||||||
values.append(valXML.text)
|
values.append(valXML.text)
|
||||||
if self._type == 'text-multi' and convert:
|
if self._type == 'text-multi' and convert_list:
|
||||||
values = "\n".join(values)
|
values = "\n".join(values)
|
||||||
return values
|
return values
|
||||||
else:
|
else:
|
||||||
@ -127,6 +135,17 @@ class FormField(ElementBase):
|
|||||||
del self['value']
|
del self['value']
|
||||||
valXMLName = '{%s}value' % self.namespace
|
valXMLName = '{%s}value' % self.namespace
|
||||||
|
|
||||||
|
if not self._type:
|
||||||
|
if isinstance(value, bool):
|
||||||
|
log.debug("Passed a 'boolean' as value of an untyped field, assuming it is a 'boolean'")
|
||||||
|
self._type = "boolean"
|
||||||
|
elif isinstance(value, str):
|
||||||
|
log.debug("Passed a 'str' as value of an untyped field, assuming it is a 'text-single'")
|
||||||
|
self._type = "text-single"
|
||||||
|
elif isinstance(value, (list, tuple)):
|
||||||
|
log.debug("Passed a %s as value of an untyped field, assuming it is a 'text-multi'")
|
||||||
|
self._type = "text-multi"
|
||||||
|
|
||||||
if self._type == 'boolean':
|
if self._type == 'boolean':
|
||||||
if value in self.true_values:
|
if value in self.true_values:
|
||||||
valXML = ET.Element(valXMLName)
|
valXML = ET.Element(valXMLName)
|
||||||
@ -180,3 +199,6 @@ FormField.setOptions = FormField.set_options
|
|||||||
FormField.setRequired = FormField.set_required
|
FormField.setRequired = FormField.set_required
|
||||||
FormField.setTrue = FormField.set_true
|
FormField.setTrue = FormField.set_true
|
||||||
FormField.setValue = FormField.set_value
|
FormField.setValue = FormField.set_value
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
@ -162,7 +162,7 @@ class XEP_0009(BasePlugin):
|
|||||||
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_call') > 1:
|
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_call') > 1:
|
||||||
return
|
return
|
||||||
# Reply with error by default
|
# Reply with error by default
|
||||||
error = self.client.plugin['xep_0009']._item_not_found(iq)
|
error = self.xmpp.plugin['xep_0009']._item_not_found(iq)
|
||||||
error.send()
|
error.send()
|
||||||
|
|
||||||
def _on_jabber_rpc_method_response(self, iq, forwarded=False):
|
def _on_jabber_rpc_method_response(self, iq, forwarded=False):
|
||||||
@ -175,7 +175,7 @@ class XEP_0009(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_response') > 1:
|
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_response') > 1:
|
||||||
return
|
return
|
||||||
error = self.client.plugin['xep_0009']._recpient_unavailable(iq)
|
error = self.xmpp.plugin['xep_0009']._recipient_unvailable(iq)
|
||||||
error.send()
|
error.send()
|
||||||
|
|
||||||
def _on_jabber_rpc_method_fault(self, iq, forwarded=False):
|
def _on_jabber_rpc_method_fault(self, iq, forwarded=False):
|
||||||
@ -188,7 +188,7 @@ class XEP_0009(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_fault') > 1:
|
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_fault') > 1:
|
||||||
return
|
return
|
||||||
error = self.client.plugin['xep_0009']._recpient_unavailable(iq)
|
error = self.xmpp.plugin['xep_0009']._recipient_unvailable(iq)
|
||||||
error.send()
|
error.send()
|
||||||
|
|
||||||
def _on_jabber_rpc_error(self, iq, forwarded=False):
|
def _on_jabber_rpc_error(self, iq, forwarded=False):
|
||||||
@ -201,7 +201,7 @@ class XEP_0009(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
if not forwarded and self.xmpp.event_handled('jabber_rpc_error') > 1:
|
if not forwarded and self.xmpp.event_handled('jabber_rpc_error') > 1:
|
||||||
return
|
return
|
||||||
error = self.client.plugin['xep_0009']._recpient_unavailable(iq, iq.get_payload())
|
error = self.xmpp.plugin['xep_0009']._recipient_unvailable(iq)
|
||||||
error.send()
|
error.send()
|
||||||
|
|
||||||
def _send_fault(self, iq, fault_xml): #
|
def _send_fault(self, iq, fault_xml): #
|
||||||
|
@ -57,6 +57,9 @@ class XEP_0030(BasePlugin):
|
|||||||
Given Given A single node
|
Given Given A single node
|
||||||
====== ======= ============================
|
====== ======= ============================
|
||||||
|
|
||||||
|
Adding information for a given node without specifying the JID will
|
||||||
|
use the bound JID and therefore must be done after the bind happens.
|
||||||
|
|
||||||
Stream Handlers:
|
Stream Handlers:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
@ -9,6 +9,7 @@ from typing import (
|
|||||||
Set,
|
Set,
|
||||||
Tuple,
|
Tuple,
|
||||||
Union,
|
Union,
|
||||||
|
Dict,
|
||||||
)
|
)
|
||||||
from slixmpp.xmlstream import ElementBase, ET
|
from slixmpp.xmlstream import ElementBase, ET
|
||||||
|
|
||||||
@ -144,6 +145,25 @@ class DiscoInfo(ElementBase):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def dict_identities(self, lang: Optional[str] = None) -> Set[Dict[str, str]]:
|
||||||
|
"""
|
||||||
|
Return the set of all identities, each one as a dict with
|
||||||
|
category, type, xml_lang, and name keys.
|
||||||
|
|
||||||
|
:param lang: If there is a need to filter identities by lang.
|
||||||
|
"""
|
||||||
|
ids = self.get_identities(lang=lang, dedupe=True)
|
||||||
|
dict_ids = set()
|
||||||
|
for identity in ids:
|
||||||
|
dict_ids.add({
|
||||||
|
'category': identity[0],
|
||||||
|
'type': identity[1],
|
||||||
|
'xml_lang': identity[2],
|
||||||
|
'name': identity[3],
|
||||||
|
})
|
||||||
|
return dict_ids
|
||||||
|
|
||||||
|
|
||||||
def get_identities(self, lang: Optional[str] = None, dedupe: bool = True
|
def get_identities(self, lang: Optional[str] = None, dedupe: bool = True
|
||||||
) -> Iterable[IdentityType]:
|
) -> Iterable[IdentityType]:
|
||||||
"""
|
"""
|
||||||
@ -165,11 +185,11 @@ class DiscoInfo(ElementBase):
|
|||||||
identities = []
|
identities = []
|
||||||
for id_xml in self.xml.findall('{%s}identity' % self.namespace):
|
for id_xml in self.xml.findall('{%s}identity' % self.namespace):
|
||||||
xml_lang = id_xml.attrib.get('{%s}lang' % self.xml_ns, None)
|
xml_lang = id_xml.attrib.get('{%s}lang' % self.xml_ns, None)
|
||||||
|
category = id_xml.attrib.get('category', None)
|
||||||
|
type_ = id_xml.attrib.get('type', None)
|
||||||
|
name = id_xml.attrib.get('name', None)
|
||||||
if lang is None or xml_lang == lang:
|
if lang is None or xml_lang == lang:
|
||||||
id = (id_xml.attrib['category'],
|
id = (category, type_, xml_lang, name)
|
||||||
id_xml.attrib['type'],
|
|
||||||
id_xml.attrib.get('{%s}lang' % self.xml_ns, None),
|
|
||||||
id_xml.attrib.get('name', None))
|
|
||||||
if isinstance(identities, set):
|
if isinstance(identities, set):
|
||||||
identities.add(id)
|
identities.add(id)
|
||||||
else:
|
else:
|
||||||
@ -253,10 +273,12 @@ class DiscoInfo(ElementBase):
|
|||||||
else:
|
else:
|
||||||
features = []
|
features = []
|
||||||
for feature_xml in self.xml.findall('{%s}feature' % self.namespace):
|
for feature_xml in self.xml.findall('{%s}feature' % self.namespace):
|
||||||
if isinstance(features, set):
|
feature = feature_xml.attrib.get('var', None)
|
||||||
features.add(feature_xml.attrib['var'])
|
if feature:
|
||||||
else:
|
if isinstance(features, set):
|
||||||
features.append(feature_xml.attrib['var'])
|
features.add(feature)
|
||||||
|
else:
|
||||||
|
features.append(feature)
|
||||||
return features
|
return features
|
||||||
|
|
||||||
def set_features(self, features: Iterable[str]):
|
def set_features(self, features: Iterable[str]):
|
||||||
|
@ -49,11 +49,13 @@ from slixmpp.plugins.xep_0045.stanza import (
|
|||||||
MUCUserItem,
|
MUCUserItem,
|
||||||
)
|
)
|
||||||
from slixmpp.types import (
|
from slixmpp.types import (
|
||||||
|
JidStr,
|
||||||
MucRole,
|
MucRole,
|
||||||
MucAffiliation,
|
MucAffiliation,
|
||||||
MucRoomItem,
|
MucRoomItem,
|
||||||
MucRoomItemKeys,
|
MucRoomItemKeys,
|
||||||
PresenceArgs,
|
PresenceArgs,
|
||||||
|
PresenceShows,
|
||||||
)
|
)
|
||||||
|
|
||||||
JoinResult = Tuple[Presence, Message, List[Presence], List[Message]]
|
JoinResult = Tuple[Presence, Message, List[Presence], List[Message]]
|
||||||
@ -187,7 +189,7 @@ class XEP_0045(BasePlugin):
|
|||||||
def _handle_config_change(self, msg: Message):
|
def _handle_config_change(self, msg: Message):
|
||||||
"""Handle a MUC configuration change (with status code)."""
|
"""Handle a MUC configuration change (with status code)."""
|
||||||
self.xmpp.event('groupchat_config_status', msg)
|
self.xmpp.event('groupchat_config_status', msg)
|
||||||
self.xmpp.event('muc::%s::config_status' % msg['from'].bare , msg)
|
self.xmpp.event('muc::%s::config_status' % msg['from'].bare, msg)
|
||||||
|
|
||||||
def _client_handle_presence(self, pr: Presence):
|
def _client_handle_presence(self, pr: Presence):
|
||||||
"""As a client, handle a presence stanza"""
|
"""As a client, handle a presence stanza"""
|
||||||
@ -264,7 +266,7 @@ class XEP_0045(BasePlugin):
|
|||||||
seconds: Optional[int] = None,
|
seconds: Optional[int] = None,
|
||||||
since: Optional[datetime] = None,
|
since: Optional[datetime] = None,
|
||||||
presence_options: Optional[PresenceArgs] = None,
|
presence_options: Optional[PresenceArgs] = None,
|
||||||
timeout: Optional[int] = None) -> JoinResult:
|
timeout: int = 300) -> JoinResult:
|
||||||
"""
|
"""
|
||||||
Try to join a MUC and block until we are joined or get an error.
|
Try to join a MUC and block until we are joined or get an error.
|
||||||
|
|
||||||
@ -310,7 +312,7 @@ class XEP_0045(BasePlugin):
|
|||||||
stanza.send()
|
stanza.send()
|
||||||
return await self._await_join(room, timeout)
|
return await self._await_join(room, timeout)
|
||||||
|
|
||||||
async def _await_join(self, room: JID, timeout: Optional[int] = None) -> JoinResult:
|
async def _await_join(self, room: JID, timeout: int = 300) -> JoinResult:
|
||||||
"""Do the heavy lifting for awaiting a MUC join
|
"""Do the heavy lifting for awaiting a MUC join
|
||||||
|
|
||||||
A muc join, once the join stanza is sent, is:
|
A muc join, once the join stanza is sent, is:
|
||||||
@ -358,7 +360,7 @@ class XEP_0045(BasePlugin):
|
|||||||
return (pres, subject, occupant_buffer, history_buffer)
|
return (pres, subject, occupant_buffer, history_buffer)
|
||||||
|
|
||||||
def join_muc(self, room: JID, nick: str, maxhistory="0", password='',
|
def join_muc(self, room: JID, nick: str, maxhistory="0", password='',
|
||||||
pstatus='', pshow='', pfrom='') -> asyncio.Future:
|
pstatus='', pshow: PresenceShows='chat', pfrom: JidStr='') -> asyncio.Future:
|
||||||
""" Join the specified room, requesting 'maxhistory' lines of history.
|
""" Join the specified room, requesting 'maxhistory' lines of history.
|
||||||
|
|
||||||
.. deprecated:: 1.8.0
|
.. deprecated:: 1.8.0
|
||||||
@ -412,7 +414,7 @@ class XEP_0045(BasePlugin):
|
|||||||
)
|
)
|
||||||
del self.rooms[room]
|
del self.rooms[room]
|
||||||
|
|
||||||
def set_subject(self, room: JID, subject: str, *, mfrom: Optional[JID] = None):
|
def set_subject(self, room: JidStr, subject: str, *, mfrom: Optional[JID] = None):
|
||||||
"""Set a room’s subject.
|
"""Set a room’s subject.
|
||||||
|
|
||||||
:param room: JID of the room.
|
:param room: JID of the room.
|
||||||
@ -423,7 +425,7 @@ class XEP_0045(BasePlugin):
|
|||||||
msg['subject'] = subject
|
msg['subject'] = subject
|
||||||
msg.send()
|
msg.send()
|
||||||
|
|
||||||
async def get_room_config(self, room: JID, ifrom: Optional[JID] = None,
|
async def get_room_config(self, room: JidStr, ifrom: Optional[JID] = None,
|
||||||
**iqkwargs) -> Form:
|
**iqkwargs) -> Form:
|
||||||
"""Get the room config form in 0004 plugin format.
|
"""Get the room config form in 0004 plugin format.
|
||||||
|
|
||||||
@ -438,7 +440,7 @@ class XEP_0045(BasePlugin):
|
|||||||
raise ValueError("Configuration form not found")
|
raise ValueError("Configuration form not found")
|
||||||
return form
|
return form
|
||||||
|
|
||||||
async def set_room_config(self, room: JID, config: Form, *,
|
async def set_room_config(self, room: JidStr, config: Form, *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs):
|
ifrom: Optional[JID] = None, **iqkwargs):
|
||||||
"""Send a room config form.
|
"""Send a room config form.
|
||||||
|
|
||||||
@ -451,8 +453,8 @@ class XEP_0045(BasePlugin):
|
|||||||
iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom)
|
iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom)
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def cancel_config(self, room: JID, *,
|
async def cancel_config(self, room: JidStr, *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs):
|
ifrom: Optional[JidStr] = None, **iqkwargs):
|
||||||
"""Cancel a requested config form.
|
"""Cancel a requested config form.
|
||||||
|
|
||||||
:param room: Room to cancel the form for.
|
:param room: Room to cancel the form for.
|
||||||
@ -462,8 +464,8 @@ class XEP_0045(BasePlugin):
|
|||||||
iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom)
|
iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom)
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def destroy(self, room: JID, reason: str = '', altroom: Optional[JID] = None, *,
|
async def destroy(self, room: JidStr, reason: str = '', altroom: Optional[JidStr] = None, *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs):
|
ifrom: Optional[JidStr] = None, **iqkwargs):
|
||||||
"""Destroy a room.
|
"""Destroy a room.
|
||||||
|
|
||||||
:param room: Room JID to destroy.
|
:param room: Room JID to destroy.
|
||||||
@ -479,10 +481,10 @@ class XEP_0045(BasePlugin):
|
|||||||
iq['mucowner_query']['destroy']['reason'] = reason
|
iq['mucowner_query']['destroy']['reason'] = reason
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def set_affiliation(self, room: JID, affiliation: MucAffiliation, *,
|
async def set_affiliation(self, room: JidStr, affiliation: MucAffiliation, *,
|
||||||
jid: Optional[JID] = None,
|
jid: Optional[JidStr] = None,
|
||||||
nick: Optional[str] = None, reason: str = '',
|
nick: Optional[str] = None, reason: str = '',
|
||||||
ifrom: Optional[JID] = None, **iqkwargs):
|
ifrom: Optional[JidStr] = None, **iqkwargs):
|
||||||
""" Change room affiliation for a JID or nickname.
|
""" Change room affiliation for a JID or nickname.
|
||||||
|
|
||||||
:param room: Room to modify.
|
:param room: Room to modify.
|
||||||
@ -493,7 +495,7 @@ class XEP_0045(BasePlugin):
|
|||||||
if affiliation not in AFFILIATIONS:
|
if affiliation not in AFFILIATIONS:
|
||||||
raise ValueError('%s is not a valid affiliation' % affiliation)
|
raise ValueError('%s is not a valid affiliation' % affiliation)
|
||||||
if affiliation == 'outcast' and not jid:
|
if affiliation == 'outcast' and not jid:
|
||||||
raise ValueError('Outcast affiliation requires a using a jid')
|
raise ValueError('Outcast affiliation requires using a jid')
|
||||||
if not any((jid, nick)):
|
if not any((jid, nick)):
|
||||||
raise ValueError('One of jid or nick must be set')
|
raise ValueError('One of jid or nick must be set')
|
||||||
iq = self.xmpp.make_iq_set(ito=room, ifrom=ifrom)
|
iq = self.xmpp.make_iq_set(ito=room, ifrom=ifrom)
|
||||||
@ -506,8 +508,8 @@ class XEP_0045(BasePlugin):
|
|||||||
iq['mucadmin_query']['item']['reason'] = reason
|
iq['mucadmin_query']['item']['reason'] = reason
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def get_affiliation_list(self, room: JID, affiliation: MucAffiliation, *,
|
async def get_affiliation_list(self, room: JidStr, affiliation: MucAffiliation, *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs) -> List[JID]:
|
ifrom: Optional[JidStr] = None, **iqkwargs) -> List[JID]:
|
||||||
"""Get a list of JIDs with the specified affiliation
|
"""Get a list of JIDs with the specified affiliation
|
||||||
|
|
||||||
:param room: Room to get affiliations from.
|
:param room: Room to get affiliations from.
|
||||||
@ -518,9 +520,9 @@ class XEP_0045(BasePlugin):
|
|||||||
result = await iq.send(**iqkwargs)
|
result = await iq.send(**iqkwargs)
|
||||||
return [item['jid'] for item in result['mucadmin_query']]
|
return [item['jid'] for item in result['mucadmin_query']]
|
||||||
|
|
||||||
async def send_affiliation_list(self, room: JID,
|
async def send_affiliation_list(self, room: JidStr,
|
||||||
affiliations: List[Tuple[JID, MucAffiliation]], *,
|
affiliations: List[Tuple[JidStr, MucAffiliation]], *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs):
|
ifrom: Optional[JidStr] = None, **iqkwargs):
|
||||||
"""Send an affiliation delta list.
|
"""Send an affiliation delta list.
|
||||||
|
|
||||||
:param room: Room to send the affiliations to.
|
:param room: Room to send the affiliations to.
|
||||||
@ -534,8 +536,8 @@ class XEP_0045(BasePlugin):
|
|||||||
iq['mucadmin_query'].append(item)
|
iq['mucadmin_query'].append(item)
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def set_role(self, room: JID, nick: str, role: MucRole, *,
|
async def set_role(self, room: JidStr, nick: str, role: MucRole, *,
|
||||||
reason: str = '', ifrom: Optional[JID] = None, **iqkwargs):
|
reason: str = '', ifrom: Optional[JidStr] = None, **iqkwargs):
|
||||||
""" Change role property of a nick in a room.
|
""" Change role property of a nick in a room.
|
||||||
Typically, roles are temporary (they last only as long as you are in the
|
Typically, roles are temporary (they last only as long as you are in the
|
||||||
room), whereas affiliations are permanent (they last across groupchat
|
room), whereas affiliations are permanent (they last across groupchat
|
||||||
@ -555,8 +557,8 @@ class XEP_0045(BasePlugin):
|
|||||||
iq['mucadmin_query']['item']['reason'] = reason
|
iq['mucadmin_query']['item']['reason'] = reason
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def get_roles_list(self, room: JID, role: MucRole, *,
|
async def get_roles_list(self, room: JidStr, role: MucRole, *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs) -> List[str]:
|
ifrom: Optional[JidStr] = None, **iqkwargs) -> List[str]:
|
||||||
""""Get a list of JIDs with the specified role
|
""""Get a list of JIDs with the specified role
|
||||||
|
|
||||||
:param room: Room to get roles from.
|
:param room: Room to get roles from.
|
||||||
@ -567,8 +569,8 @@ class XEP_0045(BasePlugin):
|
|||||||
result = await iq.send(**iqkwargs)
|
result = await iq.send(**iqkwargs)
|
||||||
return [item['nick'] for item in result['mucadmin_query']]
|
return [item['nick'] for item in result['mucadmin_query']]
|
||||||
|
|
||||||
async def send_role_list(self, room: JID, roles: List[Tuple[str, MucRole]], *,
|
async def send_role_list(self, room: JidStr, roles: List[Tuple[str, MucRole]], *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs):
|
ifrom: Optional[JidStr] = None, **iqkwargs):
|
||||||
"""Send a role delta list.
|
"""Send a role delta list.
|
||||||
|
|
||||||
:param room: Room to send the roles to.
|
:param room: Room to send the roles to.
|
||||||
@ -582,8 +584,8 @@ class XEP_0045(BasePlugin):
|
|||||||
iq['mucadmin_query'].append(item)
|
iq['mucadmin_query'].append(item)
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
def invite(self, room: JID, jid: JID, reason: str = '', *,
|
def invite(self, room: JidStr, jid: JidStr, reason: str = '', *,
|
||||||
mfrom: Optional[JID] = None):
|
mfrom: Optional[JidStr] = None):
|
||||||
""" Invite a jid to a room (mediated invitation).
|
""" Invite a jid to a room (mediated invitation).
|
||||||
|
|
||||||
:param room: Room to invite the user in.
|
:param room: Room to invite the user in.
|
||||||
@ -596,8 +598,8 @@ class XEP_0045(BasePlugin):
|
|||||||
msg['muc']['invite']['reason'] = reason
|
msg['muc']['invite']['reason'] = reason
|
||||||
self.xmpp.send(msg)
|
self.xmpp.send(msg)
|
||||||
|
|
||||||
def invite_server(self, room: JID, jid: JID,
|
def invite_server(self, room: JidStr, jid: JidStr,
|
||||||
invite_from: JID, reason: str = ''):
|
invite_from: JidStr, reason: str = ''):
|
||||||
"""Send a mediated invite to a user, as a MUC service.
|
"""Send a mediated invite to a user, as a MUC service.
|
||||||
|
|
||||||
.. versionadded:: 1.8.0
|
.. versionadded:: 1.8.0
|
||||||
@ -615,8 +617,8 @@ class XEP_0045(BasePlugin):
|
|||||||
msg['muc']['invite']['reason'] = reason
|
msg['muc']['invite']['reason'] = reason
|
||||||
msg.send()
|
msg.send()
|
||||||
|
|
||||||
def decline(self, room: JID, jid: JID, reason: str = '', *,
|
def decline(self, room: JidStr, jid: JidStr, reason: str = '', *,
|
||||||
mfrom: Optional[JID] = None):
|
mfrom: Optional[JidStr] = None):
|
||||||
"""Decline a mediated invitation.
|
"""Decline a mediated invitation.
|
||||||
|
|
||||||
:param room: Room the invitation came from.
|
:param room: Room the invitation came from.
|
||||||
@ -629,7 +631,7 @@ class XEP_0045(BasePlugin):
|
|||||||
msg['muc']['decline']['reason'] = reason
|
msg['muc']['decline']['reason'] = reason
|
||||||
self.xmpp.send(msg)
|
self.xmpp.send(msg)
|
||||||
|
|
||||||
def request_voice(self, room: JID, role: str, *, mfrom: Optional[JID] = None):
|
def request_voice(self, room: JidStr, role: str, *, mfrom: Optional[JidStr] = None):
|
||||||
"""Request voice in a moderated room.
|
"""Request voice in a moderated room.
|
||||||
|
|
||||||
:param room: Room to request voice from.
|
:param room: Room to request voice from.
|
||||||
@ -646,29 +648,49 @@ class XEP_0045(BasePlugin):
|
|||||||
"""Check if a JID is present in a room.
|
"""Check if a JID is present in a room.
|
||||||
|
|
||||||
:param room: Room to check.
|
:param room: Room to check.
|
||||||
:param jid: JID to check.
|
:param jid: FULL JID to check.
|
||||||
"""
|
"""
|
||||||
|
bare_match = False
|
||||||
for nick in self.rooms[room]:
|
for nick in self.rooms[room]:
|
||||||
entry = self.rooms[room][nick]
|
entry = self.rooms[room][nick]
|
||||||
if not entry.get('jid'):
|
if not entry.get('jid'):
|
||||||
continue
|
continue
|
||||||
if entry is not None and entry['jid'].full == jid:
|
|
||||||
|
if entry['jid'] == jid.full:
|
||||||
return True
|
return True
|
||||||
return False
|
elif JID(entry['jid']).bare == jid.bare:
|
||||||
|
bare_match = True
|
||||||
|
|
||||||
|
if bare_match:
|
||||||
|
logging.info(
|
||||||
|
"Could not retrieve full JID, falling back to bare JID for %s in %s",
|
||||||
|
jid, room
|
||||||
|
)
|
||||||
|
return bare_match
|
||||||
|
|
||||||
def get_nick(self, room: JID, jid: JID) -> Optional[str]:
|
def get_nick(self, room: JID, jid: JID) -> Optional[str]:
|
||||||
"""Get the nickname of a specific JID in a room.
|
"""Get the nickname of a specific JID in a room.
|
||||||
|
|
||||||
:param room: Room to inspect.
|
:param room: Room to inspect.
|
||||||
:param jid: JID whose nick to return.
|
:param jid: FULL JID whose nick to return.
|
||||||
"""
|
"""
|
||||||
|
bare_match = None
|
||||||
for nick in self.rooms[room]:
|
for nick in self.rooms[room]:
|
||||||
entry = self.rooms[room][nick]
|
entry = self.rooms[room][nick]
|
||||||
if not entry.get('jid'):
|
if not entry.get('jid'):
|
||||||
continue
|
continue
|
||||||
if entry is not None and entry['jid'].full == jid:
|
|
||||||
|
if entry['jid'] == jid.full:
|
||||||
return nick
|
return nick
|
||||||
return None
|
elif JID(entry['jid']).bare == jid.bare:
|
||||||
|
bare_match = nick
|
||||||
|
|
||||||
|
if bare_match:
|
||||||
|
logging.info(
|
||||||
|
"Could not retrieve full JID, falling back to bare JID for %s in %s",
|
||||||
|
jid, room
|
||||||
|
)
|
||||||
|
return bare_match
|
||||||
|
|
||||||
def get_joined_rooms(self) -> List[JID]:
|
def get_joined_rooms(self) -> List[JID]:
|
||||||
"""Get the list of rooms we sent a join presence to
|
"""Get the list of rooms we sent a join presence to
|
||||||
@ -704,7 +726,7 @@ class XEP_0045(BasePlugin):
|
|||||||
raise ValueError("Room %s is not joined" % room)
|
raise ValueError("Room %s is not joined" % room)
|
||||||
return list(self.rooms[room].keys())
|
return list(self.rooms[room].keys())
|
||||||
|
|
||||||
def get_users_by_affiliation(self, room: JID, affiliation='member', *, ifrom: Optional[JID] = None):
|
def get_users_by_affiliation(self, room: JidStr, affiliation='member', *, ifrom: Optional[JidStr] = None):
|
||||||
# Preserve old API
|
# Preserve old API
|
||||||
if affiliation not in AFFILIATIONS:
|
if affiliation not in AFFILIATIONS:
|
||||||
raise ValueError("Affiliation %s does not exist" % affiliation)
|
raise ValueError("Affiliation %s does not exist" % affiliation)
|
||||||
|
@ -28,7 +28,7 @@ class MUCBase(ElementBase):
|
|||||||
plugin_attrib = 'muc'
|
plugin_attrib = 'muc'
|
||||||
interfaces = {'affiliation', 'role', 'jid', 'nick', 'room', 'status_codes'}
|
interfaces = {'affiliation', 'role', 'jid', 'nick', 'room', 'status_codes'}
|
||||||
|
|
||||||
def get_status_codes(self) -> Set[str]:
|
def get_status_codes(self) -> Set[int]:
|
||||||
status = self.xml.findall(f'{{{NS_USER}}}status')
|
status = self.xml.findall(f'{{{NS_USER}}}status')
|
||||||
return {int(status.attrib['code']) for status in status}
|
return {int(status.attrib['code']) for status in status}
|
||||||
|
|
||||||
@ -275,7 +275,8 @@ class MUCUserItem(ElementBase):
|
|||||||
jid = self.xml.attrib.get('jid', None)
|
jid = self.xml.attrib.get('jid', None)
|
||||||
if jid:
|
if jid:
|
||||||
return JID(jid)
|
return JID(jid)
|
||||||
return jid
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class MUCActor(ElementBase):
|
class MUCActor(ElementBase):
|
||||||
@ -288,7 +289,8 @@ class MUCActor(ElementBase):
|
|||||||
jid = self.xml.attrib.get('jid', None)
|
jid = self.xml.attrib.get('jid', None)
|
||||||
if jid:
|
if jid:
|
||||||
return JID(jid)
|
return JID(jid)
|
||||||
return jid
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class MUCDestroy(ElementBase):
|
class MUCDestroy(ElementBase):
|
||||||
|
@ -326,7 +326,10 @@ class XEP_0050(BasePlugin):
|
|||||||
iq['command']['actions'] = actions
|
iq['command']['actions'] = actions
|
||||||
iq['command']['status'] = 'executing'
|
iq['command']['status'] = 'executing'
|
||||||
else:
|
else:
|
||||||
iq['command']['actions'] = ['complete']
|
actions = ['complete']
|
||||||
|
if session['allow_prev']:
|
||||||
|
actions.append('prev')
|
||||||
|
iq['command']['actions'] = actions
|
||||||
iq['command']['status'] = 'executing'
|
iq['command']['status'] = 'executing'
|
||||||
|
|
||||||
iq['command']['notes'] = session['notes']
|
iq['command']['notes'] = session['notes']
|
||||||
|
@ -464,10 +464,10 @@ class XEP_0060(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
Retrieve the ItemIDs hosted by a given node, using disco.
|
Retrieve the ItemIDs hosted by a given node, using disco.
|
||||||
"""
|
"""
|
||||||
self.xmpp['xep_0030'].get_items(jid, node, ifrom=ifrom,
|
return self.xmpp['xep_0030'].get_items(jid, node, ifrom=ifrom,
|
||||||
callback=callback, timeout=timeout,
|
callback=callback, timeout=timeout,
|
||||||
iterator=iterator,
|
iterator=iterator,
|
||||||
timeout_callback=timeout_callback)
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def modify_affiliations(self, jid, node, affiliations=None, ifrom=None,
|
def modify_affiliations(self, jid, node, affiliations=None, ifrom=None,
|
||||||
timeout_callback=None, callback=None,
|
timeout_callback=None, callback=None,
|
||||||
|
@ -7,7 +7,8 @@ import logging
|
|||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from asyncio import Future
|
from asyncio import Future, Lock
|
||||||
|
from collections import defaultdict
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from slixmpp import __version__
|
from slixmpp import __version__
|
||||||
@ -94,6 +95,9 @@ class XEP_0115(BasePlugin):
|
|||||||
disco.assign_verstring = self.assign_verstring
|
disco.assign_verstring = self.assign_verstring
|
||||||
disco.get_verstring = self.get_verstring
|
disco.get_verstring = self.get_verstring
|
||||||
|
|
||||||
|
# prevent concurrent fetches for the same hash
|
||||||
|
self._locks = defaultdict(Lock)
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp['xep_0030'].del_feature(feature=stanza.Capabilities.namespace)
|
self.xmpp['xep_0030'].del_feature(feature=stanza.Capabilities.namespace)
|
||||||
self.xmpp.del_filter('out', self._filter_add_caps)
|
self.xmpp.del_filter('out', self._filter_add_caps)
|
||||||
@ -137,7 +141,7 @@ class XEP_0115(BasePlugin):
|
|||||||
|
|
||||||
self.xmpp.event('entity_caps', p)
|
self.xmpp.event('entity_caps', p)
|
||||||
|
|
||||||
async def _process_caps(self, pres):
|
async def _process_caps(self, pres: Presence):
|
||||||
if not pres['caps']['hash']:
|
if not pres['caps']['hash']:
|
||||||
log.debug("Received unsupported legacy caps: %s, %s, %s",
|
log.debug("Received unsupported legacy caps: %s, %s, %s",
|
||||||
pres['caps']['node'],
|
pres['caps']['node'],
|
||||||
@ -147,7 +151,11 @@ class XEP_0115(BasePlugin):
|
|||||||
return
|
return
|
||||||
|
|
||||||
ver = pres['caps']['ver']
|
ver = pres['caps']['ver']
|
||||||
|
async with self._locks[ver]:
|
||||||
|
await self._process_caps_wrapped(pres, ver)
|
||||||
|
self._locks.pop(ver, None)
|
||||||
|
|
||||||
|
async def _process_caps_wrapped(self, pres: Presence, ver: str):
|
||||||
existing_verstring = await self.get_verstring(pres['from'].full)
|
existing_verstring = await self.get_verstring(pres['from'].full)
|
||||||
if str(existing_verstring) == str(ver):
|
if str(existing_verstring) == str(ver):
|
||||||
return
|
return
|
||||||
|
@ -137,7 +137,14 @@ 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:
|
||||||
rtt = await self.ping(self.xmpp.boundjid.host, timeout=self.timeout)
|
ifrom = None
|
||||||
|
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.")
|
||||||
|
@ -15,6 +15,32 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class XEP_0221(BasePlugin):
|
class XEP_0221(BasePlugin):
|
||||||
|
"""
|
||||||
|
XEP-0221: Data Forms Media Element
|
||||||
|
|
||||||
|
In certain implementations of Data Forms (XEP-0004), it can be
|
||||||
|
helpful to include media data such as small images. One example is
|
||||||
|
CAPTCHA Forms (XEP-0158). This plugin implements a method for
|
||||||
|
including media data in a data form.
|
||||||
|
|
||||||
|
Typical use pattern:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.register_plugin('xep_0221')
|
||||||
|
self['xep_0050'].add_command(node="showimage",
|
||||||
|
name="Show my image",
|
||||||
|
handler=self.form_handler)
|
||||||
|
|
||||||
|
def form_handler(self,iq,session):
|
||||||
|
image_url="https://xmpp.org/images/logos/xmpp-logo.svg"
|
||||||
|
form=self['xep_0004'].make_form('result','My Image')
|
||||||
|
form.addField(var='myimage', ftype='text-single', label='My Image', value=image_url)
|
||||||
|
form.field['myimage']['media'].add_uri(value=image_url, itype="image/svg")
|
||||||
|
session['payload']=form
|
||||||
|
return session
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
name = 'xep_0221'
|
name = 'xep_0221'
|
||||||
description = 'XEP-0221: Data Forms Media Element'
|
description = 'XEP-0221: Data Forms Media Element'
|
||||||
|
@ -20,6 +20,18 @@ class XEP_0223(BasePlugin):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
XEP-0223: Persistent Storage of Private Data via PubSub
|
XEP-0223: Persistent Storage of Private Data via PubSub
|
||||||
|
|
||||||
|
If a specific pubsub node requires additional publish options, edit the
|
||||||
|
:attr:`.node_profile` attribute of this plugin:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.xmpp.plugin["xep_0223"].node_profiles["urn:some:node"] = {
|
||||||
|
"pubsub#max_items" = "max"
|
||||||
|
}
|
||||||
|
|
||||||
|
This makes :meth:`.store` add these publish options whenever it is called
|
||||||
|
for the ``urn:some:node`` node.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = 'xep_0223'
|
name = 'xep_0223'
|
||||||
@ -28,6 +40,7 @@ class XEP_0223(BasePlugin):
|
|||||||
|
|
||||||
profile = {'pubsub#persist_items': True,
|
profile = {'pubsub#persist_items': True,
|
||||||
'pubsub#access_model': 'whitelist'}
|
'pubsub#access_model': 'whitelist'}
|
||||||
|
node_profiles = dict[str, dict[str, str]]()
|
||||||
|
|
||||||
def configure(self, node: str, **iqkwargs) -> Future:
|
def configure(self, node: str, **iqkwargs) -> Future:
|
||||||
"""
|
"""
|
||||||
@ -35,8 +48,12 @@ class XEP_0223(BasePlugin):
|
|||||||
|
|
||||||
:param node: Node to set the configuration at.
|
:param node: Node to set the configuration at.
|
||||||
"""
|
"""
|
||||||
config = self.xmpp['xep_0004'].Form()
|
config = self.xmpp['xep_0004'].stanza.Form()
|
||||||
config['type'] = 'submit'
|
config['type'] = 'submit'
|
||||||
|
config.add_field(
|
||||||
|
var='FORM_TYPE',
|
||||||
|
ftype='hidden',
|
||||||
|
value='http://jabber.org/protocol/pubsub#node_config')
|
||||||
|
|
||||||
for field, value in self.profile.items():
|
for field, value in self.profile.items():
|
||||||
config.add_field(var=field, value=value)
|
config.add_field(var=field, value=value)
|
||||||
@ -70,7 +87,8 @@ class XEP_0223(BasePlugin):
|
|||||||
value='http://jabber.org/protocol/pubsub#publish-options')
|
value='http://jabber.org/protocol/pubsub#publish-options')
|
||||||
|
|
||||||
fields = options['fields']
|
fields = options['fields']
|
||||||
for field, value in self.profile.items():
|
profile = self.profile | self.node_profiles.get(node, {})
|
||||||
|
for field, value in profile.items():
|
||||||
if field not in fields:
|
if field not in fields:
|
||||||
options.add_field(var=field)
|
options.add_field(var=field)
|
||||||
options.get_fields()[field]['value'] = value
|
options.get_fields()[field]['value'] = value
|
||||||
|
@ -10,6 +10,7 @@ from asyncio import Future
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from slixmpp import JID
|
from slixmpp import JID
|
||||||
|
from slixmpp.exceptions import XMPPError
|
||||||
from slixmpp.stanza import Iq, Message, Presence
|
from slixmpp.stanza import Iq, Message, Presence
|
||||||
from slixmpp.xmlstream.handler import CoroutineCallback
|
from slixmpp.xmlstream.handler import CoroutineCallback
|
||||||
from slixmpp.xmlstream.matcher import StanzaPath
|
from slixmpp.xmlstream.matcher import StanzaPath
|
||||||
@ -139,6 +140,13 @@ class XEP_0231(BasePlugin):
|
|||||||
self.xmpp.event('bob', iq)
|
self.xmpp.event('bob', iq)
|
||||||
elif iq['type'] == 'get':
|
elif iq['type'] == 'get':
|
||||||
data = await self.api['get_bob'](iq['to'], None, iq['from'], args=cid)
|
data = await self.api['get_bob'](iq['to'], None, iq['from'], args=cid)
|
||||||
|
|
||||||
|
if data is None:
|
||||||
|
raise XMPPError(
|
||||||
|
"item-not-found",
|
||||||
|
f"Bits of binary '{cid}' is not available",
|
||||||
|
)
|
||||||
|
|
||||||
if isinstance(data, Iq):
|
if isinstance(data, Iq):
|
||||||
data['id'] = iq['id']
|
data['id'] = iq['id']
|
||||||
data.send()
|
data.send()
|
||||||
|
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()
|
@ -1,5 +1,6 @@
|
|||||||
from slixmpp.plugins.base import register_plugin
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
from . import stanza, vcard4
|
from . import stanza, vcard4
|
||||||
|
from .vcard4 import XEP_0292
|
||||||
|
|
||||||
register_plugin(vcard4.XEP_0292)
|
register_plugin(vcard4.XEP_0292)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
# Slixmpp: The Slick XMPP Library
|
# Slixmpp: The Slick XMPP Library
|
||||||
# Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
# Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||||
# This file is part of Slixmpp.
|
# This file is part of Slixmpp.
|
||||||
# See the file LICENSE for copying permissio
|
# See the file LICENSE for copying permissio
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import slixmpp
|
|
||||||
from slixmpp.stanza import Message
|
from slixmpp.stanza import Message
|
||||||
|
from slixmpp.jid import JID
|
||||||
from slixmpp.xmlstream.handler import Callback
|
from slixmpp.xmlstream.handler import Callback
|
||||||
from slixmpp.xmlstream.matcher import StanzaPath
|
from slixmpp.xmlstream.matcher import StanzaPath
|
||||||
from slixmpp.xmlstream import register_stanza_plugin
|
from slixmpp.xmlstream import register_stanza_plugin
|
||||||
@ -45,5 +45,59 @@ class XEP_0308(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp.plugin['xep_0030'].add_feature(Replace.namespace)
|
self.xmpp.plugin['xep_0030'].add_feature(Replace.namespace)
|
||||||
|
|
||||||
def _handle_correction(self, msg):
|
def is_correction(self, msg: Message):
|
||||||
|
return msg.xml.find('{%s}replace' % Replace.namespace) is not None
|
||||||
|
|
||||||
|
def _handle_correction(self, msg: Message):
|
||||||
self.xmpp.event('message_correction', msg)
|
self.xmpp.event('message_correction', msg)
|
||||||
|
|
||||||
|
def build_correction(self, id_to_replace: str, mto: JID,
|
||||||
|
mfrom: Optional[JID] = None, mtype: str = 'chat',
|
||||||
|
mbody: str = '') -> Message:
|
||||||
|
"""
|
||||||
|
Build a corrected message.
|
||||||
|
|
||||||
|
:param id_to_replace: The id of the original message.
|
||||||
|
:param mto: Recipient of the message, must be the same as the original
|
||||||
|
message.
|
||||||
|
:param mfrom: Sender of the message, must be the same as the original
|
||||||
|
message.
|
||||||
|
:param mtype: Type of the message, must be the send as the original
|
||||||
|
message.
|
||||||
|
:param mbody: The corrected message body.
|
||||||
|
"""
|
||||||
|
msg = self.xmpp.make_message(
|
||||||
|
mto=mto,
|
||||||
|
mfrom=mfrom,
|
||||||
|
mbody=mbody,
|
||||||
|
mtype=mtype
|
||||||
|
)
|
||||||
|
msg['replace']['id'] = id_to_replace
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def correct_message(self, msg: Message, body: str) -> Message:
|
||||||
|
"""
|
||||||
|
Send a correction to an existing message.
|
||||||
|
|
||||||
|
:param msg: The message that must be replaced.
|
||||||
|
:param body: The body to set in the correcting message.
|
||||||
|
:returns: The message that was sent.
|
||||||
|
"""
|
||||||
|
to_replace = msg['id']
|
||||||
|
mto = msg['to']
|
||||||
|
mfrom = msg['from']
|
||||||
|
mtype = msg['type']
|
||||||
|
if not to_replace:
|
||||||
|
raise ValueError('No available ID for replacing the message')
|
||||||
|
if not mto:
|
||||||
|
raise ValueError('No available recipient JID')
|
||||||
|
|
||||||
|
new = self.build_correction(
|
||||||
|
id_to_replace=to_replace,
|
||||||
|
mto=mto,
|
||||||
|
mfrom=mfrom,
|
||||||
|
mtype=mtype,
|
||||||
|
mbody=body,
|
||||||
|
)
|
||||||
|
new.send()
|
||||||
|
return new
|
||||||
|
@ -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)
|
@ -138,10 +138,10 @@ class XEP_0356(BasePlugin):
|
|||||||
|
|
||||||
Raises ValueError if the server did not advertise the corresponding privileges
|
Raises ValueError if the server did not advertise the corresponding privileges
|
||||||
|
|
||||||
:param jid: user we want to add or modify roster items
|
Here is an example of a roster_items value:
|
||||||
:param roster_items: a dict containing the roster items' JIDs as keys and
|
|
||||||
nested dicts containing names, subscriptions and groups.
|
.. code-block:: json
|
||||||
Example:
|
|
||||||
{
|
{
|
||||||
"friend1@example.com": {
|
"friend1@example.com": {
|
||||||
"name": "Friend 1",
|
"name": "Friend 1",
|
||||||
@ -152,8 +152,13 @@ class XEP_0356(BasePlugin):
|
|||||||
"name": "Friend 2",
|
"name": "Friend 2",
|
||||||
"subscription": "from",
|
"subscription": "from",
|
||||||
"groups": ["group3"],
|
"groups": ["group3"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:param jid: user we want to add or modify roster items
|
||||||
|
:param roster_items: a dict containing the roster items' JIDs as keys and
|
||||||
|
nested dicts containing names, subscriptions and groups.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(jid, str):
|
if isinstance(jid, str):
|
||||||
jid = JID(jid)
|
jid = JID(jid)
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
# This file is part of Slixmpp.
|
# This file is part of Slixmpp.
|
||||||
# See the file LICENSE for copying permission.
|
# See the file LICENSE for copying permission.
|
||||||
from slixmpp.plugins.base import register_plugin
|
from slixmpp.plugins.base import register_plugin
|
||||||
from slixmpp.plugins.xep_0424.stanza import *
|
from .retraction import XEP_0424
|
||||||
from slixmpp.plugins.xep_0424.retraction import XEP_0424
|
|
||||||
|
|
||||||
register_plugin(XEP_0424)
|
register_plugin(XEP_0424)
|
||||||
|
@ -31,7 +31,7 @@ class XEP_0424(BasePlugin):
|
|||||||
stanza.register_plugins()
|
stanza.register_plugins()
|
||||||
self.xmpp.register_handler(Callback(
|
self.xmpp.register_handler(Callback(
|
||||||
"Message Retracted",
|
"Message Retracted",
|
||||||
StanzaPath("message/apply_to/retract"),
|
StanzaPath("message/retract"),
|
||||||
self._handle_retract_message,
|
self._handle_retract_message,
|
||||||
))
|
))
|
||||||
|
|
||||||
@ -64,7 +64,6 @@ class XEP_0424(BasePlugin):
|
|||||||
if include_fallback:
|
if include_fallback:
|
||||||
msg['body'] = fallback_text
|
msg['body'] = fallback_text
|
||||||
msg.enable('fallback')
|
msg.enable('fallback')
|
||||||
msg['apply_to']['id'] = id
|
msg['retract']['id'] = id
|
||||||
msg['apply_to'].enable('retract')
|
|
||||||
msg.enable('store')
|
msg.enable('store')
|
||||||
msg.send()
|
msg.send()
|
||||||
|
@ -8,28 +8,27 @@ from slixmpp.xmlstream import (
|
|||||||
ElementBase,
|
ElementBase,
|
||||||
register_stanza_plugin,
|
register_stanza_plugin,
|
||||||
)
|
)
|
||||||
from slixmpp.plugins.xep_0422.stanza import ApplyTo
|
|
||||||
from slixmpp.plugins.xep_0359 import OriginID
|
|
||||||
|
|
||||||
|
|
||||||
NS = 'urn:xmpp:message-retract:0'
|
NS = 'urn:xmpp:message-retract:1'
|
||||||
|
|
||||||
|
|
||||||
class Retract(ElementBase):
|
class Retract(ElementBase):
|
||||||
namespace = NS
|
namespace = NS
|
||||||
name = 'retract'
|
name = 'retract'
|
||||||
plugin_attrib = 'retract'
|
plugin_attrib = 'retract'
|
||||||
|
interfaces = {'reason', 'id'}
|
||||||
|
sub_interfaces = {'reason'}
|
||||||
|
|
||||||
|
|
||||||
class Retracted(ElementBase):
|
class Retracted(ElementBase):
|
||||||
namespace = NS
|
namespace = NS
|
||||||
name = 'retracted'
|
name = 'retracted'
|
||||||
plugin_attrib = 'retracted'
|
plugin_attrib = 'retracted'
|
||||||
interfaces = {'stamp'}
|
interfaces = {'stamp', 'id', 'reason'}
|
||||||
|
sub_interfaces = {'reason'}
|
||||||
|
|
||||||
|
|
||||||
def register_plugins():
|
def register_plugins():
|
||||||
register_stanza_plugin(ApplyTo, Retract)
|
register_stanza_plugin(Message, Retract)
|
||||||
register_stanza_plugin(Message, Retracted)
|
register_stanza_plugin(Message, Retracted)
|
||||||
|
|
||||||
register_stanza_plugin(Retracted, OriginID)
|
|
||||||
|
@ -13,10 +13,10 @@ from slixmpp.plugins.xep_0425 import stanza
|
|||||||
|
|
||||||
|
|
||||||
class XEP_0425(BasePlugin):
|
class XEP_0425(BasePlugin):
|
||||||
'''XEP-0425: Message Moderation'''
|
'''XEP-0425: Moderated Message Retraction'''
|
||||||
|
|
||||||
name = 'xep_0425'
|
name = 'xep_0425'
|
||||||
description = 'XEP-0425: Message Moderation'
|
description = 'XEP-0425: Moderated Message Retraction'
|
||||||
dependencies = {'xep_0424', 'xep_0421'}
|
dependencies = {'xep_0424', 'xep_0421'}
|
||||||
stanza = stanza
|
stanza = stanza
|
||||||
namespace = stanza.NS
|
namespace = stanza.NS
|
||||||
@ -25,7 +25,7 @@ class XEP_0425(BasePlugin):
|
|||||||
stanza.register_plugins()
|
stanza.register_plugins()
|
||||||
self.xmpp.register_handler(Callback(
|
self.xmpp.register_handler(Callback(
|
||||||
'Moderated Message',
|
'Moderated Message',
|
||||||
StanzaPath('message/apply_to/moderated/retract'),
|
StanzaPath('message/retract/moderated'),
|
||||||
self._handle_moderated,
|
self._handle_moderated,
|
||||||
))
|
))
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ class XEP_0425(BasePlugin):
|
|||||||
async def moderate(self, room: JID, id: str, reason: str = '', *,
|
async def moderate(self, room: JID, id: str, reason: str = '', *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs):
|
ifrom: Optional[JID] = None, **iqkwargs):
|
||||||
iq = self.xmpp.make_iq_set(ito=room.bare, ifrom=ifrom)
|
iq = self.xmpp.make_iq_set(ito=room.bare, ifrom=ifrom)
|
||||||
iq['apply_to']['id'] = id
|
iq['moderate']['id'] = id
|
||||||
iq['apply_to']['moderate']['reason'] = reason
|
iq['moderate']['reason'] = reason
|
||||||
iq['apply_to']['moderate'].enable('retract')
|
iq['moderate'].enable('retract')
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
@ -8,19 +8,18 @@ from slixmpp.xmlstream import (
|
|||||||
ElementBase,
|
ElementBase,
|
||||||
register_stanza_plugin,
|
register_stanza_plugin,
|
||||||
)
|
)
|
||||||
from slixmpp.plugins.xep_0422.stanza import ApplyTo
|
|
||||||
from slixmpp.plugins.xep_0421.stanza import OccupantId
|
from slixmpp.plugins.xep_0421.stanza import OccupantId
|
||||||
from slixmpp.plugins.xep_0424.stanza import Retract, Retracted
|
from slixmpp.plugins.xep_0424.stanza import Retract, Retracted
|
||||||
|
|
||||||
|
|
||||||
NS = 'urn:xmpp:message-moderate:0'
|
NS = 'urn:xmpp:message-moderate:1'
|
||||||
|
|
||||||
|
|
||||||
class Moderate(ElementBase):
|
class Moderate(ElementBase):
|
||||||
namespace = NS
|
namespace = NS
|
||||||
name = 'moderate'
|
name = 'moderate'
|
||||||
plugin_attrib = 'moderate'
|
plugin_attrib = 'moderate'
|
||||||
interfaces = {'reason'}
|
interfaces = {'id', 'reason'}
|
||||||
sub_interfaces = {'reason'}
|
sub_interfaces = {'reason'}
|
||||||
|
|
||||||
|
|
||||||
@ -28,17 +27,17 @@ class Moderated(ElementBase):
|
|||||||
namespace = NS
|
namespace = NS
|
||||||
name = 'moderated'
|
name = 'moderated'
|
||||||
plugin_attrib = 'moderated'
|
plugin_attrib = 'moderated'
|
||||||
interfaces = {'reason', 'by'}
|
interfaces = {'by'}
|
||||||
sub_interfaces = {'reason'}
|
|
||||||
|
|
||||||
|
|
||||||
def register_plugins():
|
def register_plugins():
|
||||||
register_stanza_plugin(Iq, ApplyTo)
|
# for moderation requests
|
||||||
register_stanza_plugin(ApplyTo, Moderate)
|
register_stanza_plugin(Iq, Moderate)
|
||||||
register_stanza_plugin(Moderate, Retract)
|
register_stanza_plugin(Moderate, Retract)
|
||||||
|
|
||||||
register_stanza_plugin(Message, Moderated)
|
# for moderation events
|
||||||
register_stanza_plugin(ApplyTo, Moderated)
|
register_stanza_plugin(Retract, Moderated)
|
||||||
register_stanza_plugin(Moderated, Retract)
|
|
||||||
register_stanza_plugin(Moderated, Retracted)
|
|
||||||
register_stanza_plugin(Moderated, OccupantId)
|
register_stanza_plugin(Moderated, OccupantId)
|
||||||
|
|
||||||
|
# for tombstones
|
||||||
|
register_stanza_plugin(Retracted, Moderated)
|
||||||
|
@ -18,3 +18,7 @@ class XEP_0446(BasePlugin):
|
|||||||
name = "xep_0446"
|
name = "xep_0446"
|
||||||
description = "XEP-0446: File metadata element"
|
description = "XEP-0446: File metadata element"
|
||||||
stanza = stanza
|
stanza = stanza
|
||||||
|
dependencies = {'xep_0300', 'xep_0264'}
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
stanza.register_plugins()
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from slixmpp.plugins.xep_0082 import format_datetime, parse
|
from slixmpp.plugins.xep_0082 import format_datetime, parse
|
||||||
from slixmpp.xmlstream import ElementBase
|
from slixmpp.plugins.xep_0300 import Hash
|
||||||
|
from slixmpp.plugins.xep_0264.stanza import Thumbnail
|
||||||
|
from slixmpp.xmlstream import ElementBase, register_stanza_plugin
|
||||||
|
|
||||||
NS = "urn:xmpp:file:metadata:0"
|
NS = "urn:xmpp:file:metadata:0"
|
||||||
|
|
||||||
@ -10,15 +13,42 @@ class File(ElementBase):
|
|||||||
name = "file"
|
name = "file"
|
||||||
namespace = NS
|
namespace = NS
|
||||||
plugin_attrib = "file"
|
plugin_attrib = "file"
|
||||||
interfaces = sub_interfaces = {"media-type", "name", "date", "size", "hash", "desc"}
|
interfaces = sub_interfaces = {
|
||||||
|
"media-type",
|
||||||
|
"name",
|
||||||
|
"date",
|
||||||
|
"size",
|
||||||
|
"desc",
|
||||||
|
"width",
|
||||||
|
"height",
|
||||||
|
"length"
|
||||||
|
}
|
||||||
|
|
||||||
|
def set_width(self, width: int):
|
||||||
|
self.__set_if_positive("width", width)
|
||||||
|
|
||||||
|
def get_width(self) -> Optional[int]:
|
||||||
|
return _positive_int_or_none(self._get_sub_text("width"))
|
||||||
|
|
||||||
|
def set_height(self, height: int):
|
||||||
|
self.__set_if_positive("height", height)
|
||||||
|
|
||||||
|
def get_height(self) -> Optional[int]:
|
||||||
|
return _positive_int_or_none(self._get_sub_text("height"))
|
||||||
|
|
||||||
|
def set_length(self, length: int):
|
||||||
|
self.__set_if_positive("length", length)
|
||||||
|
|
||||||
|
def get_length(self) -> Optional[int]:
|
||||||
|
return _positive_int_or_none(self._get_sub_text("length"))
|
||||||
|
|
||||||
def set_size(self, size: int):
|
def set_size(self, size: int):
|
||||||
self._set_sub_text("size", str(size))
|
self.__set_if_positive("size", size)
|
||||||
|
|
||||||
def get_size(self):
|
def get_size(self) -> Optional[int]:
|
||||||
return _int_or_none(self._get_sub_text("size"))
|
return _positive_int_or_none(self._get_sub_text("size"))
|
||||||
|
|
||||||
def get_date(self):
|
def get_date(self) -> Optional[datetime]:
|
||||||
try:
|
try:
|
||||||
return parse(self._get_sub_text("date"))
|
return parse(self._get_sub_text("date"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -30,9 +60,18 @@ class File(ElementBase):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __set_if_positive(self, key: str, value: int):
|
||||||
|
if value <= 0:
|
||||||
|
raise ValueError(f"Invalid value for element {key}: {value}")
|
||||||
|
self._set_sub_text(key, str(value))
|
||||||
|
|
||||||
def _int_or_none(v):
|
|
||||||
|
def _positive_int_or_none(v: str) -> Optional[int]:
|
||||||
try:
|
try:
|
||||||
return int(v)
|
return int(v)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def register_plugins():
|
||||||
|
register_stanza_plugin(File, Hash)
|
||||||
|
register_stanza_plugin(File, Thumbnail)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
from slixmpp.plugins import BasePlugin
|
from slixmpp.plugins import BasePlugin
|
||||||
from slixmpp.types import JidStr
|
from slixmpp.types import JidStr
|
||||||
from slixmpp.xmlstream import StanzaBase
|
from slixmpp.xmlstream import StanzaBase
|
||||||
@ -36,13 +38,35 @@ class XEP_0461(BasePlugin):
|
|||||||
def _handle_reply_to_message(self, msg: StanzaBase):
|
def _handle_reply_to_message(self, msg: StanzaBase):
|
||||||
self.xmpp.event("message_reply", msg)
|
self.xmpp.event("message_reply", msg)
|
||||||
|
|
||||||
def send_reply(self, reply_to: JidStr, reply_id: str, **msg_kwargs):
|
def make_reply(self, reply_to: JidStr, reply_id: str,
|
||||||
|
fallback: Optional[str] = None,
|
||||||
|
quoted_nick: Optional[str] = None, **msg_kwargs):
|
||||||
|
"""Create a replies message stanza
|
||||||
|
|
||||||
|
:param reply_to: Full JID of the quoted author
|
||||||
|
:param reply_id: ID of the message to reply to
|
||||||
|
:param fallback: Body of the quoted message
|
||||||
|
:param quoted_nick: nickname of the quoted participant
|
||||||
|
:param msg_kwargs: Parameters are consistent with the make_message method,
|
||||||
|
required parameters are ``mto`` and ``mbody``
|
||||||
|
"""
|
||||||
|
|
||||||
|
msg = self.xmpp.make_message(**msg_kwargs)
|
||||||
|
msg["reply"]["to"] = reply_to
|
||||||
|
msg["reply"]["id"] = reply_id
|
||||||
|
if fallback:
|
||||||
|
msg["reply"].add_quoted_fallback(fallback, quoted_nick)
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def send_reply(self, reply_to: JidStr, reply_id: str,
|
||||||
|
fallback: Optional[str] = None,
|
||||||
|
quoted_nick: Optional[str] = None, **msg_kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
:param reply_to: Full JID of the quoted author
|
:param reply_to: Full JID of the quoted author
|
||||||
:param reply_id: ID of the message to reply to
|
:param reply_id: ID of the message to reply to
|
||||||
|
:param fallback: Body of the quoted message
|
||||||
|
:param quoted_nick: nickname of the quoted participant
|
||||||
"""
|
"""
|
||||||
msg = self.xmpp.make_message(**msg_kwargs)
|
msg = self.make_reply(reply_to, reply_id, fallback, quoted_nick, **msg_kwargs)
|
||||||
msg["reply"]["to"] = reply_to
|
|
||||||
msg["reply"]["id"] = reply_id
|
|
||||||
msg.send()
|
msg.send()
|
||||||
|
@ -14,11 +14,12 @@ class Reply(ElementBase):
|
|||||||
interfaces = {"id", "to"}
|
interfaces = {"id", "to"}
|
||||||
|
|
||||||
def add_quoted_fallback(self, fallback: str, nickname: Optional[str] = None):
|
def add_quoted_fallback(self, fallback: str, nickname: Optional[str] = None):
|
||||||
"""
|
r"""
|
||||||
Add plain text fallback for clients not implementing XEP-0461.
|
Add plain text fallback for clients not implementing XEP-0461.
|
||||||
|
|
||||||
|
|
||||||
``msg["reply"].add_quoted_fallback("Some text", "Bob")`` will
|
``msg["reply"].add_quoted_fallback("Some text", "Bob")`` will
|
||||||
prepend "> Bob:\n> Some text\n" to the body of the message, and set the
|
prepend ``> Bob:\n> Some text\n`` to the body of the message, and set the
|
||||||
fallback_body attributes accordingly, so that clients implementing
|
fallback_body attributes accordingly, so that clients implementing
|
||||||
XEP-0461 can hide the fallback text.
|
XEP-0461 can hide the fallback text.
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class Reply(ElementBase):
|
|||||||
if nickname:
|
if nickname:
|
||||||
quoted = "> " + nickname + ":\n" + quoted
|
quoted = "> " + nickname + ":\n" + quoted
|
||||||
msg["body"] = quoted + msg["body"]
|
msg["body"] = quoted + msg["body"]
|
||||||
fallback = Fallback()
|
fallback_elem = Fallback()
|
||||||
fallback["for"] = NS
|
fallback_elem["for"] = NS
|
||||||
fallback["body"]["start"] = 0
|
fallback_elem["body"]["start"] = 0
|
||||||
fallback["body"]["end"] = len(quoted)
|
fallback_elem["body"]["end"] = len(quoted)
|
||||||
msg.append(fallback)
|
msg.append(fallback_elem)
|
||||||
|
|
||||||
def get_fallback_body(self) -> str:
|
def get_fallback_body(self) -> str:
|
||||||
msg = self.parent()
|
msg = self.parent()
|
||||||
@ -50,6 +51,23 @@ class Reply(ElementBase):
|
|||||||
return body[start:end]
|
return body[start:end]
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def strip_fallback_content(self) -> str:
|
||||||
|
msg = self.parent()
|
||||||
|
for fallback in msg["fallbacks"]:
|
||||||
|
if fallback["for"] == NS:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return msg["body"]
|
||||||
|
|
||||||
|
start = fallback["body"]["start"]
|
||||||
|
end = fallback["body"]["end"]
|
||||||
|
body = msg["body"]
|
||||||
|
|
||||||
|
if 0 <= start < end <= len(body):
|
||||||
|
return body[:start] + body[end:]
|
||||||
|
else:
|
||||||
|
return body
|
||||||
|
|
||||||
|
|
||||||
def register_plugins():
|
def register_plugins():
|
||||||
|
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)
|
11
slixmpp/plugins/xep_0482/__init__.py
Normal file
11
slixmpp/plugins/xep_0482/__init__.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2025 Mathieu Pasquet
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permissio
|
||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from slixmpp.plugins.xep_0482 import stanza
|
||||||
|
from slixmpp.plugins.xep_0482.call_invites import XEP_0482
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0482)
|
55
slixmpp/plugins/xep_0482/call_invites.py
Normal file
55
slixmpp/plugins/xep_0482/call_invites.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2025 Mathieu Pasquet
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permissio
|
||||||
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from slixmpp.stanza import Message
|
||||||
|
from slixmpp.jid import JID
|
||||||
|
from slixmpp.xmlstream.handler import Callback
|
||||||
|
from slixmpp.xmlstream.matcher import StanzaPath
|
||||||
|
from slixmpp.xmlstream import register_stanza_plugin
|
||||||
|
from slixmpp.plugins import BasePlugin
|
||||||
|
from slixmpp.plugins.xep_0482 import stanza
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0482(BasePlugin):
|
||||||
|
|
||||||
|
"""
|
||||||
|
XEP-0482: Call Invites
|
||||||
|
|
||||||
|
This plugin defines the stanza elements for Call Invites, as well as new
|
||||||
|
events:
|
||||||
|
|
||||||
|
- `call-invite`
|
||||||
|
- `call-reject`
|
||||||
|
- `call-retract`
|
||||||
|
- `call-leave`
|
||||||
|
- `call-left`
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = 'xep_0482'
|
||||||
|
description = 'XEP-0482: Call Invites'
|
||||||
|
dependencies = set()
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
stanza.register_plugins()
|
||||||
|
|
||||||
|
for event in ('invite', 'reject', 'retract', 'leave', 'left'):
|
||||||
|
self.xmpp.register_handler(
|
||||||
|
Callback(f'Call {event}',
|
||||||
|
StanzaPath(f'message/call-{event}'),
|
||||||
|
self._handle_event))
|
||||||
|
def _handle_event(self, message):
|
||||||
|
for event in ('invite', 'reject', 'retract', 'leave', 'left'):
|
||||||
|
if message.get_plugin(f'call-{event}', check=True):
|
||||||
|
self.xmpp.event(f'call-{event}')
|
||||||
|
|
||||||
|
def plugin_end(self):
|
||||||
|
for event in ('invite', 'reject', 'retract', 'leave', 'left'):
|
||||||
|
self.xmpp.remove_handler(f'Call {event}')
|
102
slixmpp/plugins/xep_0482/stanza.py
Normal file
102
slixmpp/plugins/xep_0482/stanza.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2025 Mathieu Pasquet
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permission
|
||||||
|
|
||||||
|
from typing import Tuple, List, Optional
|
||||||
|
from slixmpp import Message
|
||||||
|
from slixmpp.jid import JID
|
||||||
|
from slixmpp.xmlstream import ElementBase, register_stanza_plugin
|
||||||
|
|
||||||
|
NS = 'urn:xmpp:call-invites:0'
|
||||||
|
|
||||||
|
|
||||||
|
class Jingle(ElementBase):
|
||||||
|
name = 'jingle'
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = 'jingle'
|
||||||
|
plugin_multi_attrib = 'jingles'
|
||||||
|
interfaces = {'sid', 'jid'}
|
||||||
|
|
||||||
|
def set_jid(self, value: JID) -> None:
|
||||||
|
if not isinstance(value, JID):
|
||||||
|
try:
|
||||||
|
value = JID(value)
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError(f'"jid" must be a valid JID object')
|
||||||
|
self.xml.attrib['jid'] = value.full
|
||||||
|
|
||||||
|
def get_jid(self) -> Optional[JID]:
|
||||||
|
try:
|
||||||
|
return JID(self.xml.attrib.get('jid', ''))
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class External(ElementBase):
|
||||||
|
name = 'external'
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = 'external'
|
||||||
|
plugin_multi_attrib = 'externals'
|
||||||
|
interfaces = {'uri'}
|
||||||
|
|
||||||
|
|
||||||
|
class Invite(ElementBase):
|
||||||
|
name = 'invite'
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = 'call-invite'
|
||||||
|
interfaces = {'video'}
|
||||||
|
|
||||||
|
def get_methods(self) -> Tuple[List[Jingle], List[External]]:
|
||||||
|
return (self['jingles'], self['externals'])
|
||||||
|
|
||||||
|
def set_video(self, value: bool) -> None:
|
||||||
|
if not isinstance(value, bool):
|
||||||
|
raise ValueError(f'Invalid value for the video attribute: {value}')
|
||||||
|
self.xml.attrib['video'] = str(value).lower()
|
||||||
|
|
||||||
|
def get_video(self) -> bool:
|
||||||
|
vid = self.xml.attrib.get('video', 'false').lower()
|
||||||
|
return vid == 'true'
|
||||||
|
|
||||||
|
|
||||||
|
class Retract(ElementBase):
|
||||||
|
name = 'retract'
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = 'call-retract'
|
||||||
|
interfaces = {'id'}
|
||||||
|
|
||||||
|
|
||||||
|
class Accept(ElementBase):
|
||||||
|
name = 'accept'
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = 'call-accept'
|
||||||
|
interfaces = {'id'}
|
||||||
|
|
||||||
|
|
||||||
|
class Reject(ElementBase):
|
||||||
|
name = 'reject'
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = 'call-reject'
|
||||||
|
interfaces = {'id'}
|
||||||
|
|
||||||
|
|
||||||
|
class Left(ElementBase):
|
||||||
|
name = 'left'
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = 'call-left'
|
||||||
|
interfaces = {'id'}
|
||||||
|
|
||||||
|
|
||||||
|
def register_plugins() -> None:
|
||||||
|
register_stanza_plugin(Message, Invite)
|
||||||
|
register_stanza_plugin(Message, Retract)
|
||||||
|
register_stanza_plugin(Message, Accept)
|
||||||
|
register_stanza_plugin(Message, Reject)
|
||||||
|
register_stanza_plugin(Message, Left)
|
||||||
|
|
||||||
|
register_stanza_plugin(Invite, Jingle, iterable=True)
|
||||||
|
register_stanza_plugin(Invite, External, iterable=True)
|
||||||
|
|
||||||
|
register_stanza_plugin(Accept, Jingle)
|
||||||
|
register_stanza_plugin(Accept, External)
|
8
slixmpp/plugins/xep_0490/__init__.py
Normal file
8
slixmpp/plugins/xep_0490/__init__.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from .mds import XEP_0490
|
||||||
|
|
||||||
|
register_plugin(XEP_0490)
|
||||||
|
|
||||||
|
__all__ = ['stanza', 'XEP_0490']
|
42
slixmpp/plugins/xep_0490/mds.py
Normal file
42
slixmpp/plugins/xep_0490/mds.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from asyncio import Future
|
||||||
|
|
||||||
|
from slixmpp import Iq
|
||||||
|
from slixmpp.plugins import BasePlugin
|
||||||
|
from slixmpp.types import JidStr
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from ..xep_0004 import Form
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0490(BasePlugin):
|
||||||
|
"""
|
||||||
|
XEP-0490: Message Displayed Synchronization
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "xep_0490"
|
||||||
|
description = "XEP-0490: Message Displayed Synchronization"
|
||||||
|
dependencies = {"xep_0060", "xep_0163", "xep_0223", "xep_0359"}
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
stanza.register_plugin()
|
||||||
|
self.xmpp.plugin["xep_0163"].register_pep(
|
||||||
|
"message_displayed_synchronization",
|
||||||
|
stanza.Displayed,
|
||||||
|
)
|
||||||
|
self.xmpp.plugin["xep_0223"].node_profiles[self.stanza.NS] = {
|
||||||
|
"pubsub#max_items": "max",
|
||||||
|
"pubsub#send_last_published_item": "never",
|
||||||
|
}
|
||||||
|
|
||||||
|
def flag_chat(self, chat: JidStr, stanza_id: str, **kwargs) -> Future[Iq]:
|
||||||
|
displayed = stanza.Displayed()
|
||||||
|
displayed["stanza_id"]["id"] = stanza_id
|
||||||
|
return self.xmpp.plugin["xep_0223"].store(
|
||||||
|
displayed, node=stanza.NS, id=str(chat), **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
def catch_up(self, **kwargs):
|
||||||
|
return self.xmpp.plugin["xep_0060"].get_items(
|
||||||
|
self.xmpp.boundjid.bare, stanza.NS, **kwargs
|
||||||
|
)
|
17
slixmpp/plugins/xep_0490/stanza.py
Normal file
17
slixmpp/plugins/xep_0490/stanza.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from slixmpp import register_stanza_plugin
|
||||||
|
from slixmpp.plugins.xep_0060.stanza import Item
|
||||||
|
from slixmpp.xmlstream import ElementBase
|
||||||
|
from slixmpp.plugins.xep_0359.stanza import StanzaID
|
||||||
|
|
||||||
|
NS = "urn:xmpp:mds:displayed:0"
|
||||||
|
|
||||||
|
|
||||||
|
class Displayed(ElementBase):
|
||||||
|
namespace = NS
|
||||||
|
name = "displayed"
|
||||||
|
plugin_attrib = "displayed"
|
||||||
|
|
||||||
|
|
||||||
|
def register_plugin():
|
||||||
|
register_stanza_plugin(Displayed, StanzaID)
|
||||||
|
register_stanza_plugin(Item, Displayed)
|
13
slixmpp/plugins/xep_0492/__init__.py
Normal file
13
slixmpp/plugins/xep_0492/__init__.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2025 nicoco
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permission.
|
||||||
|
|
||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from .notify import XEP_0492
|
||||||
|
|
||||||
|
register_plugin(XEP_0492)
|
||||||
|
|
||||||
|
__all__ = ["stanza", "XEP_0492"]
|
21
slixmpp/plugins/xep_0492/notify.py
Normal file
21
slixmpp/plugins/xep_0492/notify.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2025 nicoco
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permission.
|
||||||
|
|
||||||
|
from slixmpp.plugins import BasePlugin
|
||||||
|
from . import stanza
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0492(BasePlugin):
|
||||||
|
"""
|
||||||
|
XEP-0492: Chat notification settings
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "xep_0492"
|
||||||
|
description = "XEP-0492: Chat notification settings"
|
||||||
|
dependencies = {"xep_0402"}
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
stanza.register_plugin()
|
106
slixmpp/plugins/xep_0492/stanza.py
Normal file
106
slixmpp/plugins/xep_0492/stanza.py
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2025 nicoco
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permission.
|
||||||
|
|
||||||
|
from typing import Literal, Optional, cast
|
||||||
|
|
||||||
|
from slixmpp import register_stanza_plugin
|
||||||
|
from slixmpp.plugins.xep_0402.stanza import Extensions
|
||||||
|
from slixmpp.types import ClientTypes
|
||||||
|
from slixmpp.xmlstream import ElementBase
|
||||||
|
|
||||||
|
NS = "urn:xmpp:notification-settings:0"
|
||||||
|
|
||||||
|
WhenLiteral = Literal["never", "always", "on-mention"]
|
||||||
|
|
||||||
|
|
||||||
|
class Notify(ElementBase):
|
||||||
|
"""
|
||||||
|
Chat notification settings element
|
||||||
|
|
||||||
|
|
||||||
|
To enable it on a Conference element, use configure() like this:
|
||||||
|
|
||||||
|
.. code-block::python
|
||||||
|
|
||||||
|
# C being a Conference element
|
||||||
|
C['extensions']["notify"].configure("always", client_type="pc")
|
||||||
|
|
||||||
|
Which will add the <notify> element to the <extensions> element.
|
||||||
|
"""
|
||||||
|
|
||||||
|
namespace = NS
|
||||||
|
name = "notify"
|
||||||
|
plugin_attrib = "notify"
|
||||||
|
interfaces = {"notify"}
|
||||||
|
|
||||||
|
def configure(self, when: WhenLiteral, client_type: Optional[ClientTypes] = None) -> None:
|
||||||
|
"""
|
||||||
|
Configure the chat notification settings for this bookmark.
|
||||||
|
|
||||||
|
This method ensures that there are no conflicting settings, e.g.,
|
||||||
|
both a <never /> and a <always /> element.
|
||||||
|
"""
|
||||||
|
cls = _CLASS_MAP[when]
|
||||||
|
element = cls()
|
||||||
|
if client_type is not None:
|
||||||
|
element["client-type"] = client_type
|
||||||
|
|
||||||
|
match = client_type if client_type is not None else ""
|
||||||
|
for child in self:
|
||||||
|
if isinstance(child, _Base) and child["client-type"] == match:
|
||||||
|
self.xml.remove(child.xml)
|
||||||
|
|
||||||
|
self.append(element)
|
||||||
|
|
||||||
|
def get_config(
|
||||||
|
self, client_type: Optional[ClientTypes] = None
|
||||||
|
) -> Optional[WhenLiteral]:
|
||||||
|
"""
|
||||||
|
Get the chat notification settings for this bookmark.
|
||||||
|
|
||||||
|
:param client_type: Optionally, get the notification for a specific client type.
|
||||||
|
If unset, returns the global notification setting.
|
||||||
|
|
||||||
|
:return: The chat notification setting as a string, or None if unset.
|
||||||
|
"""
|
||||||
|
match = client_type if client_type is not None else ""
|
||||||
|
for child in self:
|
||||||
|
if isinstance(child, _Base) and child["client-type"] == match:
|
||||||
|
return cast(WhenLiteral, child.name)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class _Base(ElementBase):
|
||||||
|
namespace = NS
|
||||||
|
interfaces = {"client-type"}
|
||||||
|
|
||||||
|
|
||||||
|
class Never(_Base):
|
||||||
|
name = "never"
|
||||||
|
|
||||||
|
|
||||||
|
class Always(_Base):
|
||||||
|
name = "always"
|
||||||
|
|
||||||
|
|
||||||
|
class OnMention(_Base):
|
||||||
|
name = "on-mention"
|
||||||
|
|
||||||
|
|
||||||
|
class Advanced(ElementBase):
|
||||||
|
namespace = NS
|
||||||
|
name = plugin_attrib = "advanced"
|
||||||
|
|
||||||
|
|
||||||
|
_CLASS_MAP = {
|
||||||
|
"never": Never,
|
||||||
|
"always": Always,
|
||||||
|
"on-mention": OnMention,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def register_plugin():
|
||||||
|
register_stanza_plugin(Extensions, Notify)
|
||||||
|
register_stanza_plugin(Notify, Advanced)
|
@ -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,8 @@ 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
|
||||||
|
from slixmpp.plugins.xep_0490 import XEP_0490
|
||||||
|
|
||||||
|
|
||||||
class PluginsDict(TypedDict):
|
class PluginsDict(TypedDict):
|
||||||
@ -162,12 +166,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 +199,5 @@ 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
|
||||||
|
xep_0490: XEP_0490
|
||||||
|
@ -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):
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
# Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
|
# Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
|
||||||
# This file is part of Slixmpp.
|
# This file is part of Slixmpp.
|
||||||
# See the file LICENSE for copying permission.
|
# See the file LICENSE for copying permission.
|
||||||
|
import atexit
|
||||||
import unittest
|
import unittest
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
@ -750,3 +751,12 @@ class SlixTest(unittest.TestCase):
|
|||||||
Error.namespace = 'jabber:client'
|
Error.namespace = 'jabber:client'
|
||||||
for st in Message, Iq, Presence:
|
for st in Message, Iq, Presence:
|
||||||
register_stanza_plugin(st, Error)
|
register_stanza_plugin(st, Error)
|
||||||
|
|
||||||
|
|
||||||
|
@atexit.register
|
||||||
|
def cleanup():
|
||||||
|
try:
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
@ -53,17 +53,20 @@ MucAffiliation = Literal[
|
|||||||
'outcast', 'member', 'admin', 'owner', 'none'
|
'outcast', 'member', 'admin', 'owner', 'none'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
OptJid = Optional[JID]
|
||||||
|
JidStr = Union[str, JID]
|
||||||
|
OptJidStr = Optional[Union[str, JID]]
|
||||||
|
|
||||||
class PresenceArgs(TypedDict, total=False):
|
class PresenceArgs(TypedDict, total=False):
|
||||||
pfrom: JID
|
pfrom: JidStr
|
||||||
pto: JID
|
pto: JidStr
|
||||||
pshow: PresenceShows
|
pshow: PresenceShows
|
||||||
ptype: PresenceTypes
|
ptype: PresenceTypes
|
||||||
pstatus: str
|
pstatus: str
|
||||||
|
|
||||||
|
|
||||||
class MucRoomItem(TypedDict, total=False):
|
class MucRoomItem(TypedDict, total=False):
|
||||||
jid: JID
|
jid: str
|
||||||
role: MucRole
|
role: MucRole
|
||||||
affiliation: MucAffiliation
|
affiliation: MucAffiliation
|
||||||
show: Optional[PresenceShows]
|
show: Optional[PresenceShows]
|
||||||
@ -75,10 +78,6 @@ MucRoomItemKeys = Literal[
|
|||||||
'jid', 'role', 'affiliation', 'show', 'status', 'alt_nick',
|
'jid', 'role', 'affiliation', 'show', 'status', 'alt_nick',
|
||||||
]
|
]
|
||||||
|
|
||||||
OptJid = Optional[JID]
|
|
||||||
JidStr = Union[str, JID]
|
|
||||||
OptJidStr = Optional[Union[str, JID]]
|
|
||||||
|
|
||||||
MAMDefault = Literal['always', 'never', 'roster']
|
MAMDefault = Literal['always', 'never', 'roster']
|
||||||
|
|
||||||
FilterString = Literal['in', 'out', 'out_sync']
|
FilterString = Literal['in', 'out', 'out_sync']
|
||||||
@ -98,6 +97,7 @@ ErrorConditions = Literal[
|
|||||||
"not-allowed",
|
"not-allowed",
|
||||||
"not-authorized",
|
"not-authorized",
|
||||||
"payment-required",
|
"payment-required",
|
||||||
|
"policy-violation",
|
||||||
"recipient-unavailable",
|
"recipient-unavailable",
|
||||||
"redirect",
|
"redirect",
|
||||||
"registration-required",
|
"registration-required",
|
||||||
@ -110,8 +110,21 @@ ErrorConditions = Literal[
|
|||||||
"unexpected-request",
|
"unexpected-request",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# https://xmpp.org/registrar/disco-categories.html#client
|
||||||
|
ClientTypes = Literal[
|
||||||
|
"bot",
|
||||||
|
"console",
|
||||||
|
"game",
|
||||||
|
"handheld",
|
||||||
|
"pc",
|
||||||
|
"phone",
|
||||||
|
"sms",
|
||||||
|
"tablet",
|
||||||
|
"web",
|
||||||
|
]
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'Protocol', 'TypedDict', 'Literal', 'OptJid', 'OptJidStr', 'JidStr', 'MAMDefault',
|
'Protocol', 'TypedDict', 'Literal', 'OptJid', 'OptJidStr', 'JidStr', 'MAMDefault',
|
||||||
'PresenceTypes', 'PresenceShows', 'MessageTypes', 'IqTypes', 'MucRole',
|
'PresenceTypes', 'PresenceShows', 'MessageTypes', 'IqTypes', 'MucRole',
|
||||||
'MucAffiliation', 'FilterString', 'ErrorConditions', 'ErrorTypes'
|
'MucAffiliation', 'FilterString', 'ErrorConditions', 'ErrorTypes', 'ClientTypes'
|
||||||
]
|
]
|
||||||
|
@ -181,7 +181,7 @@ class SCRAM(Mech):
|
|||||||
channel_binding = True
|
channel_binding = True
|
||||||
required_credentials = {'username', 'password'}
|
required_credentials = {'username', 'password'}
|
||||||
optional_credentials = {'authzid', 'channel_binding'}
|
optional_credentials = {'authzid', 'channel_binding'}
|
||||||
security = {'encrypted', 'unencrypted_scram'}
|
security = {'tls_version', 'encrypted', 'unencrypted_scram', 'binding_proposed'}
|
||||||
|
|
||||||
def setup(self, name):
|
def setup(self, name):
|
||||||
self.use_channel_binding = False
|
self.use_channel_binding = False
|
||||||
@ -244,11 +244,15 @@ class SCRAM(Mech):
|
|||||||
self.cnonce = bytes(('%s' % random.random())[2:])
|
self.cnonce = bytes(('%s' % random.random())[2:])
|
||||||
|
|
||||||
gs2_cbind_flag = b'n'
|
gs2_cbind_flag = b'n'
|
||||||
if self.credentials['channel_binding']:
|
if self.security_settings['binding_proposed']:
|
||||||
if self.use_channel_binding:
|
if self.credentials['channel_binding'] and \
|
||||||
gs2_cbind_flag = b'p=tls-unique'
|
self.use_channel_binding:
|
||||||
else:
|
if self.security_settings['tls_version'] != 'TLSv1.3':
|
||||||
gs2_cbind_flag = b'y'
|
gs2_cbind_flag = b'p=tls-unique'
|
||||||
|
else:
|
||||||
|
gs2_cbind_flag = b'p=tls-exporter'
|
||||||
|
else:
|
||||||
|
gs2_cbind_flag = b'y'
|
||||||
|
|
||||||
authzid = b''
|
authzid = b''
|
||||||
if self.credentials['authzid']:
|
if self.credentials['authzid']:
|
||||||
@ -280,7 +284,7 @@ class SCRAM(Mech):
|
|||||||
raise SASLCancelled('Invalid nonce')
|
raise SASLCancelled('Invalid nonce')
|
||||||
|
|
||||||
cbind_data = b''
|
cbind_data = b''
|
||||||
if self.use_channel_binding:
|
if self.use_channel_binding and self.credentials['channel_binding']:
|
||||||
cbind_data = self.credentials['channel_binding']
|
cbind_data = self.credentials['channel_binding']
|
||||||
cbind_input = self.gs2_header + cbind_data
|
cbind_input = self.gs2_header + cbind_data
|
||||||
channel_binding = b'c=' + b64encode(cbind_input).replace(b'\n', b'')
|
channel_binding = b'c=' + b64encode(cbind_input).replace(b'\n', b'')
|
||||||
|
@ -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.4'
|
__version__ = '1.8.6'
|
||||||
__version_info__ = (1, 8, 4)
|
__version_info__ = (1, 8, 6)
|
||||||
|
@ -732,6 +732,9 @@ class ElementBase(object):
|
|||||||
return plugin[full_attrib]
|
return plugin[full_attrib]
|
||||||
return plugin
|
return plugin
|
||||||
else:
|
else:
|
||||||
|
# XXX: This is legacy from SleekXMPP
|
||||||
|
# We've probably missed the opportunity to fix it
|
||||||
|
logging.warning("Unknown stanza interface: %s" % full_attrib)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def __setitem__(self, attrib: str, value: Any) -> Any:
|
def __setitem__(self, attrib: str, value: Any) -> Any:
|
||||||
@ -1230,7 +1233,7 @@ class ElementBase(object):
|
|||||||
if type(item) == XML_TYPE:
|
if type(item) == XML_TYPE:
|
||||||
return self.appendxml(item)
|
return self.appendxml(item)
|
||||||
else:
|
else:
|
||||||
raise TypeError
|
raise TypeError(f"Cannot append {item!r} to a stanza")
|
||||||
self.xml.append(item.xml)
|
self.xml.append(item.xml)
|
||||||
if item.__class__ == self.plugin_tag_map.get(item.tag_name(), None):
|
if item.__class__ == self.plugin_tag_map.get(item.tag_name(), None):
|
||||||
self.init_plugin(item.plugin_attrib,
|
self.init_plugin(item.plugin_attrib,
|
||||||
|
@ -281,7 +281,8 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
__slow_tasks: List[Task]
|
__slow_tasks: List[Task]
|
||||||
__queued_stanzas: List[Tuple[Union[StanzaBase, str], bool]]
|
__queued_stanzas: List[Tuple[Union[StanzaBase, str], bool]]
|
||||||
|
|
||||||
def __init__(self, host: str = '', port: int = 0):
|
def __init__(self, host: str = '', port: int = 0,
|
||||||
|
ssl_context: Optional[ssl.SSLContext] = None):
|
||||||
self.transport = None
|
self.transport = None
|
||||||
self.socket = None
|
self.socket = None
|
||||||
self._connect_loop_wait = 0
|
self._connect_loop_wait = 0
|
||||||
@ -290,17 +291,20 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
self.xml_depth = 0
|
self.xml_depth = 0
|
||||||
self.xml_root = None
|
self.xml_root = None
|
||||||
|
|
||||||
self.force_starttls = None
|
self.force_starttls = True
|
||||||
self.disable_starttls = None
|
self.disable_starttls = False
|
||||||
|
|
||||||
self.waiting_queue = asyncio.Queue()
|
self.waiting_queue = asyncio.Queue()
|
||||||
|
|
||||||
# A dict of {name: handle}
|
# A dict of {name: handle}
|
||||||
self.scheduled_events = {}
|
self.scheduled_events = {}
|
||||||
|
|
||||||
self.ssl_context = ssl.create_default_context()
|
if ssl_context is None:
|
||||||
self.ssl_context.check_hostname = True
|
self.ssl_context = ssl.create_default_context()
|
||||||
self.ssl_context.verify_mode = ssl.CERT_REQUIRED
|
self.ssl_context.check_hostname = True
|
||||||
|
self.ssl_context.verify_mode = ssl.CERT_REQUIRED
|
||||||
|
else:
|
||||||
|
self.ssl_context = ssl_context
|
||||||
|
|
||||||
self.event_when_connected = "connected"
|
self.event_when_connected = "connected"
|
||||||
|
|
||||||
@ -371,7 +375,23 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
@property
|
@property
|
||||||
def loop(self) -> AbstractEventLoop:
|
def loop(self) -> AbstractEventLoop:
|
||||||
if self._loop is None:
|
if self._loop is None:
|
||||||
self._loop = asyncio.get_event_loop()
|
try:
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.simplefilter("ignore")
|
||||||
|
self._loop = asyncio.get_event_loop()
|
||||||
|
# We do not know what exception will be raised in the future
|
||||||
|
# instead of the warning
|
||||||
|
except Exception:
|
||||||
|
try:
|
||||||
|
current = asyncio.get_running_loop()
|
||||||
|
except RuntimeError:
|
||||||
|
current = None
|
||||||
|
if current is not None:
|
||||||
|
self._loop = current
|
||||||
|
else:
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
|
asyncio.set_event_loop(loop)
|
||||||
|
self._loop = loop
|
||||||
return self._loop
|
return self._loop
|
||||||
|
|
||||||
@loop.setter
|
@loop.setter
|
||||||
@ -405,8 +425,10 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
self.disconnected.set_result(True)
|
self.disconnected.set_result(True)
|
||||||
self.disconnected = asyncio.Future()
|
self.disconnected = asyncio.Future()
|
||||||
|
|
||||||
def connect(self, host: str = '', port: int = 0, use_ssl: Optional[bool] = False,
|
def connect(self, host: str = '', port: int = 0,
|
||||||
force_starttls: Optional[bool] = True, disable_starttls: Optional[bool] = False) -> None:
|
use_ssl: Optional[bool] = None,
|
||||||
|
force_starttls: Optional[bool] = None,
|
||||||
|
disable_starttls: Optional[bool] = None) -> asyncio.Future:
|
||||||
"""Create a new socket and connect to the server.
|
"""Create a new socket and connect to the server.
|
||||||
|
|
||||||
:param host: The name of the desired server for the connection.
|
:param host: The name of the desired server for the connection.
|
||||||
@ -425,6 +447,7 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
upgrade to TLS, even if the server provides
|
upgrade to TLS, even if the server provides
|
||||||
it. Use this for example if you’re on
|
it. Use this for example if you’re on
|
||||||
localhost
|
localhost
|
||||||
|
:returns: A future on the current connection attempt
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self._run_out_filters is None or self._run_out_filters.done():
|
if self._run_out_filters is None or self._run_out_filters.done():
|
||||||
@ -456,8 +479,14 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
self._connect_routine(),
|
self._connect_routine(),
|
||||||
loop=self.loop,
|
loop=self.loop,
|
||||||
)
|
)
|
||||||
|
return self._current_connection_attempt
|
||||||
|
|
||||||
async def _connect_routine(self) -> None:
|
async def _connect_routine(self) -> Optional[asyncio.Future]:
|
||||||
|
"""
|
||||||
|
Returns None if the attempt was canceled or if the connection succeeded
|
||||||
|
(cancelling done manually by the library user, so that should be known)
|
||||||
|
or the next connection attempt future if a new try has been scheduled.
|
||||||
|
"""
|
||||||
self.event_when_connected = "connected"
|
self.event_when_connected = "connected"
|
||||||
|
|
||||||
if self._connect_loop_wait > 0:
|
if self._connect_loop_wait > 0:
|
||||||
@ -482,7 +511,7 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
ssl_context = None
|
ssl_context = None
|
||||||
|
|
||||||
if self._current_connection_attempt is None:
|
if self._current_connection_attempt is None:
|
||||||
return
|
return None
|
||||||
try:
|
try:
|
||||||
server_hostname = self.default_domain if self.use_ssl else None
|
server_hostname = self.default_domain if self.use_ssl else None
|
||||||
await self.loop.create_connection(lambda: self,
|
await self.loop.create_connection(lambda: self,
|
||||||
@ -494,11 +523,12 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
except Socket.gaierror as e:
|
except Socket.gaierror as e:
|
||||||
self.event('connection_failed',
|
self.event('connection_failed',
|
||||||
'No DNS record available for %s' % self.default_domain)
|
'No DNS record available for %s' % self.default_domain)
|
||||||
self.reschedule_connection_attempt()
|
return self.reschedule_connection_attempt()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.debug('Connection failed: %s', e)
|
log.debug('Connection failed: %s', e)
|
||||||
self.event("connection_failed", e)
|
self.event("connection_failed", e)
|
||||||
self.reschedule_connection_attempt()
|
return self.reschedule_connection_attempt()
|
||||||
|
return None
|
||||||
|
|
||||||
def process(self, *, forever: bool = True, timeout: Optional[int] = None) -> None:
|
def process(self, *, forever: bool = True, timeout: Optional[int] = None) -> None:
|
||||||
"""Process all the available XMPP events (receiving or sending data on the
|
"""Process all the available XMPP events (receiving or sending data on the
|
||||||
@ -523,7 +553,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.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))
|
||||||
@ -634,19 +664,22 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
self._set_disconnected_future()
|
self._set_disconnected_future()
|
||||||
self.event("disconnected", self.disconnect_reason or exception)
|
self.event("disconnected", self.disconnect_reason or exception)
|
||||||
|
|
||||||
def reschedule_connection_attempt(self) -> None:
|
def reschedule_connection_attempt(self) -> Optional[asyncio.Future]:
|
||||||
"""
|
"""
|
||||||
Increase the exponential back-off and initate another background
|
Increase the exponential back-off and initate another background
|
||||||
_connect_routine call to connect to the server.
|
_connect_routine call to connect to the server.
|
||||||
|
|
||||||
|
:returns: A future on the next scheduled connection attempt.
|
||||||
"""
|
"""
|
||||||
# abort if there is no ongoing connection attempt
|
# abort if there is no ongoing connection attempt
|
||||||
if self._current_connection_attempt is None:
|
if self._current_connection_attempt is None:
|
||||||
return
|
return None
|
||||||
self._connect_loop_wait = min(300, self._connect_loop_wait * 2 + 1)
|
self._connect_loop_wait = min(300, self._connect_loop_wait * 2 + 1)
|
||||||
self._current_connection_attempt = asyncio.ensure_future(
|
self._current_connection_attempt = asyncio.ensure_future(
|
||||||
self._connect_routine(),
|
self._connect_routine(),
|
||||||
loop=self.loop,
|
loop=self.loop,
|
||||||
)
|
)
|
||||||
|
return self._current_connection_attempt
|
||||||
|
|
||||||
def cancel_connection_attempt(self) -> None:
|
def cancel_connection_attempt(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -849,6 +882,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)
|
||||||
@ -1347,6 +1382,7 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
if isinstance(data, (RootStanza, str)) and not passthrough:
|
if isinstance(data, (RootStanza, str)) and not passthrough:
|
||||||
self.__queued_stanzas.append((data, use_filters))
|
self.__queued_stanzas.append((data, use_filters))
|
||||||
log.debug('NOT SENT: %s %s', type(data), data)
|
log.debug('NOT SENT: %s %s', type(data), data)
|
||||||
|
self.event('stanza_not_sent', data)
|
||||||
return
|
return
|
||||||
self.waiting_queue.put_nowait((data, use_filters))
|
self.waiting_queue.put_nowait((data, use_filters))
|
||||||
|
|
||||||
@ -1410,7 +1446,11 @@ class XMLStream(asyncio.BaseProtocol):
|
|||||||
|
|
||||||
# Convert the raw XML object into a stanza object. If no registered
|
# Convert the raw XML object into a stanza object. If no registered
|
||||||
# stanza type applies, a generic StanzaBase stanza will be used.
|
# stanza type applies, a generic StanzaBase stanza will be used.
|
||||||
stanza: Optional[StanzaBase] = self._build_stanza(xml)
|
try:
|
||||||
|
stanza: Optional[StanzaBase] = self._build_stanza(xml)
|
||||||
|
except Exception as exc:
|
||||||
|
log.exception("Unable to parse stanza: %s,\n%s", exc, xml)
|
||||||
|
stanza = None
|
||||||
for filter in self.__filters['in']:
|
for filter in self.__filters['in']:
|
||||||
if stanza is not None:
|
if stanza is not None:
|
||||||
filter = cast(SyncFilter, filter)
|
filter = cast(SyncFilter, filter)
|
||||||
|
@ -95,6 +95,21 @@ class TestDataForms(SlixTest):
|
|||||||
</message>
|
</message>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
def testMultiLineField(self):
|
||||||
|
msg = self.Message()
|
||||||
|
form = msg['form']
|
||||||
|
form.addField(var='f1',
|
||||||
|
value='Some text\non several\n\nlines')
|
||||||
|
self.check(msg, """
|
||||||
|
<message>
|
||||||
|
<x xmlns="jabber:x:data" type="form">
|
||||||
|
<field var="f1">
|
||||||
|
<value>Some text\non several\n\nlines</value>
|
||||||
|
</field>
|
||||||
|
</x>
|
||||||
|
</message>
|
||||||
|
""")
|
||||||
|
|
||||||
def testSetValues(self):
|
def testSetValues(self):
|
||||||
"""Testing setting form values"""
|
"""Testing setting form values"""
|
||||||
|
|
||||||
@ -117,7 +132,7 @@ class TestDataForms(SlixTest):
|
|||||||
<value>b</value>
|
<value>b</value>
|
||||||
</field>
|
</field>
|
||||||
</x>
|
</x>
|
||||||
</message>""")
|
</message>""", use_values=False)
|
||||||
|
|
||||||
def testSubmitType(self):
|
def testSubmitType(self):
|
||||||
"""Test that setting type to 'submit' clears extra details"""
|
"""Test that setting type to 'submit' clears extra details"""
|
||||||
|
@ -34,6 +34,7 @@ class TestJabberSearch(SlixTest):
|
|||||||
ifrom="juliet@capulet.com/balcony", ito="characters.shakespeare.lit"
|
ifrom="juliet@capulet.com/balcony", ito="characters.shakespeare.lit"
|
||||||
)
|
)
|
||||||
iq["search"]["form"].add_field(var="x-gender", value="male")
|
iq["search"]["form"].add_field(var="x-gender", value="male")
|
||||||
|
iq["id"] = "0"
|
||||||
self.check(
|
self.check(
|
||||||
iq,
|
iq,
|
||||||
"""
|
"""
|
||||||
|
26
tests/test_stanza_xep_0308.py
Normal file
26
tests/test_stanza_xep_0308.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import unittest
|
||||||
|
from slixmpp import Message
|
||||||
|
from slixmpp.test import SlixTest
|
||||||
|
from slixmpp.plugins.xep_0308 import Replace
|
||||||
|
from slixmpp.xmlstream import register_stanza_plugin
|
||||||
|
|
||||||
|
|
||||||
|
class TestCorrectStanza(SlixTest):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
register_stanza_plugin(Message, Replace)
|
||||||
|
|
||||||
|
def testBuild(self):
|
||||||
|
"""Test that the element is created correctly."""
|
||||||
|
msg = Message()
|
||||||
|
msg['type'] = 'chat'
|
||||||
|
msg['replace']['id'] = 'toto123'
|
||||||
|
|
||||||
|
self.check(msg, """
|
||||||
|
<message type="chat">
|
||||||
|
<replace xmlns="urn:xmpp:message-correct:0" id="toto123"/>
|
||||||
|
</message>
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestCorrectStanza)
|
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)
|
@ -2,38 +2,33 @@ import unittest
|
|||||||
from slixmpp import Message
|
from slixmpp import Message
|
||||||
from slixmpp.test import SlixTest
|
from slixmpp.test import SlixTest
|
||||||
from slixmpp.plugins.xep_0424 import stanza
|
from slixmpp.plugins.xep_0424 import stanza
|
||||||
from slixmpp.plugins.xep_0422 import stanza as astanza
|
|
||||||
|
|
||||||
|
|
||||||
class TestRetraction(SlixTest):
|
class TestRetraction(SlixTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
astanza.register_plugins()
|
|
||||||
stanza.register_plugins()
|
stanza.register_plugins()
|
||||||
|
|
||||||
def testRetract(self):
|
def testRetract(self):
|
||||||
message = Message()
|
message = Message()
|
||||||
message['apply_to']['id'] = 'some-id'
|
message['retract']['id'] = 'some-id'
|
||||||
message['apply_to']['retract']
|
|
||||||
|
|
||||||
self.check(message, """
|
self.check(message, """
|
||||||
<message>
|
<message>
|
||||||
<apply-to xmlns="urn:xmpp:fasten:0" id="some-id">
|
<retract xmlns="urn:xmpp:message-retract:1" id="some-id"/>
|
||||||
<retract xmlns="urn:xmpp:message-retract:0"/>
|
|
||||||
</apply-to>
|
|
||||||
</message>
|
</message>
|
||||||
""", use_values=False)
|
""", use_values=False)
|
||||||
|
|
||||||
def testRetracted(self):
|
def testRetracted(self):
|
||||||
message = Message()
|
message = Message()
|
||||||
message['retracted']['stamp'] = '2019-09-20T23:09:32Z'
|
message['retracted']['stamp'] = '2019-09-20T23:09:32Z'
|
||||||
message['retracted']['origin_id']['id'] = 'originid'
|
message['retracted']['id'] = 'originid'
|
||||||
|
|
||||||
self.check(message, """
|
self.check(message, """
|
||||||
<message>
|
<message>
|
||||||
<retracted stamp="2019-09-20T23:09:32Z" xmlns="urn:xmpp:message-retract:0">
|
<retracted stamp="2019-09-20T23:09:32Z"
|
||||||
<origin-id xmlns="urn:xmpp:sid:0" id="originid"/>
|
xmlns="urn:xmpp:message-retract:1"
|
||||||
</retracted>
|
id="originid" />
|
||||||
</message>
|
</message>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
@ -1,45 +1,48 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from slixmpp import Message, Iq, JID
|
from slixmpp import Message, Iq, JID
|
||||||
from slixmpp.test import SlixTest
|
from slixmpp.test import SlixTest
|
||||||
|
from slixmpp.plugins.xep_0424 import stanza as stanza424
|
||||||
from slixmpp.plugins.xep_0425 import stanza
|
from slixmpp.plugins.xep_0425 import stanza
|
||||||
|
|
||||||
|
|
||||||
class TestModeration(SlixTest):
|
class TestModeration(SlixTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
stanza424.register_plugins()
|
||||||
stanza.register_plugins()
|
stanza.register_plugins()
|
||||||
|
|
||||||
def testModerate(self):
|
def testModerate(self):
|
||||||
iq = Iq()
|
iq = Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['id'] = 'a'
|
iq['id'] = 'a'
|
||||||
iq['apply_to']['id'] = 'some-id'
|
iq['moderate']['id'] = 'some-id'
|
||||||
iq['apply_to']['moderate'].enable('retract')
|
iq['moderate'].enable('retract')
|
||||||
iq['apply_to']['moderate']['reason'] = 'R'
|
iq['moderate']['reason'] = 'R'
|
||||||
|
|
||||||
self.check(iq, """
|
self.check(iq, """
|
||||||
<iq type='set' id='a'>
|
<iq type='set' id='a'>
|
||||||
<apply-to id="some-id" xmlns="urn:xmpp:fasten:0">
|
<moderate xmlns='urn:xmpp:message-moderate:1' id='some-id'>
|
||||||
<moderate xmlns='urn:xmpp:message-moderate:0'>
|
<retract xmlns='urn:xmpp:message-retract:1'/>
|
||||||
<retract xmlns='urn:xmpp:message-retract:0'/>
|
<reason>R</reason>
|
||||||
<reason>R</reason>
|
</moderate>
|
||||||
</moderate>
|
|
||||||
</apply-to>
|
|
||||||
</iq>
|
</iq>
|
||||||
""", use_values=False)
|
""")
|
||||||
|
|
||||||
def testModerated(self):
|
def testModerated(self):
|
||||||
message = Message()
|
message = Message()
|
||||||
message['moderated']['by'] = JID('toto@titi')
|
message['retract']['id'] = 'some-id'
|
||||||
message['moderated']['retracted']['stamp'] = '2019-09-20T23:09:32Z'
|
message['retract']['moderated']['by'] = JID('toto@titi')
|
||||||
message['moderated']['reason'] = 'R'
|
message['retract']['moderated']['occupant-id']['id'] = 'oc-id'
|
||||||
|
message['retract']['reason'] = 'R'
|
||||||
|
|
||||||
self.check(message, """
|
self.check(message, """
|
||||||
<message>
|
<message>
|
||||||
<moderated xmlns="urn:xmpp:message-moderate:0" by="toto@titi">
|
<retract id='some-id' xmlns='urn:xmpp:message-retract:1'>
|
||||||
<retracted stamp="2019-09-20T23:09:32Z" xmlns="urn:xmpp:message-retract:0" />
|
<moderated by='toto@titi' xmlns='urn:xmpp:message-moderate:1'>
|
||||||
|
<occupant-id xmlns="urn:xmpp:occupant-id:0" id="oc-id" />
|
||||||
|
</moderated>
|
||||||
<reason>R</reason>
|
<reason>R</reason>
|
||||||
</moderated>
|
</retract>
|
||||||
</message>
|
</message>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
101
tests/test_stanza_xep_0446.py
Normal file
101
tests/test_stanza_xep_0446.py
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from slixmpp.test import SlixTest
|
||||||
|
from slixmpp.plugins.xep_0446 import stanza
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileMeta(SlixTest):
|
||||||
|
def setUp(self):
|
||||||
|
stanza.register_plugins()
|
||||||
|
|
||||||
|
def test_simple(self):
|
||||||
|
file = stanza.File()
|
||||||
|
file["desc"] = "a description"
|
||||||
|
file["name"] = "toto.jpg"
|
||||||
|
file["media-type"] = "image/jpeg"
|
||||||
|
file["height"] = 1024
|
||||||
|
file["width"] = 768
|
||||||
|
file["size"] = 2048
|
||||||
|
self.check(
|
||||||
|
file,
|
||||||
|
"""
|
||||||
|
<file xmlns='urn:xmpp:file:metadata:0'>
|
||||||
|
<desc>a description</desc>
|
||||||
|
<name>toto.jpg</name>
|
||||||
|
<media-type>image/jpeg</media-type>
|
||||||
|
<height>1024</height>
|
||||||
|
<width>768</width>
|
||||||
|
<size>2048</size>
|
||||||
|
</file>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_bad_value(self):
|
||||||
|
file = stanza.File()
|
||||||
|
file["desc"] = "My great video"
|
||||||
|
file["name"] = "toto.mp4"
|
||||||
|
file["media-type"] = "video/3gpp"
|
||||||
|
file["height"] = 1024
|
||||||
|
file["width"] = 768
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
file["length"] = -100
|
||||||
|
|
||||||
|
def test_hash_element(self):
|
||||||
|
file = stanza.File()
|
||||||
|
file["desc"] = "My great video"
|
||||||
|
file["name"] = "toto.3gp"
|
||||||
|
file["media-type"] = "video/3gpp"
|
||||||
|
file["height"] = 1024
|
||||||
|
file["width"] = 768
|
||||||
|
file["length"] = 2000
|
||||||
|
file["hash"]["algo"] = "sha3-256"
|
||||||
|
file["hash"]["value"] = "abcdef="
|
||||||
|
self.check(
|
||||||
|
file,
|
||||||
|
"""
|
||||||
|
<file xmlns='urn:xmpp:file:metadata:0'>
|
||||||
|
<desc>My great video</desc>
|
||||||
|
<name>toto.3gp</name>
|
||||||
|
<media-type>video/3gpp</media-type>
|
||||||
|
<height>1024</height>
|
||||||
|
<width>768</width>
|
||||||
|
<length>2000</length>
|
||||||
|
<hash xmlns='urn:xmpp:hashes:2' algo="sha3-256">abcdef=</hash>
|
||||||
|
</file>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_thumbnail_element(self):
|
||||||
|
file = stanza.File()
|
||||||
|
file["desc"] = "a description"
|
||||||
|
file["name"] = "toto.jpg"
|
||||||
|
file["media-type"] = "image/jpeg"
|
||||||
|
file["height"] = 1024
|
||||||
|
file["width"] = 768
|
||||||
|
file["size"] = 2048
|
||||||
|
file["thumbnail"]["media-type"] = "image/png"
|
||||||
|
file["thumbnail"]["uri"] = "cid:sha1+deadbeef@bob.xmpp.org"
|
||||||
|
file["thumbnail"]["width"] = 128
|
||||||
|
file["thumbnail"]["height"] = 96
|
||||||
|
self.check(
|
||||||
|
file,
|
||||||
|
"""
|
||||||
|
<file xmlns='urn:xmpp:file:metadata:0'>
|
||||||
|
<desc>a description</desc>
|
||||||
|
<name>toto.jpg</name>
|
||||||
|
<media-type>image/jpeg</media-type>
|
||||||
|
<height>1024</height>
|
||||||
|
<width>768</width>
|
||||||
|
<size>2048</size>
|
||||||
|
<thumbnail xmlns='urn:xmpp:thumbs:1'
|
||||||
|
uri='cid:sha1+deadbeef@bob.xmpp.org'
|
||||||
|
media-type='image/png'
|
||||||
|
width='128'
|
||||||
|
height='96'/>
|
||||||
|
</file>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestFileMeta)
|
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)
|
42
tests/test_stanza_xep_0482.py
Normal file
42
tests/test_stanza_xep_0482.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import unittest
|
||||||
|
from slixmpp import Message
|
||||||
|
from slixmpp.jid import JID
|
||||||
|
from slixmpp.test import SlixTest
|
||||||
|
from slixmpp.plugins.xep_0482 import stanza
|
||||||
|
from slixmpp.plugins.xep_0482.stanza import External, Jingle
|
||||||
|
from slixmpp.xmlstream import register_stanza_plugin
|
||||||
|
|
||||||
|
|
||||||
|
class TestCallInviteStanza(SlixTest):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
stanza.register_plugins()
|
||||||
|
|
||||||
|
def test_invite(self):
|
||||||
|
"""Test that the element is created correctly."""
|
||||||
|
msg = Message()
|
||||||
|
msg['call-invite']['video'] = True
|
||||||
|
jingle = Jingle()
|
||||||
|
jingle['sid'] = 'toto'
|
||||||
|
jingle['jid'] = JID('toto@example.com/m')
|
||||||
|
external = External()
|
||||||
|
external['uri'] = "https://example.com/call"
|
||||||
|
msg['call-invite'].append(jingle)
|
||||||
|
msg['call-invite'].append(external)
|
||||||
|
|
||||||
|
self.check(msg, """
|
||||||
|
<message>
|
||||||
|
<invite xmlns="urn:xmpp:call-invites:0" video="true">
|
||||||
|
<jingle sid="toto" jid="toto@example.com/m" />
|
||||||
|
<external uri="https://example.com/call" />
|
||||||
|
</invite>
|
||||||
|
</message>
|
||||||
|
""")
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
msg['call-invite'].get_methods(),
|
||||||
|
([jingle], [external]),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestCallInviteStanza)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user