nodes: 0, module; 1, function_definition; 2, function_name:list_kadastrale_afdelingen_by_gemeente; 3, parameters; 4, block; 5, identifier:self; 6, identifier:gemeente; 7, default_parameter; 8, expression_statement; 9, try_statement; 10, expression_statement; 11, function_definition; 12, if_statement; 13, for_statement; 14, return_statement; 15, identifier:sort; 16, integer:1; 17, string; 18, block; 19, except_clause; 20, call; 21, function_name:creator; 22, parameters; 23, block; 24, attribute; 25, block; 26, else_clause; 27, identifier:a; 28, identifier:afdelingen; 29, block; 30, identifier:afdelingen; 31, string_content; 32, expression_statement; 33, identifier:AttributeError; 34, block; 35, attribute; 36, argument_list; 37, expression_statement; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, return_statement; 42, subscript; 43, identifier:is_configured; 44, expression_statement; 45, expression_statement; 46, block; 47, expression_statement; 48, escape_sequence:\; 49, assignment; 50, expression_statement; 51, expression_statement; 52, identifier:gemeente; 53, identifier:clear_gateway; 54, assignment; 55, assignment; 56, assignment; 57, assignment; 58, list_comprehension; 59, attribute; 60, string; 61, assignment; 62, assignment; 63, expression_statement; 64, call; 65, identifier:gid; 66, attribute; 67, assignment; 68, assignment; 69, identifier:url; 70, binary_operator:self.base_url + '/municipality/%s/department' % gid; 71, identifier:h; 72, attribute; 73, identifier:p; 74, dictionary; 75, identifier:res; 76, call; 77, call; 78, for_in_clause; 79, identifier:self; 80, identifier:caches; 81, string_content:permanent; 82, identifier:key; 83, binary_operator:'list_kadastrale_afdelingen_by_gemeente_rest#%s#%s' % (gid, sort); 84, identifier:afdelingen; 85, call; 86, assignment; 87, attribute; 88, argument_list; 89, identifier:gemeente; 90, identifier:id; 91, identifier:gid; 92, identifier:gemeente; 93, identifier:gemeente; 94, call; 95, attribute; 96, binary_operator:'/municipality/%s/department' % gid; 97, identifier:self; 98, identifier:base_headers; 99, pair; 100, attribute; 101, argument_list; 102, identifier:Afdeling; 103, argument_list; 104, identifier:r; 105, subscript; 106, string; 107, tuple; 108, attribute; 109, argument_list; 110, identifier:afdelingen; 111, call; 112, identifier:a; 113, identifier:set_gateway; 114, identifier:self; 115, attribute; 116, argument_list; 117, identifier:self; 118, identifier:base_url; 119, string; 120, identifier:gid; 121, string; 122, comparison_operator:sort == 1; 123, call; 124, identifier:json; 125, keyword_argument; 126, keyword_argument; 127, keyword_argument; 128, identifier:res; 129, string; 130, string_content:list_kadastrale_afdelingen_by_gemeente_rest#%s#%s; 131, identifier:gid; 132, identifier:sort; 133, subscript; 134, identifier:get_or_create; 135, identifier:key; 136, identifier:creator; 137, identifier:creator; 138, argument_list; 139, identifier:self; 140, identifier:get_gemeente_by_id; 141, identifier:gid; 142, string_content:/municipality/%s/department; 143, string_content:orderbyCode; 144, identifier:sort; 145, integer:1; 146, identifier:capakey_rest_gateway_request; 147, argument_list; 148, identifier:id; 149, subscript; 150, identifier:naam; 151, subscript; 152, identifier:gemeente; 153, identifier:gemeente; 154, string_content:departments; 155, attribute; 156, string; 157, identifier:url; 158, identifier:h; 159, identifier:p; 160, identifier:r; 161, string; 162, identifier:r; 163, string; 164, identifier:self; 165, identifier:caches; 166, string_content:permanent; 167, string_content:departmentCode; 168, string_content:departmentName
code: def list_kadastrale_afdelingen_by_gemeente(self, gemeente, sort=1):
          '''
          List all `kadastrale afdelingen` in a `gemeente`.
  
          :param gemeente: The :class:`Gemeente` for which the \
              `afdelingen` are wanted.
          :param integer sort: Field to sort on.
          :rtype: A :class:`list` of :class:`Afdeling`.
          '''
          try:
              gid = gemeente.id
          except AttributeError:
              gid = gemeente
              gemeente = self.get_gemeente_by_id(gid)
          gemeente.clear_gateway()
  
          def creator():
              url = self.base_url + '/municipality/%s/department' % gid
              h = self.base_headers
              p = {
                  'orderbyCode': sort == 1
              }
              res = capakey_rest_gateway_request(url, h, p).json()
              return [
                  Afdeling(
                      id=r['departmentCode'],
                      naam=r['departmentName'],
                      gemeente=gemeente
                  ) for r in res['departments']]
  
          if self.caches['permanent'].is_configured:
              key = 'list_kadastrale_afdelingen_by_gemeente_rest#%s#%s' % (gid, sort)
              afdelingen = self.caches['permanent'].get_or_create(key, creator)
          else:
              afdelingen = creator()
          for a in afdelingen:
              a.set_gateway(self)
          return afdelingen