nodes: 0, module; 1, function_definition; 2, function_name:GetCredentials; 3, parameters; 4, block; 5, identifier:package_name; 6, identifier:scopes; 7, identifier:client_id; 8, identifier:client_secret; 9, identifier:user_agent; 10, default_parameter; 11, default_parameter; 12, comment:# pylint: disable=unused-argument; 13, default_parameter; 14, comment:# pylint: disable=unused-argument; 15, default_parameter; 16, dictionary_splat_pattern; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, for_statement; 21, expression_statement; 22, expression_statement; 23, if_statement; 24, raise_statement; 25, identifier:credentials_filename; 26, None; 27, identifier:api_key; 28, None; 29, identifier:client; 30, None; 31, identifier:oauth2client_args; 32, None; 33, identifier:kwds; 34, comment:"""Attempt to get credentials, using an oauth dance as the last resort."""; 35, assignment; 36, assignment; 37, identifier:method; 38, identifier:_CREDENTIALS_METHODS; 39, block; 40, assignment; 41, assignment; 42, comparison_operator:credentials is not None; 43, block; 44, call; 45, identifier:scopes; 46, call; 47, identifier:client_info; 48, dictionary; 49, expression_statement; 50, if_statement; 51, identifier:credentials_filename; 52, boolean_operator; 53, identifier:credentials; 54, call; 55, identifier:credentials; 56, None; 57, return_statement; 58, attribute; 59, argument_list; 60, attribute; 61, argument_list; 62, pair; 63, pair; 64, pair; 65, pair; 66, assignment; 67, comparison_operator:credentials is not None; 68, block; 69, identifier:credentials_filename; 70, call; 71, identifier:CredentialsFromFile; 72, argument_list; 73, identifier:credentials; 74, identifier:exceptions; 75, identifier:CredentialsError; 76, string; 77, identifier:util; 78, identifier:NormalizeScopes; 79, identifier:scopes; 80, string; 81, identifier:client_id; 82, string; 83, identifier:client_secret; 84, string; 85, call; 86, string; 87, boolean_operator; 88, identifier:credentials; 89, call; 90, identifier:credentials; 91, None; 92, return_statement; 93, attribute; 94, argument_list; 95, identifier:credentials_filename; 96, identifier:client_info; 97, keyword_argument; 98, string_content:Could not create valid credentials; 99, string_content:client_id; 100, string_content:client_secret; 101, string_content:scope; 102, attribute; 103, argument_list; 104, string_content:user_agent; 105, identifier:user_agent; 106, binary_operator:'%s-generated/0.1' % package_name; 107, identifier:method; 108, argument_list; 109, identifier:credentials; 110, attribute; 111, identifier:expanduser; 112, string; 113, identifier:oauth2client_args; 114, identifier:oauth2client_args; 115, string; 116, identifier:join; 117, call; 118, string; 119, identifier:package_name; 120, identifier:client_info; 121, dictionary_splat; 122, identifier:os; 123, identifier:path; 124, string_content:~/.apitools.token; 125, string_content:; 126, identifier:sorted; 127, argument_list; 128, string_content:%s-generated/0.1; 129, identifier:kwds; 130, identifier:scopes
code: def GetCredentials(package_name, scopes, client_id, client_secret, user_agent,
                     credentials_filename=None,
                     api_key=None,  # pylint: disable=unused-argument
                     client=None,  # pylint: disable=unused-argument
                     oauth2client_args=None,
                     **kwds):
      """Attempt to get credentials, using an oauth dance as the last resort."""
      scopes = util.NormalizeScopes(scopes)
      client_info = {
          'client_id': client_id,
          'client_secret': client_secret,
          'scope': ' '.join(sorted(scopes)),
          'user_agent': user_agent or '%s-generated/0.1' % package_name,
      }
      for method in _CREDENTIALS_METHODS:
          credentials = method(client_info, **kwds)
          if credentials is not None:
              return credentials
      credentials_filename = credentials_filename or os.path.expanduser(
          '~/.apitools.token')
      credentials = CredentialsFromFile(credentials_filename, client_info,
                                        oauth2client_args=oauth2client_args)
      if credentials is not None:
          return credentials
      raise exceptions.CredentialsError('Could not create valid credentials')