jajcus / pyxmpp Goto Github PK
View Code? Open in Web Editor NEWXMPP implementation for Python
Home Page: http://pyxmpp.jajcus.net/
License: GNU Lesser General Public License v2.1
XMPP implementation for Python
Home Page: http://pyxmpp.jajcus.net/
License: GNU Lesser General Public License v2.1
In the xmppstringprep.py file I've notice a probable bug in bidi_check function:
in the 231 and 233 lines the code assign 1 in has_l line, but the 231 lines should be assign this value to has_ral, I think.
I would like to simple include ''pyxmpp'' in my ''zc.buildout'' configs without defining the download URI in the ''dependency_links'' section. You guys already have a pypi account but do not provide a download link also your snapshot names seem to have no valid version string, could you change them to use svn revision numbers or something setuptools can understand?
Also would it be possible to include your dependencies in the ''install_requires'' section of the setup.py file? A patch for that is attached.
When type == None it said to be treated as "normal" but the assignment is incorrect:
{{{
if not typ:
typ=="normal"
}}}
should be:
{{{
if not typ:
typ="normal"
}}}
on client connect with pyxmpp to a jabberd2 server, a "no nonce" error ococurs.
this is because the parser returns " charset" " user" and so one...
the simple strimcompare fails.
I add a small strip.
I dont know if this breaks something: but it works.
I already build at the ComponentStream...
(with an very old version I hacked component 2.0 support in)
(but with current this doenst work - i will expect this later)
patch:
--- pyxmpp/sasl/digest_md5.py (Revision 677)
+++ pyxmpp/sasl/digest_md5.py (Arbeitskopie)
@@ -254,6 +254,7 @@
var=m.group("var")
val=m.group("val")
self.__logger.debug("%r: %r" % (var,val))
var=var.lstrip(' ');
if var=="realm":
realms.append(_unquote(val))
elif var=="nonce":
Questions(jabber*G): white at addoma.de
Adding the following code to the script removes the error:
import logging
logging.basicConfig()
I don't get the error with 'echobot.py' which has the 'import logging' line.
{{{
from pyxmpp.jabber.vcard import VCard, VCardName
v = VCard('')
n = VCardName('N', '')
n.given = 'Christopher; a semi-colon and a sentence, too.'
v.content['N'] = n
v.as_xml().serialize()
'\nChristopher; a semi-colon and a sentence, too.\n'
xml = [c for c in v.as_xml().children][0] #list comprehension to compensate for \nChristopher; a semi-colon and a sentence, too.Christopher; a semi-colon and a sentence, too.\n'
v.rfc2426()
'begin:VCARD\r\nversion:3.0\r\nn:;Christopher; a semi-colon and a sentence, too.;;;\r\nend:VCARD\r\n'
v3 = VCard(v.rfc2426())
Traceback (most recent call last):
File "", line 1, in
File "C:\workspace\lib\pyxmpp\jabber\vcard.py", line 1363, in init
self.n = None
File "C:\workspace\lib\pyxmpp\jabber\vcard.py", line 1477, in from_rfc2426
continue
File "C:\workspace\lib\pyxmpp\jabber\vcard.py", line 1508, in _process_rfc2425_record
if params:
File "C:\workspace\lib\pyxmpp\jabber\vcard.py", line 303, in __init
n=n.next
ValueError: too many values to unpack
}}}
since the semicolons are not backslash escaped, nor unescaped, string values with ';' in them cannot be handled properly.
a regex which can be used to properly split strings with escaped semicolons using a negative lookbehind assertion:
{{{non_quoted_semicolon_re=re.compile(r'(?<!);')}}}
I'll append patches and such as I finalize my fixes.
"When using the SASL SCRAM mechanism, the SCRAM-SHA-256-PLUS variant SHOULD be preferred over the SCRAM-SHA-256 variant, and SHA-256 variants [RFC7677] SHOULD be preferred over SHA-1 variants [RFC5802]".
There is not SCRAM-SHA-1(-PLUS):
There is not SCRAM-SHA-256(-PLUS):
I add SCRAM-SHA-512(-PLUS): https://xmpp.org/extensions/inbox/hash-recommendations.html
Linked to:
As in summary. Documentation for Stanza.get_from_jid() states that this method returns a unicode object, when in fact pyxmpp.jid.JID is returned.
Hi,
I'm writing a simple client and I'm using an account on jabster.pl for testing. It seems however that check for the source JID in Client._roster_push is a little bit overzelous. The problem appears when one wants to connect to a specified resource name.
It raises ClientError exception which causes the roster push to fail and crashes the application (yes, I know it can be catched around loop_iter). The if check should look if the roster doesn't come from a substring of the JID or something.
The backtrace:
2009-03-03 21:57:38,302 DEBUG [streambase] IN: ""
2009-03-03 21:57:38,306 DEBUG [streamtls] OUT: '<default1:query xmlns="jabber:iq:roster" xmlns:default1="jabber:iq:roster"><default1:item subscription="none" jid="[email protected]"/>/default1:query'
Traceback (most recent call last):
File "/home/neuro/workspace/smoa-dev-node/src/smoa-dev-node.py", line 125, in
main()
File "/home/neuro/workspace/smoa-dev-node/src/smoa-dev-node.py", line 63, in main
core_obj.loop()
File "/home/neuro/workspace/smoa-dev-node/src/core/core.py", line 97, in loop
self.tmanager.iter_all()
File "/home/neuro/workspace/smoa-dev-node/src/core/transportmanager.py", line 45, in iter_all
obj.iter()
File "/home/neuro/workspace/smoa-dev-node/src/transport/xmpp.py", line 61, in iter
self._client.stream.loop_iter(1)
File "usr/lib/python2.6/site-packages/pyxmpp/streambase.py", line 598, in loop_iter
File "usr/lib/python2.6/site-packages/pyxmpp/streambase.py", line 616, in _loop_iter
File "usr/lib/python2.6/site-packages/pyxmpp/streamtls.py", line 179, in _process
File "usr/lib/python2.6/site-packages/pyxmpp/streambase.py", line 637, in _process
File "usr/lib/python2.6/site-packages/pyxmpp/streamtls.py", line 174, in _read
File "usr/lib/python2.6/site-packages/pyxmpp/streambase.py", line 661, in _read
File "usr/lib/python2.6/site-packages/pyxmpp/streambase.py", line 677, in _feed_reader
File "usr/lib/python2.6/site-packages/pyxmpp/xmlextra.py", line 537, in feed
File "usr/lib/python2.6/site-packages/pyxmpp/xmlextra.py", line 57, in _stanza
File "usr/lib/python2.6/site-packages/pyxmpp/streambase.py", line 401, in stanza
File "usr/lib/python2.6/site-packages/pyxmpp/stream.py", line 107, in _process_node
File "usr/lib/python2.6/site-packages/pyxmpp/streambase.py", line 710, in _process_node
File "usr/lib/python2.6/site-packages/pyxmpp/stanzaprocessor.py", line 271, in process_stanza
File "usr/lib/python2.6/site-packages/pyxmpp/stanzaprocessor.py", line 141, in process_iq
File "usr/lib/python2.6/site-packages/pyxmpp/client.py", line 346, in __roster_push
pyxmpp.exceptions.ClientError: Got roster update from wrong source
When I connected to jabber.org server(ejabberd server), the pyxmpp library can not handle rosters list. my suggestion :
change file pyxmpp\stanzaprocessor.py line 112:
'' elif ( (fr==self.peer or fr==self.me)''
to:
''elif ( (fr==self.peer or fr==self.me or fr.bare() == self.me.bare())''
will fix the bug.
lines 489 and 490 need to be reversed in [source:trunk/pyxmpp/jabber/vcard.py##L489 vcard.py]
{{{
value=[""]_7
v=value.split(";")
}}}
should be
{{{
v=value.split(";")
value=[""]_7
}}}
Hi,
I'm working on jabberd2 to implement c2s SASL external authentication based on TLS certificates.
I've used pyxmpp as the testing library for the connections and I can only say it works :)
Implemented stuff:
The following stadards were used:
The following patch is made against pyxmpp-1.0.1 release tarball. I'm also attaching a testing script which successfully connects to my modified jabberd2 server (patches to that server will be posted soon).
pyxmpp.revision is constructed using a
Forwarded message from Debian bug #530498
From: Tim Retout [email protected]
To: Debian Bug Tracking System [email protected]
Subject: python-pyxmpp-doc: echobot.py fails on "normal" message type
Date: Mon, 25 May 2009 08:34:59 +0100
Package: python-pyxmpp-doc
Version: 1.0.1-1
Severity: minor
Tags: patch
There's a small problem in the echobot.py example script when the
received message is the "normal" type. This is the end of the stack
trace:
File "echobot.py", line 75, in message
print u'Type: "normal".' % (t,)
TypeError: not all arguments converted during string formatting
Here is a fix:
--- examples/echobot.py.orig 2009-05-25 08:24:16.000000000 +0100
+++ examples/echobot.py 2009-05-25 08:25:17.000000000 +0100
@@ -72,7 +72,7 @@
if t:
print u'Type: "%s".' % (t,)
else:
print u'Type: "normal".' % (t,)
print u'Type: "normal".'
if stanza.get_type()=="headline":
# 'headline' messages should never be replied to
return True
SVN commits and Trac ticket changes notifications should be tested.
[source:trunk/pyxmpp/jabber/vcard.py##L394 line 394 of vcard.py] fails when there is no key {{{"value"}}} in the {{{rfc2425parameters}}} dict object. The current code below:
{{{
if rfc2425parameters.get("value").lower()=="uri":
}}}
when {{{"value"}}} does not exist in the dictionary, {{{get("value")}}} returns {{{None}}}, resulting in {{{None.lower()}}} which finally throws an exception:
{{{
AttributeError: 'NoneType' object has no attribute 'lower'
}}}
This is caused by the default return value from get, which itself defaults to {{{None}}}. My fix is to include a default value of empty string:
{{{
if rfc2425parameters.get("value", '').lower()=="uri":
I also had some trouble with not all of the attributes being initialized when parsing from !rfc2425 versions, my fix is to move the initialization with {{{None}}} out of the if statement on [source:trunk/pyxmpp/jabber/vcard.py##L370 line 370 of vcard.py].
{{{
if isinstance(value,libxml2.xmlNode):
self.uri,self.type,self.image=[None]_3
}}}
becomes
{{{
self.uri,self.type,self.image=[None]_3
if isinstance(value,libxml2.xmlNode):
}}}
I needed thread-safety for timeout callbacks, to ensure that only one of the response/error/timeout callbacks can be called.
The patches are centered around the implementation of {{{dict.pop()}}} for the {{{ExpiringDictionary}}} and transactional removal from the dictionary before doing callbacks. This prevents another callback from being called while the first one is in progress.
patches attached.
python 2.6 and pyxmpp 1.0.1 results in
{{{
.../pyxmpp/jabberd/componentstream.py:27: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
}}}
pls fix :)
in processing input bind result stanza:
[email protected]/pyxmpp
to="myserver.com/838805ce" field was incorrect processed.
suggestion :
insert after stanzaprocessor.py line 265 :
if to and to.node == None :
to = None
hi, I'm looking some way to monitor raw xml stream, and noticed that in changelog of 2003:
2003-08-08 08:02 +0000 [r96] Jacek Konieczny [email protected]
* pyxmpp/stream.py:
- data_in() and data_out() methods to override for 'raw XML
console'
but data_in() and data_out methods are missing in the new version.
How can I monitor the raw xml stream?
Hi,
I'm working on jabberd2 to implement c2s SASL external authentication based on TLS certificates.
I've used pyxmpp as the testing library for the connections and I can only say it works :)
Implemented stuff:[[BR]]
The following stadards were used:[[BR]]
The following patch is made against pyxmpp-1.0.1 release tarball. I'm also attaching a testing script which successfully connects to my modified jabberd2 server (patches to that server will be posted soon).
when using function roster.add_item:
may be passed. instead, when using function roster.remove_item:
=> roster.remove_item should comply and accept:
r.
test
Please add support of XEP-0443: XMPP Compliance Suites 2021: https://xmpp.org/extensions/xep-0443.html
Which replaces:
iq with unknown type makes jabber loop throw exception.
how to reproduce:
send such iq from Psi XML console:
and application listening on [email protected]/someresource will exit with such traceback:
Traceback (most recent call last):
File "core.py", line 28, in ?
jab.loop(1)
File "/usr/lib/python2.4/site-packages/pyxmpp/client.py", line 240, in loop
act=stream.loop_iter(timeout)
File "/usr/lib/python2.4/site-packages/pyxmpp/streambase.py", line 619, in loop_iter
return self._loop_iter(timeout)
File "/usr/lib/python2.4/site-packages/pyxmpp/streambase.py", line 637, in _loop_iter
self._process()
File "/usr/lib/python2.4/site-packages/pyxmpp/streamtls.py", line 178, in _process
StreamBase._process(self)
File "/usr/lib/python2.4/site-packages/pyxmpp/streambase.py", line 658, in _process
self._read()
File "/usr/lib/python2.4/site-packages/pyxmpp/streamtls.py", line 173, in _read
StreamBase._read(self)
File "/usr/lib/python2.4/site-packages/pyxmpp/streambase.py", line 682, in _read
self._feed_reader(r)
File "/usr/lib/python2.4/site-packages/pyxmpp/streambase.py", line 698, in _feed_reader
r=self._reader.feed(data)
File "/usr/lib/python2.4/site-packages/pyxmpp/xmlextra.py", line 539, in feed
return self.reader.feed(s)
File "/usr/lib/python2.4/site-packages/pyxmpp/xmlextra.py", line 59, in _stanza
self.stanza(doc,node)
File "/usr/lib/python2.4/site-packages/pyxmpp/streambase.py", line 422, in stanza
self._process_node(node)
File "/usr/lib/python2.4/site-packages/pyxmpp/stream.py", line 107, in _process_node
StreamBase._process_node(self,xmlnode)
File "/usr/lib/python2.4/site-packages/pyxmpp/streambase.py", line 731, in _process_node
self.process_stanza(stanza)
File "/usr/lib/python2.4/site-packages/pyxmpp/stanzaprocessor.py", line 235, in process_stanza
if self.process_iq(stanza):
File "/usr/lib/python2.4/site-packages/pyxmpp/stanzaprocessor.py", line 111, in process_iq
r=stanza.make_error_response("feature-not-implemented")
File "/usr/lib/python2.4/site-packages/pyxmpp/iq.py", line 99, in make_error_response
raise StanzaError,"Errors may only be generated for 'set' or 'get' iq"
pyxmpp.stanza.StanzaError: Errors may only be generated for 'set' or 'get' iq
After successfully registering a new user pyxmpp.jabber.clientstream.LegacyClientStream incorrectly sets self.password to be an instance of pyxmpp.jabber.dataforms.Field when it should be a string. Looks like the '.value' is missing. Patch attached.
While minor, I have seen this test fail by "skipping" intermediate cache states which are expected to be visited during the test. To make the test completely reliable, we basically need to know the last "update time" for the cache item (expose the 'now' obtained in CacheItem.update_state), and make sure the clock difference corresponds to the correct cache state.
I'm attaching a sample diff for a new test and CacheItem which exposes the last cache update time (although we probably shouldn't change the internals just to get the test to pass reliably).
line 99 of echobot.py in the examples has a coding error
to see the error send a message to the id the bot logs on as then logout
run the bot and it will fail on line 99
Note: line 99 has no %s to be filled in with the variable
code should be changed from:
print u'Type: normal.' % (t,)
to
print u'Type: normal.',
xmlextra.endElement() eats exceptions, instead of letting them propagate.
While it's bad style to let exceptions get away from callbacks, it may happen and then errors don't get reported. In my case an unexpected UnicodeEncodeError from pyxmpp code itself wasn't caught in my code, wreaked some havoc and vanished without a trace. Not a pleasant thing to debug.
Relevant part of a stack from my case to illustrate the issue:
{{{
File "/home/karol/programowanie/pyxmpp/pyxmpp/xmlextra.py", line 214, in endElement
self._handler.stanza(self._doc, node1)
File "/home/karol/programowanie/pyxmpp/pyxmpp/streambase.py", line 401, in stanza
self._process_node(node)
File "/home/karol/programowanie/pyxmpp/pyxmpp/stream.py", line 107, in _process_node
StreamBase._process_node(self,xmlnode)
File "/home/karol/programowanie/pyxmpp/pyxmpp/streambase.py", line 710, in _process_node
self.process_stanza(stanza)
File "/home/karol/programowanie/pyxmpp/pyxmpp/stanzaprocessor.py", line 274, in process_stanza
if self.process_message(stanza):
File "/home/karol/programowanie/pyxmpp/pyxmpp/stanzaprocessor.py", line 209, in process_message
return self.__try_handlers(self._message_handlers,"normal",stanza)
File "/home/karol/programowanie/pyxmpp/pyxmpp/stanzaprocessor.py", line 185, in __try_handlers
response = handler(stanza)
File "/home/karol/programowanie/soc/tmp/jabberbot/xmppbot.py", line 372, in handle_message
response = self.handle_internal_command(sender, command)
File "/home/karol/programowanie/soc/tmp/jabberbot/xmppbot.py", line 402, in handle_internal_command
self.send_search_form(sender)
File "/home/karol/programowanie/soc/tmp/jabberbot/xmppbot.py", line 319, in send_search_form
message.add_content(form)
File "/home/karol/programowanie/pyxmpp/pyxmpp/stanza.py", line 303, in add_content
content.as_xml(parent = self.xmlnode, doc = common_doc)
File "/home/karol/programowanie/pyxmpp/pyxmpp/objects.py", line 91, in as_xml
self.complete_xml_element(xmlnode, doc1)
File "/home/karol/programowanie/pyxmpp/pyxmpp/jabber/dataforms.py", line 632, in complete_xml_element
xmlnode.newTextChild(ns, "title", self.title)
File "/usr/lib64/python2.3/site-packages/libxml2.py", line 3325, in newTextChild
ret = libxml2mod.xmlNewTextChild(self._o, ns__o, name, content)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u015b' in position 2: ordinal not in range(128)
}}}
{{{
pyxmpp-based handler has following code:
{{{
def _message_any(self, msg):
user = self.registry.get(jid_to_dbkey(msg.get_from()))
if user is None:
self.stream.send(msg.make_error_response('forbidden'))
return True
...
}}}
and this code produces following stanza coming to client:
{{{
As far as I understand, subject and body have incorrect namespace (and psi ignores these body and subject).
Possible hackish workaround is to call
{{{
def strip_pyxmpp_ns(stanza):
from pyxmpp.xmlextra import COMMON_NS, common_doc
namespaces = {'pyxmpp': COMMON_NS }
badnodes = stanza.xpath_eval('pyxmpp:*', namespaces)
if badnodes:
logging.debug("pyxmpp bug workaround: striping namespace from %s" % badnodes)
for node in badnodes:
nslist = node.removeNsDef(COMMON_NS)
if nslist is not None:
node.reconciliateNs(common_doc)
nslist.freeNsList()
}}}
When i try use pyxmpp with pyload, i have this error:
Exception in thread Thread-5:
Traceback (most recent call last):
File "/ffp/lib/python2.7/threading.py", line 808, in __bootstrap_inner
self.run()
File "/i-data/0a3e5834/ffp@apps/pyload/module/plugins/hooks/XMPPInterface.py", line 97, in run
self.connect()
File "/ffp/lib/python2.7/site-packages/pyxmpp/jabber/client.py", line 110, in connect
Client.connect(self, register)
File "/ffp/lib/python2.7/site-packages/pyxmpp/client.py", line 150, in connect
stream.connect()
File "/ffp/lib/python2.7/site-packages/pyxmpp/clientstream.py", line 126, in connect
self._connect(server,port)
File "/ffp/lib/python2.7/site-packages/pyxmpp/clientstream.py", line 148, in _connect
Stream._connect(self,server,port,service,self.my_jid.domain)
File "/ffp/lib/python2.7/site-packages/pyxmpp/streambase.py", line 206, in _connect
socket.SOCK_STREAM, allow_cname = allow_cname)
File "/ffp/lib/python2.7/site-packages/pyxmpp/resolver.py", line 180, in getaddrinfo
proto=socket.getprotobyname("tcp")
error: protocol not found
here is XMPPinterface.py - https://github.com/pyload/pyload/blob/stable/module/plugins/hooks/XMPPInterface.py
I istalled pyxmpp 1.1.2 via pip. What should i do ?
The following patch fixes these issues:
http://kolos.math.uni.lodz.pl/~grzywacz/pyxmpp_unicode.patch
python-lxml can deal with incremental parsing, reducing the complexity, making the code easier to use and embed.
No need for locking, no need for custom extensions.
http://codespeak.net/lxml/tutorial.html#incremental-parsing
and namespaces are much easier to deal with using lxml.
Hi there,
I've done a small patch to pyxmpp-1.0.0.s20061212 to be able to open connections to jabber servers which use tls right from the beginning on port 5223 instead of doing starttls on port 5222. It's not as neat as I'd like it to be but it seems to work. :)
Hope it's of any use to you.
PyXMPP doesn't check the return code of socket.send (in streambase.py and streamtls.py) which could result in truncated data being sent to the server. See the documentation for socket.send: "Returns the number of bytes sent. Applications are responsible for checking that all data has been sent; if only some of the data was transmitted, the application needs to attempt delivery of the remaining data."
setup.py should check dependencies and show what is missing.
According to XEP-004, Option elements can't have more than 1 element. pyxmpp uses "values" argument to Option constructor to create multiple elements, which has no use and is against the specification. Passing a single-element list containing a string is not intuitive and error prone. Passing a "vaa" string produces output like:
v a aHi, we all know vcard-temp is bad and that the -temp wants to tell us something,no need for libxml2 to issue an annoying warning everytime it sees the namespace.
It is possible to have a XEPs and RFCs support page with version (XEP-XXXX v1.2)?
Examples:
just change line 242 from[[BR]]
{{{pr=Presence(stanza_type=accept_responses[self.get_type()],}}}[[BR]]
to[[BR]]
{{{pr=Presence(stanza_type=deny_responses[self.get_type()],}}}
When using the default tls certificate verify function, the following exception appears:
Traceback (most recent call last):
File "/usr/lib64/python2.4/site-packages/pyxmpp/streamtls.py", line 376, in tls_default_verify_callback
if ok and not tls_is_certificate_valid(store_context):
It is easily fixed by adding the missing "self." in front of tls_is_certificate_valid on line 376 in streamtls.py.
I experienced the problem with pyxmpp-1.0.0.s20061212.
test
dataforms.Option.label and dataforms.Field.type are optional as per JEP-0004
dataforms.py always attaches these attributes when building the xml.
patch below:
{{{
--- pyxmpp/jabber/dataforms.py (revision 661)
+++ pyxmpp/jabber/dataforms.py (working copy)
@@ -70,7 +70,8 @@
- xmlnode
: libxml2.xmlNode
- doc
: libxml2.xmlDoc
"""
_unused = doc
xmlnode.setProp("label", self.label.encode("utf-8"))
if self.label is not None:
xmlnode.setProp("label", self.label.encode("utf-8"))
for value in self.values:
xmlnode.newTextChild(xmlnode.ns(), "value", value.encode("utf-8"))
return xmlnode
doc
: libxml2.xmlDoc
""" xmlnode.setProp("type", self.type)
if self.type is not None:
xmlnode.setProp("type", self.type)
if not self.label is None:
xmlnode.setProp("label", self.label)
if not self.name is None:
Hi,
the PyXMPP API currently on http://pyxmpp.jajcus.net/api/ seems to be quite out of date, e.g. it doesn't have anything on interfaces, which seem to be quite important in the current state of PyXMPP.
Would you might updating it?
cheers,
B.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.