• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python auth.BasicAuthHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中weibopy.auth.BasicAuthHandler的典型用法代码示例。如果您正苦于以下问题:Python BasicAuthHandler类的具体用法?Python BasicAuthHandler怎么用?Python BasicAuthHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BasicAuthHandler类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
        
    def unread(self):
        count = self.api.unread()
        self.obj = count
        mentions = self.getAtt("mentions")
        comments = self.getAtt("comments")
        followers = self.getAtt("followers")
        dm = self.getAtt("dm")
        print("mentions---"+ str(mentions) +":"+ str(comments) +":"+ str(followers) +":"+ str(dm))
开发者ID:chengjun,项目名称:Research,代码行数:32,代码来源:unread.py


示例2: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
        
    def mentions(self):
        comments = self.api.mentions()
        for comment in comments:
            self.obj = comment
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("mentions---"+ str(mid) +":"+ text)
开发者ID:chengjun,项目名称:Research,代码行数:31,代码来源:mention.py


示例3: test

class test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
        
    def friends(self):
        timeline = self.api.friends()
        for line in timeline:
            self.obj = line
            fid = self.getAtt("id")
            name = self.getAtt("screen_name")
            print("friends---"+ str(fid) +":"+ name)
开发者ID:chengjun,项目名称:Research,代码行数:31,代码来源:getFriends.py


示例4: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth, source=self.consumer_key)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
    
    def upload(self, filename, message):
        status = self.api.upload(filename, status=message)        
        self.obj = status
        id = self.getAtt("id")
        text = self.getAtt("text")
        self.obj = self.getAtt("user")
        profile_image_url  = self.getAtt("profile_image_url")
        print("upload,id="+ str(id) +",text="+ text +",profile_image_url="+ profile_image_url)
开发者ID:chengjun,项目名称:Research,代码行数:32,代码来源:upload.py


示例5: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth, source=self.consumer_key)
        
    def basicAuth(self, source, username, password):
        self.authType = 'basicauth'
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
    def get_privacy(self):
        privacy = self.api.get_privacy()
        self.obj = privacy
        ct = self.getAtt("comment")
        dm = self.getAtt("dm")
        real_name = self.getAtt("real_name")
        geo = self.getAtt("geo")
        badge = self.getAtt("badge") 
        print ("privacy---"+ str(ct) + str(dm) + str(real_name) + str(geo) + str(badge))
    def update_privacy(self):
        update_privacy = self.api.update_privacy(comment=0)        
开发者ID:chengjun,项目名称:Research,代码行数:35,代码来源:privacy.py


示例6: Test

class Test(unittest.TestCase):

    consumer_key = ""
    consumer_secret = ""

    def __init__(self):
        """ constructor """

    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ""

    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth, source=self.consumer_key)

    def basicAuth(self, source, username, password):
        self.authType = "basicauth"
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth, source=source)

    def counts(self):
        counts = self.api.counts(ids="1864372538,1484854960,1877120192")
        for count in counts:
            self.obj = count
            mid = self.getAtt("id")
            comments = self.getAtt("comments")
            rt = self.getAtt("rt")
            print("mentions---" + str(mid) + ":" + str(comments) + ":" + str(rt))
开发者ID:rahulsoni9,项目名称:Research,代码行数:33,代码来源:counts.py


示例7: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
        
    def friends_timeline(self):
        timeline = self.api.friends_timeline(count=2, page=1)
        for line in timeline:
            self.obj = line
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("friends_timeline---"+ str(mid) +":"+ text)

    def comments_timeline(self):
        timeline = self.api.comments_timeline(count=2, page=1)
        for line in timeline:
            self.obj = line
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("comments_timeline---"+ str(mid) +":"+ text)
            
    def user_timeline(self):
        timeline = self.api.user_timeline(count=5, page=1)
        for line in timeline:
            self.obj = line
            mid = self.getAtt("id")
            text = self.getAtt("text")
            created_at = self.getAtt("created_at")
            print("user_timeline---"+ str(mid) +":"+ str(created_at)+":"+ text)
        timeline = self.api.user_timeline(count=20, page=2)
        
    def public_timeline(self):
        timeline = self.api.public_timeline(count=2, page=1)
        for line in timeline:
            self.obj = line
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("public_timeline---"+ str(mid) +":"+ text)
开发者ID:chengjun,项目名称:Research,代码行数:57,代码来源:getTimelines.py


示例8: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth, source=self.consumer_key)
        
    def basicAuth(self, source, username, password):
        self.authType = 'basicauth'
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
    def tags(self):
        tags = self.api.tags(user_id=1377583044)
        for line in tags:
            self.obj = line
            tagid=self.getAtt("id")
            value = self.getAtt(tagid)
            print (tagid,value)
    def tag_create(self ,message):
#        message = message.encode("utf-8")
        tag_create = self.api.tag_create(tags=message)
        for line in tag_create:
            self.obj = line
            tagid = self.getAtt("tagid")
            print ("tag_create---"+tagid)
    def tag_suggestions(self):
        tag_suggestions=self.api.tag_suggestions()
        for line in tag_suggestions:
            self.obj = line
            id = self.getAtt("id")
            value = self.getAtt("value")
            print ("tag_suggestions---"+ id +":"+ value)
    def tag_destroy(self,tag_id):
        tag_destroy=self.api.tag_destroy(tag_id)
        self.obj=tag_destroy
        result=self.getAtt("result")
        print ("tag_destroy---"+ result)
    def tag_destroy_batch(self,tag_ids):
        tag_destroy_batch=self.api.tag_destroy_batch(tag_ids)
        for line in tag_destroy_batch:
            self.obj = line
            tagid=self.getAtt("tagid")
            print ("tag_destroy_batch---"+ tagid)                        
开发者ID:chengjun,项目名称:Research,代码行数:56,代码来源:tags.py


示例9: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
        
    def direct_message(self):
        messages = self.api.direct_messages()
        mid = ''
        for msg in messages:
            self.obj = msg
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("direct_message---"+ str(mid) +":"+ text)
        return mid
    
    def sent_direct_messages(self):
        messages = self.api.sent_direct_messages()
        for msg in messages:
            self.obj = msg
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("sent_direct_messages---"+ str(mid) +":"+ text)
            
    def new_direct_message(self):
        msg = self.api.new_direct_message(id=1114365581,text='directMessages--test-²âÊÔ-'+ str(time.time()))
        self.obj = msg
        mid = self.getAtt("id")
        text = self.getAtt("text")
        print("new_direct_message---"+ str(mid) +":"+ text)
            
    def destroy_direct_message(self, id):
        msg = self.api.destroy_direct_message(id)
        self.obj = msg
        mid = self.getAtt("id")
        text = self.getAtt("text")
        print("destroy_direct_message---"+ str(mid) +":"+ text)
开发者ID:chengjun,项目名称:Research,代码行数:55,代码来源:directMessages.py


示例10: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
    
    def create_friendship(self):
        user = self.api.create_friendship(id=1114365581)
        self.obj = user
        uid = self.getAtt("id")
        screen_name = self.getAtt("screen_name")
        print("create_friendship---"+ str(uid) +":"+ screen_name)
        
    def destroy_friendship(self):
        user = self.api.destroy_friendship(id=1114365581)
        self.obj = user
        uid = self.getAtt("id")
        screen_name = self.getAtt("screen_name")
        print("destroy_friendship---"+ str(uid) +":"+ screen_name)
        
    def exists_friendship(self):
        self.obj = self.api.exists_friendship(user_a=1772333754, user_b=1773365880)
        friends = self.getAtt("friends")
        print("exists_friendship--- "+ str(friends))
        
    def show_friendship(self, uid):
        showList = self.api.show_friendship(target_id=uid)
        for obj in showList:
            self.obj = obj
            uid = self.getAtt("id")
            screen_name = self.getAtt("screen_name")
            print("show_friendship---"+ str(uid) +":"+ screen_name)
开发者ID:chengjun,项目名称:Research,代码行数:50,代码来源:friendships.py


示例11: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.authType = 'basicauth'
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
        
    def favorites(self):
        statuses = self.api.favorites(id=1773365880)
        for status in statuses:
            self.obj = status
            sid = self.getAtt("id")
            text = self.getAtt("text")
            print("favorites---"+ str(sid) +":"+ text)
        
    def create_favorite(self, id):
        status = self.api.create_favorite(id)
        self.obj = status
        sid = self.getAtt("id")
        text = self.getAtt("text")
        print("create_favorite---"+ str(sid) +":"+ text)
            
    def destroy_favorite(self, id):
        msg = self.api.destroy_favorite(id)
        self.obj = msg
        mid = self.getAtt("id")
        text = self.getAtt("text")
        print("destroy_favorite---"+ str(mid) +":"+ text)
开发者ID:chengjun,项目名称:Research,代码行数:46,代码来源:favorites.py


示例12: __init__

 def __init__(self, username, password, listener, timeout=5.0, retry_count = None,
                 retry_time = 10.0, snooze_time = 5.0, buffer_size=1500, headers=None):
     self.auth = BasicAuthHandler(username, password)
     self.running = False
     self.timeout = timeout
     self.retry_count = retry_count
     self.retry_time = retry_time
     self.snooze_time = snooze_time
     self.buffer_size = buffer_size
     self.listener = listener
     self.api = API()
     self.headers = headers or {}
     self.body = None
开发者ID:ybak,项目名称:myblog,代码行数:13,代码来源:streaming.py


示例13: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
    
    def friends_ids(self):
        fids = self.api.friends_ids()
        self.obj = fids
        ids = self.getAtt("ids")
        next_cursor = self.getAtt("next_cursor")
        previous_cursor = self.getAtt("previous_cursor")
        print("friends_ids---"+ str(ids) +":next_cursor"+ str(next_cursor) +":previous_cursor"+ str(previous_cursor))
        
    def followers_ids(self):
        fids = self.api.followers_ids()
        self.obj = fids
        ids = self.getAtt("ids")
        next_cursor = self.getAtt("next_cursor")
        previous_cursor = self.getAtt("previous_cursor")
        print("followers_ids---"+ str(ids) +":next_cursor"+ str(next_cursor) +":previous_cursor"+ str(previous_cursor))
开发者ID:chengjun,项目名称:Research,代码行数:39,代码来源:ids.py


示例14: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)    
    
    def update(self, message):
        status = self.api.update_status(lat='39', long='110', status=message)
        self.obj = status
        id = self.getAtt("id")
        text = self.getAtt("text")
        print("update---"+ str(id) +":"+ text)
        
    def destroy_status(self, id):
        status = self.api.destroy_status(id)
        self.obj = status
        id = self.getAtt("id")
        text = self.getAtt("text")
        print("update---"+ str(id) +":"+ text)
开发者ID:chengjun,项目名称:Research,代码行数:36,代码来源:oauthSetTokenUpdate.py


示例15: basicAuth

 def basicAuth(self, source, username, password):
     self.authType = 'basicauth'
     self.auth = BasicAuthHandler(username, password)
     self.api = API(self.auth,source=source)
开发者ID:chengjun,项目名称:Research,代码行数:4,代码来源:tags.py


示例16: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth, source=self.consumer_key)
        
    def basicAuth(self, source, username, password):
        self.authType = 'basicauth'
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
        
    def comments(self, id):
        comments = self.api.comments(id=id)
        for comment in comments:
            self.obj = comment
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("comments---"+ str(mid) +":"+ text)
    
    def comments_timeline(self):
        comments = self.api.comments_timeline()
        for comment in comments:
            self.obj = comment
            mid = self.getAtt("id")
            text = self.getAtt("text")
            print("comments_timeline---"+ str(mid) +":"+ text)
    
    def comments_by_me(self):
        comments = self.api.comments_by_me(count=5)
        mid = ''
        for comment in comments:
            self.obj = comment
            mid = self.getAtt("id")
            text = self.getAtt("text")
            created_at = self.getAtt("created_at")
            print('comments_by_me,id='+ str(mid) +',text='+ text+',created_at='+ str(created_at))
        return mid
    
    def comment(self, mid):
        comment = self.api.comment(id=mid, comment='commect-test-²âÊÔ--'+ str(time.time()))
        self.obj = comment
        mid = self.getAtt("id")
        text = self.getAtt("text")
        print("comment---"+ str(mid) +":"+ text)
    
    def comment_destroy (self, mid):
        comment = self.api.comment_destroy(mid)
        self.obj = comment
        mid = self.getAtt("id")
        text = self.getAtt("text")
        print("comment_destroy---"+ str(mid) +":"+ text)
开发者ID:chengjun,项目名称:Research,代码行数:65,代码来源:comment.py


示例17: Test

class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth, source=self.consumer_key)
        
    def basicAuth(self, source, username, password):
        self.authType = 'basicauth'
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
    
    def trends(self):
        trends = self.api.trends(user_id=1377583044,count=20, page=1)
#        print str(len(trends))
        for line in trends:
            self.obj=line
            num = self.getAtt("num")
            trend_id = self.getAtt("trend_id")
            hotword = self.getAtt("hotword")
            print ("trends---"+ num +":"+ hotword +":"+trend_id)
    def trends_statuses(self , message):
        message = message.encode("utf-8")
        trends_statuses = self.api.trends_statuses(message)
        for line in trends_statuses:
            self.obj=line
            id = self.getAtt("id")
            text = self.getAtt("text")
            print ("ToReader---"+ str(id) + ":" +text)
#            print text 
    def trends_follow(self , message):
        message = message.encode("utf-8")
        trends_follow = self.api.trends_follow(message)
    def trends_destroy(self , id):
        trends_destroy=self.api.trends_destroy(id)
    def trends_hourly(self):
        trends_hourly = self.api.trends_hourly(base_app=0)
        self.obj=trends_hourly
        query = self.getAtt("trends")
        as_of = self.getAtt("as_of")
        for key in query:
            key = time.strftime('%Y-%m-%d',time.localtime(as_of))
            for line in query[key]:
                query = line["query"]
                name = line["name"]
                print ("trends_hourly---"+"Query:" + query+",Name:"+ name)
    def trends_daily(self):
        trends_daily=self.api.trends_daily(base_app=0)
        self.obj=trends_daily
        query=self.getAtt("trends")
        as_of=self.getAtt("as_of")
        for key in query:
            key=time.strftime('%Y-%m-%d',time.localtime(as_of))
            for line in query[key]:
                query=line["query"]
                name=line["name"]
                print ("trends_daily---"+"Query:" + query+",Name:"+ name) 
    def trends_weekly(self):
        trends_weekly=self.api.trends_weekly(base_app=0)
        self.obj=trends_weekly
        query=self.getAtt("trends")
        as_of=self.getAtt("as_of")
        for key in query:
            key = time.strftime('%Y-%m-%d',time.localtime(as_of))
            for line in query[key]:
                query=line["query"]
                name=line["name"]  
                print ("trends_weekly---"+"Query:" + query+",Name:"+ name)  
开发者ID:chengjun,项目名称:Research,代码行数:81,代码来源:trends.py


示例18: Stream

class Stream(object):

    host = 'stream.twitter.com'

    def __init__(self, username, password, listener, timeout=5.0, retry_count = None,
                    retry_time = 10.0, snooze_time = 5.0, buffer_size=1500, headers=None):
        self.auth = BasicAuthHandler(username, password)
        self.running = False
        self.timeout = timeout
        self.retry_count = retry_count
        self.retry_time = retry_time
        self.snooze_time = snooze_time
        self.buffer_size = buffer_size
        self.listener = listener
        self.api = API()
        self.headers = headers or {}
        self.body = None

    def _run(self):
        # setup
        self.auth.apply_auth(None, None, self.headers, None)

        # enter loop
        error_counter = 0
        conn = None
        while self.running:
            if self.retry_count and error_counter > self.retry_count:
                # quit if error count greater than retry count
                break
            try:
                conn = httplib.HTTPConnection(self.host)
                conn.connect()
                conn.sock.settimeout(self.timeout)
                conn.request('POST', self.url, self.body, headers=self.headers)
                resp = conn.getresponse()
                if resp.status != 200:
                    if self.listener.on_error(resp.status) is False:
                        break
                    error_counter += 1
                    sleep(self.retry_time)
                else:
                    error_counter = 0
                    self._read_loop(resp)
            except timeout:
                if self.listener.on_timeout() == False:
                    break
                if self.running is False:
                    break
                conn.close()
                sleep(self.snooze_time)
            except Exception:
                # any other exception is fatal, so kill loop
                break

        # cleanup
        self.running = False
        if conn:
            conn.close()

    def _read_loop(self, resp):
        data = ''
        while self.running:
            if resp.isclosed():
                break

            # read length
            length = ''
            while True:
                c = resp.read(1)
                if c == '\n':
                    break
                length += c
            length = length.strip()
            if length.isdigit():
                length = int(length)
            else:
                continue

            # read data and pass into listener
            data = resp.read(length)
            if self.listener.on_data(data) is False:
                self.running = False

    def _start(self, async):
        self.running = True
        if async:
            Thread(target=self._run).start()
        else:
            self._run()

    def firehose(self, count=None, async=False):
        if self.running:
            raise WeibopError('Stream object already connected!')
        self.url = '/%i/statuses/firehose.json?delimited=length' % STREAM_VERSION
        if count:
            self.url += '&count=%s' % count
        self._start(async)
开发者ID:ybak,项目名称:myblog,代码行数:97,代码来源:streaming.py


示例19: setAccessToken

 def setAccessToken(self, key, secret):
     self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
     self.auth.setAccessToken(key, secret)
     self.api = API(self.auth, source=self.consumer_key)
开发者ID:chengjun,项目名称:Research,代码行数:4,代码来源:tags.py



注:本文中的weibopy.auth.BasicAuthHandler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python auth.OAuthHandler类代码示例发布时间:2022-05-26
下一篇:
Python api.API类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap