symbian-qemu-0.9.1-12/python-2.6.1/Demo/sockets/finger.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 #! /usr/bin/env python
       
     2 
       
     3 # Python interface to the Internet finger daemon.
       
     4 #
       
     5 # Usage: finger [options] [user][@host] ...
       
     6 #
       
     7 # If no host is given, the finger daemon on the local host is contacted.
       
     8 # Options are passed uninterpreted to the finger daemon!
       
     9 
       
    10 
       
    11 import sys, string
       
    12 from socket import *
       
    13 
       
    14 
       
    15 # Hardcode the number of the finger port here.
       
    16 # It's not likely to change soon...
       
    17 #
       
    18 FINGER_PORT = 79
       
    19 
       
    20 
       
    21 # Function to do one remote finger invocation.
       
    22 # Output goes directly to stdout (although this can be changed).
       
    23 #
       
    24 def finger(host, args):
       
    25     s = socket(AF_INET, SOCK_STREAM)
       
    26     s.connect((host, FINGER_PORT))
       
    27     s.send(args + '\n')
       
    28     while 1:
       
    29         buf = s.recv(1024)
       
    30         if not buf: break
       
    31         sys.stdout.write(buf)
       
    32     sys.stdout.flush()
       
    33 
       
    34 
       
    35 # Main function: argument parsing.
       
    36 #
       
    37 def main():
       
    38     options = ''
       
    39     i = 1
       
    40     while i < len(sys.argv) and sys.argv[i][:1] == '-':
       
    41         options = options + sys.argv[i] + ' '
       
    42         i = i+1
       
    43     args = sys.argv[i:]
       
    44     if not args:
       
    45         args = ['']
       
    46     for arg in args:
       
    47         if '@' in arg:
       
    48             at = string.index(arg, '@')
       
    49             host = arg[at+1:]
       
    50             arg = arg[:at]
       
    51         else:
       
    52             host = ''
       
    53         finger(host, options + arg)
       
    54 
       
    55 
       
    56 # Call the main function.
       
    57 #
       
    58 main()