Ho bisogno di collegarmi alla mia applicazione twisted in fase di esecuzione e sto cercando di ottenere twisted.manhole affinché funzioni per quello scopo. Sono su Mac OSX 10.6 con twistato 8.2 come installato di default.tombino a spirale: come accedere ai server nell'applicazione?
Il sample server using twistd funziona. Ci sono DeprecationWarnings all'avvio su md5, sha e twisted.protocols.telnet, ma il server passo d'uomo faccia veramente ciò che si suppone e posso accedere interni della mia domanda:
host:client user$ telnet localhost 4040
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
twisted.manhole.telnet.ShellFactory
Twisted 8.2.0
username: admin
password: *****
>>> dir()
['_', '__builtins__', 'factory', 'service']
>>> factory
<twisted.manhole.telnet.ShellFactory instance at 0x101256440>
>>> service
<twisted.application.internet.TCPServer instance at 0x10124ff38>
>>> service.parent
<twisted.application.service.MultiService instance at 0x1014b0cf8>
>>>
Ora cerco di integrare questo principio in la mia domanda:
# test_manhole.tac
from twisted.application.internet import TCPServer
from twisted.application.service import Application, IServiceCollection
from twisted.manhole.telnet import ShellFactory
shell_factory = ShellFactory()
shell_factory.username = 'admin'
shell_factory.password = 'admin'
shell_factory.namespace['some_value'] = 42
shell_tcp_server = TCPServer(4040, shell_factory)
application = Application('test')
serviceCollection = IServiceCollection(application)
shell_tcp_server.setServiceParent(serviceCollection)
eseguire il codice di cui sopra in un guscio:
host:server user$ twistd -noy test_manhole.tac
(omitting the same DeprecationWarnings about md5, sha and twisted.protocols.telnet as earlier)
2011-08-24 16:52:13+1000 [-] Log opened.
2011-08-24 16:52:13+1000 [-] twistd 8.2.0 (/usr/bin/python2.6 2.6.1) starting up.
2011-08-24 16:52:13+1000 [-] reactor class: twisted.internet.selectreactor.SelectReactor.
2011-08-24 16:52:13+1000 [-] twisted.manhole.telnet.ShellFactory starting on 4040
2011-08-24 16:52:13+1000 [-] Starting factory <twisted.manhole.telnet.ShellFactory instance at 0x1012cfdd0>
2011-08-24 16:52:13+1000 [-] start service: <twisted.application.internet.TCPServer instance at 0x1012cff80>
in un secondo guscio, eseguire un client telnet:
0.123.516,410617 millionshost:client user$ telnet localhost 4040
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
twisted.manhole.telnet.ShellFactory
Twisted 8.2.0
username: admin
password: *****
>>> dir()
['_', '__builtins__', 'factory', 'service', 'some_value']
>>> factory
<twisted.manhole.telnet.ShellFactory instance at 0x1012cfdd0>
>>> service
>>> service == None
True
>>> service.parent
...
exceptions.AttributeError: 'NoneType' object has no attribute 'parent'
>>> some_value
42
Quindi sembra che l'oggetto servizio non sia utilizzabile per accedere agli interni dell'applicazione.
OK, dal momento che twisted.protocols.telnet
sembra comunque essere stata sostituita da twisted.conch.telnet
, provare a utilizzare il modulo più recente:
# test_manhole_2.tac
from twisted.application.service import Application, IServiceCollection
from twisted.conch.manhole_tap import makeService
options = \
{
# for some reason, these must
# all exist, even if None
'namespace' : None,
'passwd' : 'users.txt',
'sshPort' : None,
'telnetPort' : '4040',
}
shell_service = makeService(options)
application = Application('test')
serviceCollection = IServiceCollection(application)
shell_service.setServiceParent(serviceCollection)
Il 'file di password' users.txt
può contenere non più di una riga con un nome utente e una password del campione, per esempio admin:admin
.
avviare il server di test:
host:server user$ twistd -noy test_manhole_2.tac
(omitting DeprecationWarnings about md5 and sha)
2011-08-24 17:44:26+1000 [-] Log opened.
2011-08-24 17:44:26+1000 [-] twistd 8.2.0 (/usr/bin/python2.6 2.6.1) starting up.
2011-08-24 17:44:26+1000 [-] reactor class: twisted.internet.selectreactor.SelectReactor.
2011-08-24 17:44:26+1000 [-] twisted.internet.protocol.ServerFactory starting on 4040
2011-08-24 17:44:26+1000 [-] Starting factory <twisted.internet.protocol.ServerFactory instance at 0x10181e710>
2011-08-24 17:44:26+1000 [-] start service: <twisted.application.service.MultiService instance at 0x1012553b0>
2011-08-24 17:44:26+1000 [-] start service: <twisted.application.internet.TCPServer instance at 0x10181e998>
In un secondo guscio, eseguire un client telnet - notare che alcune di queste è in realtà congetture come readline buggy Mac OSX (o qualsiasi altra cosa è il dare la colpa) sembra a ingoiare qualche uscita della shell:
host:client user$ telnet localhost 4040
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Username: admin
Password: *****
>>> dir()
['__builtins__']
Così ora sembra sono passato da avere un service
oggetto inutile nessun oggetto.
Come si usa twisted.manhole correttamente?
Solo per curiosità, la password è "admin"? –
sì. continuo a utilizzare la porta 4040, l'admin del nome utente e l'amministratore della password. – ssc