472,354 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 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 763

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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.