MCPcopy
hub / github.com/scrapy/scrapy / _get_serialized_fields

Method _get_serialized_fields

scrapy/exporters.py:74–110  ·  view source on GitHub ↗

Return the fields to export as an iterable of tuples (name, serialized_value)

(
        self, item: Any, default_value: Any = None, include_empty: bool | None = None
    )

Source from the content-addressed store, hash-verified

72 pass
73
74 def _get_serialized_fields(
75 self, item: Any, default_value: Any = None, include_empty: bool | None = None
76 ) -> Iterable[tuple[str, Any]]:
77 """Return the fields to export as an iterable of tuples
78 (name, serialized_value)
79 """
80 item = ItemAdapter(item)
81
82 if include_empty is None:
83 include_empty = self.export_empty_fields
84
85 if self.fields_to_export is None:
86 field_iter = item.field_names() if include_empty else item.keys()
87 elif isinstance(self.fields_to_export, Mapping):
88 if include_empty:
89 field_iter = self.fields_to_export.items()
90 else:
91 field_iter = (
92 (x, y) for x, y in self.fields_to_export.items() if x in item
93 )
94 elif include_empty:
95 field_iter = self.fields_to_export
96 else:
97 field_iter = (x for x in self.fields_to_export if x in item)
98
99 for field_name in field_iter:
100 if isinstance(field_name, str):
101 item_field, output_field = field_name, field_name
102 else:
103 item_field, output_field = field_name
104 if item_field in item:
105 field_meta = item.get_field_meta(item_field)
106 value = self.serialize_field(field_meta, output_field, item[item_field])
107 else:
108 value = default_value
109
110 yield output_field, value
111
112
113class JsonLinesItemExporter(BaseItemExporter):

Callers 9

export_itemMethod · 0.80
export_itemMethod · 0.80
export_itemMethod · 0.80
export_itemMethod · 0.80
export_itemMethod · 0.80
export_itemMethod · 0.80
export_itemMethod · 0.80
export_itemMethod · 0.80
test_fields_to_exportMethod · 0.80

Calls 3

serialize_fieldMethod · 0.95
keysMethod · 0.80
itemsMethod · 0.80

Tested by 1

test_fields_to_exportMethod · 0.64