telnetAPI.py :  » Network » Grail-Internet-Browser » grail-0.6 » protocols » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Grail Internet Browser 
Grail Internet Browser » grail 0.6 » protocols » telnetAPI.py
"""Telnet protocol handler for URLs of the form telnet://host[:port]

For Unix only; requires xterm in your $PATH.

"""

import os, urllib
from nullAPI import null_access

class telnet_access(null_access):

    def __init__(self, url, method, params):
        null_access.__init__(self, url, method, params)
        host, junk = urllib.splithost(url)
        userpasswd, host = urllib.splituser(host)
        host, port = urllib.splitport(host)
        
        # XXX I tried doing this using os.system(), but the file
        # descriptors that Grail has open seemed to be confusing
        # telnet or xterm.  So we need to close all file descriptors,
        # and this must be done in the child process, so now that
        # we're forking anyway, we might as well use os.exec*.

        # XXX To do: reap child processes after they've died!
        # Use os.waitpid(-1, os.WNOHANG) to do this.
        # But perhaps we should only wait for pids originating in this
        # module.

        cmd = ["xterm", "-e", "telnet", host]
        if port:
            cmd.append(str(port))
        pid = os.fork()
        if pid:
            # Parent process
            return

        # Child process
        try:
            # Close all file descriptors
            # XXX How to know how many there are?
            for i in range(3, 200):
                try:
                    os.close(i)
                except os.error:
                    pass
            # XXX Assume xterm is on $PATH
            os.execvp(cmd[0], cmd)
            # This doesn't return when successful
        except:
            print "Exception in os.execvp() or os.close()"
            # Don't fall back in the the parent's stack!
            os._exit(127)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.