#!/usr/bin/python #!/bin/sh #exec `which python` -c "`tail -n +4 $0`" $@ '''\ this is a test ''' import os, sys, string, re, urllib, time sys.argv.pop(0) while len(sys.argv) > 0: print sys.argv[0] sys.argv.pop(0) sys.exit() from icalendar import Calendar import calendar cal = Calendar().from_string(open("/home/dave/dave.ics").read()) for x in cal.walk(): if x.name == 'VTODO': print x.keys() break # first one only cats = {} catskeys = cats.keys() catskeys.sort() for cat in catskeys: print cat print "-----------------------------" for x in cats[cat]: for k in x.keys(): if k == 'UID': uid = str(x['UID']) print uid if k == 'STATUS': if x[k] != 'NEEDS-ACTION': continue elif k == 'DUE': sys.stdout.write("%s - " % (x[k])) elif k == 'SUMMARY': print x[k] elif k == 'DESCRIPTION': if x[k] == x['SUMMARY']: continue else: print x[k] print sys.exit() # test: if list is empty, is it okay to do? (yes)... for a,b in x: #def reload(): # return [ (1,2), (2,3) ] # #l = reload() #while 1: # for a,b in l: # print str(a) # print str(b) # time.sleep(1) # l = reload() #sys.exit() #class Cfg(): # def __init__(self): # self.weather = "KSFO" # #def splituser(src): # nick,user = src.split("!") # nick = nick.replace(":","") # login, host = user.split("@") # login = login.replace("~","") # return nick, login, host # #def splitprivmsg(line): # ''' line is something like: # :dave!~dcapella@obie.danger.com PRIVMSG #sysbot :robo pizza # returns: # sender nick, sender host, target (channel, nick), message # ''' # fields = line.split() # if len(fields) == 4: # src, cmd, target, msg = line.split() # else: # src = fields[0] # target = fields[2] # msg = " ".join(fields[3:]) # sender, login, host = splituser(src) # if msg[:6] == ":robo ": # msg = msg[6:] # return sender, host, target, msg # #line = ":dave!~dcapella@obie.danger.com PRIVMSG #sysbot :robo wx mountain view,ca" #cfg = Cfg() #weather(cfg,line) #sys.exit() class MyOpener(urllib.FancyURLopener): version = "Mozilla/5.0 (Danger hiptop 4.6; U; rv:1.7.12) Gecko/20050920" urllib._urlopener = MyOpener() data = urllib.urlopen("http://grox.net/news/bbc.html").read() url = "http://www.google.com/search?q=exrc&ie=utf-8&oe=utf-8&aq=t" #data = urllib.urlopen(url).read() #data = sys.stdin.read() import sgmllib class Parser(sgmllib.SGMLParser): def __init__(self,verbose=0): sgmllib.SGMLParser.__init__(self, verbose) self.contents = "" self.urls = [] self.skip = False self.link = False def handle_data(self, data): x = ''' if not self.skip: self.contents += data ''' if self.link: self.contents += data + "\n" def start_script(self, attributes): self.skip = True def end_script(self): self.skip = False def start_a(self, attributes): for name, value in attributes: if name == "href": self.urls.append(value) self.link = True def end_a(self): self.link = False p = Parser() p.feed(data) p.close() #print p.contents # print page contents s = p.contents.replace("\r","\n") for line in s.split("\n"): line = line.strip() if line: print line for url in p.urls: # print links contained on page print url sys.exit() #import subprocess #cmd = ["ls", "-d", "/tmp"] #p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #(results, serr) = p.communicate() #print results #sys.exit() def baseN(num,b): if num == 0: return "0" result = "" while num != 0: num, d = divmod(num, b) result += "0123456789abcdefghijklmnopqrstuvwxyz"[d] return result[::-1] # reverse def t(): print __doc__ t() sys.exit() import socket irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) irc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) irc.connect(('foo', 12345)) sys.exit() #os.umask(0122) # files are 0644 #os.umask(0117) # files are 0660 #fd = open("/home/dave/tst", "w") #fd.close #sys.exit() print "argc: %d" % (len(sys.argv)) del sys.argv[0] while len(sys.argv): print sys.argv[0] del sys.argv[0] sys.exit() args = sys.argv[1:] print "len argv: %d len args: %d args: %s" % (len(sys.argv), len(args), str(args)) sys.exit() #p = os.popen("cat tst") #while True: # line = p.readline().rstrip() # if line == "": break # print line #p.close() #sys.exit() print len(sys.argv) ; sys.exit() ############################################################ # is_valid_mac #mac = sys.argv[1].lower() #if re.search('^([0-9a-f]{1,2}:){5}[0-9a-f]{1,2}$',mac): # sys.exit(0) #else: # sys.exit(1) ############################################################ #if os.isatty(0): print "stdin is a tty." #else: print "stdin is NOT a tty." #if os.isatty(1): print "stdout is a tty." #else: print "stdout is NOT a tty." #sys.exit() ############################################################ import cgi from stat import * #import cgitb; cgitb.enable() def _ctoi(c): if type(c) == type(""): return ord(c) else: return c def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126 ############################################################ #def dot2int_example(dotaddr): # ''' # convert dotted-quad ip address to an int. from: # http://web.mit.edu/asedeno/Public/edna.grobda.py # ''' # a, b, c, d = map(int, string.split(dotaddr, '.')) # return (a << 24) + (b << 16) + (c << 8) + (d << 0) def dot2int(ipaddr): ''' mine: convert dotted-quad ip address to an int '64.62.222.180' -> 1077862068 ''' q1, q2, q3, q4 = ipaddr.split(".") return (int(q1) << 24) + (int(q2) << 16) + (int(q3) << 8) + int(q4) #print dot2int('64.62.222.180') ; sys.exit() def acl_ok(ipaddr): if not acls: return 1 ipaddr = dot2int(ipaddr) for allowed, mask in acls: if (ipaddr & mask) == (allowed & mask): return 1 return 0 import socket acls = [] allowed = ['64.62.222.180', '10.0.0.0/16', 'otto.grox.net'] for addr in allowed: if '/' in addr: addr, masklen = string.split(addr, '/') masklen = int(masklen) else: masklen = 32 if not re.match(r'^\d+\.\d+\.\d+\.\d+$', addr): addr = socket.gethostbyname(addr) mask = ~((1 << (32-masklen)) - 1) entry = (dot2int(addr), mask) if not entry in acls: acls.append(entry) print acl_ok('64.62.222.180') print acl_ok('10.0.0.32') print acl_ok(socket.gethostbyname('grox.net')) sys.exit() ############################################################ i = 0 for port in range(45,77): ltr = string.ascii_letters[i + 4] print '''\ %s_r%d %s ssh -lroot r%d ''' % (ltr, port, ltr, port, port) i += 1 sys.exit() print "argv: ", " ".join(sys.argv[1:]) ; sys.exit() s = "this is a test" print s.split()[-1:][0] sys.exit() while 1: try: line = raw_input().rstrip() if line == "": continue if "nterest" in line: host = line.split()[-1:][0] line = raw_input().rstrip() if "open" in line: print host, ": ", line except EOFError: sys.exit() iam = os.getuid() print "content-type: text/plain\r\n\r\n" #for k in os.environ.keys(): # print "%s:%s" % (k,os.environ[k]) #home = os.environ['HOME'] home = '/tmp' owner = os.stat(home)[ST_UID] print "my home: %s. owner: %d" % (home, owner) if not 'REQUEST_METHOD' in os.environ.keys(): print >> sys.stderr, "this is not a cgi" if iam != "root": print >> sys.stderr, "you are not root. you are %s." % (iam) sys.exit() else: print "my uid: %s" % (iam) if iam != owner: print "you do not own %s." % (home) form = cgi.FieldStorage() for key in form.keys(): value = form[key].value print "%s:%s" % (key, cgi.escape(value)) ############################################################ if 'HOME' in os.environ.keys(): print os.environ['HOME'] import time print "sleeping 2.5 seconds..." time.sleep(2.5) sys.exit() import urllib url = 'http://grox.net/ip' #fd = urllib.urlopen( string.join((url,query),"?") ) fd = urllib.urlopen(url) print fd.read() fd.close() #try: # open('zzzzz') #except Exception, msg: # print "error: %s" % (msg) #sys.exit(1) # #while 1: # try: # line = raw_input() # line = string.replace(line, "<", "\n<") # print line # except EOFError: # break #class C: # def __init__(self, db='dcdb',host='dcdb',port=3306,mode='read'): # if db: self.db = db # if host: self.host = host # if port: self.port = port # if mode: self.mode = mode # #c = C(db='dc',port=42) #print "db: %s host: %s port: %d mode: %s" % (c.db,c.host,c.port,c.mode) # #c = C(mode='write',host='me') #print "db: %s host: %s port: %d mode: %s" % (c.db,c.host,c.port,c.mode) #import getopt #try: # opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="]) #except getopt.GetoptError, err: # # print help information and exit: # print str(err) # will print something like "option -a not recognized" # usage() # sys.exit(2) #output = None #verbose = False #for o, a in opts: # if o == "-v": # verbose = True # elif o in ("-h", "--help"): # usage() # sys.exit() # elif o in ("-o", "--output"): # output = a # else: # assert False, "unhandled option" import socket print socket.gethostname() ############################################################ # eof: tester.py vim: set ts=4 sts=4 sw=4 tw=80 et: