def authorize_client(client, auth_type=None, service=None, source=None,
                     scopes=None, oauth_type=None, consumer_key=None,
                     consumer_secret=None):
  if auth_type is None:
    auth_type = int(get_param(
        'auth_type', 'Please choose the authorization mechanism you want'
        ' to use.\n'
        '1. to use your email address and password (ClientLogin)\n'
        '2. to use a web browser to visit an auth web page (AuthSub)\n'
        '3. if you have registed to use OAuth\n'))

  # Get the scopes for the services we want to access.
  if auth_type == AUTHSUB or auth_type == OAUTH:
    if scopes is None:
      scopes = get_param(
          'scopes', 'Enter the URL prefixes (scopes) for the resources you '
          'would like to access.\nFor multiple scope URLs, place a comma '
          'between each URL.\n'
          'Example: http://www.google.com/calendar/feeds/,'
          'http://www.google.com/m8/feeds/\n').split(',')
    elif isinstance(scopes, (str, unicode)):
      scopes = scopes.split(',')

  if auth_type == CLIENT_LOGIN:
    email = get_param('email', 'Please enter your username')
    password = get_param('password', 'Password', True)
    if service is None:
      service = get_param(
          'service', 'What is the name of the service you wish to access?'
          '\n(See list:'
          ' http://code.google.com/apis/gdata/faq.html#clientlogin)')
    if source is None:
      source = get_param('source', ask=False)
    client.client_login(email, password, source=source, service=service)
  elif auth_type == AUTHSUB:
    auth_sub_token = get_param('auth_sub_token', ask=False)
    session_token = get_param('session_token', ask=False)
    private_key = None
    auth_url = None
    single_use_token = None
    rsa_private_key = get_param(
        'rsa_private_key', 
        'If you want to use secure mode AuthSub, please provide the\n'
        ' location of your RSA private key which corresponds to the\n'
        ' certificate you have uploaded for your domain. If you do not\n'
        ' have an RSA key, simply press enter')

    if rsa_private_key:
      try:
        private_key_file = open(rsa_private_key, 'rb')
        private_key = private_key_file.read()
        private_key_file.close()
      except IOError:
        print 'Unable to read private key from file'

    if private_key is not None:
      if client.auth_token is None:
        if session_token:
          client.auth_token = gdata.gauth.SecureAuthSubToken(
              session_token, private_key, scopes)
          return
        elif auth_sub_token:
          client.auth_token = gdata.gauth.SecureAuthSubToken(
              auth_sub_token, private_key, scopes)
          client.upgrade_token()
          return
 
      auth_url = gdata.gauth.generate_auth_sub_url(
          'http://gauthmachine.appspot.com/authsub', scopes, True)
      print 'with a private key, get ready for this URL', auth_url

    else:
      if client.auth_token is None:
        if session_token:
          client.auth_token = gdata.gauth.AuthSubToken(session_token, scopes)
          return
        elif auth_sub_token:
          client.auth_token = gdata.gauth.AuthSubToken(auth_sub_token, scopes)
          client.upgrade_token()
          return

        auth_url = gdata.gauth.generate_auth_sub_url(
            'http://gauthmachine.appspot.com/authsub', scopes)

    print 'Visit the following URL in your browser to authorize this app:'
    print str(auth_url)
    print 'After agreeing to authorize the app, copy the token value from the'
    print ' URL. Example: "www.google.com/?token=ab12" token value is ab12'
    token_value = raw_input('Please enter the token value: ')
    if private_key is not None:
      single_use_token = gdata.gauth.SecureAuthSubToken(
          token_value, private_key, scopes)
    else:
      single_use_token = gdata.gauth.AuthSubToken(token_value, scopes)
    client.auth_token = single_use_token
    client.upgrade_token()

  elif auth_type == OAUTH:
    if oauth_type is None:
      oauth_type = int(get_param(
          'oauth_type', 'Please choose the authorization mechanism you want'
          ' to use.\n'
          '1. use an HMAC signature using your consumer key and secret\n'
          '2. use RSA with your private key to sign requests\n'))

    consumer_key = get_param(
        'consumer_key', 'Please enter your OAuth conumer key '
        'which identifies your app')

    if oauth_type == HMAC:
      consumer_secret = get_param(
          'consumer_secret', 'Please enter your OAuth conumer secret '
          'which you share with the OAuth provider', True)
      # Swap out this code once the client supports requesting an oauth token.
      # Get a request token.
      request_token = client.get_oauth_token(
          scopes, 'http://gauthmachine.appspot.com/oauth', consumer_key,
          consumer_secret=consumer_secret)
    elif oauth_type == RSA:
      rsa_private_key = get_param(
          'rsa_private_key', 
          'Please provide the location of your RSA private key which\n'
          ' corresponds to the certificate you have uploaded for your domain.')
      try:
        private_key_file = open(rsa_private_key, 'rb')
        private_key = private_key_file.read()
        private_key_file.close()
      except IOError:
        print 'Unable to read private key from file'
        
      request_token = client.get_oauth_token(
          scopes, 'http://gauthmachine.appspot.com/oauth', consumer_key,
          rsa_private_key=private_key)
    else:
      print 'Invalid OAuth signature type'
      return None

    # Authorize the request token in the browser.
    print 'Visit the following URL in your browser to authorize this app:'
    print str(request_token.generate_authorization_url())
    print 'After agreeing to authorize the app, copy URL from the browser\'s'
    print ' address bar.'
    url = raw_input('Please enter the url: ')
    gdata.gauth.authorize_request_token(request_token, url)
    # Exchange for an access token.
    client.auth_token = client.get_access_token(request_token)

  else:
    print 'Invalid authorization type.'
    return None
Creates a generator returning tuples of information about each record
dataset/ETHPy150Open kuri65536/python-for-android/python-build/python-libs/gdata/build/lib/gdata/sample_util.py/authorize_client--crossover with--dataset/ETHPy150Open wbond/oscrypto/oscrypto/_tls.py/_parse_tls_records