# Path: moedjpack/moepad/mpconf.py
# class MpConfig(object):
# class MpConfigRedisHandler(MpConfig):
#     def __init__(self):
#     def getConfig(self):
#     def __init__(self):
#     def getConfig(self):
# 
# Path: moedjpack/moepad/weibowrapper.py
# class WeiboAuthInfoRedis(WeiboAuthInfo):
#     def __init__(self, user_type):
#         super(WeiboAuthInfoRedis, self).__init__(user_type)
#         self.mckey = "WeiboAuth" + user_type
# 
#     def load(self):
#         args = rs.get(self.mckey)
#         if args:
#             for key in args.keys():
#                 setattr(self, key, args[key])
# 
#     def save(self):
#         print self.__dict__
#         confs = sub_dict(self.__dict__,
#                          ['uid', 'access_token', 'expires_in', 'user_type'])
#         rs.hmset(self.mckey, confs)
#         rs.expire(self.mckey, confs['expires_in'])
# 
#     def clean(self):
#         rs.hdel(self.mckey)
# 
# Path: moedjpack/moepad/mputils.py
# def sub_dict(somedict, somekeys, default=None):
# def loggerInit(logfile):
# def utcnow():
# def _deletePrefix(key):
# def create_default_db():


import logging
import redis
import pickle
from django.http import HttpResponse
from django.shortcuts import *
from django.contrib.auth.decorators import login_required
from moedjpack import qqweibo
from moedjpack.moepad.mpconf import MPConf
from moedjpack.moepad.weibowrapper import WeiboAuthInfoRedis
from moedjpack.moepad import weibo
from moedjpack.moepad.mputils import rs
    WeiboAuthObj.clean()
    return redirect(authSinaUrl())


@login_required
def clean_auth(request):
    rs.delete('WeiboAuthoriginal')
    return render_to_response("info.html",
                              {'information': '授权信息已清除'})


def getWeiboAuthedApi(source, user_type):
    if user_type == "original":
        weiboData = OriWeiboAuth
    elif user_type == "retweet":
        weiboData = RtWeiboAuth
    else:
        log.error("invalid user type getWeiboAuthedApi")
        raise e

    if source == 'sina':
        client = weibo.APIClient(
            SinaAppKey, SinaAppSecret, MoePadSite+"/sinacallback")
        client.set_access_token(weiboData.access_token, weiboData.expires_in)

        return client


@login_required
def loginSina(request, user_type):

# Path: moedjpack/moepad/mpconf.py
# class MpConfig(object):
# class MpConfigRedisHandler(MpConfig):
#     def __init__(self):
#     def getConfig(self):
#     def __init__(self):
#     def getConfig(self):
# 
# Path: moedjpack/moepad/weibowrapper.py
# class WeiboAuthInfoRedis(WeiboAuthInfo):
#     def __init__(self, user_type):
#         super(WeiboAuthInfoRedis, self).__init__(user_type)
#         self.mckey = "WeiboAuth" + user_type
# 
#     def load(self):
#         args = rs.get(self.mckey)
#         if args:
#             for key in args.keys():
#                 setattr(self, key, args[key])
# 
#     def save(self):
#         print self.__dict__
#         confs = sub_dict(self.__dict__,
#                          ['uid', 'access_token', 'expires_in', 'user_type'])
#         rs.hmset(self.mckey, confs)
#         rs.expire(self.mckey, confs['expires_in'])
# 
#     def clean(self):
#         rs.hdel(self.mckey)
# 
# Path: moedjpack/moepad/mputils.py
# def sub_dict(somedict, somekeys, default=None):
# def loggerInit(logfile):
# def utcnow():
# def _deletePrefix(key):
# def create_default_db():


# Path: moedjpack/auth/views.py
import logging
import redis
import pickle
from django.http import HttpResponse
from django.shortcuts import *
from django.contrib.auth.decorators import login_required
from moedjpack import qqweibo
from moedjpack.moepad.mpconf import MPConf
from moedjpack.moepad.weibowrapper import WeiboAuthInfoRedis
from moedjpack.moepad import weibo
from moedjpack.moepad.mputils import rs

    WeiboAuthObj.clean()
    return redirect(authSinaUrl())


@login_required
def clean_auth(request):
    rs.delete('WeiboAuthoriginal')
    return render_to_response("info.html",
                              {'information': '授权信息已清除'})


def getWeiboAuthedApi(source, user_type):
    if user_type == "original":
        weiboData = OriWeiboAuth
    elif user_type == "retweet":
        weiboData = RtWeiboAuth
    else:
        log.error("invalid user type getWeiboAuthedApi")
        raise e

    if source == 'sina':
        client = weibo.APIClient(
            SinaAppKey, SinaAppSecret, MoePadSite+"/sinacallback")
        client.set_access_token(weiboData.access_token, weiboData.expires_in)

        return client


@login_required
def loginSina(request, user_type):

    rs.set("current_user_type", user_type)