2011-08-24 12 views
5

मुझे रनटाइम पर अपने twisted एप्लिकेशन से कनेक्ट करने की आवश्यकता है और मैं उस अंत तक मेरे लिए काम करने के लिए twisted.manhole प्राप्त करने का प्रयास कर रहा हूं। मैं मैक ओएसएक्स 10.6 पर डिफ़ॉल्ट रूप से स्थापित 8.2 के साथ हूं।घुमावदार मैनहोल: एप्लिकेशन में सर्वर का उपयोग कैसे करें?

sample server using twistd काम करता है। वहाँ md5, शा और twisted.protocols.telnet के बारे में स्टार्टअप पर DeprecationWarnings हैं, लेकिन मैनहोल सर्वर वास्तव में क्या यह माना जाता है करता है और मैं अपने आवेदन के आंतरिक उपयोग कर सकते हैं:

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> 
>>> 

अब मैं में इस एकीकृत करने के लिए कोशिश अपने आवेदन: एक दूसरे खोल में

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> 

, चलाने के एक टेलनेट ग्राहक:

# 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) 

एक खोल में उपरोक्त कोड भागो

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', '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 

तो ऐसा लगता है कि सेवा ऑब्जेक्ट एप्लिकेशन आंतरिकों तक पहुंचने के लिए उपयोग योग्य नहीं है।

ठीक है, twisted.protocols.telnet के बाद से वैसे भी, नए मॉड्यूल का उपयोग करके देखें twisted.conch.telnet ने ले लिया है लगता है:

# 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) 

'पासवर्ड फ़ाइल' users.txt एक नमूना उपयोगकर्ता नाम और पासवर्ड के रूप में एक पंक्ति के हो सकते हैं, जैसे admin:admin

परीक्षण सर्वर शुरू करें:

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> 

एक दूसरे खोल में, एक टेलनेट ग्राहक चलाने - ध्यान दें कि इस में से कुछ वास्तव में गाड़ी मैक OSX ReadLine के रूप में अटकलबाजी है (या जो कुछ भी इसके लिए जिम्मेदार है) लगता है कुछ खोल उत्पादन निगल करने के लिए:

host:client user$ telnet localhost 4040 
Trying 127.0.0.1... 
Connected to localhost. 
Escape character is '^]'. 
Username: admin 
Password: ***** 

>>> dir() 
['__builtins__'] 

तो अब यह मैं सभी में कोई ऑब्जेक्ट में एक बेकार service वस्तु होने से चले गए हैं लगता है।

twisted.manhole कैसे सही ढंग से उपयोग किया जाता है?

+1

जिज्ञासा से बाहर, पासवर्ड "व्यवस्थापक" है? –

+0

हां। मैं बंदरगाह 4040, उपयोगकर्ता नाम व्यवस्थापक और पासवर्ड व्यवस्थापक का उपयोग जारी रखें। – ssc

उत्तर

5

twisted.conch का उपयोग जारी रखें और नामस्थान शब्दकोश में कुछ डालें।

namespace = {"your_application_object": some_object} 

options = { 
    # for some reason, these must 
    # all exist, even if None 
    'namespace' : namespace, 
    'passwd'  : 'users.txt', 
    'sshPort' : None, 
    'telnetPort' : '4040', 
} 
संबंधित मुद्दे

 संबंधित मुद्दे