나는 표준 대기열에 들어오는 메시지를 인쇄하는 기본 jabber 계정을 초기화하는 클래스 MyJabber를 가지고 있습니다. 내가 응용 프로그램을 실행하면올바른 방법으로 트위스트 반응기를 초기화하는 방법은 무엇입니까?
jabber = MyJabber(options, to_irc)
jabber.addReactor()
reactor.run()
내가 addReactor의 '인쇄'를 볼 수 있지만 :
def addReactor(self):
print 'inside AddReactor'
factory = client.basicClientFactory(self.jid, self.option['jabber']['password'])
print "factory initialized"
factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authd)
print 'factory bootsraped'
reactor.connectTCP(self.option['jabber']['server'], 5222, factory)
가 이런 식으로라고 :
반응기에 클라이언트를 추가하는 코드는 다음입니다 그 후 더 이상 아무것도.
def authd(self, xmlstream):
global thexmlstream
thexmlstream = xmlstream
# need to send presence so clients know we're
# actually online.
print 'Initializing...'
presence = domish.Element(('jabber:client', 'presence'))
presence.addElement('status').addContent('Online')
xmlstream.send(presence)
# add a callback for the messages
print 'Add gotMessaged callback'
xmlstream.addObserver('/message', gotMessage)
print 'Add * callback'
xmlstream.addObserver('/*', gotSomething)
참고 측면 : 내가 클래스 정의를 변경하고, 내가 하나의 응용 프로그램으로 코드를 사용하는 경우 , 그것은 잘 작동 . 원자로 코드에 문제 없습니다. 왜냐하면 모든 프로토콜에 의해 공유되는 구성 요소이기 때문에 원자로 구성 요소가 클래스 정의 외부에서도 활성화 될 수 있기 때문입니다. 그러나 그것은 달려있다. 질문의 요점은 원자로와 관련되어 있습니다 :) xmpp 코드가 잘 작동합니다. – giskard
"클래스 정의 외부"또는 ("내재 된)"클래스 정의 내부에는 근본적인 차이점이 없습니다. 하나의 접근 방식을 취하는 코드 버전이 다른 접근 방식을 사용하는 동안 작동하지 않는다면 하나에서 다른 버전으로 변환 할 때 몇 가지 버그가 발생했습니다. 하지만 여기 게시 한 코드를 읽는 것만으로도 어떤 버그인지 알 수있는 방법이 없습니다. –