@@ -464,7 +464,7 @@ <h1 class="title">Module <code>gedcom.parser</code></h1>
464464 for family_member in family.get_child_elements():
465465
466466 if family_member.get_tag() == gedcom.tags.GEDCOM_TAG_CHILD \
467- and family_member.get_value() == individual.get_pointer():
467+ and family_member.get_value() == individual.get_pointer():
468468
469469 for child in family_member.get_child_elements():
470470 if child.get_value() == "Natural":
@@ -546,19 +546,32 @@ <h1 class="title">Module <code>gedcom.parser</code></h1>
546546
547547 # Other methods
548548
549+ def to_gedcom_string(self, recursive=False):
550+ """Formats all elements and optionally all of the sub-elements into a GEDCOM string
551+ :type recursive: bool
552+ """
553+ is_gte_python_3 = version_info[0] >= 3
554+ output = '' if is_gte_python_3 else b''
555+
556+ for element in self.get_root_child_elements():
557+ if is_gte_python_3:
558+ output += element.to_gedcom_string(recursive)
559+ else:
560+ output += element.to_gedcom_string(recursive).encode('utf-8-sig')
561+
562+ return output
563+
549564 def print_gedcom(self):
550565 """Write GEDCOM data to stdout"""
551566 from sys import stdout
552567 self.save_gedcom(stdout)
553568
554- def save_gedcom(self, open_file):
569+ def save_gedcom(self, open_file, recursive=True ):
555570 """Save GEDCOM data to a file
556571 :type open_file: file
572+ :type recursive: bool
557573 """
558- if version_info[0] >= 3:
559- open_file.write(self.get_root_element().to_gedcom_string(True))
560- else:
561- open_file.write(self.get_root_element().to_gedcom_string(True).encode('utf-8-sig'))</ code > </ pre >
574+ open_file.write(self.to_gedcom_string(recursive))</ code > </ pre >
562575</ details >
563576</ section >
564577< section >
@@ -989,7 +1002,7 @@ <h3>Ancestors</h3>
9891002 for family_member in family.get_child_elements():
9901003
9911004 if family_member.get_tag() == gedcom.tags.GEDCOM_TAG_CHILD \
992- and family_member.get_value() == individual.get_pointer():
1005+ and family_member.get_value() == individual.get_pointer():
9931006
9941007 for child in family_member.get_child_elements():
9951008 if child.get_value() == "Natural":
@@ -1071,19 +1084,32 @@ <h3>Ancestors</h3>
10711084
10721085 # Other methods
10731086
1087+ def to_gedcom_string(self, recursive=False):
1088+ """Formats all elements and optionally all of the sub-elements into a GEDCOM string
1089+ :type recursive: bool
1090+ """
1091+ is_gte_python_3 = version_info[0] >= 3
1092+ output = '' if is_gte_python_3 else b''
1093+
1094+ for element in self.get_root_child_elements():
1095+ if is_gte_python_3:
1096+ output += element.to_gedcom_string(recursive)
1097+ else:
1098+ output += element.to_gedcom_string(recursive).encode('utf-8-sig')
1099+
1100+ return output
1101+
10741102 def print_gedcom(self):
10751103 """Write GEDCOM data to stdout"""
10761104 from sys import stdout
10771105 self.save_gedcom(stdout)
10781106
1079- def save_gedcom(self, open_file):
1107+ def save_gedcom(self, open_file, recursive=True ):
10801108 """Save GEDCOM data to a file
10811109 :type open_file: file
1110+ :type recursive: bool
10821111 """
1083- if version_info[0] >= 3:
1084- open_file.write(self.get_root_element().to_gedcom_string(True))
1085- else:
1086- open_file.write(self.get_root_element().to_gedcom_string(True).encode('utf-8-sig'))</ code > </ pre >
1112+ open_file.write(self.to_gedcom_string(recursive))</ code > </ pre >
10871113</ details >
10881114< h3 > Methods</ h3 >
10891115< dl >
@@ -1450,7 +1476,7 @@ <h3>Methods</h3>
14501476 for family_member in family.get_child_elements():
14511477
14521478 if family_member.get_tag() == gedcom.tags.GEDCOM_TAG_CHILD \
1453- and family_member.get_value() == individual.get_pointer():
1479+ and family_member.get_value() == individual.get_pointer():
14541480
14551481 for child in family_member.get_child_elements():
14561482 if child.get_value() == "Natural":
@@ -1649,23 +1675,48 @@ <h3>Methods</h3>
16491675</ details >
16501676</ dd >
16511677< dt id ="gedcom.parser.Parser.save_gedcom "> < code class ="name flex ">
1652- < span > def < span class ="ident "> save_gedcom</ span > </ span > (< span > self, open_file)</ span >
1678+ < span > def < span class ="ident "> save_gedcom</ span > </ span > (< span > self, open_file, recursive=True )</ span >
16531679</ code > </ dt >
16541680< dd >
16551681< section class ="desc "> < p > Save GEDCOM data to a file
1656- :type open_file: file</ p > </ section >
1682+ :type open_file: file
1683+ :type recursive: bool</ p > </ section >
16571684< details class ="source ">
16581685< summary >
16591686< span > Expand source code</ span >
16601687</ summary >
1661- < pre > < code class ="python "> def save_gedcom(self, open_file):
1688+ < pre > < code class ="python "> def save_gedcom(self, open_file, recursive=True ):
16621689 """Save GEDCOM data to a file
16631690 :type open_file: file
1691+ :type recursive: bool
16641692 """
1665- if version_info[0] >= 3:
1666- open_file.write(self.get_root_element().to_gedcom_string(True))
1667- else:
1668- open_file.write(self.get_root_element().to_gedcom_string(True).encode('utf-8-sig'))</ code > </ pre >
1693+ open_file.write(self.to_gedcom_string(recursive))</ code > </ pre >
1694+ </ details >
1695+ </ dd >
1696+ < dt id ="gedcom.parser.Parser.to_gedcom_string "> < code class ="name flex ">
1697+ < span > def < span class ="ident "> to_gedcom_string</ span > </ span > (< span > self, recursive=False)</ span >
1698+ </ code > </ dt >
1699+ < dd >
1700+ < section class ="desc "> < p > Formats all elements and optionally all of the sub-elements into a GEDCOM string
1701+ :type recursive: bool</ p > </ section >
1702+ < details class ="source ">
1703+ < summary >
1704+ < span > Expand source code</ span >
1705+ </ summary >
1706+ < pre > < code class ="python "> def to_gedcom_string(self, recursive=False):
1707+ """Formats all elements and optionally all of the sub-elements into a GEDCOM string
1708+ :type recursive: bool
1709+ """
1710+ is_gte_python_3 = version_info[0] >= 3
1711+ output = '' if is_gte_python_3 else b''
1712+
1713+ for element in self.get_root_child_elements():
1714+ if is_gte_python_3:
1715+ output += element.to_gedcom_string(recursive)
1716+ else:
1717+ output += element.to_gedcom_string(recursive).encode('utf-8-sig')
1718+
1719+ return output</ code > </ pre >
16691720</ details >
16701721</ dd >
16711722</ dl >
@@ -1710,6 +1761,7 @@ <h4><code><a title="gedcom.parser.Parser" href="#gedcom.parser.Parser">Parser</a
17101761< li > < code > < a title ="gedcom.parser.Parser.parse_file " href ="#gedcom.parser.Parser.parse_file "> parse_file</ a > </ code > </ li >
17111762< li > < code > < a title ="gedcom.parser.Parser.print_gedcom " href ="#gedcom.parser.Parser.print_gedcom "> print_gedcom</ a > </ code > </ li >
17121763< li > < code > < a title ="gedcom.parser.Parser.save_gedcom " href ="#gedcom.parser.Parser.save_gedcom "> save_gedcom</ a > </ code > </ li >
1764+ < li > < code > < a title ="gedcom.parser.Parser.to_gedcom_string " href ="#gedcom.parser.Parser.to_gedcom_string "> to_gedcom_string</ a > </ code > </ li >
17131765</ ul >
17141766</ li >
17151767</ ul >
0 commit comments