code: def _get_fields(attrs, field_class, pop=False, ordered=False):
      fields = [
          (field_name, field_value)
          for field_name, field_value in iteritems(attrs)
          if is_instance_or_subclass(field_value, field_class)
      ]
      if pop:
          for field_name, _ in fields:
              del attrs[field_name]
      if ordered:
          fields.sort(key=lambda pair: pair[1]._creation_index)
      return fields