473,382 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Problem with Twisted

Hello. I have something like that:

from twisted.words.protocols.jabber import xmlstream
from twisted.internet import protocol
from twisted.words.xish import domish, utility
from twisted.internet import reactor
from twisted.python import log
import sys, hashlib
log.startLogging(sys.stdout)
def magicHash(password, sid):
magic1 = 0x50305735
magic2 = 0x12345671
sum = 7
for s in range(len(password)):
z = ord(password[s]);
if (z == ' '):
continue
if (z == '\t'):
continue
magic1 = magic1 ^ ((((magic1 & 0x3f) + sum) * z) + (magic1
<< 8))
magic2 = magic2 + ((magic2 << 8) ^ magic1)
sum += z
magic1 = magic1 & 0x7fffffff
magic2 = magic2 & 0x7fffffff

return ('%08x%08x'%(magic1, magic2))

def ping(xmlstream):
print 'ping'
xmlstream.send(' \t ')
reactor.callLater(40, ping, xmlstream)

class TlenAuthInitializer(object):
def __init__(self, xs):
print "Wykonywanie TlenAuthInitializer"
self.xmlstream = xs
def initialize(self):
print "Wykonywanie TlenAuthInitializer - initialize"
iq = xmlstream.IQ(self.xmlstream, "set")
print '1'
iq['id'] = self.xmlstream.sid
print '2'
q = iq.addElement('query', 'jabber:iq:auth')
print '3'
q.addElement('username', content = self.xmlstream.authenticator.jid)
print '4'
q.addElement('digest', content =
hashlib.sha1(magicHash(self.xmlstream.authenticato r.password,
self.xmlstream.sid)).hexdigest())
print '4'
q.addElement('resource', content = 't')
print '6'
q.addElement('host', content = 'tlen.pl')
print q.toXml(prefixes=self.prefixes, closeElement=0)
print '7'
d = iq.send('q')
print '8'
d.addCallback(self._authreply)
print '9'
d.addErrBack(self._authfail)
print '10'

def _authreply(self, el):
print "Wykonywanie TlenAuthInitializer - _authreply"
print el.toXml()
reactor.callLater(40, ping, self.xmlstream)

def _authfail(self, el):
print "Wykonywanie TlenAuthInitializer - _authfail"
print el.toXml()

class TlenAuthenticator(xmlstream.ConnectAuthenticator):
def __init__(self, jid, password, host):
print "Wykonywanie TlenAuthenticator"
xmlstream.ConnectAuthenticator.__init__(self, host)
self.jid = jid
self.password = password

def associateWithStream(self, xs):
print "Wykonywanie TlenAuthenticator - associateWithStream"
xs.version = (0, 0)
xmlstream.ConnectAuthenticator.associateWithStream (self, xs)

inits = [(TlenAuthInitializer, True)]
for initClass, required in inits:
init = initClass(xs)
init.required = required
xs.initializers.append(init)

class TlenStream(xmlstream.XmlStream):
def sendHeader(self):
print "Wykonywanie TlenStream - sendHeader"
rootElem = domish.Element((None, 's'))
rootElem['v'] = '9'
rootElem['t'] = '06000224'
self.rootElem = rootElem
self.send(rootElem.toXml(prefixes=self.prefixes, closeElement=0))
self._headerSent = True
print 'XMLed rootElem from sendHeader
'+rootElem.toXml(prefixes=self.prefixes, closeElement=0)

def sendFooter(self):
print "Wykonywanie TlenStream - sendFooter"
self.send('</s>')

def onDocumentStart(self, rootelem):
print "Wykonywanie TlenStream - onDocumentStart"
xmlstream.XmlStream.onDocumentStart(self, rootelem)
print 'rootelem from onDocumentStart '+rootelem.toXml()
if rootelem.hasAttribute("i"):
self.sid = rootelem["i"]
self.authenticator.streamStarted(rootelem)

class TlenStreamFactory(xmlstream.XmlStreamFactory):
def __init__(self, authenticator):
print "Wykonywanie TlenStreamFactory"
xmlstream.XmlStreamFactory.__init__(self, authenticator)
self.authenticator = authenticator
def buildProtocol(self, _):
print "Wykonywanie TlenStreamFactory - buildProtocol"
self.resetDelay()
# Create the stream and register all the bootstrap observers
xs = TlenStream(self.authenticator)
xs.factory = self
for event, fn in self.bootstraps: xs.addObserver(event, fn)
return xs

def lg(el):
print 'all>',el
def err(el):
print 'err>', el
factory = TlenStreamFactory(TlenAuthenticator('portsentry',
'linux1991','s1.tlen.pl' ))
factory.addBootstrap('/*', lg)

reactor.connectTCP('s1.tlen.pl', 443, factory)
reactor.run()

Now... I have problem with that. It not print me any errors but there
is something with d = iq.send('q') on TlenAuthInitializer -
initialize. I dont know why but python print me just "6" and stops...
its strange... anyone have suggestions?
Sep 1 '08 #1
0 796

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fazer | last post by:
Hello, I am very interested in fooling around with Twisted Matrix's HTTP Web Server. I was thinking if .rpy scripts would run much faster than traditional CGI scripts? After looking how...
2
by: Mark Carter | last post by:
I'm trying to create a mail server in Twisted. I either get SMTPSenderRefused or SMTPException: SMTP AUTH extension not supported by server. What do I need to do to get it to work?
2
by: Taki Jeden | last post by:
Hi Anybody used wxPython with twisted? I started putting together a Twisted-based app with wx GUI, and the widgets just don't work - some controls do not show up etc. - at least on my system....
2
by: SeSe | last post by:
Hi, I am new to Twisted. I use a Twisted 1.3.0 on MS Windows XP Home Edition, my python version is 2.3 I try the TCP echoserv.py and echoclient.py example. But the client always fail with...
13
by: Bob Greschke | last post by:
We have some equipment that communicates at 57600 baud RS232. The path from the PC is USB to a Phillips USB hub, then off of that a TUSB3410 USB/Serial converter. The driver for the 3410 chip...
1
by: PeterG | last post by:
Hi, I am relatively new to Python, and am learning it as part of a university module... Im currently undertaking a project to create an IM server and IM gui client. I have a very basic...
0
by: huisan.wang | last post by:
Hello everyone, I am writing a program with twisted and dbus and got a such problem. If i run the code as $python local_proxy.py There is an error like this: Traceback (most recent call...
2
by: Jean-Paul Calderone | last post by:
On Mon, 12 May 2008 11:16:08 -0700 (PDT), petr.poupa@gmail.com wrote: I'm not sure if you need to write a server or a client. In your original code, you had a client which repeatedly established...
1
by: Jean-Paul Calderone | last post by:
On Fri, 21 Nov 2008 00:20:49 -0200, Gabriel Genellina <gagsl-py2@yahoo.com.arwrote: If you want to try this program out on POSIX, make sure you change the time.clock() calls to time.time() calls...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.