"""A simple web server to handle OAuth 2.0 redirects.

Partial code taken from google api python client.
see: https://code.google.com/p/google-api-python-client/source/browse/oauth2client/tools.py
Original author: <EMAIL> (<NAME>)
"""

import BaseHTTPServer
import socket
import sys
try:
  from urlparse import parse_qsl
except ImportError:
  from cgi import parse_qsl


class ClientRedirectServer(BaseHTTPServer.HTTPServer):
  """A server to handle OAuth 2.0 redirects back to localhost.

  Waits for a single request and parses the query parameters
  into query_params and then stops serving.
  """
  query_params = {}
  query_path = ""


class ClientRedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  """A handler for OAuth 2.0 redirects back to localhost.

  Waits for a single request and parses the query parameters
  into the servers query_params and then stops serving.
  """

  def do_GET(s):
    """Handle a GET request.

    Parses the query parameters and prints a message
    if the flow has completed. Note that we can't detect
    if an error occurred.
    """
    s.send_response(200)
    s.send_header("Content-type", "text/html")
    s.end_headers()
    s.server.query_path = s.path
    query = s.path.split('?', 1)[-1]
    query = dict(parse_qsl(query))
    s.server.query_params = query
    s.wfile.write("<html><head><title>Authentication Status</title></head>")
    s.wfile.write("<body><p>The authentication flow has completed.</p>")
    s.wfile.write("</body></html>")

  def log_message(self, format, *args):
    """Do not log messages to stdout while running as command line program."""
    pass


"""A simple web server to handle OAuth 2.0 redirects.

Partial code taken from google api python client.
see: https://code.google.com/p/google-api-python-client/source/browse/oauth2client/tools.py
Original author: <EMAIL> (<NAME>)
"""

import BaseHTTPServer
import socket
import sys
try:
  from urlparse import parse_qsl
except ImportError:
  from cgi import parse_qsl


class ClientRedirectServer(BaseHTTPServer.HTTPServer):
  """A server to handle OAuth 2.0 redirects back to localhost.

  Waits for a single request and parses the query parameters
  into query_params and then stops serving.
  """
  query_params = {}
  query_path = ""


class ClientRedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  """A handler for OAuth 2.0 redirects back to localhost.

  Waits for a single request and parses the query parameters
  into the servers query_params and then stops serving.
  """

  def do_GET(s):
    """Handle a GET request.

    Parses the query parameters and prints a message
    if the flow has completed. Note that we can't detect
    if an error occurred.
    """
    s.send_response(200)
    s.send_header("Content-type", "text/html")
    s.end_headers()
    s.server.query_path = s.path
    query = s.path.split('?', 1)[-1]
    query = dict(parse_qsl(query))
    s.server.query_params = query
    s.wfile.write("<html><head><title>Authentication Status</title></head>")
    s.wfile.write("<body><p>The authentication flow has completed.</p>")
    s.wfile.write("</body></html>")

  def log_message(self, format, *args):
    """Do not log messages to stdout while running as command line program."""
    pass


A simple web server to handle OAuth 2.0 redirects.  Partial code taken from google api python client. see: https://code.google.com/p/google-api-python-client/source/browse/oauth2client/tools.py Original author: <EMAIL> (<NAME>) A server to handle OAuth 2.0 redirects back to localhost.    Waits for a single request and parses the query parameters   into query_params and then stops serving. A handler for OAuth 2.0 redirects back to localhost.    Waits for a single request and parses the query parameters   into the servers query_params and then stops serving. Handle a GET request.      Parses the query parameters and prints a message     if the flow has completed. Note that we can't detect     if an error occurred. Do not log messages to stdout while running as command line program.