+ -
当前位置:首页 → 问答吧 → 解释下面这段python代码

解释下面这段python代码

时间:2010-10-19

来源:互联网

最好详细点
Python code

class loginInfo(QtCore.QThread):
    def __init__(self, conn, parent):
        QtCore.QThread.__init__(self, parent)
        self.conn = conn
        self.username, self.password = self.conn.getUsernameAndPassword()
    def run(self):
        mutex2.lock()
        self.status = self.getConnection()
        mutex2.unlock()
    def getConnection(self):
        md5passwd = hashlib.md5(self.password).hexdigest()
        self.passwd = md5passwd[8:24]
        self.conn.setPasswd(self.passwd)
        self.conn = httplib.HTTPConnection("www.cc98.org")
        self.conn.putrequest("GET", "/index.asp")
        self.conn.endheaders()
        res = self.conn.getresponse()
        res.read()
        self.cookie = res.getheader("set-cookie")
        sessionlist = re.findall(r"ASPSESSION.*(?=; path=/)", self.cookie)
        session = sessionlist[0]
        self.cookie = "BoardList=BoardID=Show; " + session
        data = urllib.urlencode({"a":"i", "u":self.username, "p":md5passwd, "userhidden":"2"})
        Content_Length = data.__len__()
        self.conn.putrequest("GET", "/sign.asp")
        self.conn.putheader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
        self.conn.putheader("Cookie", self.cookie)
        self.conn.putheader("Content-Length", str(Content_Length))
        self.conn.endheaders()
        self.conn.send(data)
        res = self.conn.getresponse()
        if res.read() != "9898":
            return False
        userinfo = re.findall(r"aspsky.*?(?=;\s)", res.getheader("set-cookie"))
        self.cookie = "BoardList=BoardID=Show; upNum=0; " + session + "; " + userinfo[0]
        return True 
    def getStatus(self):
        return self.status
    def getCookie(self):
        return self.cookie


作者: zhbzljxw   发布时间: 2010-10-19

这问题就好像“教我Python,最好从头教”一样。需要别人帮助的时候,要让别人相信你自己努力过了。否则完全是在浪费别人的时间。

作者: iambic   发布时间: 2010-10-19