# Path: torext/make_settings.py
# class Settings(dict, SingletonMixin):
#     def __init__(self):
#     def __getattr__(self, key):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __str__(self):
#     def add_key_callback(self, key, callback):
# 
# Path: torext/compat.py
# PY3 = sys.version_info.major == 3
# PY2 = sys.version_info.major == 2
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):


import logging
import hashlib
import requests
import time
from tornado import escape
from tornado import httpclient
from tornado import gen
from tornado.escape import json_decode
from tornado.httputil import url_concat
from tornado.auth import OAuthMixin, OAuth2Mixin
from tornado.util import bytes_type
from torext import settings
from torext.compat import urlencode, quote, urljoin

    def _oauth_get_user(self, access_token, callback):
        callback = self.async_callback(self._parse_user_response, callback)
        self.douban_request(
            "/people/@me",
            access_token=access_token, callback=callback)

    def _parse_user_response(self, callback, user):
        if user:
            user["uid"] = user["db:uid"]["$t"]
        callback(user)


class TencentOAuthMixin(OAuthMixin):
    _OAUTH_REQUEST_TOKEN_URL = "http://open.t.qq.com/cgi-bin/request_token"
    _OAUTH_ACCESS_TOKEN_URL = "http://open.t.qq.com/cgi-bin/access_token"
    _OAUTH_AUTHORIZE_URL = "http://open.t.qq.com/cgi-bin/authorize"
    _OAUTH_API_DOMAIN = "open.t.qq.com/api"
    #_OAUTH_VERSION = "1.0"

    def tencent_request(self, path, callback, access_token=None,
                        post_args=None, **args):
        # as Tencent is so fucking shit
        # that it use OAuth1.0a but only let the parameter
        # ``oauth_version`` pass value of 1.0,
        # there will be very fucking weird problem occurs
        # if we don't manually change the _OAUTH_VERSION to be 1.0
        # before oauth parameters are generated
        self._OAUTH_VERSION = '1.0'


# Path: torext/make_settings.py
# class Settings(dict, SingletonMixin):
#     def __init__(self):
#     def __getattr__(self, key):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __str__(self):
#     def add_key_callback(self, key, callback):
# 
# Path: torext/compat.py
# PY3 = sys.version_info.major == 3
# PY2 = sys.version_info.major == 2
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):


# Path: torext/handlers/oauth.py
import logging
import hashlib
import requests
import time
from tornado import escape
from tornado import httpclient
from tornado import gen
from tornado.escape import json_decode
from tornado.httputil import url_concat
from tornado.auth import OAuthMixin, OAuth2Mixin
from tornado.util import bytes_type
from torext import settings
from torext.compat import urlencode, quote, urljoin


    def _oauth_get_user(self, access_token, callback):
        callback = self.async_callback(self._parse_user_response, callback)
        self.douban_request(
            "/people/@me",
            access_token=access_token, callback=callback)

    def _parse_user_response(self, callback, user):
        if user:
            user["uid"] = user["db:uid"]["$t"]
        callback(user)


class TencentOAuthMixin(OAuthMixin):
    _OAUTH_REQUEST_TOKEN_URL = "http://open.t.qq.com/cgi-bin/request_token"
    _OAUTH_ACCESS_TOKEN_URL = "http://open.t.qq.com/cgi-bin/access_token"
    _OAUTH_AUTHORIZE_URL = "http://open.t.qq.com/cgi-bin/authorize"
    _OAUTH_API_DOMAIN = "open.t.qq.com/api"
    #_OAUTH_VERSION = "1.0"

    def tencent_request(self, path, callback, access_token=None,
                        post_args=None, **args):
        # as Tencent is so fucking shit
        # that it use OAuth1.0a but only let the parameter
        # ``oauth_version`` pass value of 1.0,
        # there will be very fucking weird problem occurs
        # if we don't manually change the _OAUTH_VERSION to be 1.0
        # before oauth parameters are generated
        self._OAUTH_VERSION = '1.0'


        url = quote("http://" + self._OAUTH_API_DOMAIN + path, ':/')