@@ -15,31 +15,34 @@ def contain_new_line(elems):
1515 ])
1616
1717
18- def serialize (resource , with_junk = False ):
19- parts = []
20- if resource .comment :
21- parts .append (
22- "{}\n \n " .format (
23- serialize_comment (resource .comment )
18+ class FluentSerializer (object ):
19+ def __init__ (self , with_junk = False ):
20+ self .with_junk = with_junk
21+
22+ def serialize (self , resource ):
23+ parts = []
24+ if resource .comment :
25+ parts .append (
26+ "{}\n \n " .format (
27+ serialize_comment (resource .comment )
28+ )
2429 )
25- )
26- for entry in resource .body :
27- if not isinstance (entry , ast .Junk ) or with_junk :
28- parts .append (serialize_entry (entry ))
29-
30- return "" .join (parts )
31-
32-
33- def serialize_entry (entry ):
34- if isinstance (entry , ast .Message ):
35- return serialize_message (entry )
36- if isinstance (entry , ast .Section ):
37- return serialize_section (entry )
38- if isinstance (entry , ast .Comment ):
39- return serialize_comment (entry )
40- if isinstance (entry , ast .Junk ):
41- return serialize_junk (entry )
42- raise Exception ('Unknown entry type: {}' .format (entry .type ))
30+ for entry in resource .body :
31+ if not isinstance (entry , ast .Junk ) or self .with_junk :
32+ parts .append (self .serialize_entry (entry ))
33+
34+ return "" .join (parts )
35+
36+ def serialize_entry (self , entry ):
37+ if isinstance (entry , ast .Message ):
38+ return serialize_message (entry )
39+ if isinstance (entry , ast .Section ):
40+ return serialize_section (entry )
41+ if isinstance (entry , ast .Comment ):
42+ return serialize_comment (entry )
43+ if isinstance (entry , ast .Junk ):
44+ return serialize_junk (entry )
45+ raise Exception ('Unknown entry type: {}' .format (entry .type ))
4346
4447
4548def serialize_comment (comment ):
0 commit comments