Compare commits

..

7 Commits

Author SHA1 Message Date
nicoco
e45901064c replace setup.py and mypy.ini with pyproject.toml 2023-07-23 16:04:50 +02:00
nicoco
0b6496a7b1 remove unused CI conf files 2023-07-23 15:34:57 +02:00
mathieui
7732af8991 Move references from lab.louiz.org to codeberg 2023-07-06 15:26:57 +02:00
nicoco
25c28ff5d1 xep_0461/add_quoted_fallback: add optional nickname argument
+ a little docstring that doesn't hurt
2023-06-05 20:48:38 +02:00
nicoco
e3e0d8f43e xep_0313/fin: add 'stable' and 'complete' attribs 2023-06-05 14:18:07 +02:00
nicoco
13729e47a6 add xeps 0385 and 0447 to plugins.PLUGINS 2023-06-05 14:18:07 +02:00
nicoco
f12860bfad fix misleading error msg
plugins.__all__ became plugins.PLUGINS a few commits ago
2023-06-05 14:18:07 +02:00
16 changed files with 159 additions and 155 deletions

View File

@@ -1,7 +0,0 @@
language: python
python:
- "3.7"
- "3.8-dev"
install:
- "pip install ."
script: testall.py

View File

@@ -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>`_

50
_custom_build.py Normal file
View File

@@ -0,0 +1,50 @@
"""
Cythonize the .pyx file for sdist, and compile it for wheels.
NB: produced wheels are not valid, but the sdist should be.
"""
import os
from Cython.Build import cythonize
from subprocess import check_output, CalledProcessError, DEVNULL, call
from tempfile import TemporaryFile
from setuptools.command.build_py import build_py
def check_include(library_name, header):
command = [os.environ.get("PKG_CONFIG", "pkg-config"), "--cflags", library_name]
try:
cflags = check_output(command).decode("utf-8").split()
except FileNotFoundError:
print("pkg-config not found.")
return False
except CalledProcessError:
# pkg-config already prints the missing libraries on stderr.
return False
command = [os.environ.get("CC", "cc")] + cflags + ["-E", "-"]
with TemporaryFile("w+") as c_file:
c_file.write("#include <%s>" % header)
c_file.seek(0)
try:
return call(command, stdin=c_file, stdout=DEVNULL, stderr=DEVNULL) == 0
except FileNotFoundError:
print("%s headers not found." % library_name)
return False
class Build(build_py):
def run(self):
self.run_command("build_ext")
return super().run()
def initialize_options(self):
super().initialize_options()
has_python_headers = check_include("python3", "Python.h")
has_stringprep_headers = check_include("libidn", "stringprep.h")
if has_python_headers and has_stringprep_headers:
self.distribution.ext_modules = cythonize("slixmpp/stringprep.pyx")
else:
print("Falling back to the slow stringprep module.")

View File

@@ -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>
@@ -1012,56 +1012,56 @@
<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> </Version>
</release> </release>
<release> <release>
<Version> <Version>
<revision>1.8.1</revision> <revision>1.8.1</revision>
<created>2022-03-20</created> <created>2022-03-20</created>
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.8.1/slixmpp-slix-1.8.1.tar.gz"/> <file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.1.tar.gz"/>
</Version> </Version>
</release> </release>
<release> <release>
<Version> <Version>
<revision>1.8.2</revision> <revision>1.8.2</revision>
<created>2022-04-06</created> <created>2022-04-06</created>
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.8.2/slixmpp-slix-1.8.2.tar.gz"/> <file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.2.tar.gz"/>
</Version> </Version>
</release> </release>
<release> <release>
<Version> <Version>
<revision>1.8.3</revision> <revision>1.8.3</revision>
<created>2022-11-12</created> <created>2022-11-12</created>
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.8.3/slixmpp-slix-1.8.3.tar.gz"/> <file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.3.tar.gz"/>
</Version> </Version>
</release> </release>
<release> <release>
<Version> <Version>
<revision>1.8.4</revision> <revision>1.8.4</revision>
<created>2023-05-28</created> <created>2023-05-28</created>
<file-release rdf:resource="https://lab.louiz.org/poezio/slixmpp/-/archive/slix-1.8.4/slixmpp-slix-1.8.4.tar.gz"/> <file-release rdf:resource="https://codeberg.org/poezio/slixmpp/archive/slix-1.8.4.tar.gz"/>
</Version> </Version>
</release> </release>
</Project> </Project>

View File

@@ -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

View File

@@ -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::

View File

@@ -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

View File

@@ -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+,

View File

@@ -1,15 +0,0 @@
[mypy]
check_untyped_defs = False
ignore_missing_imports = True
[mypy-slixmpp.types]
ignore_errors = True
[mypy-slixmpp.thirdparty.*]
ignore_errors = True
[mypy-slixmpp.plugins.*]
ignore_errors = True
[mypy-slixmpp.plugins.base]
ignore_errors = False

67
pyproject.toml Normal file
View File

@@ -0,0 +1,67 @@
[project]
name = "slixmpp"
version = "1.8.4"
description = 'Slixmpp is an elegant Python library for XMPP (aka Jabber).'
requires-python = ">=3.7"
dependencies = [
"aiodns >= 1.0",
"pyasn1",
"pyasn1_modules",
"typing_extensions; python_version < '3.8.0'",
]
classifiers = [
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Internet :: XMPP',
'Topic :: Software Development :: Libraries :: Python Modules',
]
readme = "README.rst"
license = { file = "LICENSE" }
[[project.authors]]
name = "Florent Le Coz"
email = "louiz@louiz.org"
[project.urls]
Repository = 'https://codeberg.org/poezio/slixmpp'
[project.optional-dependencies]
XEP-0363 = ['aiohttp']
XEP-0444 = ['emoji']
XEP-0454 = ['cryptography']
Safer-XML-parsing = ['defusedxml']
[build-system]
requires = ["setuptools", "cython"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
packages = ["slixmpp"]
py-modules = ["_custom_build"]
[tool.setuptools.cmdclass]
build_py = "_custom_build.Build"
[tool.mypy]
check_untyped_defs = false
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = 'slixmpp.types'
ignore_errors = true
[[tool.mypy.overrides]]
module = 'slixmpp.thirdparty.*'
ignore_errors = true
[[tool.mypy.overrides]]
module = 'slixmpp.plugins.*'
ignore_errors = true
[[tool.mypy.overrides]]
module = 'slixmpp.plugins.base'
ignore_errors = false

103
setup.py
View File

@@ -1,103 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2011 Nathanael C. Fritz
# All Rights Reserved
#
# This software is licensed as described in the README.rst and LICENSE
# file, which you should have received as part of this distribution.
import runpy
import os
from pathlib import Path
from subprocess import call, DEVNULL, check_output, CalledProcessError
from tempfile import TemporaryFile
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from run_tests import TestCommand
version_mod = runpy.run_path('slixmpp/version.py')
VERSION = version_mod['__version__']
DESCRIPTION = ('Slixmpp is an elegant Python library for XMPP (aka Jabber).')
with open('README.rst', encoding='utf8') as readme:
LONG_DESCRIPTION = readme.read()
CLASSIFIERS = [
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Internet :: XMPP',
'Topic :: Software Development :: Libraries :: Python Modules',
]
packages = [str(mod.parent) for mod in Path('slixmpp').rglob('__init__.py')]
def check_include(library_name, header):
command = [os.environ.get('PKG_CONFIG', 'pkg-config'), '--cflags', library_name]
try:
cflags = check_output(command).decode('utf-8').split()
except FileNotFoundError:
print('pkg-config not found.')
return False
except CalledProcessError:
# pkg-config already prints the missing libraries on stderr.
return False
command = [os.environ.get('CC', 'cc')] + cflags + ['-E', '-']
with TemporaryFile('w+') as c_file:
c_file.write('#include <%s>' % header)
c_file.seek(0)
try:
return call(command, stdin=c_file, stdout=DEVNULL, stderr=DEVNULL) == 0
except FileNotFoundError:
print('%s headers not found.' % library_name)
return False
HAS_PYTHON_HEADERS = check_include('python3', 'Python.h')
HAS_STRINGPREP_HEADERS = check_include('libidn', 'stringprep.h')
ext_modules = None
if HAS_PYTHON_HEADERS and HAS_STRINGPREP_HEADERS:
try:
from Cython.Build import cythonize
except ImportError:
print('Cython not found, falling back to the slow stringprep module.')
else:
ext_modules = cythonize('slixmpp/stringprep.pyx')
else:
print('Falling back to the slow stringprep module.')
setup(
name="slixmpp",
version=VERSION,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
author='Florent Le Coz',
author_email='louiz@louiz.org',
url='https://lab.louiz.org/poezio/slixmpp',
license='MIT',
platforms=['any'],
package_data={'slixmpp': ['py.typed']},
packages=packages,
ext_modules=ext_modules,
install_requires=[
'aiodns>=1.0',
'pyasn1',
'pyasn1_modules',
'typing_extensions; python_version < "3.8.0"',
],
extras_require={
'XEP-0363': ['aiohttp'],
'XEP-0444 compliance': ['emoji'],
'XEP-0454': ['cryptography'],
'Safer XML parsing': ['defusedxml'],
},
classifiers=CLASSIFIERS,
cmdclass={'test': TestCommand}
)

View File

@@ -285,7 +285,7 @@ class BaseXMPP(XMLStream):
if plugin in plugins.PLUGINS: 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."""

View File

@@ -101,6 +101,7 @@ PLUGINS = [
'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_0402', # PEP Native Bookmarks
'xep_0403', # MIX-Presence 'xep_0403', # MIX-Presence
@@ -115,6 +116,7 @@ PLUGINS = [
'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_0447', # Stateless file sharing
'xep_0461', # Message Replies 'xep_0461', # Message Replies
# Meant to be imported by plugins # Meant to be imported by plugins
] ]

View File

@@ -187,7 +187,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)

View File

@@ -1,3 +1,5 @@
from typing import Optional
from slixmpp.stanza import Message from slixmpp.stanza import Message
from slixmpp.xmlstream import ElementBase, register_stanza_plugin from slixmpp.xmlstream import ElementBase, register_stanza_plugin
@@ -38,9 +40,22 @@ class FeatureFallBack(ElementBase):
else: else:
return body return body
def add_quoted_fallback(self, fallback: str): def add_quoted_fallback(self, fallback: str, nickname: Optional[str] = None):
"""
Add plain text fallback for clients not implementing XEP-0461.
``msg["feature_fallback"].add_quoted_fallback("Some text", "Bob")`` will
prepend "> Bob:\n> Some text\n" to the body of the message, and set the
fallback_body attributes accordingly, so that clients implementing
XEP-0461 can hide the fallback text.
:param fallback: Body of the quoted message.
:param nickname: Optional, nickname of the quoted participant.
"""
msg = self.parent() msg = self.parent()
quoted = "\n".join("> " + x.strip() for x in fallback.split("\n")) + "\n" quoted = "\n".join("> " + x.strip() for x in fallback.split("\n")) + "\n"
if nickname:
quoted = "> " + nickname + ":\n" + quoted
msg["body"] = quoted + msg["body"] msg["body"] = quoted + msg["body"]
msg["feature_fallback"]["for"] = NS msg["feature_fallback"]["for"] = NS
msg["feature_fallback"]["fallback_body"]["start"] = 0 msg["feature_fallback"]["fallback_body"]["start"] = 0

View File

@@ -1,5 +0,0 @@
[tox]
envlist = py34
[testenv]
deps = nose
commands = nosetests --where=tests --exclude=live -i slixtest.py