nodes: 0, module; 1, function_definition; 2, function_name:find_items; 3, parameters; 4, block; 5, identifier:self; 6, identifier:q; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, if_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, comment:# Build up any restrictions; 22, if_statement; 23, expression_statement; 24, expression_statement; 25, if_statement; 26, identifier:shape; 27, identifier:ID_ONLY; 28, identifier:depth; 29, identifier:SHALLOW; 30, identifier:additional_fields; 31, None; 32, identifier:order_fields; 33, None; 34, identifier:calendar_view; 35, None; 36, identifier:page_size; 37, None; 38, identifier:max_items; 39, None; 40, identifier:offset; 41, integer:0; 42, comment:"""
          Private method to call the FindItem service
  
          :param q: a Q instance containing any restrictions
          :param shape: controls whether to return (id, chanegkey) tuples or Item objects. If additional_fields is
                 non-null, we always return Item objects.
          :param depth: controls the whether to return soft-deleted items or not.
          :param additional_fields: the extra properties we want on the return objects. Default is no properties. Be
                 aware that complex fields can only be fetched with fetch() (i.e. the GetItem service).
          :param order_fields: the SortOrder fields, if any
          :param calendar_view: a CalendarView instance, if any
          :param page_size: the requested number of items per page
          :param max_items: the max number of items to return
          :param offset: the offset relative to the first item in the item collection
          :return: a generator for the returned item IDs or items
          """; 43, comparison_operator:shape not in SHAPE_CHOICES; 44, block; 45, comparison_operator:depth not in ITEM_TRAVERSAL_CHOICES; 46, block; 47, not_operator; 48, block; 49, identifier:additional_fields; 50, block; 51, boolean_operator; 52, block; 53, call; 54, block; 55, elif_clause; 56, else_clause; 57, call; 58, assignment; 59, boolean_operator; 60, block; 61, else_clause; 62, identifier:shape; 63, identifier:SHAPE_CHOICES; 64, raise_statement; 65, identifier:depth; 66, identifier:ITEM_TRAVERSAL_CHOICES; 67, raise_statement; 68, attribute; 69, expression_statement; 70, return_statement; 71, for_statement; 72, for_statement; 73, comparison_operator:calendar_view is not None; 74, not_operator; 75, raise_statement; 76, attribute; 77, argument_list; 78, expression_statement; 79, expression_statement; 80, attribute; 81, block; 82, block; 83, attribute; 84, argument_list; 85, identifier:items; 86, call; 87, comparison_operator:shape == ID_ONLY; 88, comparison_operator:additional_fields is None; 89, for_statement; 90, block; 91, call; 92, call; 93, identifier:self; 94, identifier:folders; 95, call; 96, identifier:f; 97, identifier:additional_fields; 98, block; 99, identifier:f; 100, identifier:additional_fields; 101, block; 102, identifier:calendar_view; 103, None; 104, call; 105, call; 106, identifier:q; 107, identifier:is_empty; 108, assignment; 109, assignment; 110, identifier:q; 111, identifier:query_string; 112, expression_statement; 113, expression_statement; 114, expression_statement; 115, expression_statement; 116, identifier:log; 117, identifier:debug; 118, string; 119, attribute; 120, attribute; 121, identifier:shape; 122, identifier:depth; 123, identifier:additional_fields; 124, conditional_expression:restriction.q if restriction else None; 125, attribute; 126, argument_list; 127, identifier:shape; 128, identifier:ID_ONLY; 129, identifier:additional_fields; 130, None; 131, identifier:i; 132, identifier:items; 133, block; 134, for_statement; 135, identifier:ValueError; 136, argument_list; 137, identifier:ValueError; 138, argument_list; 139, attribute; 140, argument_list; 141, expression_statement; 142, if_statement; 143, identifier:isinstance; 144, argument_list; 145, identifier:ValueError; 146, argument_list; 147, identifier:restriction; 148, None; 149, identifier:query_string; 150, None; 151, assignment; 152, assignment; 153, assignment; 154, assignment; 155, string_content:Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s); 156, identifier:self; 157, identifier:folders; 158, identifier:self; 159, identifier:account; 160, attribute; 161, identifier:restriction; 162, None; 163, call; 164, identifier:call; 165, keyword_argument; 166, keyword_argument; 167, keyword_argument; 168, keyword_argument; 169, keyword_argument; 170, keyword_argument; 171, keyword_argument; 172, keyword_argument; 173, keyword_argument; 174, expression_statement; 175, identifier:i; 176, identifier:items; 177, block; 178, binary_operator:"'shape' %s must be one of %s" % (shape, SHAPE_CHOICES); 179, binary_operator:"'depth' %s must be one of %s" % (depth, ITEM_TRAVERSAL_CHOICES); 180, identifier:log; 181, identifier:debug; 182, string; 183, call; 184, attribute; 185, block; 186, identifier:calendar_view; 187, identifier:CalendarView; 188, binary_operator:"'calendar_view' %s must be a CalendarView instance" % calendar_view; 189, identifier:restriction; 190, None; 191, identifier:query_string; 192, call; 193, identifier:restriction; 194, call; 195, identifier:query_string; 196, None; 197, identifier:restriction; 198, identifier:q; 199, identifier:FindItem; 200, argument_list; 201, identifier:additional_fields; 202, identifier:additional_fields; 203, identifier:restriction; 204, identifier:restriction; 205, identifier:order_fields; 206, identifier:order_fields; 207, identifier:shape; 208, identifier:shape; 209, identifier:query_string; 210, identifier:query_string; 211, identifier:depth; 212, identifier:depth; 213, identifier:calendar_view; 214, identifier:calendar_view; 215, identifier:max_items; 216, conditional_expression:calendar_view.max_items if calendar_view else max_items; 217, identifier:offset; 218, identifier:offset; 219, yield; 220, if_statement; 221, string:"'shape' %s must be one of %s"; 222, tuple; 223, string:"'depth' %s must be one of %s"; 224, tuple; 225, string_content:Folder list is empty; 226, attribute; 227, argument_list; 228, attribute; 229, identifier:is_complex; 230, raise_statement; 231, string:"'calendar_view' %s must be a CalendarView instance"; 232, identifier:calendar_view; 233, identifier:Restriction; 234, argument_list; 235, identifier:Restriction; 236, argument_list; 237, keyword_argument; 238, keyword_argument; 239, keyword_argument; 240, attribute; 241, identifier:calendar_view; 242, identifier:max_items; 243, conditional_expression:i if isinstance(i, Exception) else Item.id_from_xml(i); 244, call; 245, block; 246, else_clause; 247, identifier:shape; 248, identifier:SHAPE_CHOICES; 249, identifier:depth; 250, identifier:ITEM_TRAVERSAL_CHOICES; 251, identifier:self; 252, identifier:validate_item_field; 253, keyword_argument; 254, identifier:f; 255, identifier:field; 256, call; 257, identifier:q; 258, keyword_argument; 259, keyword_argument; 260, identifier:q; 261, keyword_argument; 262, keyword_argument; 263, identifier:account; 264, attribute; 265, identifier:folders; 266, attribute; 267, identifier:chunk_size; 268, identifier:page_size; 269, identifier:calendar_view; 270, identifier:max_items; 271, identifier:i; 272, call; 273, call; 274, identifier:isinstance; 275, argument_list; 276, expression_statement; 277, block; 278, identifier:field; 279, identifier:f; 280, identifier:ValueError; 281, argument_list; 282, identifier:folders; 283, attribute; 284, identifier:applies_to; 285, attribute; 286, identifier:folders; 287, attribute; 288, identifier:applies_to; 289, attribute; 290, identifier:self; 291, identifier:account; 292, identifier:self; 293, identifier:folders; 294, identifier:isinstance; 295, argument_list; 296, attribute; 297, argument_list; 298, identifier:i; 299, identifier:Exception; 300, yield; 301, expression_statement; 302, binary_operator:"find_items() does not support field '%s'. Use fetch() instead" % f.field.name; 303, identifier:self; 304, identifier:folders; 305, identifier:Restriction; 306, identifier:ITEMS; 307, identifier:self; 308, identifier:folders; 309, identifier:Restriction; 310, identifier:ITEMS; 311, identifier:i; 312, identifier:Exception; 313, identifier:Item; 314, identifier:id_from_xml; 315, identifier:i; 316, identifier:i; 317, yield; 318, string:"find_items() does not support field '%s'. Use fetch() instead"; 319, attribute; 320, call; 321, attribute; 322, identifier:name; 323, attribute; 324, argument_list; 325, identifier:f; 326, identifier:field; 327, call; 328, identifier:from_xml; 329, keyword_argument; 330, keyword_argument; 331, attribute; 332, argument_list; 333, identifier:elem; 334, identifier:i; 335, identifier:account; 336, attribute; 337, identifier:Folder; 338, identifier:item_model_from_tag; 339, attribute; 340, identifier:self; 341, identifier:account; 342, identifier:i; 343, identifier:tag
code: def find_items(self, q, shape=ID_ONLY, depth=SHALLOW, additional_fields=None, order_fields=None,
                     calendar_view=None, page_size=None, max_items=None, offset=0):
          """
          Private method to call the FindItem service
  
          :param q: a Q instance containing any restrictions
          :param shape: controls whether to return (id, chanegkey) tuples or Item objects. If additional_fields is
                 non-null, we always return Item objects.
          :param depth: controls the whether to return soft-deleted items or not.
          :param additional_fields: the extra properties we want on the return objects. Default is no properties. Be
                 aware that complex fields can only be fetched with fetch() (i.e. the GetItem service).
          :param order_fields: the SortOrder fields, if any
          :param calendar_view: a CalendarView instance, if any
          :param page_size: the requested number of items per page
          :param max_items: the max number of items to return
          :param offset: the offset relative to the first item in the item collection
          :return: a generator for the returned item IDs or items
          """
          if shape not in SHAPE_CHOICES:
              raise ValueError("'shape' %s must be one of %s" % (shape, SHAPE_CHOICES))
          if depth not in ITEM_TRAVERSAL_CHOICES:
              raise ValueError("'depth' %s must be one of %s" % (depth, ITEM_TRAVERSAL_CHOICES))
          if not self.folders:
              log.debug('Folder list is empty')
              return
          if additional_fields:
              for f in additional_fields:
                  self.validate_item_field(field=f)
              for f in additional_fields:
                  if f.field.is_complex:
                      raise ValueError("find_items() does not support field '%s'. Use fetch() instead" % f.field.name)
          if calendar_view is not None and not isinstance(calendar_view, CalendarView):
              raise ValueError("'calendar_view' %s must be a CalendarView instance" % calendar_view)
  
          # Build up any restrictions
          if q.is_empty():
              restriction = None
              query_string = None
          elif q.query_string:
              restriction = None
              query_string = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
          else:
              restriction = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
              query_string = None
          log.debug(
              'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)',
              self.folders,
              self.account,
              shape,
              depth,
              additional_fields,
              restriction.q if restriction else None,
          )
          items = FindItem(account=self.account, folders=self.folders, chunk_size=page_size).call(
              additional_fields=additional_fields,
              restriction=restriction,
              order_fields=order_fields,
              shape=shape,
              query_string=query_string,
              depth=depth,
              calendar_view=calendar_view,
              max_items=calendar_view.max_items if calendar_view else max_items,
              offset=offset,
          )
          if shape == ID_ONLY and additional_fields is None:
              for i in items:
                  yield i if isinstance(i, Exception) else Item.id_from_xml(i)
          else:
              for i in items:
                  if isinstance(i, Exception):
                      yield i
                  else:
                      yield Folder.item_model_from_tag(i.tag).from_xml(elem=i, account=self.account)