Added updates with respect to recent changes to TimedRotatingFileHandler.
[python.git] / Demo / sockets / finger.py
blobe8b9ed2b08c5b90fc6efaa255538ee4a370a0e29
1 #! /usr/bin/env python
3 # Python interface to the Internet finger daemon.
5 # Usage: finger [options] [user][@host] ...
7 # If no host is given, the finger daemon on the local host is contacted.
8 # Options are passed uninterpreted to the finger daemon!
11 import sys, string
12 from socket import *
15 # Hardcode the number of the finger port here.
16 # It's not likely to change soon...
18 FINGER_PORT = 79
21 # Function to do one remote finger invocation.
22 # Output goes directly to stdout (although this can be changed).
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()
35 # Main function: argument parsing.
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)
56 # Call the main function.
58 main()