# -*- coding: utf-8 -*-

import json
import random

from webclient import WebBrowser
from protocol import (WEBQQ_APPID,
    get_timestamp,
    get_clientid,
    get_password,
    )

class WebQQException(Exception):
    pass

class WebQQClient(WebBrowser):
    def __init__(self, *args, **kwargs):
        super(WebQQClient, self).__init__()

    def need_username(self):
        return False

    def need_password(self):
        return False

    def check_verify_code(self, uin=None, appid=None):
        verify_code1 = ''
        verify_code2 = ''
        return (verify_code1, verify_code2)

    def need_login_ptlogin2(self):
        return True

    def login_ptlogin2(self, username = None, password = None, verify_code1 = None, verify_code2 = None):
        return True

    def need_login_web2(self):
        return True

    def login_web2(self):
        return True

    def login(self, username=None, password=None):
        if not self.need_login_ptlogin2():
            if not self.need_login_web2():
                return True
            else:
                if self.login_web2():
                    return True
                else:
                    return False
        else:
            verify_code1, verify_code2 = self.check_verify_code()
            if not self.login_ptlogin2(username=username,password=password,verify_code1=verify_code1,verify_code2=verify_code2):
                self.set_runflag(False)
                return False

            if not self.login_web2():
                self.set_runflag(False)
                return False

        return True

    def logout(self):
        return True

    def heartbeat(self):
        print 'Bom..bong!'

    def poll(self):
        return 'poll'

    def handle(self, data):
        print data

    def get_handlers(self):
        return [self.handle]

    def set_runflag(self, value):
        self.runflag = value

    def run_forever(self):
        i=0
        while True:
            i=i+1
            if i>100:
                break
            print i

@@ -356,94 +356,676 @@
 ()%0D%0A
-%0D%0A    def need_username(self):%0D%0A        return False%0D%0A%0D%0A    def need_password(self):%0D%0A
+        self.handle_count = 0%0D%0A        self.clientid = get_clientid()%0D%0A        self.psessionid = ''%0D%0A        self.ptwebqq    = ''%0D%0A        self.vfwebqq    = ''%0D%0A        self.skey       = ''%0D%0A        #self.uin      = uin%0D%0A        #self.password = password%0D%0A%0D%0A        self.set_runflag(False)%0D%0A        print 'clientid',self.clientid%0D%0A%0D%0A    def need_username(self):%0D%0A        '''%E7%94%A8%E6%88%B7%E5%90%8D%E6%98%AFQQ%E7%99%BB%E5%BD%95%E8%B4%A6%E5%8F%B7(%E6%95%B0%E5%AD%97, %E9%95%BF%E5%BA%A6%E5%A4%A7%E4%BA%8E5)%E6%88%96%E8%80%85%E9%82%AE%E7%AE%B1%E5%9C%B0%E5%9D%80'''%0D%0A        if self.username is None or len(self.username)%3C5 :%0D%0A            return True%0D%0A        else:%0D%0A            return False%0D%0A%0D%0A    def need_password(self):%0D%0A        if self.password is None or len(self.password)%3C8 :%0D%0A            return True%0D%0A        else:%0D%0A    
     

修改初始化函数, 是否需要用户名函数, 是否需要密码等函数