1919from typing import TextIO
2020from xml .sax import saxutils
2121
22- from odin import Resource , fields , serializers
22+ from odin import fields , serializers
2323from odin .fields import StringField , composite
2424from odin .utils import attribute_field_iter_items , element_field_iter_items , getmeta
2525
@@ -48,7 +48,7 @@ def _serialize_to_string(value):
4848def dump (
4949 fp : TextIO ,
5050 resource , # type: Resource
51- line_ending = "" , # type: str
51+ line_ending : str = "" ,
5252):
5353 """
5454 Dump a resource to a file like object.
@@ -60,9 +60,7 @@ def dump(
6060
6161 # Write container and any attributes
6262 attributes = "" .join (
63- " {}={}" .format (
64- f .name , saxutils .quoteattr (_serialize_to_string (v ))
65- ) # Encode attributes
63+ f" { f .name } ={ saxutils .quoteattr (_serialize_to_string (v ))} " # Encode attributes
6664 for f , v in attribute_field_iter_items (resource )
6765 )
6866 fp .write (f"<{ meta .name } { attributes } >{ line_ending } " )
@@ -84,27 +82,16 @@ def dump(
8482 elif isinstance (field , fields .ArrayField ):
8583 for v in value :
8684 fp .write (
87- "<{}>{}</{}>{}" .format (
88- field .name , _serialize_to_string (v ), field .name , line_ending
89- )
85+ f"<{ field .name } >{ _serialize_to_string (v )} </{ field .name } >{ line_ending } "
9086 )
9187
9288 elif isinstance (field , TextField ):
9389 if value is not None :
94- fp .write (
95- "{}{}" .format (
96- saxutils .escape (_serialize_to_string (value )), line_ending
97- )
98- )
90+ fp .write (f"{ saxutils .escape (_serialize_to_string (value ))} { line_ending } " )
9991
10092 else :
10193 fp .write (
102- "<{}>{}</{}>{}" .format (
103- field .name ,
104- saxutils .escape (_serialize_to_string (value )),
105- field .name ,
106- line_ending ,
107- )
94+ f"<{ field .name } >{ saxutils .escape (_serialize_to_string (value ))} </{ field .name } >{ line_ending } "
10895 )
10996
11097 fp .write (f"</{ meta .name } >{ line_ending } " )
0 commit comments