nodes: 0, module; 1, function_definition; 2, function_name:sorted_files_from_bucket; 3, parameters; 4, block; 5, identifier:bucket; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, return_statement; 13, identifier:keys; 14, None; 15, comment:"""Return files from bucket sorted by given keys.
  
      :param bucket: :class:`~invenio_files_rest.models.Bucket` containing the
          files.
      :param keys: Keys order to be used.
      :returns: Sorted list of bucket items.
      """; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, call; 21, identifier:keys; 22, boolean_operator; 23, identifier:total; 24, call; 25, identifier:sortby; 26, call; 27, identifier:values; 28, call; 29, identifier:sorted; 30, argument_list; 31, identifier:keys; 32, list; 33, identifier:len; 34, argument_list; 35, identifier:dict; 36, argument_list; 37, attribute; 38, argument_list; 39, identifier:values; 40, keyword_argument; 41, identifier:keys; 42, call; 43, call; 44, identifier:all; 45, identifier:key; 46, lambda; 47, identifier:zip; 48, argument_list; 49, attribute; 50, argument_list; 51, lambda_parameters; 52, call; 53, identifier:keys; 54, call; 55, identifier:ObjectVersion; 56, identifier:get_by_bucket; 57, identifier:bucket; 58, identifier:x; 59, attribute; 60, argument_list; 61, identifier:range; 62, argument_list; 63, identifier:sortby; 64, identifier:get; 65, attribute; 66, identifier:total; 67, identifier:total; 68, identifier:x; 69, identifier:key
code: def sorted_files_from_bucket(bucket, keys=None):
      """Return files from bucket sorted by given keys.
  
      :param bucket: :class:`~invenio_files_rest.models.Bucket` containing the
          files.
      :param keys: Keys order to be used.
      :returns: Sorted list of bucket items.
      """
      keys = keys or []
      total = len(keys)
      sortby = dict(zip(keys, range(total)))
      values = ObjectVersion.get_by_bucket(bucket).all()
      return sorted(values, key=lambda x: sortby.get(x.key, total))