# Path: tornado/httpclient.py
# class HTTPClient(object):
# class AsyncHTTPClient(object):
# class HTTPRequest(object):
# class HTTPResponse(object):
# class HTTPError(Exception):
#     def __init__(self):
#     def __del__(self):
#     def close(self):
#     def fetch(self, request, **kwargs):
#         def callback(response):
#     def _async_clients(cls):
#     def __new__(cls, io_loop=None, max_clients=10, force_instance=False, 
#                 **kwargs):
#     def close(self):
#     def fetch(self, request, callback, **kwargs):
#     def configure(impl, **kwargs):
#     def __init__(self, url, method="GET", headers=None, body=None,
#                  auth_username=None, auth_password=None,
#                  connect_timeout=20.0, request_timeout=20.0,
#                  if_modified_since=None, follow_redirects=True,
#                  max_redirects=5, user_agent=None, use_gzip=True,
#                  network_interface=None, streaming_callback=None,
#                  header_callback=None, prepare_curl_callback=None,
#                  proxy_host=None, proxy_port=None, proxy_username=None,
#                  proxy_password='', allow_nonstandard_methods=False,
#                  validate_cert=True, ca_certs=None,
#                  allow_ipv6=None,
#                  client_key=None, client_cert=None):
#     def __init__(self, request, code, headers={}, buffer=None,
#                  effective_url=None, error=None, request_time=None,
#                  time_info={}):
#     def _get_body(self):
#     def rethrow(self):
#     def __repr__(self):
#     def __init__(self, code, message=None, response=None):
# def main():
# 
# Path: tornado/escape.py
#             def _json_decode(s):
# def xhtml_escape(value):
# def xhtml_unescape(value):
# def json_encode(value):
# def json_decode(value):
# def squeeze(value):
# def url_escape(value):
#     def url_unescape(value, encoding='utf-8'):
#     def url_unescape(value, encoding='utf-8'):
#     def parse_qs_bytes(qs, keep_blank_values=False, strict_parsing=False):
# def utf8(value):
# def to_unicode(value):
# def to_basestring(value):
# def recursive_unicode(obj):
# def linkify(text, shorten=False, extra_params="",
#             require_protocol=False, permitted_protocols=["http", "https"]):
#     def make_link(m):
# def _convert_entity(m):
# def _build_unicode_map():
# _XHTML_ESCAPE_RE = re.compile('[&<>"]')
# _XHTML_ESCAPE_DICT = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;'}
# _UTF8_TYPES = (bytes, type(None))
# _TO_UNICODE_TYPES = (unicode, type(None))
# _BASESTRING_TYPES = (basestring, type(None))
# _URL_RE = re.compile(ur"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)""")
# _HTML_UNICODE_MAP = _build_unicode_map()
# 
# Path: tornado/httputil.py
# def url_concat(url, args):
#     """Concatenate url and argument dictionary regardless of whether
#     url has existing query parameters.
# 
#     >>> url_concat("http://example.com/foo?a=b", dict(c="d"))
#     'http://example.com/foo?a=b&c=d'
#     """
#     if not args: return url
#     if url[-1] not in ('?', '&'):
#         url += '&' if ('?' in url) else '?'
#     return url + urllib.urlencode(args)
# 
# Path: tornado/util.py
# class ObjectDict(dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# def import_object(name):
#     def b(s):
#     def b(s):
# def doctests():


import base64
import binascii
import hashlib
import hmac
import logging
import time
import urllib
import urlparse
import uuid
from tornado import httpclient
from tornado import escape
from tornado.httputil import url_concat
from tornado.util import bytes_type, b

    See GoogleMixin below for example implementations.
    """
    def authenticate_redirect(self, callback_uri=None,
                              ax_attrs=["name","email","language","username"]):
        """Returns the authentication URL for this service.

        After authentication, the service will redirect back to the given
        callback URI.

        We request the given attributes for the authenticated user by
        default (name, email, language, and username). If you don't need
        all those attributes for your app, you can request fewer with
        the ax_attrs keyword argument.
        """
        callback_uri = callback_uri or self.request.uri
        args = self._openid_args(callback_uri, ax_attrs=ax_attrs)
        self.redirect(self._OPENID_ENDPOINT + "?" + urllib.urlencode(args))

    def get_authenticated_user(self, callback, http_client=None):
        """Fetches the authenticated user data upon redirect.

        This method should be called by the handler that receives the
        redirect from the authenticate_redirect() or authorize_redirect()
        methods.
        """
        # Verify the OpenID response via direct request to the OP
        args = dict((k, v[-1]) for k, v in self.request.arguments.iteritems())
        args["openid.mode"] = u"check_authentication"
        url = self._OPENID_ENDPOINT

# Path: tornado/httpclient.py
# class HTTPClient(object):
# class AsyncHTTPClient(object):
# class HTTPRequest(object):
# class HTTPResponse(object):
# class HTTPError(Exception):
#     def __init__(self):
#     def __del__(self):
#     def close(self):
#     def fetch(self, request, **kwargs):
#         def callback(response):
#     def _async_clients(cls):
#     def __new__(cls, io_loop=None, max_clients=10, force_instance=False, 
#                 **kwargs):
#     def close(self):
#     def fetch(self, request, callback, **kwargs):
#     def configure(impl, **kwargs):
#     def __init__(self, url, method="GET", headers=None, body=None,
#                  auth_username=None, auth_password=None,
#                  connect_timeout=20.0, request_timeout=20.0,
#                  if_modified_since=None, follow_redirects=True,
#                  max_redirects=5, user_agent=None, use_gzip=True,
#                  network_interface=None, streaming_callback=None,
#                  header_callback=None, prepare_curl_callback=None,
#                  proxy_host=None, proxy_port=None, proxy_username=None,
#                  proxy_password='', allow_nonstandard_methods=False,
#                  validate_cert=True, ca_certs=None,
#                  allow_ipv6=None,
#                  client_key=None, client_cert=None):
#     def __init__(self, request, code, headers={}, buffer=None,
#                  effective_url=None, error=None, request_time=None,
#                  time_info={}):
#     def _get_body(self):
#     def rethrow(self):
#     def __repr__(self):
#     def __init__(self, code, message=None, response=None):
# def main():
# 
# Path: tornado/escape.py
#             def _json_decode(s):
# def xhtml_escape(value):
# def xhtml_unescape(value):
# def json_encode(value):
# def json_decode(value):
# def squeeze(value):
# def url_escape(value):
#     def url_unescape(value, encoding='utf-8'):
#     def url_unescape(value, encoding='utf-8'):
#     def parse_qs_bytes(qs, keep_blank_values=False, strict_parsing=False):
# def utf8(value):
# def to_unicode(value):
# def to_basestring(value):
# def recursive_unicode(obj):
# def linkify(text, shorten=False, extra_params="",
#             require_protocol=False, permitted_protocols=["http", "https"]):
#     def make_link(m):
# def _convert_entity(m):
# def _build_unicode_map():
# _XHTML_ESCAPE_RE = re.compile('[&<>"]')
# _XHTML_ESCAPE_DICT = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;'}
# _UTF8_TYPES = (bytes, type(None))
# _TO_UNICODE_TYPES = (unicode, type(None))
# _BASESTRING_TYPES = (basestring, type(None))
# _URL_RE = re.compile(ur"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)""")
# _HTML_UNICODE_MAP = _build_unicode_map()
# 
# Path: tornado/httputil.py
# def url_concat(url, args):
#     """Concatenate url and argument dictionary regardless of whether
#     url has existing query parameters.
# 
#     >>> url_concat("http://example.com/foo?a=b", dict(c="d"))
#     'http://example.com/foo?a=b&c=d'
#     """
#     if not args: return url
#     if url[-1] not in ('?', '&'):
#         url += '&' if ('?' in url) else '?'
#     return url + urllib.urlencode(args)
# 
# Path: tornado/util.py
# class ObjectDict(dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# def import_object(name):
#     def b(s):
#     def b(s):
# def doctests():


# Path: tornado/auth.py
import base64
import binascii
import hashlib
import hmac
import logging
import time
import urllib
import urlparse
import uuid
from tornado import httpclient
from tornado import escape
from tornado.httputil import url_concat
from tornado.util import bytes_type, b


    See GoogleMixin below for example implementations.
    """
    def authenticate_redirect(self, callback_uri=None,
                              ax_attrs=["name","email","language","username"]):
        """Returns the authentication URL for this service.

        After authentication, the service will redirect back to the given
        callback URI.

        We request the given attributes for the authenticated user by
        default (name, email, language, and username). If you don't need
        all those attributes for your app, you can request fewer with
        the ax_attrs keyword argument.
        """
        callback_uri = callback_uri or self.request.uri
        args = self._openid_args(callback_uri, ax_attrs=ax_attrs)
        self.redirect(self._OPENID_ENDPOINT + "?" + urllib.urlencode(args))

    def get_authenticated_user(self, callback, http_client=None):
        """Fetches the authenticated user data upon redirect.

        This method should be called by the handler that receives the
        redirect from the authenticate_redirect() or authorize_redirect()
        methods.
        """
        # Verify the OpenID response via direct request to the OP
        args = dict((k, v[-1]) for k, v in self.request.arguments.iteritems())
        args["openid.mode"] = u"check_authentication"
        url = self._OPENID_ENDPOINT

        if http_client is None: http_client = httpclient.AsyncHTTPClient()