depy.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:depy 作者: bruienne 项目源码 文件源码
def init_stoken(self, stoken):
        """
        Loads the required stoken.json file from disk.
        """
        with open(stoken) as data_file:
            self.mytoken = json.load(data_file)

        # Verify that the stoken data is somewhat sane, i.e. has the required
        #   keys and their values start with expected prepends.
        try:
            for k, prefix in (('consumer_secret', 'CS_'),
                              ('access_token', 'AT_'),
                              ('consumer_key', 'CK_'),
                              ('access_secret', 'AS_')):
                if not self.mytoken.get(k).startswith(prefix):
                    print 'Error parsing stoken file: bad value for:\n%s = %s\n' % (k, self.mytoken[k])
                    sys.exit(-1)

        except AttributeError:
            print 'Error parsing stoken file: missing key for:\n%s\n' % (k)
            sys.exit(-1)

        # Set the required OAuth1 keys from the source stoken
        self.oauth = OAuth1Session(client_key=self.mytoken['consumer_key'],
                                   client_secret=self.mytoken['consumer_secret'],
                                   resource_owner_key=self.mytoken['access_token'],
                                   resource_owner_secret=self.mytoken['access_secret'],
                                   realm='ADM')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号