Compare commits
251 Commits
slix-1.8.0
...
master
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 | ||
![]() |
76a11d4899 | ||
![]() |
dcfa0f20f9 | ||
![]() |
7732af8991 | ||
![]() |
25c28ff5d1 | ||
![]() |
e3e0d8f43e | ||
![]() |
13729e47a6 | ||
![]() |
f12860bfad | ||
![]() |
bcbc7281e7 | ||
![]() |
8787aa1064 | ||
![]() |
f3522eb84b | ||
![]() |
da9646cdaa | ||
![]() |
db1fc5fbc5 | ||
![]() |
209554e63f | ||
![]() |
2d02ef9bcb | ||
![]() |
18c3db4d6e | ||
![]() |
6d6fdc6419 | ||
![]() |
4936fb06bf | ||
![]() |
5e47286445 | ||
![]() |
8bead23799 | ||
![]() |
56c906f207 | ||
![]() |
876c82037f | ||
![]() |
fae4a38e84 | ||
![]() |
2b59d299a1 | ||
![]() |
51a4efb0f4 | ||
![]() |
8f77bd4ee5 | ||
![]() |
71128349a4 | ||
![]() |
bc2cebae6c | ||
![]() |
2080d08d63 | ||
![]() |
e16f72d32d | ||
![]() |
4fa068da54 | ||
![]() |
21e5cd4435 | ||
![]() |
1a40699bcc | ||
![]() |
ebb8bd1e71 | ||
![]() |
78b42bdbbe | ||
![]() |
abd3f40e96 | ||
![]() |
b6f148e4e6 | ||
![]() |
968fb0bac3 | ||
![]() |
8dcbcbf8a0 | ||
![]() |
de7b2d33a3 | ||
![]() |
fd1af054c5 | ||
![]() |
e34fbfb28f | ||
![]() |
af16832ad0 | ||
![]() |
40a857de65 | ||
![]() |
79ffa1668f | ||
![]() |
b4b1efe058 | ||
![]() |
de358464d0 | ||
![]() |
92b4f2a7eb | ||
![]() |
1f934d375c | ||
![]() |
700ce6b32e | ||
![]() |
5efa9804ba | ||
![]() |
9b0be1ca2b | ||
![]() |
5c19f16287 | ||
![]() |
af07864cbb | ||
![]() |
dc4b1c7367 | ||
![]() |
4a6064772c | ||
![]() |
80a89061f1 | ||
![]() |
8f4d8f76d1 | ||
![]() |
656248ede7 | ||
![]() |
980afe791f | ||
![]() |
3725177d0b | ||
![]() |
26fb0d1f91 | ||
![]() |
5eb17e7633 | ||
![]() |
fdca7d82c4 | ||
![]() |
9b89401b36 | ||
![]() |
7300f1285e | ||
![]() |
9b51be1e17 | ||
![]() |
89b1e1e682 | ||
![]() |
a7501abe56 | ||
![]() |
6940e4276b | ||
![]() |
752f4258df | ||
![]() |
b60b1b985d | ||
![]() |
e93e43df66 | ||
![]() |
cfd1af88eb | ||
![]() |
65636b8cce | ||
![]() |
7a0fb97083 | ||
![]() |
189bbcce19 | ||
![]() |
79607e43f1 | ||
![]() |
e062181f84 | ||
![]() |
97b0c7ffac | ||
![]() |
c2ece57dee | ||
![]() |
afdfa1ee57 | ||
![]() |
cba5dc7ddc | ||
![]() |
b3a6c7a4ea | ||
![]() |
11e27d1d7d | ||
![]() |
fbdff30dda | ||
![]() |
62701bc562 | ||
![]() |
b14918808c | ||
![]() |
f5cb9fe66b | ||
![]() |
8bd53f7098 | ||
![]() |
c955cf1c66 | ||
![]() |
6904ae63f5 | ||
![]() |
1caada197a | ||
![]() |
450aaa7f86 | ||
![]() |
d43c83800e | ||
![]() |
14786abd34 | ||
![]() |
1f47acaec1 | ||
![]() |
ed820bf551 | ||
![]() |
afedfa4b06 | ||
![]() |
5998069203 | ||
![]() |
356f16f5af | ||
![]() |
b8f301b26f | ||
![]() |
ffaeb31219 | ||
![]() |
9560f39de7 | ||
![]() |
f7a38a028a | ||
![]() |
65d70fe417 | ||
![]() |
108a256537 | ||
![]() |
78a5f79240 | ||
![]() |
fc63768cfc | ||
![]() |
90e79af18a | ||
![]() |
5e5a741994 | ||
![]() |
b44ab17c8f | ||
![]() |
afb5419b68 | ||
![]() |
a1a5f3984d | ||
![]() |
8eb8769862 | ||
![]() |
5ceb48bbcd | ||
![]() |
916894ab7c | ||
![]() |
2b45c22fcb | ||
![]() |
566e7dc771 | ||
![]() |
aa492f905c | ||
![]() |
e1a240ec6c | ||
![]() |
771839242c | ||
![]() |
8bac744009 | ||
![]() |
88d2f5dae4 | ||
![]() |
f7902d056e | ||
![]() |
41afbb10df | ||
![]() |
aca4addb9c | ||
![]() |
914ce40fd5 | ||
![]() |
82ff68cfac | ||
![]() |
28d44ecf74 | ||
![]() |
fcec6742cf | ||
![]() |
fedbb248ec | ||
![]() |
e8679fe32b | ||
![]() |
06e4e480c1 | ||
![]() |
82ee250295 | ||
![]() |
53d38a8115 | ||
![]() |
41d733e77f | ||
![]() |
0fba8fd7f8 | ||
![]() |
b899baabd8 | ||
![]() |
acad41f3b7 | ||
![]() |
bde5aaaf3e | ||
![]() |
7222ade0dd | ||
![]() |
14a6c7801d | ||
![]() |
b52540e49f | ||
![]() |
c1aeab328b | ||
![]() |
51644e301b | ||
![]() |
bc8af3cc61 | ||
![]() |
3c08f471cf | ||
![]() |
54b724c28b | ||
![]() |
abd699593f | ||
![]() |
4202ed4cd5 | ||
![]() |
60df4ef7aa | ||
![]() |
ad610c7ded |
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,70 +0,0 @@
|
|||||||
stages:
|
|
||||||
- lint
|
|
||||||
- test
|
|
||||||
- trigger
|
|
||||||
|
|
||||||
mypy:
|
|
||||||
stage: lint
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3
|
|
||||||
script:
|
|
||||||
- pip3 install mypy
|
|
||||||
- mypy slixmpp
|
|
||||||
|
|
||||||
test:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: ubuntu:latest
|
|
||||||
script:
|
|
||||||
- apt update
|
|
||||||
- apt install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp
|
|
||||||
- ./run_tests.py
|
|
||||||
|
|
||||||
test-3.10:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3.10
|
|
||||||
script:
|
|
||||||
- apt update
|
|
||||||
- apt install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp
|
|
||||||
- ./run_tests.py
|
|
||||||
|
|
||||||
test-3.11:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: python:3.11-rc
|
|
||||||
allow_failure: true
|
|
||||||
script:
|
|
||||||
- apt update
|
|
||||||
- apt install -y python3 python3-pip cython3 gpg
|
|
||||||
- pip3 install emoji aiohttp
|
|
||||||
- ./run_tests.py
|
|
||||||
|
|
||||||
test_integration:
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
image: ubuntu:latest
|
|
||||||
only:
|
|
||||||
variables:
|
|
||||||
- $CI_ACCOUNT1
|
|
||||||
- $CI_ACCOUNT2
|
|
||||||
script:
|
|
||||||
- apt update
|
|
||||||
- apt 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
|
|
22
.readthedocs.yaml
Normal file
22
.readthedocs.yaml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# .readthedocs.yaml
|
||||||
|
# Read the Docs configuration file
|
||||||
|
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||||
|
|
||||||
|
# Required
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
# Set the version of Python and other tools you might need
|
||||||
|
build:
|
||||||
|
os: ubuntu-22.04
|
||||||
|
tools:
|
||||||
|
python: "3.11"
|
||||||
|
|
||||||
|
# Build documentation in the docs/ directory with Sphinx
|
||||||
|
sphinx:
|
||||||
|
configuration: docs/conf.py
|
||||||
|
|
||||||
|
# We recommend specifying your dependencies to enable reproducible builds:
|
||||||
|
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
|
||||||
|
python:
|
||||||
|
install:
|
||||||
|
- requirements: docs/requirements.txt
|
@ -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"
|
@ -5,7 +5,7 @@ To contribute, the preferred way is to commit your changes on some
|
|||||||
publicly-available git repository (on a fork `on github
|
publicly-available git repository (on a fork `on github
|
||||||
<https://github.com/poezio/slixmpp>`_ or on your own repository) and to
|
<https://github.com/poezio/slixmpp>`_ or on your own repository) and to
|
||||||
notify the developers with either:
|
notify the developers with either:
|
||||||
- a ticket `on the bug tracker <https://lab.louiz.org/poezio/slixmpp/issues/new>`_
|
- a ticket `on the bug tracker <https://codeberg.org/poezio/slixmpp/issues/new>`_
|
||||||
- a pull request on github
|
- a pull request on github
|
||||||
- a simple message on `the XMPP MUC <xmpp:slixmpp@muc.poez.io>`_
|
- a simple message on `the XMPP MUC <xmpp:slixmpp@muc.poez.io>`_
|
||||||
|
|
||||||
|
141
doap.xml
141
doap.xml
@ -8,13 +8,13 @@
|
|||||||
<shortdesc xml:lang="en">Elegant Python library for XMPP</shortdesc>
|
<shortdesc xml:lang="en">Elegant Python library for XMPP</shortdesc>
|
||||||
<shortdesc xml:lang="fr">Bibliothèque pour XMPP élégante, en Python</shortdesc>
|
<shortdesc xml:lang="fr">Bibliothèque pour XMPP élégante, en Python</shortdesc>
|
||||||
|
|
||||||
<homepage rdf:resource="https://lab.louiz.org/poezio/slixmpp/"/>
|
<homepage rdf:resource="https://codeberg.org/poezio/slixmpp/"/>
|
||||||
<download-page rdf:resource="https://lab.louiz.org/poezio/slixmpp/tags"/>
|
<download-page rdf:resource="https://codeberg.org/poezio/slixmpp/tags"/>
|
||||||
<bug-database rdf:resource="https://lab.louiz.org/poezio/slixmpp/issues"/>
|
<bug-database rdf:resource="https://codeberg.org/poezio/slixmpp/issues"/>
|
||||||
<developer-forum rdf:resource="xmpp:slixmpp@muc.poez.io?join"/>
|
<developer-forum rdf:resource="xmpp:slixmpp@muc.poez.io?join"/>
|
||||||
<support-forum rdf:resource="xmpp:slixmpp@muc.poez.io?join"/>
|
<support-forum rdf:resource="xmpp:slixmpp@muc.poez.io?join"/>
|
||||||
|
|
||||||
<license rdf:resource="https://lab.louiz.org/poezio/slixmpp/blob/master/LICENSE"/>
|
<license rdf:resource="https://codeberg.org/poezio/slixmpp/raw/brach/master/LICENSE"/>
|
||||||
|
|
||||||
<language>en</language>
|
<language>en</language>
|
||||||
|
|
||||||
@ -59,8 +59,8 @@
|
|||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<GitRepository>
|
<GitRepository>
|
||||||
<browse rdf:resource="https://lab.louiz.org/poezio/slixmpp"/>
|
<browse rdf:resource="https://codeberg.org/poezio/slixmpp"/>
|
||||||
<location rdf:resource="https://lab.louiz.org/poezio/slixmpp.git"/>
|
<location rdf:resource="https://codeberg.org/poezio/slixmpp.git"/>
|
||||||
</GitRepository>
|
</GitRepository>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
@ -455,6 +455,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-0175.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>1.2</xmpp:version>
|
||||||
|
<xmpp:since>1.0</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
<implements>
|
<implements>
|
||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0184.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0184.html"/>
|
||||||
@ -608,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"/>
|
||||||
@ -674,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"/>
|
||||||
@ -776,7 +800,7 @@
|
|||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0377.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0377.html"/>
|
||||||
<xmpp:status>complete</xmpp:status>
|
<xmpp:status>complete</xmpp:status>
|
||||||
<xmpp:version>0.2</xmpp:version>
|
<xmpp:version>0.3</xmpp:version>
|
||||||
<xmpp:since>1.6.0</xmpp:since>
|
<xmpp:since>1.6.0</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
@ -848,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>
|
||||||
@ -856,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>
|
||||||
@ -892,6 +916,55 @@
|
|||||||
<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>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0454.html"/>
|
||||||
|
<xmpp:status>partial</xmpp:status>
|
||||||
|
<xmpp:version>0.1.0</xmpp:version>
|
||||||
|
<xmpp:since>1.8.1</xmpp:since>
|
||||||
|
<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>
|
||||||
|
</implements>
|
||||||
|
|
||||||
<release>
|
<release>
|
||||||
<Version>
|
<Version>
|
||||||
@ -995,28 +1068,70 @@
|
|||||||
<Version>
|
<Version>
|
||||||
<revision>1.6.0</revision>
|
<revision>1.6.0</revision>
|
||||||
<created>2020-12-12</created>
|
<created>2020-12-12</created>
|
||||||
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.6.0/slixmpp-slix-1.6.0.tar.gz"/>
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.6.0.tar.gz"/>
|
||||||
</Version>
|
</Version>
|
||||||
</release>
|
</release>
|
||||||
<release>
|
<release>
|
||||||
<Version>
|
<Version>
|
||||||
<revision>1.7.0</revision>
|
<revision>1.7.0</revision>
|
||||||
<created>2021-01-29</created>
|
<created>2021-01-29</created>
|
||||||
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.7.0/slixmpp-slix-1.7.0.tar.gz"/>
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.7.0.tar.gz"/>
|
||||||
</Version>
|
</Version>
|
||||||
</release>
|
</release>
|
||||||
<release>
|
<release>
|
||||||
<Version>
|
<Version>
|
||||||
<revision>1.7.1</revision>
|
<revision>1.7.1</revision>
|
||||||
<created>2021-04-30</created>
|
<created>2021-04-30</created>
|
||||||
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.7.1/slixmpp-slix-1.7.1.tar.gz"/>
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.7.1.tar.gz"/>
|
||||||
</Version>
|
</Version>
|
||||||
</release>
|
</release>
|
||||||
<release>
|
<release>
|
||||||
<Version>
|
<Version>
|
||||||
<revision>1.8.0</revision>
|
<revision>1.8.0</revision>
|
||||||
<created>2022-02-27</created>
|
<created>2022-02-27</created>
|
||||||
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.8.0/slixmpp-slix-1.8.0.tar.gz"/>
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.0.tar.gz"/>
|
||||||
|
</Version>
|
||||||
|
</release>
|
||||||
|
<release>
|
||||||
|
<Version>
|
||||||
|
<revision>1.8.1</revision>
|
||||||
|
<created>2022-03-20</created>
|
||||||
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.1.tar.gz"/>
|
||||||
|
</Version>
|
||||||
|
</release>
|
||||||
|
<release>
|
||||||
|
<Version>
|
||||||
|
<revision>1.8.2</revision>
|
||||||
|
<created>2022-04-06</created>
|
||||||
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.2.tar.gz"/>
|
||||||
|
</Version>
|
||||||
|
</release>
|
||||||
|
<release>
|
||||||
|
<Version>
|
||||||
|
<revision>1.8.3</revision>
|
||||||
|
<created>2022-11-12</created>
|
||||||
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.3.tar.gz"/>
|
||||||
|
</Version>
|
||||||
|
</release>
|
||||||
|
<release>
|
||||||
|
<Version>
|
||||||
|
<revision>1.8.4</revision>
|
||||||
|
<created>2023-05-28</created>
|
||||||
|
<file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.4.tar.gz"/>
|
||||||
|
</Version>
|
||||||
|
</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>
|
</Version>
|
||||||
</release>
|
</release>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -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
|
||||||
|
18
docs/api/plugins/xep_0055.rst
Normal file
18
docs/api/plugins/xep_0055.rst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
XEP-0055: Jabber search
|
||||||
|
=======================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0055
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0055
|
||||||
|
:members:
|
||||||
|
:exclude-members: session_bind, plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0055.stanza
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
@ -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:
|
||||||
|
|
17
docs/api/plugins/xep_0292.rst
Normal file
17
docs/api/plugins/xep_0292.rst
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
XEP-0292: vCard4 Over XMPP
|
||||||
|
==========================
|
||||||
|
|
||||||
|
.. module:: slixmpp.plugins.xep_0292
|
||||||
|
|
||||||
|
.. autoclass:: XEP_0292
|
||||||
|
:members:
|
||||||
|
:exclude-members: plugin_init, plugin_end
|
||||||
|
|
||||||
|
|
||||||
|
Stanza elements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: slixmpp.plugins.xep_0292.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`
|
||||||
|
@ -11,7 +11,7 @@ Create and Run a Server Component
|
|||||||
<xmpp:slixmpp@muc.poez.io?join>`_.
|
<xmpp:slixmpp@muc.poez.io?join>`_.
|
||||||
|
|
||||||
If you have not yet installed Slixmpp, do so now by either checking out a version
|
If you have not yet installed Slixmpp, do so now by either checking out a version
|
||||||
with `Git <https://lab.louiz.org/poezio/slixmpp>`_.
|
with `Git <https://codeberg.org/poezio/slixmpp>`_.
|
||||||
|
|
||||||
Many XMPP applications eventually graduate to requiring to run as a server
|
Many XMPP applications eventually graduate to requiring to run as a server
|
||||||
component in order to meet scalability requirements. To demonstrate how to
|
component in order to meet scalability requirements. To demonstrate how to
|
||||||
|
@ -11,7 +11,7 @@ Slixmpp Quickstart - Echo Bot
|
|||||||
<xmpp:slixmpp@muc.poez.io?join>`_.
|
<xmpp:slixmpp@muc.poez.io?join>`_.
|
||||||
|
|
||||||
If you have not yet installed Slixmpp, do so now by either checking out a version
|
If you have not yet installed Slixmpp, do so now by either checking out a version
|
||||||
with `Git <https://lab.louiz.org/poezio/slixmpp>`_.
|
with `Git <https://codeberg.org/poezio/slixmpp>`_.
|
||||||
|
|
||||||
As a basic starting project, we will create an echo bot which will reply to any
|
As a basic starting project, we will create an echo bot which will reply to any
|
||||||
messages sent to it. We will also go through adding some basic command line configuration
|
messages sent to it. We will also go through adding some basic command line configuration
|
||||||
@ -325,7 +325,7 @@ The Final Product
|
|||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Here then is what the final result should look like after working through the guide above. The code
|
Here then is what the final result should look like after working through the guide above. The code
|
||||||
can also be found in the Slixmpp `examples directory <https://lab.louiz.org/poezio/slixmpp/tree/master/examples>`_.
|
can also be found in the Slixmpp `examples directory <https://codeberg.org/poezio/slixmpp/src/branch/master/examples>`_.
|
||||||
|
|
||||||
.. compound::
|
.. compound::
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ Multi-User Chat (MUC) Bot
|
|||||||
<xmpp:slixmpp@muc.poez.io?join>`_.
|
<xmpp:slixmpp@muc.poez.io?join>`_.
|
||||||
|
|
||||||
If you have not yet installed Slixmpp, do so now by either checking out a version
|
If you have not yet installed Slixmpp, do so now by either checking out a version
|
||||||
from `Git <https://lab.louiz.org/poezio/slixmpp>`_.
|
from `Git <https://codeberg.org/poezio/slixmpp>`_.
|
||||||
|
|
||||||
Now that you've got the basic gist of using Slixmpp by following the
|
Now that you've got the basic gist of using Slixmpp by following the
|
||||||
echobot example (:ref:`echobot`), we can use one of the bundled plugins
|
echobot example (:ref:`echobot`), we can use one of the bundled plugins
|
||||||
|
@ -4,9 +4,9 @@ Slixmpp
|
|||||||
.. sidebar:: Get the Code
|
.. sidebar:: Get the Code
|
||||||
|
|
||||||
The latest source code for Slixmpp may be found on the `Git repo
|
The latest source code for Slixmpp may be found on the `Git repo
|
||||||
<https://lab.louiz.org/poezio/slixmpp>`_. ::
|
<https://codeberg.org/poezio/slixmpp>`_. ::
|
||||||
|
|
||||||
git clone https://lab.louiz.org/poezio/slixmpp
|
git clone https://codeberg.org/poezio/slixmpp
|
||||||
|
|
||||||
An XMPP chat room is available for discussing and getting help with slixmpp.
|
An XMPP chat room is available for discussing and getting help with slixmpp.
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ Slixmpp
|
|||||||
`slixmpp@muc.poez.io <xmpp:slixmpp@muc.poez.io?join>`_
|
`slixmpp@muc.poez.io <xmpp:slixmpp@muc.poez.io?join>`_
|
||||||
|
|
||||||
**Reporting bugs**
|
**Reporting bugs**
|
||||||
You can report bugs at http://lab.louiz.org/poezio/slixmpp/issues.
|
You can report bugs at http://codeberg.org/poezio/slixmpp/issues.
|
||||||
|
|
||||||
Slixmpp is an :ref:`MIT licensed <license>` XMPP library for Python 3.7+,
|
Slixmpp is an :ref:`MIT licensed <license>` XMPP library for Python 3.7+,
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,11 +5,16 @@
|
|||||||
# 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 typing import Optional
|
||||||
|
|
||||||
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
import slixmpp
|
import slixmpp
|
||||||
|
from slixmpp import JID
|
||||||
from slixmpp.exceptions import IqTimeout
|
from slixmpp.exceptions import IqTimeout
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -21,20 +26,40 @@ class HttpUpload(slixmpp.ClientXMPP):
|
|||||||
A basic client asking an entity if they confirm the access to an HTTP URL.
|
A basic client asking an entity if they confirm the access to an HTTP URL.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, jid, password, recipient, filename, domain=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
jid: JID,
|
||||||
|
password: str,
|
||||||
|
recipient: JID,
|
||||||
|
filename: Path,
|
||||||
|
domain: Optional[JID] = None,
|
||||||
|
encrypted: bool = False,
|
||||||
|
):
|
||||||
slixmpp.ClientXMPP.__init__(self, jid, password)
|
slixmpp.ClientXMPP.__init__(self, jid, password)
|
||||||
|
|
||||||
self.recipient = recipient
|
self.recipient = recipient
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
|
self.encrypted = encrypted
|
||||||
|
|
||||||
self.add_event_handler("session_start", self.start)
|
self.add_event_handler("session_start", self.start)
|
||||||
|
|
||||||
async def start(self, event):
|
async def start(self, event):
|
||||||
log.info('Uploading file %s...', self.filename)
|
log.info('Uploading file %s...', self.filename)
|
||||||
try:
|
try:
|
||||||
url = await self['xep_0363'].upload_file(
|
upload_file = self['xep_0363'].upload_file
|
||||||
self.filename, domain=self.domain, timeout=10
|
if self.encrypted and not self['xep_0454']:
|
||||||
|
print(
|
||||||
|
'The xep_0454 module isn\'t available. '
|
||||||
|
'Ensure you have \'cryptography\' '
|
||||||
|
'from extras_require installed.',
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
elif self.encrypted:
|
||||||
|
upload_file = self['xep_0454'].upload_file
|
||||||
|
url = await upload_file(
|
||||||
|
self.filename, domain=self.domain, timeout=10,
|
||||||
)
|
)
|
||||||
except IqTimeout:
|
except IqTimeout:
|
||||||
raise TimeoutError('Could not send message in time')
|
raise TimeoutError('Could not send message in time')
|
||||||
@ -79,6 +104,10 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument("--domain",
|
parser.add_argument("--domain",
|
||||||
help="Domain to use for HTTP File Upload (leave out for your own server’s)")
|
help="Domain to use for HTTP File Upload (leave out for your own server’s)")
|
||||||
|
|
||||||
|
parser.add_argument("-e", "--encrypt", dest="encrypted",
|
||||||
|
help="Whether to encrypt", action="store_true",
|
||||||
|
default=False)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Setup logging.
|
# Setup logging.
|
||||||
@ -86,15 +115,41 @@ if __name__ == '__main__':
|
|||||||
format='%(levelname)-8s %(message)s')
|
format='%(levelname)-8s %(message)s')
|
||||||
|
|
||||||
if args.jid is None:
|
if args.jid is None:
|
||||||
args.jid = input("Username: ")
|
args.jid = JID(input("Username: "))
|
||||||
if args.password is None:
|
if args.password is None:
|
||||||
args.password = getpass("Password: ")
|
args.password = getpass("Password: ")
|
||||||
|
|
||||||
xmpp = HttpUpload(args.jid, args.password, args.recipient, args.file, args.domain)
|
domain = args.domain
|
||||||
|
if domain is not None:
|
||||||
|
domain = JID(domain)
|
||||||
|
|
||||||
|
if args.encrypted:
|
||||||
|
print(
|
||||||
|
'You are using the --encrypt flag. '
|
||||||
|
'Be aware that the transport being used is NOT end-to-end '
|
||||||
|
'encrypted. The server will be able to decrypt the file.',
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
|
||||||
|
xmpp = HttpUpload(
|
||||||
|
jid=args.jid,
|
||||||
|
password=args.password,
|
||||||
|
recipient=JID(args.recipient),
|
||||||
|
filename=Path(args.file),
|
||||||
|
domain=domain,
|
||||||
|
encrypted=args.encrypted,
|
||||||
|
)
|
||||||
xmpp.register_plugin('xep_0066')
|
xmpp.register_plugin('xep_0066')
|
||||||
xmpp.register_plugin('xep_0071')
|
xmpp.register_plugin('xep_0071')
|
||||||
xmpp.register_plugin('xep_0128')
|
xmpp.register_plugin('xep_0128')
|
||||||
xmpp.register_plugin('xep_0363')
|
xmpp.register_plugin('xep_0363')
|
||||||
|
try:
|
||||||
|
xmpp.register_plugin('xep_0454')
|
||||||
|
except slixmpp.plugins.base.PluginNotFound:
|
||||||
|
log.error(
|
||||||
|
'Could not load xep_0454. '
|
||||||
|
'Ensure you have \'cryptography\' from extras_require installed.'
|
||||||
|
)
|
||||||
|
|
||||||
# Connect to the XMPP server and start processing XMPP stanzas.
|
# Connect to the XMPP server and start processing XMPP stanzas.
|
||||||
xmpp.connect()
|
xmpp.connect()
|
||||||
|
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
|
||||||
|
|
||||||
|
16
setup.py
16
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')
|
||||||
|
|
||||||
@ -80,16 +86,22 @@ setup(
|
|||||||
long_description=LONG_DESCRIPTION,
|
long_description=LONG_DESCRIPTION,
|
||||||
author='Florent Le Coz',
|
author='Florent Le Coz',
|
||||||
author_email='louiz@louiz.org',
|
author_email='louiz@louiz.org',
|
||||||
url='https://lab.louiz.org/poezio/slixmpp',
|
url='https://codeberg.org/poezio/slixmpp',
|
||||||
license='MIT',
|
license='MIT',
|
||||||
platforms=['any'],
|
platforms=['any'],
|
||||||
package_data={'slixmpp': ['py.typed']},
|
package_data={'slixmpp': ['py.typed']},
|
||||||
packages=packages,
|
packages=packages,
|
||||||
ext_modules=ext_modules,
|
ext_modules=ext_modules,
|
||||||
install_requires=['aiodns>=1.0', 'pyasn1', 'pyasn1_modules', 'typing_extensions; python_version < "3.8.0"'],
|
install_requires=[
|
||||||
|
'aiodns >= 1.0; sys_platform=="linux" or sys_platform=="darwin"',
|
||||||
|
'pyasn1',
|
||||||
|
'pyasn1_modules',
|
||||||
|
'typing_extensions; python_version < "3.8.0"',
|
||||||
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
'XEP-0363': ['aiohttp'],
|
'XEP-0363': ['aiohttp'],
|
||||||
'XEP-0444 compliance': ['emoji'],
|
'XEP-0444 compliance': ['emoji'],
|
||||||
|
'XEP-0454': ['cryptography'],
|
||||||
'Safer XML parsing': ['defusedxml'],
|
'Safer XML parsing': ['defusedxml'],
|
||||||
},
|
},
|
||||||
classifiers=CLASSIFIERS,
|
classifiers=CLASSIFIERS,
|
||||||
|
@ -4,13 +4,16 @@
|
|||||||
# 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
|
import logging
|
||||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
from os import getenv
|
||||||
|
|
||||||
# Use defusedxml if available
|
# Use defusedxml if wanted
|
||||||
try:
|
# Since enabling it can have adverse consequences for the programs using
|
||||||
|
# slixmpp, do not enable it by default.
|
||||||
|
if getenv('SLIXMPP_ENABLE_DEFUSEDXML', default='false').lower() == 'true':
|
||||||
|
try:
|
||||||
import defusedxml
|
import defusedxml
|
||||||
defusedxml.defuse_stdlib()
|
defusedxml.defuse_stdlib()
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from slixmpp.stanza import Message, Presence, Iq
|
from slixmpp.stanza import Message, Presence, Iq
|
||||||
@ -24,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__'
|
||||||
|
]
|
||||||
|
@ -140,7 +140,7 @@ class BaseXMPP(XMLStream):
|
|||||||
self.use_presence_ids = True
|
self.use_presence_ids = True
|
||||||
|
|
||||||
#: XEP-0359 <origin-id/> tag that gets added to <message/> stanzas.
|
#: XEP-0359 <origin-id/> tag that gets added to <message/> stanzas.
|
||||||
self.use_origin_id = True
|
self.use_origin_id = False
|
||||||
|
|
||||||
#: The API registry is a way to process callbacks based on
|
#: The API registry is a way to process callbacks based on
|
||||||
#: JID+node combinations. Each callback in the registry is
|
#: JID+node combinations. Each callback in the registry is
|
||||||
@ -279,13 +279,13 @@ class BaseXMPP(XMLStream):
|
|||||||
if self.plugin_whitelist:
|
if self.plugin_whitelist:
|
||||||
plugin_list = self.plugin_whitelist
|
plugin_list = self.plugin_whitelist
|
||||||
else:
|
else:
|
||||||
plugin_list = plugins.__all__
|
plugin_list = plugins.PLUGINS
|
||||||
|
|
||||||
for plugin in plugin_list:
|
for plugin in plugin_list:
|
||||||
if plugin in plugins.__all__:
|
if plugin in plugins.PLUGINS:
|
||||||
self.register_plugin(plugin)
|
self.register_plugin(plugin)
|
||||||
else:
|
else:
|
||||||
raise NameError("Plugin %s not in plugins.__all__." % plugin)
|
raise NameError("Plugin %s not in plugins.PLUGINS." % plugin)
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Return a plugin given its name, if it has been registered."""
|
"""Return a plugin given its name, if it has been registered."""
|
||||||
@ -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,6 +331,7 @@ 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()
|
||||||
|
if id is not None:
|
||||||
iq['id'] = str(id)
|
iq['id'] = str(id)
|
||||||
iq['to'] = ito
|
iq['to'] = ito
|
||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
|
@ -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,13 +9,17 @@
|
|||||||
import logging
|
import logging
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
from asyncio import Future
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
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
|
||||||
|
from slixmpp.stanza.error import Error
|
||||||
from slixmpp.xmlstream import XMLStream
|
from slixmpp.xmlstream import XMLStream
|
||||||
from slixmpp.xmlstream import ET
|
|
||||||
from slixmpp.xmlstream.matcher import MatchXPath
|
from slixmpp.xmlstream.matcher import MatchXPath
|
||||||
from slixmpp.xmlstream.handler import Callback
|
from slixmpp.xmlstream.handler import Callback
|
||||||
|
from slixmpp.xmlstream.stanzabase import register_stanza_plugin
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -39,9 +43,17 @@ class ComponentXMPP(BaseXMPP):
|
|||||||
should be used instead of the standard
|
should be used instead of the standard
|
||||||
``'jabber:component:accept'`` namespace.
|
``'jabber:component:accept'`` namespace.
|
||||||
Defaults to ``False``.
|
Defaults to ``False``.
|
||||||
|
:param fix_error_ns: Fix the namespace of error stanzas.
|
||||||
|
If you use ``use_jc_ns`` namespace, you probably want that, but
|
||||||
|
it can be a problem if you use both a ClientXMPP and a ComponentXMPP
|
||||||
|
in the same interpreter. This is ``False`` by default for backwards
|
||||||
|
compatibility.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, jid, secret, host=None, port=None, plugin_config=None, plugin_whitelist=None, use_jc_ns=False):
|
def __init__(self, jid, secret,
|
||||||
|
host=None, port=None, plugin_config=None,
|
||||||
|
plugin_whitelist=None, use_jc_ns=False,
|
||||||
|
fix_error_ns=False):
|
||||||
|
|
||||||
if not plugin_whitelist:
|
if not plugin_whitelist:
|
||||||
plugin_whitelist = []
|
plugin_whitelist = []
|
||||||
@ -53,6 +65,8 @@ class ComponentXMPP(BaseXMPP):
|
|||||||
else:
|
else:
|
||||||
default_ns = 'jabber:component:accept'
|
default_ns = 'jabber:component:accept'
|
||||||
BaseXMPP.__init__(self, jid, default_ns)
|
BaseXMPP.__init__(self, jid, default_ns)
|
||||||
|
if fix_error_ns:
|
||||||
|
self._fix_error_ns()
|
||||||
|
|
||||||
self.auto_authorize = None
|
self.auto_authorize = None
|
||||||
self.stream_header = '<stream:stream %s %s to="%s">' % (
|
self.stream_header = '<stream:stream %s %s to="%s">' % (
|
||||||
@ -77,7 +91,14 @@ class ComponentXMPP(BaseXMPP):
|
|||||||
self.add_event_handler('presence_probe',
|
self.add_event_handler('presence_probe',
|
||||||
self._handle_probe)
|
self._handle_probe)
|
||||||
|
|
||||||
def connect(self, host=None, port=None, use_ssl=False):
|
def _fix_error_ns(self):
|
||||||
|
Error.namespace = self.default_ns
|
||||||
|
for st in Message, Iq, Presence:
|
||||||
|
register_stanza_plugin(st, Error)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
@ -87,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):
|
||||||
"""
|
"""
|
||||||
|
@ -5,6 +5,11 @@
|
|||||||
# :copyright: (c) 2011 Nathanael C. Fritz
|
# :copyright: (c) 2011 Nathanael C. Fritz
|
||||||
# :license: MIT, see LICENSE for more details
|
# :license: MIT, see LICENSE for more details
|
||||||
|
|
||||||
|
from typing import Dict, Optional
|
||||||
|
|
||||||
|
from .types import ErrorConditions, ErrorTypes, JidStr
|
||||||
|
|
||||||
|
|
||||||
class XMPPError(Exception):
|
class XMPPError(Exception):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -37,12 +42,17 @@ class XMPPError(Exception):
|
|||||||
Defaults to ``True``.
|
Defaults to ``True``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, condition='undefined-condition', text='',
|
def __init__(self, condition: ErrorConditions='undefined-condition', text='',
|
||||||
etype='cancel', extension=None, extension_ns=None,
|
etype: Optional[ErrorTypes]=None, extension=None, extension_ns=None,
|
||||||
extension_args=None, clear=True):
|
extension_args=None, clear=True, by: Optional[JidStr] = None):
|
||||||
if extension_args is None:
|
if extension_args is None:
|
||||||
extension_args = {}
|
extension_args = {}
|
||||||
|
if condition not in _DEFAULT_ERROR_TYPES:
|
||||||
|
raise ValueError("This is not a valid condition type", condition)
|
||||||
|
if etype is None:
|
||||||
|
etype = _DEFAULT_ERROR_TYPES[condition]
|
||||||
|
|
||||||
|
self.by = by
|
||||||
self.condition = condition
|
self.condition = condition
|
||||||
self.text = text
|
self.text = text
|
||||||
self.etype = etype
|
self.etype = etype
|
||||||
@ -110,3 +120,30 @@ class PresenceError(XMPPError):
|
|||||||
etype=pres['error']['type'],
|
etype=pres['error']['type'],
|
||||||
)
|
)
|
||||||
self.presence = pres
|
self.presence = pres
|
||||||
|
|
||||||
|
|
||||||
|
_DEFAULT_ERROR_TYPES: Dict[ErrorConditions, ErrorTypes] = {
|
||||||
|
"bad-request": "modify",
|
||||||
|
"conflict": "cancel",
|
||||||
|
"feature-not-implemented": "cancel",
|
||||||
|
"forbidden": "auth",
|
||||||
|
"gone": "modify",
|
||||||
|
"internal-server-error": "wait",
|
||||||
|
"item-not-found": "cancel",
|
||||||
|
"jid-malformed": "modify",
|
||||||
|
"not-acceptable": "modify",
|
||||||
|
"not-allowed": "cancel",
|
||||||
|
"not-authorized": "auth",
|
||||||
|
"payment-required": "auth",
|
||||||
|
"policy-violation": "modify",
|
||||||
|
"recipient-unavailable": "wait",
|
||||||
|
"redirect": "modify",
|
||||||
|
"registration-required": "auth",
|
||||||
|
"remote-server-not-found": "cancel",
|
||||||
|
"remote-server-timeout": "wait",
|
||||||
|
"resource-constraint": "wait",
|
||||||
|
"service-unavailable": "cancel",
|
||||||
|
"subscription-required": "auth",
|
||||||
|
"undefined-condition": "cancel",
|
||||||
|
"unexpected-request": "modify",
|
||||||
|
}
|
||||||
|
@ -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
|
||||||
|
@ -3,8 +3,12 @@
|
|||||||
# Copyright (C) 2011 Nathanael C. Fritz
|
# Copyright (C) 2011 Nathanael C. Fritz
|
||||||
# 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.xmlstream import StanzaBase, ElementBase
|
|
||||||
from typing import Set, ClassVar
|
from typing import Set, ClassVar
|
||||||
|
from slixmpp.xmlstream import StanzaBase, ElementBase
|
||||||
|
from slixmpp.xmlstream.xmlstream import InvalidCABundle
|
||||||
|
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class STARTTLS(StanzaBase):
|
class STARTTLS(StanzaBase):
|
||||||
@ -36,6 +40,12 @@ class Proceed(StanzaBase):
|
|||||||
namespace = 'urn:ietf:params:xml:ns:xmpp-tls'
|
namespace = 'urn:ietf:params:xml:ns:xmpp-tls'
|
||||||
interfaces: ClassVar[Set[str]] = set()
|
interfaces: ClassVar[Set[str]] = set()
|
||||||
|
|
||||||
|
def exception(self, e: Exception) -> None:
|
||||||
|
log.exception('Error handling {%s}%s stanza',
|
||||||
|
self.namespace, self.name)
|
||||||
|
if isinstance(e, InvalidCABundle):
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
class Failure(StanzaBase):
|
class Failure(StanzaBase):
|
||||||
"""
|
"""
|
||||||
|
@ -303,13 +303,15 @@ class JID:
|
|||||||
|
|
||||||
:param string jid:
|
:param string jid:
|
||||||
A string of the form ``'[user@]domain[/resource]'``.
|
A string of the form ``'[user@]domain[/resource]'``.
|
||||||
|
:param bool bare:
|
||||||
|
If present, discard the provided resource.
|
||||||
|
|
||||||
:raises InvalidJID:
|
:raises InvalidJID:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ('_node', '_domain', '_resource', '_bare', '_full')
|
__slots__ = ('_node', '_domain', '_resource', '_bare', '_full')
|
||||||
|
|
||||||
def __init__(self, jid: Optional[Union[str, 'JID']] = None):
|
def __init__(self, jid: Optional[Union[str, 'JID']] = None, bare: bool = False):
|
||||||
if not jid:
|
if not jid:
|
||||||
self._node = ''
|
self._node = ''
|
||||||
self._domain = ''
|
self._domain = ''
|
||||||
@ -318,11 +320,14 @@ class JID:
|
|||||||
self._full = ''
|
self._full = ''
|
||||||
return
|
return
|
||||||
elif not isinstance(jid, JID):
|
elif not isinstance(jid, JID):
|
||||||
self._node, self._domain, self._resource = _parse_jid(jid)
|
node, domain, resource = _parse_jid(jid)
|
||||||
|
self._node = node
|
||||||
|
self._domain = domain
|
||||||
|
self._resource = resource if not bare else ''
|
||||||
else:
|
else:
|
||||||
self._node = jid._node
|
self._node = jid._node
|
||||||
self._domain = jid._domain
|
self._domain = jid._domain
|
||||||
self._resource = jid._resource
|
self._resource = jid._resource if not bare else ''
|
||||||
self._update_bare_full()
|
self._update_bare_full()
|
||||||
|
|
||||||
def unescape(self):
|
def unescape(self):
|
||||||
@ -368,7 +373,7 @@ class JID:
|
|||||||
return self._node
|
return self._node
|
||||||
|
|
||||||
@node.setter
|
@node.setter
|
||||||
def node(self, value: str):
|
def node(self, value: Optional[str]):
|
||||||
self._node = _validate_node(value)
|
self._node = _validate_node(value)
|
||||||
self._update_bare_full()
|
self._update_bare_full()
|
||||||
|
|
||||||
@ -386,7 +391,7 @@ class JID:
|
|||||||
return self._resource
|
return self._resource
|
||||||
|
|
||||||
@resource.setter
|
@resource.setter
|
||||||
def resource(self, value: str):
|
def resource(self, value: Optional[str]):
|
||||||
self._resource = _validate_resource(value)
|
self._resource = _validate_resource(value)
|
||||||
self._update_bare_full()
|
self._update_bare_full()
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Slixmpp: The Slick XMPP Library
|
# Slixmpp: The Slick XMPP Library
|
||||||
# Copyright (C) 2010 Nathanael C. Fritz
|
# Copyright (C) 2010 Nathanael C. Fritz
|
||||||
# This file is part of Slixmpp.
|
# This file is part of Slixmpp.
|
||||||
@ -7,7 +6,7 @@ from slixmpp.plugins.base import PluginManager, PluginNotFound, BasePlugin
|
|||||||
from slixmpp.plugins.base import register_plugin, load_plugin
|
from slixmpp.plugins.base import register_plugin, load_plugin
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
PLUGINS = [
|
||||||
# XEPS
|
# XEPS
|
||||||
'xep_0004', # Data Forms
|
'xep_0004', # Data Forms
|
||||||
'xep_0009', # Jabber-RPC
|
'xep_0009', # Jabber-RPC
|
||||||
@ -24,6 +23,7 @@ __all__ = [
|
|||||||
'xep_0049', # Private XML Storage
|
'xep_0049', # Private XML Storage
|
||||||
'xep_0050', # Ad-hoc Commands
|
'xep_0050', # Ad-hoc Commands
|
||||||
'xep_0054', # vcard-temp
|
'xep_0054', # vcard-temp
|
||||||
|
'xep_0055', # Jabber Search
|
||||||
'xep_0059', # Result Set Management
|
'xep_0059', # Result Set Management
|
||||||
'xep_0060', # Pubsub (Client)
|
'xep_0060', # Pubsub (Client)
|
||||||
'xep_0065', # SOCKS5 Bytestreams
|
'xep_0065', # SOCKS5 Bytestreams
|
||||||
@ -76,14 +76,17 @@ __all__ = [
|
|||||||
'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
|
||||||
|
'xep_0292', # vCard4 Over XMPP
|
||||||
'xep_0297', # Stanza Forwarding
|
'xep_0297', # Stanza Forwarding
|
||||||
'xep_0300', # Use of Cryptographic Hash Functions in XMPP
|
'xep_0300', # Use of Cryptographic Hash Functions in XMPP
|
||||||
# '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
|
||||||
@ -93,23 +96,42 @@ __all__ = [
|
|||||||
'xep_0335', # JSON Containers
|
'xep_0335', # JSON Containers
|
||||||
'xep_0352', # Client State Indication
|
'xep_0352', # Client State Indication
|
||||||
'xep_0353', # Jingle Message Initiation
|
'xep_0353', # Jingle Message Initiation
|
||||||
|
'xep_0356', # Privileged entity
|
||||||
'xep_0359', # Unique and Stable Stanza IDs
|
'xep_0359', # Unique and Stable Stanza IDs
|
||||||
'xep_0363', # HTTP File Upload
|
'xep_0363', # HTTP File Upload
|
||||||
'xep_0369', # MIX-CORE
|
'xep_0369', # MIX-CORE
|
||||||
'xep_0377', # Spam reporting
|
'xep_0377', # Spam reporting
|
||||||
'xep_0380', # Explicit Message Encryption
|
'xep_0380', # Explicit Message Encryption
|
||||||
'xep_0382', # Spoiler Messages
|
'xep_0382', # Spoiler Messages
|
||||||
|
'xep_0385', # Stateless Inline Media Sharing (SIMS)
|
||||||
'xep_0394', # Message Markup
|
'xep_0394', # Message Markup
|
||||||
|
'xep_0402', # PEP Native Bookmarks
|
||||||
'xep_0403', # MIX-Presence
|
'xep_0403', # MIX-Presence
|
||||||
'xep_0404', # MIX-Anon
|
'xep_0404', # MIX-Anon
|
||||||
'xep_0405', # MIX-PAM
|
'xep_0405', # MIX-PAM
|
||||||
'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_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
|
||||||
|
]
|
||||||
|
|
||||||
|
__all__ = PLUGINS + [
|
||||||
|
'PluginManager',
|
||||||
|
'PluginNotFound',
|
||||||
|
'BasePlugin',
|
||||||
|
'register_plugin',
|
||||||
|
'load_plugin',
|
||||||
]
|
]
|
||||||
|
@ -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): #
|
||||||
|
@ -19,6 +19,8 @@ def _extract_data(data, kind):
|
|||||||
stripped = []
|
stripped = []
|
||||||
begin_headers = False
|
begin_headers = False
|
||||||
begin_data = False
|
begin_data = False
|
||||||
|
if isinstance(data, bytes):
|
||||||
|
data = data.decode()
|
||||||
for line in data.split('\n'):
|
for line in data.split('\n'):
|
||||||
if not begin_headers and 'BEGIN PGP %s' % kind in line:
|
if not begin_headers and 'BEGIN PGP %s' % kind in line:
|
||||||
begin_headers = True
|
begin_headers = True
|
||||||
|
@ -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:
|
||||||
|
|
||||||
::
|
::
|
||||||
@ -307,7 +310,7 @@ class XEP_0030(BasePlugin):
|
|||||||
return self.api['has_identity'](jid, node, ifrom, data)
|
return self.api['has_identity'](jid, node, ifrom, data)
|
||||||
|
|
||||||
async def get_info_from_domain(self, domain=None, timeout=None,
|
async def get_info_from_domain(self, domain=None, timeout=None,
|
||||||
cached=True, callback=None):
|
cached=True, callback=None, **iqkwargs):
|
||||||
"""Fetch disco#info of specified domain and one disco#items level below
|
"""Fetch disco#info of specified domain and one disco#items level below
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -315,13 +318,13 @@ class XEP_0030(BasePlugin):
|
|||||||
domain = self.xmpp.boundjid.domain
|
domain = self.xmpp.boundjid.domain
|
||||||
|
|
||||||
if not cached or domain not in self.domain_infos:
|
if not cached or domain not in self.domain_infos:
|
||||||
infos = [self.get_info(
|
infos = [asyncio.create_task(self.get_info(
|
||||||
domain, timeout=timeout)]
|
domain, timeout=timeout, **iqkwargs))]
|
||||||
iq_items = await self.get_items(
|
iq_items = await self.get_items(
|
||||||
domain, timeout=timeout)
|
domain, timeout=timeout, **iqkwargs)
|
||||||
items = iq_items['disco_items']['items']
|
items = iq_items['disco_items']['items']
|
||||||
infos += [
|
infos += [
|
||||||
self.get_info(item[0], timeout=timeout)
|
asyncio.create_task(self.get_info(item[0], timeout=timeout, **iqkwargs))
|
||||||
for item in items]
|
for item in items]
|
||||||
info_futures, _ = await asyncio.wait(
|
info_futures, _ = await asyncio.wait(
|
||||||
infos,
|
infos,
|
||||||
@ -385,6 +388,8 @@ class XEP_0030(BasePlugin):
|
|||||||
local = True
|
local = True
|
||||||
|
|
||||||
ifrom = kwargs.pop('ifrom', None)
|
ifrom = kwargs.pop('ifrom', None)
|
||||||
|
if self.xmpp.is_component and ifrom is None:
|
||||||
|
ifrom = self.xmpp.boundjid
|
||||||
if local:
|
if local:
|
||||||
log.debug("Looking up local disco#info data "
|
log.debug("Looking up local disco#info data "
|
||||||
"for %s, node %s.", jid, node)
|
"for %s, node %s.", jid, node)
|
||||||
@ -455,9 +460,12 @@ class XEP_0030(BasePlugin):
|
|||||||
the XEP-0059 plugin, if the plugin is loaded.
|
the XEP-0059 plugin, if the plugin is loaded.
|
||||||
Otherwise the parameter is ignored.
|
Otherwise the parameter is ignored.
|
||||||
"""
|
"""
|
||||||
|
if ifrom is None and self.xmpp.is_component:
|
||||||
|
ifrom = self.xmpp.boundjid.bare
|
||||||
|
|
||||||
if local or local is None and jid is None:
|
if local or local is None and jid is None:
|
||||||
items = await self.api['get_items'](jid, node, ifrom, kwargs)
|
items = await self.api['get_items'](jid, node, ifrom, kwargs)
|
||||||
return self._wrap(kwargs.get('ifrom', None), jid, items)
|
return self._wrap(ifrom, jid, items)
|
||||||
|
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
# Check dfrom parameter for backwards compatibility
|
# Check dfrom parameter for backwards compatibility
|
||||||
|
@ -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):
|
||||||
|
feature = feature_xml.attrib.get('var', None)
|
||||||
|
if feature:
|
||||||
if isinstance(features, set):
|
if isinstance(features, set):
|
||||||
features.add(feature_xml.attrib['var'])
|
features.add(feature)
|
||||||
else:
|
else:
|
||||||
features.append(feature_xml.attrib['var'])
|
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:
|
||||||
@ -323,7 +325,6 @@ class XEP_0045(BasePlugin):
|
|||||||
|
|
||||||
def add_message(msg: Message):
|
def add_message(msg: Message):
|
||||||
delay = msg.get_plugin('delay', check=True)
|
delay = msg.get_plugin('delay', check=True)
|
||||||
print(delay)
|
|
||||||
if delay is not None and delay['from'] == room:
|
if delay is not None and delay['from'] == room:
|
||||||
history_buffer.append(msg)
|
history_buffer.append(msg)
|
||||||
|
|
||||||
@ -359,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
|
||||||
@ -413,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.
|
||||||
@ -424,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.
|
||||||
|
|
||||||
@ -439,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.
|
||||||
|
|
||||||
@ -452,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.
|
||||||
@ -463,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.
|
||||||
@ -480,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,6 +494,8 @@ 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:
|
||||||
|
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)
|
||||||
@ -505,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.
|
||||||
@ -517,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.
|
||||||
@ -533,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
|
||||||
@ -554,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.
|
||||||
@ -566,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.
|
||||||
@ -581,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.
|
||||||
@ -595,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
|
||||||
@ -614,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.
|
||||||
@ -628,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.
|
||||||
@ -645,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
|
||||||
@ -703,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):
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# 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 asyncio
|
import asyncio
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -325,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']
|
||||||
@ -619,8 +623,16 @@ class XEP_0050(BasePlugin):
|
|||||||
self.terminate_command(session)
|
self.terminate_command(session)
|
||||||
|
|
||||||
|
|
||||||
|
def _iscoroutine_or_partial_coroutine(handler):
|
||||||
|
return asyncio.iscoroutinefunction(handler) \
|
||||||
|
or isinstance(handler, functools.partial) \
|
||||||
|
and asyncio.iscoroutinefunction(handler.func)
|
||||||
|
|
||||||
|
|
||||||
async def _await_if_needed(handler, *args):
|
async def _await_if_needed(handler, *args):
|
||||||
if asyncio.iscoroutinefunction(handler):
|
if handler is None:
|
||||||
|
raise XMPPError("bad-request", text="The command is completed")
|
||||||
|
if _iscoroutine_or_partial_coroutine(handler):
|
||||||
log.debug(f"%s is async", handler)
|
log.debug(f"%s is async", handler)
|
||||||
return await handler(*args)
|
return await handler(*args)
|
||||||
else:
|
else:
|
||||||
|
@ -134,8 +134,10 @@ class XEP_0054(BasePlugin):
|
|||||||
return
|
return
|
||||||
elif iq['type'] == 'get' and self.xmpp.is_component:
|
elif iq['type'] == 'get' and self.xmpp.is_component:
|
||||||
vcard = await self.api['get_vcard'](iq['to'].bare, ifrom=iq['from'])
|
vcard = await self.api['get_vcard'](iq['to'].bare, ifrom=iq['from'])
|
||||||
if isinstance(vcard, Iq):
|
if vcard is None:
|
||||||
vcard.send()
|
raise XMPPError("item-not-found")
|
||||||
|
elif isinstance(vcard, Iq):
|
||||||
|
await vcard.send()
|
||||||
else:
|
else:
|
||||||
iq = iq.reply()
|
iq = iq.reply()
|
||||||
iq.append(vcard)
|
iq.append(vcard)
|
||||||
|
6
slixmpp/plugins/xep_0055/__init__.py
Normal file
6
slixmpp/plugins/xep_0055/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from .search import XEP_0055
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0055)
|
89
slixmpp/plugins/xep_0055/search.py
Normal file
89
slixmpp/plugins/xep_0055/search.py
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from slixmpp import CoroutineCallback, StanzaPath, Iq, register_stanza_plugin
|
||||||
|
from slixmpp.plugins import BasePlugin
|
||||||
|
from slixmpp.xmlstream import StanzaBase
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0055(BasePlugin):
|
||||||
|
"""
|
||||||
|
XEP-0055: Jabber Search
|
||||||
|
|
||||||
|
The config options are only useful for a "server-side" search feature,
|
||||||
|
and if the ``provide_search`` option is set to True.
|
||||||
|
|
||||||
|
API
|
||||||
|
===
|
||||||
|
|
||||||
|
``search_get_form``: customize the search form content (ie fields)
|
||||||
|
|
||||||
|
``search_query``: return search results
|
||||||
|
"""
|
||||||
|
name = "xep_0055"
|
||||||
|
description = "XEP-0055: Jabber search"
|
||||||
|
dependencies = {"xep_0004", "xep_0030"}
|
||||||
|
stanza = stanza
|
||||||
|
default_config = {
|
||||||
|
"form_fields": {"first", "last"},
|
||||||
|
"form_instructions": "",
|
||||||
|
"form_title": "",
|
||||||
|
"provide_search": True
|
||||||
|
}
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
register_stanza_plugin(Iq, stanza.Search)
|
||||||
|
register_stanza_plugin(stanza.Search, self.xmpp["xep_0004"].stanza.Form)
|
||||||
|
|
||||||
|
if self.provide_search:
|
||||||
|
self.xmpp["xep_0030"].add_feature(stanza.Search.namespace)
|
||||||
|
self.xmpp.register_handler(
|
||||||
|
CoroutineCallback(
|
||||||
|
"search",
|
||||||
|
StanzaPath("/iq/search"),
|
||||||
|
self._handle_search,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.api.register(self._get_form, "search_get_form")
|
||||||
|
self.api.register(self._get_results, "search_query")
|
||||||
|
|
||||||
|
async def _handle_search(self, iq: StanzaBase):
|
||||||
|
if iq["search"]["form"].get_values():
|
||||||
|
reply = await self.api["search_query"](None, None, iq.get_from(), iq)
|
||||||
|
reply["search"]["form"]["type"] = "result"
|
||||||
|
else:
|
||||||
|
reply = await self.api["search_get_form"](None, None, iq.get_from(), iq)
|
||||||
|
reply["search"]["form"].add_field(
|
||||||
|
"FORM_TYPE", value=stanza.Search.namespace, ftype="hidden"
|
||||||
|
)
|
||||||
|
reply.send()
|
||||||
|
|
||||||
|
async def _get_form(self, jid, node, ifrom, iq):
|
||||||
|
reply = iq.reply()
|
||||||
|
form = reply["search"]["form"]
|
||||||
|
form["title"] = self.form_title
|
||||||
|
form["instructions"] = self.form_instructions
|
||||||
|
for field in self.form_fields:
|
||||||
|
form.add_field(field)
|
||||||
|
return reply
|
||||||
|
|
||||||
|
async def _get_results(self, jid, node, ifrom, iq):
|
||||||
|
reply = iq.reply()
|
||||||
|
form = reply["search"]["form"]
|
||||||
|
form["type"] = "result"
|
||||||
|
|
||||||
|
for field in self.form_fields:
|
||||||
|
form.add_reported(field)
|
||||||
|
return reply
|
||||||
|
|
||||||
|
def make_search_iq(self, **kwargs):
|
||||||
|
iq = self.xmpp.make_iq(itype="set", **kwargs)
|
||||||
|
iq["search"]["form"].set_type("submit")
|
||||||
|
iq["search"]["form"].add_field(
|
||||||
|
"FORM_TYPE", value=stanza.Search.namespace, ftype="hidden"
|
||||||
|
)
|
||||||
|
return iq
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
10
slixmpp/plugins/xep_0055/stanza.py
Normal file
10
slixmpp/plugins/xep_0055/stanza.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from typing import Set, ClassVar
|
||||||
|
|
||||||
|
from slixmpp.xmlstream import ElementBase
|
||||||
|
|
||||||
|
|
||||||
|
class Search(ElementBase):
|
||||||
|
namespace = "jabber:iq:search"
|
||||||
|
name = "query"
|
||||||
|
plugin_attrib = "search"
|
||||||
|
interfaces: ClassVar[Set[str]] = set()
|
@ -464,7 +464,7 @@ 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)
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
|
||||||
from slixmpp.plugins import BasePlugin, register_plugin
|
from slixmpp.plugins import BasePlugin, register_plugin
|
||||||
from slixmpp.thirdparty import tzutc, tzoffset, parse_iso
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
@ -21,7 +20,10 @@ def parse(time_str):
|
|||||||
Arguments:
|
Arguments:
|
||||||
time_str -- A formatted timestamp string.
|
time_str -- A formatted timestamp string.
|
||||||
"""
|
"""
|
||||||
return parse_iso(time_str)
|
try:
|
||||||
|
return dt.datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S.%f%z')
|
||||||
|
except ValueError:
|
||||||
|
return dt.datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S%z')
|
||||||
|
|
||||||
|
|
||||||
def format_date(time_obj):
|
def format_date(time_obj):
|
||||||
@ -52,7 +54,7 @@ def format_time(time_obj):
|
|||||||
if isinstance(time_obj, dt.datetime):
|
if isinstance(time_obj, dt.datetime):
|
||||||
time_obj = time_obj.timetz()
|
time_obj = time_obj.timetz()
|
||||||
timestamp = time_obj.isoformat()
|
timestamp = time_obj.isoformat()
|
||||||
if time_obj.tzinfo == tzutc():
|
if time_obj.tzinfo == dt.timezone.utc:
|
||||||
timestamp = timestamp[:-6]
|
timestamp = timestamp[:-6]
|
||||||
return '%sZ' % timestamp
|
return '%sZ' % timestamp
|
||||||
return timestamp
|
return timestamp
|
||||||
@ -69,7 +71,7 @@ def format_datetime(time_obj):
|
|||||||
time_obj -- A datetime object.
|
time_obj -- A datetime object.
|
||||||
"""
|
"""
|
||||||
timestamp = time_obj.isoformat('T')
|
timestamp = time_obj.isoformat('T')
|
||||||
if time_obj.tzinfo == tzutc():
|
if time_obj.tzinfo == dt.timezone.utc:
|
||||||
timestamp = timestamp[:-6]
|
timestamp = timestamp[:-6]
|
||||||
return '%sZ' % timestamp
|
return '%sZ' % timestamp
|
||||||
return timestamp
|
return timestamp
|
||||||
@ -128,9 +130,9 @@ def time(hour=None, min=None, sec=None, micro=None, offset=None, obj=False):
|
|||||||
if micro is None:
|
if micro is None:
|
||||||
micro = now.microsecond
|
micro = now.microsecond
|
||||||
if offset in (None, 0):
|
if offset in (None, 0):
|
||||||
offset = tzutc()
|
offset = dt.timezone.utc
|
||||||
elif not isinstance(offset, dt.tzinfo):
|
elif not isinstance(offset, dt.tzinfo):
|
||||||
offset = tzoffset(None, offset)
|
offset = dt.timezone(dt.timedelta(seconds=offset))
|
||||||
value = dt.time(hour, min, sec, micro, offset)
|
value = dt.time(hour, min, sec, micro, offset)
|
||||||
if obj:
|
if obj:
|
||||||
return value
|
return value
|
||||||
@ -175,9 +177,9 @@ def datetime(year=None, month=None, day=None, hour=None,
|
|||||||
if micro is None:
|
if micro is None:
|
||||||
micro = now.microsecond
|
micro = now.microsecond
|
||||||
if offset in (None, 0):
|
if offset in (None, 0):
|
||||||
offset = tzutc()
|
offset = dt.timezone.utc
|
||||||
elif not isinstance(offset, dt.tzinfo):
|
elif not isinstance(offset, dt.tzinfo):
|
||||||
offset = tzoffset(None, offset)
|
offset = dt.timezone(dt.timedelta(seconds=offset))
|
||||||
|
|
||||||
value = dt.datetime(year, month, day, hour,
|
value = dt.datetime(year, month, day, hour,
|
||||||
min, sec, micro, offset)
|
min, sec, micro, offset)
|
||||||
|
@ -80,16 +80,16 @@ class Info(ElementBase):
|
|||||||
self._set_int('bytes', value)
|
self._set_int('bytes', value)
|
||||||
|
|
||||||
def get_height(self) -> int:
|
def get_height(self) -> int:
|
||||||
self._get_int('height')
|
return self._get_int('height')
|
||||||
|
|
||||||
def set_height(self, value: int):
|
def set_height(self, value: int):
|
||||||
self._set_int('height', value)
|
self._set_int('height', value)
|
||||||
|
|
||||||
def get_width(self) -> int:
|
def get_width(self) -> int:
|
||||||
self._get_int(self, 'width')
|
return self._get_int('width')
|
||||||
|
|
||||||
def set_width(self, value: int):
|
def set_width(self, value: int):
|
||||||
self._set_int('with', value)
|
self._set_int('width', value)
|
||||||
|
|
||||||
|
|
||||||
class Pointer(ElementBase):
|
class Pointer(ElementBase):
|
||||||
|
@ -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
|
||||||
@ -162,7 +170,7 @@ class XEP_0115(BasePlugin):
|
|||||||
if pres['caps']['hash'] not in self.hashes:
|
if pres['caps']['hash'] not in self.hashes:
|
||||||
try:
|
try:
|
||||||
log.debug("Unknown caps hash: %s", pres['caps']['hash'])
|
log.debug("Unknown caps hash: %s", pres['caps']['hash'])
|
||||||
self.xmpp['xep_0030'].get_info(jid=pres['from'], ifrom=ifrom)
|
await self.xmpp['xep_0030'].get_info(jid=pres['from'], ifrom=ifrom)
|
||||||
return
|
return
|
||||||
except XMPPError:
|
except XMPPError:
|
||||||
return
|
return
|
||||||
|
@ -60,7 +60,7 @@ class StaticCaps(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if node in (None, ''):
|
if node in (None, ''):
|
||||||
info = self.caps.get_caps(jid)
|
info = await self.caps.get_caps(jid)
|
||||||
if info and feature in info['features']:
|
if info and feature in info['features']:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class StaticCaps(object):
|
|||||||
def get_verstring(self, jid, node, ifrom, data):
|
def get_verstring(self, jid, node, ifrom, data):
|
||||||
return self.jid_vers.get(jid, None)
|
return self.jid_vers.get(jid, None)
|
||||||
|
|
||||||
def get_caps(self, jid, node, ifrom, data):
|
async def get_caps(self, jid, node, ifrom, data):
|
||||||
verstring = data.get('verstring', None)
|
verstring = data.get('verstring', None)
|
||||||
if verstring is None:
|
if verstring is None:
|
||||||
return None
|
return None
|
||||||
|
@ -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.")
|
||||||
|
@ -8,7 +8,6 @@ import datetime as dt
|
|||||||
|
|
||||||
from slixmpp.xmlstream import ElementBase
|
from slixmpp.xmlstream import ElementBase
|
||||||
from slixmpp.plugins import xep_0082
|
from slixmpp.plugins import xep_0082
|
||||||
from slixmpp.thirdparty import tzutc, tzoffset
|
|
||||||
|
|
||||||
|
|
||||||
class EntityTime(ElementBase):
|
class EntityTime(ElementBase):
|
||||||
@ -87,7 +86,7 @@ class EntityTime(ElementBase):
|
|||||||
seconds (positive or negative) to offset.
|
seconds (positive or negative) to offset.
|
||||||
"""
|
"""
|
||||||
time = xep_0082.time(offset=value)
|
time = xep_0082.time(offset=value)
|
||||||
if xep_0082.parse(time).tzinfo == tzutc():
|
if xep_0082.parse(time).tzinfo == dt.timezone.utc:
|
||||||
self._set_sub_text('tzo', 'Z')
|
self._set_sub_text('tzo', 'Z')
|
||||||
else:
|
else:
|
||||||
self._set_sub_text('tzo', time[-6:])
|
self._set_sub_text('tzo', time[-6:])
|
||||||
@ -111,6 +110,6 @@ class EntityTime(ElementBase):
|
|||||||
date = value
|
date = value
|
||||||
if not isinstance(value, dt.datetime):
|
if not isinstance(value, dt.datetime):
|
||||||
date = xep_0082.parse(value)
|
date = xep_0082.parse(value)
|
||||||
date = date.astimezone(tzutc())
|
date = date.astimezone(dt.timezone.utc)
|
||||||
value = xep_0082.format_datetime(date)
|
value = xep_0082.format_datetime(date)
|
||||||
self._set_sub_text('utc', value)
|
self._set_sub_text('utc', value)
|
||||||
|
@ -30,6 +30,10 @@ class Delay(ElementBase):
|
|||||||
|
|
||||||
def set_stamp(self, value):
|
def set_stamp(self, value):
|
||||||
if isinstance(value, dt.datetime):
|
if isinstance(value, dt.datetime):
|
||||||
|
if value.tzinfo is None:
|
||||||
|
raise ValueError(f'Datetime provided without timezone information: {value}')
|
||||||
|
if value.tzinfo != dt.timezone.utc:
|
||||||
|
value = value.astimezone(dt.timezone.utc)
|
||||||
value = xep_0082.format_datetime(value)
|
value = xep_0082.format_datetime(value)
|
||||||
self._set_attr('stamp', value)
|
self._set_attr('stamp', value)
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
6
slixmpp/plugins/xep_0234/__init__.py
Normal file
6
slixmpp/plugins/xep_0234/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from .jingle_file_transfer import XEP_0234
|
||||||
|
|
||||||
|
register_plugin(XEP_0234)
|
21
slixmpp/plugins/xep_0234/jingle_file_transfer.py
Normal file
21
slixmpp/plugins/xep_0234/jingle_file_transfer.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from slixmpp.plugins import BasePlugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0234(BasePlugin):
|
||||||
|
|
||||||
|
"""
|
||||||
|
XEP-0234: Jingle File Transfer
|
||||||
|
|
||||||
|
Minimum needed for xep 0385 (Stateless inline media sharing)
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "xep_0234"
|
||||||
|
description = "XEP-0234: Jingle File Transfer"
|
||||||
|
dependencies = {"xep_0082", "xep_0300"}
|
||||||
|
stanza = stanza
|
38
slixmpp/plugins/xep_0234/stanza.py
Normal file
38
slixmpp/plugins/xep_0234/stanza.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from slixmpp.plugins.xep_0082 import format_datetime, parse
|
||||||
|
from slixmpp.xmlstream import ElementBase
|
||||||
|
|
||||||
|
NS = "urn:xmpp:jingle:apps:file-transfer:5"
|
||||||
|
|
||||||
|
|
||||||
|
class File(ElementBase):
|
||||||
|
name = "file"
|
||||||
|
namespace = NS
|
||||||
|
plugin_attrib = "file"
|
||||||
|
interfaces = sub_interfaces = {"media-type", "name", "date", "size", "hash", "desc"}
|
||||||
|
|
||||||
|
def set_size(self, size: int):
|
||||||
|
self._set_sub_text("size", str(size))
|
||||||
|
|
||||||
|
def get_size(self):
|
||||||
|
return _int_or_none(self._get_sub_text("size"))
|
||||||
|
|
||||||
|
def get_date(self):
|
||||||
|
try:
|
||||||
|
return parse(self._get_sub_text("date"))
|
||||||
|
except ValueError:
|
||||||
|
return
|
||||||
|
|
||||||
|
def set_date(self, stamp: datetime):
|
||||||
|
try:
|
||||||
|
self._set_sub_text("date", format_datetime(stamp))
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _int_or_none(v):
|
||||||
|
try:
|
||||||
|
return int(v)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
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()
|
6
slixmpp/plugins/xep_0292/__init__.py
Normal file
6
slixmpp/plugins/xep_0292/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from . import stanza, vcard4
|
||||||
|
from .vcard4 import XEP_0292
|
||||||
|
|
||||||
|
register_plugin(vcard4.XEP_0292)
|
167
slixmpp/plugins/xep_0292/stanza.py
Normal file
167
slixmpp/plugins/xep_0292/stanza.py
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from slixmpp import ElementBase, Iq, register_stanza_plugin
|
||||||
|
|
||||||
|
NS = "urn:ietf:params:xml:ns:vcard-4.0"
|
||||||
|
|
||||||
|
|
||||||
|
class _VCardElementBase(ElementBase):
|
||||||
|
namespace = NS
|
||||||
|
|
||||||
|
|
||||||
|
class VCard4(_VCardElementBase):
|
||||||
|
name = plugin_attrib = "vcard"
|
||||||
|
interfaces = {"full_name", "given", "surname", "birthday"}
|
||||||
|
|
||||||
|
def set_full_name(self, full_name: str):
|
||||||
|
self["fn"]["text"] = full_name
|
||||||
|
|
||||||
|
def get_full_name(self):
|
||||||
|
return self["fn"]["text"]
|
||||||
|
|
||||||
|
def set_given(self, given: str):
|
||||||
|
self["n"]["given"] = given
|
||||||
|
|
||||||
|
def get_given(self):
|
||||||
|
return self["n"]["given"]
|
||||||
|
|
||||||
|
def set_surname(self, surname: str):
|
||||||
|
self["n"]["surname"] = surname
|
||||||
|
|
||||||
|
def get_surname(self):
|
||||||
|
return self["n"]["surname"]
|
||||||
|
|
||||||
|
def set_birthday(self, birthday: datetime.date):
|
||||||
|
self["bday"]["date"] = birthday
|
||||||
|
|
||||||
|
def get_birthday(self):
|
||||||
|
return self["bday"]["date"]
|
||||||
|
|
||||||
|
def add_tel(self, number: str, name: Optional[str] = None):
|
||||||
|
tel = Tel()
|
||||||
|
if name:
|
||||||
|
tel["parameters"]["type_"]["text"] = name
|
||||||
|
tel["uri"] = f"tel:{number}"
|
||||||
|
self.append(tel)
|
||||||
|
|
||||||
|
def add_address(
|
||||||
|
self, country: Optional[str] = None, locality: Optional[str] = None
|
||||||
|
):
|
||||||
|
adr = Adr()
|
||||||
|
if locality:
|
||||||
|
adr["locality"] = locality
|
||||||
|
if country:
|
||||||
|
adr["country"] = country
|
||||||
|
self.append(adr)
|
||||||
|
|
||||||
|
def add_nickname(self, nick: str):
|
||||||
|
el = Nickname()
|
||||||
|
el["text"] = nick
|
||||||
|
self.append(el)
|
||||||
|
|
||||||
|
def add_note(self, note: str):
|
||||||
|
el = Note()
|
||||||
|
el["text"] = note
|
||||||
|
self.append(el)
|
||||||
|
|
||||||
|
def add_impp(self, impp: str):
|
||||||
|
el = Impp()
|
||||||
|
el["uri"] = impp
|
||||||
|
self.append(el)
|
||||||
|
|
||||||
|
def add_url(self, url: str):
|
||||||
|
el = Url()
|
||||||
|
el["uri"] = url
|
||||||
|
self.append(el)
|
||||||
|
|
||||||
|
def add_email(self, email: str):
|
||||||
|
el = Email()
|
||||||
|
el["text"] = email
|
||||||
|
self.append(el)
|
||||||
|
|
||||||
|
|
||||||
|
class _VCardTextElementBase(_VCardElementBase):
|
||||||
|
interfaces = {"text"}
|
||||||
|
sub_interfaces = {"text"}
|
||||||
|
|
||||||
|
|
||||||
|
class Fn(_VCardTextElementBase):
|
||||||
|
name = plugin_attrib = "fn"
|
||||||
|
|
||||||
|
|
||||||
|
class Nickname(_VCardTextElementBase):
|
||||||
|
name = plugin_attrib = "nickname"
|
||||||
|
|
||||||
|
|
||||||
|
class Note(_VCardTextElementBase):
|
||||||
|
name = plugin_attrib = "note"
|
||||||
|
|
||||||
|
|
||||||
|
class _VCardUriElementBase(_VCardElementBase):
|
||||||
|
interfaces = {"uri"}
|
||||||
|
sub_interfaces = {"uri"}
|
||||||
|
|
||||||
|
|
||||||
|
class Url(_VCardUriElementBase):
|
||||||
|
name = plugin_attrib = "url"
|
||||||
|
|
||||||
|
|
||||||
|
class Impp(_VCardUriElementBase):
|
||||||
|
name = plugin_attrib = "impp"
|
||||||
|
|
||||||
|
|
||||||
|
class Email(_VCardTextElementBase):
|
||||||
|
name = plugin_attrib = "email"
|
||||||
|
|
||||||
|
|
||||||
|
class N(_VCardElementBase):
|
||||||
|
name = "n"
|
||||||
|
plugin_attrib = "n"
|
||||||
|
interfaces = sub_interfaces = {"given", "surname", "additional"}
|
||||||
|
|
||||||
|
|
||||||
|
class BDay(_VCardElementBase):
|
||||||
|
name = plugin_attrib = "bday"
|
||||||
|
interfaces = {"date"}
|
||||||
|
|
||||||
|
def set_date(self, date: datetime.date):
|
||||||
|
d = Date()
|
||||||
|
d.xml.text = date.strftime("%Y-%m-%d")
|
||||||
|
self.append(d)
|
||||||
|
|
||||||
|
def get_date(self):
|
||||||
|
for elem in self.xml:
|
||||||
|
try:
|
||||||
|
return datetime.date.fromisoformat(elem.text)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class Date(_VCardElementBase):
|
||||||
|
name = "date"
|
||||||
|
|
||||||
|
|
||||||
|
class Tel(_VCardUriElementBase):
|
||||||
|
name = plugin_attrib = "tel"
|
||||||
|
|
||||||
|
|
||||||
|
class Parameters(_VCardElementBase):
|
||||||
|
name = plugin_attrib = "parameters"
|
||||||
|
|
||||||
|
|
||||||
|
class Type(_VCardTextElementBase):
|
||||||
|
name = "type"
|
||||||
|
plugin_attrib = "type_"
|
||||||
|
|
||||||
|
|
||||||
|
class Adr(_VCardElementBase):
|
||||||
|
name = plugin_attrib = "adr"
|
||||||
|
interfaces = sub_interfaces = {"locality", "country"}
|
||||||
|
|
||||||
|
|
||||||
|
register_stanza_plugin(Parameters, Type)
|
||||||
|
register_stanza_plugin(Tel, Parameters)
|
||||||
|
for p in N, Fn, Nickname, Note, Url, Impp, Email, BDay, Tel, Adr:
|
||||||
|
register_stanza_plugin(VCard4, p, iterable=True)
|
||||||
|
register_stanza_plugin(Iq, VCard4)
|
111
slixmpp/plugins/xep_0292/vcard4.py
Normal file
111
slixmpp/plugins/xep_0292/vcard4.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import logging
|
||||||
|
from datetime import date
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from slixmpp import (
|
||||||
|
JID,
|
||||||
|
ComponentXMPP,
|
||||||
|
register_stanza_plugin,
|
||||||
|
)
|
||||||
|
from slixmpp.plugins.base import BasePlugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0292(BasePlugin):
|
||||||
|
"""
|
||||||
|
vCard4 over XMPP
|
||||||
|
|
||||||
|
Does not implement the IQ semantics that neither movim does gajim implement,
|
||||||
|
cf https://xmpp.org/extensions/xep-0292.html#self-iq-retrieval and
|
||||||
|
https://xmpp.org/extensions/xep-0292.html#self-iq-publication
|
||||||
|
|
||||||
|
Does not implement the "empty pubsub event item" as a notification mechanism,
|
||||||
|
that neither gajim nor movim implement
|
||||||
|
https://xmpp.org/extensions/xep-0292.html#sect-idm45744791178720
|
||||||
|
|
||||||
|
Relies on classic pubsub semantics instead.
|
||||||
|
"""
|
||||||
|
xmpp: ComponentXMPP
|
||||||
|
|
||||||
|
name = "xep_0292"
|
||||||
|
description = "vCard4 Over XMPP"
|
||||||
|
dependencies = {"xep_0163", "xep_0060", "xep_0030"}
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
pubsub_stanza = self.xmpp["xep_0060"].stanza
|
||||||
|
|
||||||
|
register_stanza_plugin(pubsub_stanza.Item, stanza.VCard4)
|
||||||
|
register_stanza_plugin(pubsub_stanza.EventItem, stanza.VCard4)
|
||||||
|
|
||||||
|
self.xmpp['xep_0060'].map_node_event(stanza.NS, 'vcard4')
|
||||||
|
|
||||||
|
def plugin_end(self):
|
||||||
|
self.xmpp['xep_0030'].del_feature(feature=stanza.NS)
|
||||||
|
self.xmpp['xep_0163'].remove_interest(stanza.NS)
|
||||||
|
|
||||||
|
def session_bind(self, jid):
|
||||||
|
self.xmpp['xep_0163'].register_pep('vcard4', stanza.VCard4)
|
||||||
|
|
||||||
|
def publish_vcard(
|
||||||
|
self,
|
||||||
|
full_name: Optional[str] = None,
|
||||||
|
given: Optional[str] = None,
|
||||||
|
surname: Optional[str] = None,
|
||||||
|
birthday: Optional[date] = None,
|
||||||
|
nickname: Optional[str] = None,
|
||||||
|
phone: Optional[str] = None,
|
||||||
|
note: Optional[str] = None,
|
||||||
|
url: Optional[str] = None,
|
||||||
|
email: Optional[str] = None,
|
||||||
|
country: Optional[str] = None,
|
||||||
|
locality: Optional[str] = None,
|
||||||
|
impp: Optional[str] = None,
|
||||||
|
**pubsubkwargs,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Publish a vcard using PEP
|
||||||
|
"""
|
||||||
|
vcard = stanza.VCard4()
|
||||||
|
|
||||||
|
if impp:
|
||||||
|
vcard.add_impp(impp)
|
||||||
|
|
||||||
|
if nickname:
|
||||||
|
vcard.add_nickname(nickname)
|
||||||
|
if full_name:
|
||||||
|
vcard["full_name"] = full_name
|
||||||
|
|
||||||
|
if given:
|
||||||
|
vcard["given"] = given
|
||||||
|
if surname:
|
||||||
|
vcard["surname"] = surname
|
||||||
|
if birthday:
|
||||||
|
vcard["birthday"] = birthday
|
||||||
|
|
||||||
|
if note:
|
||||||
|
vcard.add_note(note)
|
||||||
|
if url:
|
||||||
|
vcard.add_url(url)
|
||||||
|
if email:
|
||||||
|
vcard.add_email(email)
|
||||||
|
if phone:
|
||||||
|
vcard.add_tel(phone)
|
||||||
|
if country and locality:
|
||||||
|
vcard.add_address(country, locality)
|
||||||
|
elif country:
|
||||||
|
vcard.add_address(country, locality)
|
||||||
|
|
||||||
|
return self.xmpp["xep_0163"].publish(vcard, id="current", **pubsubkwargs)
|
||||||
|
|
||||||
|
def retrieve_vcard(self, jid: JID, **pubsubkwargs):
|
||||||
|
"""
|
||||||
|
Retrieve a vcard using PEP
|
||||||
|
"""
|
||||||
|
return self.xmpp["xep_0060"].get_item(
|
||||||
|
jid, stanza.VCard4.namespace, "current", **pubsubkwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
@ -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).
|
||||||
@ -187,7 +190,7 @@ class Fin(ElementBase):
|
|||||||
name = 'fin'
|
name = 'fin'
|
||||||
namespace = 'urn:xmpp:mam:2'
|
namespace = 'urn:xmpp:mam:2'
|
||||||
plugin_attrib = 'mam_fin'
|
plugin_attrib = 'mam_fin'
|
||||||
interfaces = {'results'}
|
interfaces = {'results', 'stable', 'complete'}
|
||||||
|
|
||||||
def setup(self, xml=None):
|
def setup(self, xml=None):
|
||||||
ElementBase.setup(self, xml)
|
ElementBase.setup(self, xml)
|
||||||
|
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)
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# slixmpp: The Slick XMPP Library
|
# slixmpp: The Slick XMPP Library
|
||||||
# Copyright (C) 2016 Emmanuel Gil Peyrot
|
# Copyright (C) 2016 Emmanuel Gil Peyrot
|
||||||
# This file is part of slixmpp.
|
# This file is part of slixmpp.
|
||||||
@ -68,11 +67,11 @@ class XEP_0333(BasePlugin):
|
|||||||
:param JID mto: recipient of the marker
|
:param JID mto: recipient of the marker
|
||||||
:param str id: Identifier of the marked message
|
:param str id: Identifier of the marked message
|
||||||
:param str marker: Marker to send (one of
|
:param str marker: Marker to send (one of
|
||||||
displayed, retrieved, or acknowledged)
|
displayed, received, or acknowledged)
|
||||||
:param str thread: Message thread
|
:param str thread: Message thread
|
||||||
:param str mfrom: Use a specific JID to send the message
|
:param str mfrom: Use a specific JID to send the message
|
||||||
"""
|
"""
|
||||||
if marker not in ('displayed', 'retrieved', 'acknowledged'):
|
if marker not in ('displayed', 'received', 'acknowledged'):
|
||||||
raise ValueError('Invalid marker: %s' % marker)
|
raise ValueError('Invalid marker: %s' % marker)
|
||||||
msg = self.xmpp.make_message(mto=mto, mfrom=mfrom)
|
msg = self.xmpp.make_message(mto=mto, mfrom=mfrom)
|
||||||
if thread:
|
if thread:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from slixmpp.plugins.base import register_plugin
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
from slixmpp.plugins.xep_0356 import stanza
|
from . import stanza
|
||||||
from slixmpp.plugins.xep_0356.stanza import Perm, Privilege
|
from .privilege import XEP_0356
|
||||||
from slixmpp.plugins.xep_0356.privilege import XEP_0356
|
from .stanza import Perm, Privilege
|
||||||
|
|
||||||
register_plugin(XEP_0356)
|
register_plugin(XEP_0356)
|
||||||
|
36
slixmpp/plugins/xep_0356/permissions.py
Normal file
36
slixmpp/plugins/xep_0356/permissions.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import dataclasses
|
||||||
|
from collections import defaultdict
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class RosterAccess(str, Enum):
|
||||||
|
NONE = "none"
|
||||||
|
GET = "get"
|
||||||
|
SET = "set"
|
||||||
|
BOTH = "both"
|
||||||
|
|
||||||
|
|
||||||
|
class MessagePermission(str, Enum):
|
||||||
|
NONE = "none"
|
||||||
|
OUTGOING = "outgoing"
|
||||||
|
|
||||||
|
|
||||||
|
class IqPermission(str, Enum):
|
||||||
|
NONE = "none"
|
||||||
|
GET = "get"
|
||||||
|
SET = "set"
|
||||||
|
BOTH = "both"
|
||||||
|
|
||||||
|
|
||||||
|
class PresencePermission(str, Enum):
|
||||||
|
NONE = "none"
|
||||||
|
MANAGED_ENTITY = "managed_entity"
|
||||||
|
ROSTER = "roster"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
|
class Permissions:
|
||||||
|
roster = RosterAccess.NONE
|
||||||
|
message = MessagePermission.NONE
|
||||||
|
iq = defaultdict(lambda: IqPermission.NONE)
|
||||||
|
presence = PresencePermission.NONE
|
@ -1,14 +1,16 @@
|
|||||||
import logging
|
import logging
|
||||||
import typing
|
import typing
|
||||||
|
import uuid
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from slixmpp import Message, JID, Iq
|
from slixmpp import JID, Iq, Message
|
||||||
from slixmpp.plugins.base import BasePlugin
|
from slixmpp.plugins.base import BasePlugin
|
||||||
from slixmpp.xmlstream.matcher import StanzaPath
|
from slixmpp.xmlstream import StanzaBase
|
||||||
from slixmpp.xmlstream.handler import Callback
|
from slixmpp.xmlstream.handler import Callback
|
||||||
from slixmpp.xmlstream import register_stanza_plugin
|
from slixmpp.xmlstream.matcher import StanzaPath
|
||||||
|
|
||||||
from slixmpp.plugins.xep_0356 import stanza, Privilege, Perm
|
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from .permissions import IqPermission, MessagePermission, Permissions, RosterAccess
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ class XEP_0356(BasePlugin):
|
|||||||
dependencies = {"xep_0297"}
|
dependencies = {"xep_0297"}
|
||||||
stanza = stanza
|
stanza = stanza
|
||||||
|
|
||||||
granted_privileges = {"roster": "none", "message": "none", "presence": "none"}
|
granted_privileges = defaultdict(Permissions)
|
||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
if not self.xmpp.is_component:
|
if not self.xmpp.is_component:
|
||||||
@ -49,32 +51,42 @@ class XEP_0356(BasePlugin):
|
|||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp.remove_handler("Privileges")
|
self.xmpp.remove_handler("Privileges")
|
||||||
|
|
||||||
def _handle_privilege(self, msg: Message):
|
def _handle_privilege(self, msg: StanzaBase):
|
||||||
"""
|
"""
|
||||||
Called when the XMPP server advertise the component's privileges.
|
Called when the XMPP server advertise the component's privileges.
|
||||||
|
|
||||||
Stores the privileges in this instance's granted_privileges attribute (a dict)
|
Stores the privileges in this instance's granted_privileges attribute (a dict)
|
||||||
and raises the privileges_advertised event
|
and raises the privileges_advertised event
|
||||||
"""
|
"""
|
||||||
|
permissions = self.granted_privileges[msg.get_from()]
|
||||||
for perm in msg["privilege"]["perms"]:
|
for perm in msg["privilege"]["perms"]:
|
||||||
self.granted_privileges[perm["access"]] = perm["type"]
|
access = perm["access"]
|
||||||
|
if access == "iq":
|
||||||
|
for ns in perm["namespaces"]:
|
||||||
|
permissions.iq[ns["ns"]] = ns["type"]
|
||||||
|
elif access in _VALID_ACCESSES:
|
||||||
|
setattr(permissions, access, perm["type"])
|
||||||
|
else:
|
||||||
|
log.warning("Received an invalid privileged access: %s", access)
|
||||||
log.debug(f"Privileges: {self.granted_privileges}")
|
log.debug(f"Privileges: {self.granted_privileges}")
|
||||||
self.xmpp.event("privileges_advertised")
|
self.xmpp.event("privileges_advertised")
|
||||||
|
|
||||||
def send_privileged_message(self, msg: Message):
|
def send_privileged_message(self, msg: Message):
|
||||||
if self.granted_privileges["message"] == "outgoing":
|
if (
|
||||||
self._make_privileged_message(msg).send()
|
self.granted_privileges[msg.get_from().domain].message
|
||||||
else:
|
!= MessagePermission.OUTGOING
|
||||||
log.error(
|
):
|
||||||
|
raise PermissionError(
|
||||||
"The server hasn't authorized us to send messages on behalf of other users"
|
"The server hasn't authorized us to send messages on behalf of other users"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
self._make_privileged_message(msg).send()
|
||||||
|
|
||||||
def _make_privileged_message(self, msg: Message):
|
def _make_privileged_message(self, msg: Message):
|
||||||
stanza = self.xmpp.make_message(
|
server = msg.get_from().domain
|
||||||
mto=self.xmpp.server_host, mfrom=self.xmpp.boundjid.bare
|
wrapped = self.xmpp.make_message(mto=server, mfrom=self.xmpp.boundjid.bare)
|
||||||
)
|
wrapped["privilege"]["forwarded"].append(msg)
|
||||||
stanza["privilege"]["forwarded"].append(msg)
|
return wrapped
|
||||||
return stanza
|
|
||||||
|
|
||||||
def _make_get_roster(self, jid: typing.Union[JID, str], **iq_kwargs):
|
def _make_get_roster(self, jid: typing.Union[JID, str], **iq_kwargs):
|
||||||
return self.xmpp.make_iq_get(
|
return self.xmpp.make_iq_get(
|
||||||
@ -106,9 +118,15 @@ class XEP_0356(BasePlugin):
|
|||||||
|
|
||||||
:param jid: user we want to fetch the roster from
|
:param jid: user we want to fetch the roster from
|
||||||
"""
|
"""
|
||||||
if self.granted_privileges["roster"] not in ("get", "both"):
|
if isinstance(jid, str):
|
||||||
log.error("The server did not grant us privileges to get rosters")
|
jid = JID(jid)
|
||||||
raise ValueError
|
if self.granted_privileges[jid.domain].roster not in (
|
||||||
|
RosterAccess.GET,
|
||||||
|
RosterAccess.BOTH,
|
||||||
|
):
|
||||||
|
raise PermissionError(
|
||||||
|
"The server did not grant us privileges to get rosters"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return await self._make_get_roster(jid).send(**send_kwargs)
|
return await self._make_get_roster(jid).send(**send_kwargs)
|
||||||
|
|
||||||
@ -120,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",
|
||||||
@ -136,9 +154,62 @@ class XEP_0356(BasePlugin):
|
|||||||
"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 self.granted_privileges["roster"] not in ("set", "both"):
|
if isinstance(jid, str):
|
||||||
log.error("The server did not grant us privileges to set rosters")
|
jid = JID(jid)
|
||||||
raise ValueError
|
if self.granted_privileges[jid.domain].roster not in (
|
||||||
|
RosterAccess.GET,
|
||||||
|
RosterAccess.BOTH,
|
||||||
|
):
|
||||||
|
raise PermissionError(
|
||||||
|
"The server did not grant us privileges to set rosters"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return await self._make_set_roster(jid, roster_items).send(**send_kwargs)
|
return await self._make_set_roster(jid, roster_items).send(**send_kwargs)
|
||||||
|
|
||||||
|
async def send_privileged_iq(
|
||||||
|
self, encapsulated_iq: Iq, iq_id: typing.Optional[str] = None
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Send an IQ on behalf of a user
|
||||||
|
|
||||||
|
Caution: the IQ *must* have the jabber:client namespace
|
||||||
|
"""
|
||||||
|
iq_id = iq_id or str(uuid.uuid4())
|
||||||
|
encapsulated_iq["id"] = iq_id
|
||||||
|
server = encapsulated_iq.get_to().domain
|
||||||
|
perms = self.granted_privileges.get(server)
|
||||||
|
if not perms:
|
||||||
|
raise PermissionError(f"{server} has not granted us any privilege")
|
||||||
|
itype = encapsulated_iq["type"]
|
||||||
|
for ns in encapsulated_iq.plugins.values():
|
||||||
|
type_ = perms.iq[ns.namespace]
|
||||||
|
if type_ == IqPermission.NONE:
|
||||||
|
raise PermissionError(
|
||||||
|
f"{server} has not granted any IQ privilege for namespace {ns.namespace}"
|
||||||
|
)
|
||||||
|
elif type_ == IqPermission.BOTH:
|
||||||
|
pass
|
||||||
|
elif type_ != itype:
|
||||||
|
raise PermissionError(
|
||||||
|
f"{server} has not granted IQ {itype} privilege for namespace {ns.namespace}"
|
||||||
|
)
|
||||||
|
iq = self.xmpp.make_iq(
|
||||||
|
itype=itype,
|
||||||
|
ifrom=self.xmpp.boundjid.bare,
|
||||||
|
ito=encapsulated_iq.get_from(),
|
||||||
|
id=iq_id,
|
||||||
|
)
|
||||||
|
iq["privileged_iq"].append(encapsulated_iq)
|
||||||
|
|
||||||
|
resp = await iq.send()
|
||||||
|
return resp["privilege"]["forwarded"]["iq"]
|
||||||
|
|
||||||
|
|
||||||
|
# does not include iq access that is handled differently
|
||||||
|
_VALID_ACCESSES = {"message", "roster", "presence"}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
from slixmpp.stanza import Message
|
|
||||||
from slixmpp.xmlstream import (
|
|
||||||
ElementBase,
|
|
||||||
register_stanza_plugin,
|
|
||||||
)
|
|
||||||
from slixmpp.plugins.xep_0297 import Forwarded
|
from slixmpp.plugins.xep_0297 import Forwarded
|
||||||
|
from slixmpp.stanza import Iq, Message
|
||||||
|
from slixmpp.xmlstream import ElementBase, register_stanza_plugin
|
||||||
|
|
||||||
|
NS = "urn:xmpp:privilege:2"
|
||||||
|
|
||||||
|
|
||||||
class Privilege(ElementBase):
|
class Privilege(ElementBase):
|
||||||
namespace = "urn:xmpp:privilege:1"
|
namespace = NS
|
||||||
name = "privilege"
|
name = "privilege"
|
||||||
plugin_attrib = "privilege"
|
plugin_attrib = "privilege"
|
||||||
|
|
||||||
@ -25,23 +24,40 @@ class Privilege(ElementBase):
|
|||||||
def presence(self):
|
def presence(self):
|
||||||
return self.permission("presence")
|
return self.permission("presence")
|
||||||
|
|
||||||
def add_perm(self, access, type):
|
def add_perm(self, access, type_):
|
||||||
# This should only be needed for servers, so maybe out of scope for slixmpp
|
# This should only be needed for servers, so maybe out of scope for slixmpp
|
||||||
perm = Perm()
|
perm = Perm()
|
||||||
perm["type"] = type
|
perm["type"] = type_
|
||||||
perm["access"] = access
|
perm["access"] = access
|
||||||
self.append(perm)
|
self.append(perm)
|
||||||
|
|
||||||
|
|
||||||
class Perm(ElementBase):
|
class Perm(ElementBase):
|
||||||
namespace = "urn:xmpp:privilege:1"
|
namespace = NS
|
||||||
name = "perm"
|
name = "perm"
|
||||||
plugin_attrib = "perm"
|
plugin_attrib = "perm"
|
||||||
plugin_multi_attrib = "perms"
|
plugin_multi_attrib = "perms"
|
||||||
interfaces = {"type", "access"}
|
interfaces = {"type", "access"}
|
||||||
|
|
||||||
|
|
||||||
|
class NameSpace(ElementBase):
|
||||||
|
namespace = NS
|
||||||
|
name = "namespace"
|
||||||
|
plugin_attrib = "namespace"
|
||||||
|
plugin_multi_attrib = "namespaces"
|
||||||
|
interfaces = {"ns", "type"}
|
||||||
|
|
||||||
|
|
||||||
|
class PrivilegedIq(ElementBase):
|
||||||
|
namespace = NS
|
||||||
|
name = "privileged_iq"
|
||||||
|
plugin_attrib = "privileged_iq"
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
register_stanza_plugin(Message, Privilege)
|
register_stanza_plugin(Message, Privilege)
|
||||||
|
register_stanza_plugin(Iq, Privilege)
|
||||||
register_stanza_plugin(Privilege, Forwarded)
|
register_stanza_plugin(Privilege, Forwarded)
|
||||||
register_stanza_plugin(Privilege, Perm, iterable=True)
|
register_stanza_plugin(Privilege, Perm, iterable=True)
|
||||||
|
register_stanza_plugin(Perm, NameSpace, iterable=True)
|
||||||
|
register_stanza_plugin(Iq, PrivilegedIq)
|
||||||
|
@ -14,6 +14,8 @@ from typing import (
|
|||||||
IO,
|
IO,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from slixmpp import JID, __version__
|
from slixmpp import JID, __version__
|
||||||
from slixmpp.stanza import Iq
|
from slixmpp.stanza import Iq
|
||||||
from slixmpp.plugins import BasePlugin
|
from slixmpp.plugins import BasePlugin
|
||||||
@ -99,12 +101,17 @@ class XEP_0363(BasePlugin):
|
|||||||
|
|
||||||
:param domain: Domain to disco to find a service.
|
:param domain: Domain to disco to find a service.
|
||||||
"""
|
"""
|
||||||
|
if domain is None and self.xmpp.is_component:
|
||||||
|
domain = self.xmpp.server_host
|
||||||
|
|
||||||
results = await self.xmpp['xep_0030'].get_info_from_domain(
|
results = await self.xmpp['xep_0030'].get_info_from_domain(
|
||||||
domain=domain, **iqkwargs
|
domain=domain, **iqkwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
for info in results:
|
for info in results:
|
||||||
|
if not info['disco_info']:
|
||||||
|
continue
|
||||||
for identity in info['disco_info']['identities']:
|
for identity in info['disco_info']['identities']:
|
||||||
if identity[0] == 'store' and identity[1] == 'file':
|
if identity[0] == 'store' and identity[1] == 'file':
|
||||||
candidates.append(info)
|
candidates.append(info)
|
||||||
@ -113,7 +120,7 @@ class XEP_0363(BasePlugin):
|
|||||||
if feature == Request.namespace:
|
if feature == Request.namespace:
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def request_slot(self, jid: JID, filename: str, size: int,
|
def request_slot(self, jid: JID, filename: Path, size: int,
|
||||||
content_type: Optional[str] = None, *,
|
content_type: Optional[str] = None, *,
|
||||||
ifrom: Optional[JID] = None, **iqkwargs) -> Future:
|
ifrom: Optional[JID] = None, **iqkwargs) -> Future:
|
||||||
"""Request an HTTP upload slot from a service.
|
"""Request an HTTP upload slot from a service.
|
||||||
@ -125,12 +132,12 @@ class XEP_0363(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
iq = self.xmpp.make_iq_get(ito=jid, ifrom=ifrom)
|
iq = self.xmpp.make_iq_get(ito=jid, ifrom=ifrom)
|
||||||
request = iq['http_upload_request']
|
request = iq['http_upload_request']
|
||||||
request['filename'] = filename
|
request['filename'] = str(filename)
|
||||||
request['size'] = str(size)
|
request['size'] = str(size)
|
||||||
request['content-type'] = content_type or self.default_content_type
|
request['content-type'] = content_type or self.default_content_type
|
||||||
return iq.send(**iqkwargs)
|
return iq.send(**iqkwargs)
|
||||||
|
|
||||||
async def upload_file(self, filename: str, size: Optional[int] = None,
|
async def upload_file(self, filename: Path, size: Optional[int] = None,
|
||||||
content_type: Optional[str] = None, *,
|
content_type: Optional[str] = None, *,
|
||||||
input_file: Optional[IO[bytes]]=None,
|
input_file: Optional[IO[bytes]]=None,
|
||||||
domain: Optional[JID] = None,
|
domain: Optional[JID] = None,
|
||||||
|
6
slixmpp/plugins/xep_0372/__init__.py
Normal file
6
slixmpp/plugins/xep_0372/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from .references import XEP_0372
|
||||||
|
|
||||||
|
register_plugin(XEP_0372)
|
23
slixmpp/plugins/xep_0372/references.py
Normal file
23
slixmpp/plugins/xep_0372/references.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from slixmpp import Message, register_stanza_plugin
|
||||||
|
from slixmpp.plugins import BasePlugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0372(BasePlugin):
|
||||||
|
"""
|
||||||
|
XEP-0372: References
|
||||||
|
|
||||||
|
Minimum needed for xep 0385 (Stateless inline media sharing)
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "xep_0372"
|
||||||
|
description = "XEP-0372: References"
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
register_stanza_plugin(Message, stanza.Reference)
|
9
slixmpp/plugins/xep_0372/stanza.py
Normal file
9
slixmpp/plugins/xep_0372/stanza.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from slixmpp.xmlstream import ElementBase
|
||||||
|
|
||||||
|
NAMESPACE = "urn:xmpp:reference:0"
|
||||||
|
|
||||||
|
|
||||||
|
class Reference(ElementBase):
|
||||||
|
name = plugin_attrib = "reference"
|
||||||
|
namespace = NAMESPACE
|
||||||
|
interfaces = {"type", "uri", "id", "begin", "end"}
|
@ -26,6 +26,9 @@ class XEP_0377(BasePlugin):
|
|||||||
dependencies = {'xep_0030', 'xep_0191'}
|
dependencies = {'xep_0030', 'xep_0191'}
|
||||||
stanza = stanza
|
stanza = stanza
|
||||||
|
|
||||||
|
SPAM = 'urn:xmpp:reporting:spam'
|
||||||
|
ABUSE = 'urn:xmpp:reporting:abuse'
|
||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
register_stanza_plugin(Block, stanza.Report)
|
register_stanza_plugin(Block, stanza.Report)
|
||||||
register_stanza_plugin(stanza.Report, stanza.Text)
|
register_stanza_plugin(stanza.Report, stanza.Text)
|
||||||
|
@ -13,58 +13,23 @@ class Report(ElementBase):
|
|||||||
Example sub stanza:
|
Example sub stanza:
|
||||||
::
|
::
|
||||||
|
|
||||||
<report xmlns="urn:xmpp:reporting:0">
|
<report xmlns="urn:xmpp:reporting:1" reason="urn:xmpp:reporting:abuse">
|
||||||
<text xml:lang="en">
|
<text xml:lang="en">
|
||||||
Never came trouble to my house like this.
|
Never came trouble to my house like this.
|
||||||
</text>
|
</text>
|
||||||
<spam/>
|
|
||||||
</report>
|
</report>
|
||||||
|
|
||||||
Stanza Interface:
|
The reason attribute is mandatory.
|
||||||
::
|
|
||||||
|
|
||||||
abuse -- Flag the report as abuse
|
|
||||||
spam -- Flag the report as spam
|
|
||||||
text -- Add a reason to the report
|
|
||||||
|
|
||||||
Only one <spam/> or <abuse/> element can be present at once.
|
|
||||||
"""
|
"""
|
||||||
name = "report"
|
name = "report"
|
||||||
namespace = "urn:xmpp:reporting:0"
|
namespace = "urn:xmpp:reporting:1"
|
||||||
plugin_attrib = "report"
|
plugin_attrib = "report"
|
||||||
interfaces = ("spam", "abuse", "text")
|
interfaces = ("text", "reason")
|
||||||
sub_interfaces = {'text'}
|
sub_interfaces = {'text'}
|
||||||
|
|
||||||
def _purge_spam(self):
|
|
||||||
spam = self.xml.findall('{%s}spam' % self.namespace)
|
|
||||||
for element in spam:
|
|
||||||
self.xml.remove(element)
|
|
||||||
|
|
||||||
def _purge_abuse(self):
|
|
||||||
abuse = self.xml.findall('{%s}abuse' % self.namespace)
|
|
||||||
for element in abuse:
|
|
||||||
self.xml.remove(element)
|
|
||||||
|
|
||||||
def get_spam(self):
|
|
||||||
return self.xml.find('{%s}spam' % self.namespace) is not None
|
|
||||||
|
|
||||||
def set_spam(self, value):
|
|
||||||
self._purge_spam()
|
|
||||||
if bool(value):
|
|
||||||
self._purge_abuse()
|
|
||||||
self.xml.append(ET.Element('{%s}spam' % self.namespace))
|
|
||||||
|
|
||||||
def get_abuse(self):
|
|
||||||
return self.xml.find('{%s}abuse' % self.namespace) is not None
|
|
||||||
|
|
||||||
def set_abuse(self, value):
|
|
||||||
self._purge_abuse()
|
|
||||||
if bool(value):
|
|
||||||
self._purge_spam()
|
|
||||||
self.xml.append(ET.Element('{%s}abuse' % self.namespace))
|
|
||||||
|
|
||||||
|
|
||||||
class Text(ElementBase):
|
class Text(ElementBase):
|
||||||
name = "text"
|
name = "text"
|
||||||
plugin_attrib = "text"
|
plugin_attrib = "text"
|
||||||
namespace = "urn:xmpp:reporting:0"
|
namespace = "urn:xmpp:reporting:1"
|
||||||
|
11
slixmpp/plugins/xep_0385/__init__.py
Normal file
11
slixmpp/plugins/xep_0385/__init__.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permission
|
||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
from .sims import XEP_0385
|
||||||
|
|
||||||
|
register_plugin(XEP_0385)
|
66
slixmpp/plugins/xep_0385/sims.py
Normal file
66
slixmpp/plugins/xep_0385/sims.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Iterable, Optional
|
||||||
|
|
||||||
|
from slixmpp.plugins import BasePlugin
|
||||||
|
from slixmpp.stanza import Message
|
||||||
|
from slixmpp.xmlstream import register_stanza_plugin
|
||||||
|
|
||||||
|
from . import stanza
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0385(BasePlugin):
|
||||||
|
|
||||||
|
"""
|
||||||
|
XEP-0385: Stateless Inline Media Sharing (SIMS)
|
||||||
|
|
||||||
|
Only support outgoing SIMS, incoming is not handled at all.
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "xep_0385"
|
||||||
|
description = "XEP-0385: Stateless Inline Media Sharing (SIMS)"
|
||||||
|
dependencies = {"xep_0234", "xep_0300", "xep_0372"}
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
register_stanza_plugin(self.xmpp["xep_0372"].stanza.Reference, stanza.Sims)
|
||||||
|
register_stanza_plugin(Message, stanza.Sims)
|
||||||
|
|
||||||
|
register_stanza_plugin(stanza.Sims, stanza.Sources)
|
||||||
|
register_stanza_plugin(stanza.Sims, self.xmpp["xep_0234"].stanza.File)
|
||||||
|
register_stanza_plugin(stanza.Sources, self.xmpp["xep_0372"].stanza.Reference)
|
||||||
|
|
||||||
|
def get_sims(
|
||||||
|
self,
|
||||||
|
path: Path,
|
||||||
|
uris: Iterable[str],
|
||||||
|
media_type: Optional[str],
|
||||||
|
desc: Optional[str],
|
||||||
|
):
|
||||||
|
sims = stanza.Sims()
|
||||||
|
for uri in uris:
|
||||||
|
ref = self.xmpp["xep_0372"].stanza.Reference()
|
||||||
|
ref["uri"] = uri
|
||||||
|
ref["type"] = "data"
|
||||||
|
sims["sources"].append(ref)
|
||||||
|
if media_type:
|
||||||
|
sims["file"]["media-type"] = media_type
|
||||||
|
if desc:
|
||||||
|
sims["file"]["desc"] = desc
|
||||||
|
sims["file"]["name"] = path.name
|
||||||
|
|
||||||
|
stat = path.stat()
|
||||||
|
sims["file"]["size"] = stat.st_size
|
||||||
|
sims["file"]["date"] = datetime.fromtimestamp(stat.st_mtime)
|
||||||
|
|
||||||
|
h = self.xmpp.plugin["xep_0300"].compute_hash(path)
|
||||||
|
h["value"] = h["value"].decode()
|
||||||
|
sims["file"].append(h)
|
||||||
|
|
||||||
|
ref = self.xmpp["xep_0372"].stanza.Reference()
|
||||||
|
ref.append(sims)
|
||||||
|
ref["type"] = "data"
|
||||||
|
return ref
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user