nodes: 0, module; 1, function_definition; 2, function_name:metadefs_namespace_list; 3, parameters; 4, block; 5, identifier:request; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, comment:# Listing namespaces requires the v2 API. If not supported we return an; 13, comment:# empty array so callers don't need to worry about version checking.; 14, if_statement; 15, if_statement; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, expression_statement; 20, if_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, comment:# Filter the namespaces based on the provided properties_target since this; 25, comment:# is not supported by the metadata namespaces API.; 26, expression_statement; 27, expression_statement; 28, if_statement; 29, expression_statement; 30, expression_statement; 31, if_statement; 32, expression_statement; 33, return_statement; 34, identifier:filters; 35, None; 36, identifier:sort_dir; 37, string; 38, identifier:sort_key; 39, string; 40, identifier:marker; 41, None; 42, identifier:paginate; 43, False; 44, comment:"""Retrieve a listing of Namespaces
  
      :param paginate: If true will perform pagination based on settings.
      :param marker: Specifies the namespace of the last-seen namespace.
               The typical pattern of limit and marker is to make an
               initial limited request and then to use the last
               namespace from the response as the marker parameter
               in a subsequent limited request. With paginate, limit
               is automatically set.
      :param sort_dir: The sort direction ('asc' or 'desc').
      :param sort_key: The field to sort on (for example, 'created_at'). Default
               is namespace. The way base namespaces are loaded into glance
               typically at first deployment is done in a single transaction
               giving them a potentially unpredictable sort result when using
               create_at.
      :param filters: specifies addition fields to filter on such as
               resource_types.
      :returns A tuple of three values:
          1) Current page results
          2) A boolean of whether or not there are previous page(s).
          3) A boolean of whether or not there are more page(s).
  
      """; 45, comparison_operator:get_version() < 2; 46, block; 47, comparison_operator:filters is None; 48, block; 49, assignment; 50, assignment; 51, identifier:paginate; 52, block; 53, else_clause; 54, assignment; 55, identifier:marker; 56, block; 57, assignment; 58, assignment; 59, assignment; 60, assignment; 61, assignment; 62, boolean_operator; 63, block; 64, assignment; 65, assignment; 66, identifier:paginate; 67, block; 68, else_clause; 69, assignment; 70, expression_list; 71, string_content:asc; 72, string_content:namespace; 73, call; 74, integer:2; 75, return_statement; 76, identifier:filters; 77, None; 78, expression_statement; 79, identifier:limit; 80, call; 81, identifier:page_size; 82, call; 83, expression_statement; 84, block; 85, identifier:kwargs; 86, dictionary; 87, expression_statement; 88, subscript; 89, identifier:sort_dir; 90, subscript; 91, identifier:sort_key; 92, identifier:namespaces_iter; 93, call; 94, identifier:resource_types; 95, call; 96, identifier:properties_target; 97, call; 98, identifier:resource_types; 99, identifier:properties_target; 100, expression_statement; 101, identifier:has_prev_data; 102, False; 103, identifier:has_more_data; 104, False; 105, expression_statement; 106, comment:# first and middle page condition; 107, if_statement; 108, block; 109, identifier:namespaces; 110, list_comprehension; 111, identifier:namespaces; 112, identifier:has_more_data; 113, identifier:has_prev_data; 114, identifier:get_version; 115, argument_list; 116, expression_list; 117, assignment; 118, identifier:getattr; 119, argument_list; 120, attribute; 121, argument_list; 122, assignment; 123, expression_statement; 124, pair; 125, assignment; 126, identifier:kwargs; 127, string; 128, identifier:kwargs; 129, string; 130, attribute; 131, argument_list; 132, attribute; 133, argument_list; 134, attribute; 135, argument_list; 136, assignment; 137, assignment; 138, comparison_operator:len(namespaces) > page_size; 139, block; 140, comment:# first page condition when reached via prev back; 141, elif_clause; 142, comment:# last page condition; 143, elif_clause; 144, expression_statement; 145, call; 146, for_in_clause; 147, list; 148, False; 149, False; 150, identifier:filters; 151, dictionary; 152, identifier:settings; 153, string; 154, integer:1000; 155, identifier:utils; 156, identifier:get_page_size; 157, identifier:request; 158, identifier:request_size; 159, binary_operator:page_size + 1; 160, assignment; 161, string; 162, identifier:filters; 163, subscript; 164, identifier:marker; 165, string_content:sort_dir; 166, string_content:sort_key; 167, attribute; 168, identifier:list; 169, keyword_argument; 170, keyword_argument; 171, dictionary_splat; 172, identifier:filters; 173, identifier:get; 174, string; 175, identifier:filters; 176, identifier:get; 177, string; 178, identifier:namespaces_iter; 179, call; 180, identifier:namespaces; 181, call; 182, call; 183, identifier:page_size; 184, expression_statement; 185, expression_statement; 186, comment:# middle page condition; 187, if_statement; 188, boolean_operator; 189, block; 190, comparison_operator:marker is not None; 191, block; 192, assignment; 193, identifier:Namespace; 194, argument_list; 195, identifier:namespace; 196, identifier:namespaces; 197, string_content:API_RESULT_LIMIT; 198, identifier:page_size; 199, integer:1; 200, identifier:request_size; 201, identifier:limit; 202, string_content:filters; 203, identifier:kwargs; 204, string; 205, call; 206, identifier:metadefs_namespace; 207, identifier:page_size; 208, identifier:request_size; 209, identifier:limit; 210, identifier:limit; 211, identifier:kwargs; 212, string_content:resource_types; 213, string_content:properties_target; 214, identifier:filter_properties_target; 215, argument_list; 216, identifier:list; 217, argument_list; 218, identifier:len; 219, argument_list; 220, call; 221, assignment; 222, comparison_operator:marker is not None; 223, block; 224, comparison_operator:sort_dir == 'desc'; 225, comparison_operator:marker is not None; 226, expression_statement; 227, identifier:marker; 228, None; 229, expression_statement; 230, identifier:namespaces; 231, call; 232, identifier:namespace; 233, string_content:marker; 234, identifier:glanceclient; 235, argument_list; 236, identifier:namespaces_iter; 237, identifier:resource_types; 238, identifier:properties_target; 239, call; 240, identifier:namespaces; 241, attribute; 242, argument_list; 243, identifier:has_more_data; 244, True; 245, identifier:marker; 246, None; 247, expression_statement; 248, identifier:sort_dir; 249, string; 250, identifier:marker; 251, None; 252, assignment; 253, assignment; 254, identifier:list; 255, argument_list; 256, identifier:request; 257, string; 258, attribute; 259, argument_list; 260, identifier:namespaces; 261, identifier:pop; 262, unary_operator; 263, assignment; 264, string_content:desc; 265, identifier:has_more_data; 266, True; 267, identifier:has_prev_data; 268, True; 269, identifier:namespaces_iter; 270, string_content:2; 271, identifier:itertools; 272, identifier:islice; 273, identifier:namespaces_iter; 274, identifier:request_size; 275, integer:1; 276, identifier:has_prev_data; 277, True
code: def metadefs_namespace_list(request,
                              filters=None,
                              sort_dir='asc',
                              sort_key='namespace',
                              marker=None,
                              paginate=False):
      """Retrieve a listing of Namespaces
  
      :param paginate: If true will perform pagination based on settings.
      :param marker: Specifies the namespace of the last-seen namespace.
               The typical pattern of limit and marker is to make an
               initial limited request and then to use the last
               namespace from the response as the marker parameter
               in a subsequent limited request. With paginate, limit
               is automatically set.
      :param sort_dir: The sort direction ('asc' or 'desc').
      :param sort_key: The field to sort on (for example, 'created_at'). Default
               is namespace. The way base namespaces are loaded into glance
               typically at first deployment is done in a single transaction
               giving them a potentially unpredictable sort result when using
               create_at.
      :param filters: specifies addition fields to filter on such as
               resource_types.
      :returns A tuple of three values:
          1) Current page results
          2) A boolean of whether or not there are previous page(s).
          3) A boolean of whether or not there are more page(s).
  
      """
      # Listing namespaces requires the v2 API. If not supported we return an
      # empty array so callers don't need to worry about version checking.
      if get_version() < 2:
          return [], False, False
  
      if filters is None:
          filters = {}
      limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
      page_size = utils.get_page_size(request)
  
      if paginate:
          request_size = page_size + 1
      else:
          request_size = limit
  
      kwargs = {'filters': filters}
      if marker:
          kwargs['marker'] = marker
      kwargs['sort_dir'] = sort_dir
      kwargs['sort_key'] = sort_key
  
      namespaces_iter = glanceclient(request, '2').metadefs_namespace.list(
          page_size=request_size, limit=limit, **kwargs)
  
      # Filter the namespaces based on the provided properties_target since this
      # is not supported by the metadata namespaces API.
      resource_types = filters.get('resource_types')
      properties_target = filters.get('properties_target')
      if resource_types and properties_target:
          namespaces_iter = filter_properties_target(namespaces_iter,
                                                     resource_types,
                                                     properties_target)
  
      has_prev_data = False
      has_more_data = False
      if paginate:
          namespaces = list(itertools.islice(namespaces_iter, request_size))
          # first and middle page condition
          if len(namespaces) > page_size:
              namespaces.pop(-1)
              has_more_data = True
              # middle page condition
              if marker is not None:
                  has_prev_data = True
          # first page condition when reached via prev back
          elif sort_dir == 'desc' and marker is not None:
              has_more_data = True
          # last page condition
          elif marker is not None:
              has_prev_data = True
      else:
          namespaces = list(namespaces_iter)
  
      namespaces = [Namespace(namespace) for namespace in namespaces]
      return namespaces, has_more_data, has_prev_data