摘要: #能够将XML文档转换为字典和列表的组合,是一个不错的主意from xml.parsers import expatclass Element(object): '''analyze a element''' def __init__(self, name, attributes): #record tag and attribute dictionary self.name = name self.attributes = attributes #clear the element cdata and its childre... 阅读全文
posted @ 2012-08-25 14:17 苍术厚朴 阅读(3012) 评论(0) 推荐(1) 编辑
摘要: import xml.dom.minidomdocument = """\<slideshow><title>Demo slideshow</title><slide><title>Slide title</title><point>This is a demo</point><point>Of a program for processing slides</point></slide><slide><title& 阅读全文
posted @ 2012-08-25 11:20 苍术厚朴 阅读(491) 评论(0) 推荐(0) 编辑
摘要: #需要使用SSH协议登录本地或远程计算机,并发送命令# use ssh to control remote computersimport os, sys, paramikofrom getpass import getpassparamiko.util.log_to_file('auto_ssh.log',0)def parse_user(user,default_host, default_port): '''given name [@host[:port]],return name,host,port,if not, return default 阅读全文
posted @ 2012-08-25 10:47 苍术厚朴 阅读(794) 评论(0) 推荐(0) 编辑
摘要: 需要你的主线程把处理任务托付给一个工作线程池Queue.Queue是用来协调工作线程池的最简单和最有效率的方法。因为它已经有了全局变量的保护(加锁和解锁)#-*-coding:utf-8-*-import threading, Queue, time, sys#global varialbesQin = Queue.Queue()Qout = Queue.Queue()Qerr = Queue.Queue()Pool = [ ]def report_error(): '''put error information into Qerr to report the err 阅读全文
posted @ 2012-08-25 08:50 苍术厚朴 阅读(340) 评论(0) 推荐(0) 编辑
摘要: 需要将某个网络端口转发到另外一个主机(forwarding),但可能会是不同的端口(redirecting)import sys, socket, time, threadingLOGGING = Trueloglock = threading.Lock()def log(s, *a): if LOGGING: loglock.acquire() try: print '%s:%s' %(time.ctime(), (s%a)) sys.stdout.flush() finally: ... 阅读全文
posted @ 2012-08-25 08:41 苍术厚朴 阅读(2504) 评论(0) 推荐(0) 编辑
摘要: import BaseHTTPServer, shutil, osfrom cStringIO import StringIOclass MyHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): #The http path we service and the command we service cmds = {'/ping':'ping www.thinkware.se', '/netstat': 'netstat -a', '/tracert' 阅读全文
posted @ 2012-08-25 01:17 苍术厚朴 阅读(1841) 评论(0) 推荐(0) 编辑