# 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_consumer_token(self):
        return dict(key=settings.networks['weibo']['consumer_key'],
                    secret=settings.networks['weibo']['consumer_secret'])

    def _oauth_get_user(self, access_token, callback):
        callback = self.async_callback(self._parse_user_response, callback)
        self.weibo_request(
            "/users/show",
            access_token=access_token, callback=callback,
            user_id=access_token["user_id"])

    def _parse_user_response(self, callback, user):
        if user:
            user["username"] = user["screen_name"]
        callback(user)


class DoubanOAuthMixin(OAuthMixin):
    _OAUTH_REQUEST_TOKEN_URL = "http://www.douban.com/service/auth/request_token"
    _OAUTH_ACCESS_TOKEN_URL = "http://www.douban.com/service/auth/access_token"
    _OAUTH_AUTHORIZE_URL = "http://www.douban.com/service/auth/authorize"
    _OAUTH_API_DOMAIN = "api.douban.com"
    _OAUTH_VERSION = "1.0"

    def douban_request(self, path, callback, access_token=None,
                       post_args=None, **args):
        # due to some special string like ``@`` may appear in url,
        # and they are required to be quoted before generated to be oauth parameters,
        # (unfortunately tornado don't voluntarily do that)
        # we forwardly quote the url before it is handled.

# 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_consumer_token(self):
        return dict(key=settings.networks['weibo']['consumer_key'],
                    secret=settings.networks['weibo']['consumer_secret'])

    def _oauth_get_user(self, access_token, callback):
        callback = self.async_callback(self._parse_user_response, callback)
        self.weibo_request(
            "/users/show",
            access_token=access_token, callback=callback,
            user_id=access_token["user_id"])

    def _parse_user_response(self, callback, user):
        if user:
            user["username"] = user["screen_name"]
        callback(user)


class DoubanOAuthMixin(OAuthMixin):
    _OAUTH_REQUEST_TOKEN_URL = "http://www.douban.com/service/auth/request_token"
    _OAUTH_ACCESS_TOKEN_URL = "http://www.douban.com/service/auth/access_token"
    _OAUTH_AUTHORIZE_URL = "http://www.douban.com/service/auth/authorize"
    _OAUTH_API_DOMAIN = "api.douban.com"
    _OAUTH_VERSION = "1.0"

    def douban_request(self, path, callback, access_token=None,
                       post_args=None, **args):
        # due to some special string like ``@`` may appear in url,
        # and they are required to be quoted before generated to be oauth parameters,
        # (unfortunately tornado don't voluntarily do that)
        # we forwardly quote the url before it is handled.

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