@@ -464,7 +464,7 @@ <h1 class="title">Module <code>gedcom.parser</code></h1>
464
464
for family_member in family.get_child_elements():
465
465
466
466
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():
468
468
469
469
for child in family_member.get_child_elements():
470
470
if child.get_value() == "Natural":
@@ -546,19 +546,32 @@ <h1 class="title">Module <code>gedcom.parser</code></h1>
546
546
547
547
# Other methods
548
548
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
+
549
564
def print_gedcom(self):
550
565
"""Write GEDCOM data to stdout"""
551
566
from sys import stdout
552
567
self.save_gedcom(stdout)
553
568
554
- def save_gedcom(self, open_file):
569
+ def save_gedcom(self, open_file, recursive=True ):
555
570
"""Save GEDCOM data to a file
556
571
:type open_file: file
572
+ :type recursive: bool
557
573
"""
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 >
562
575
</ details >
563
576
</ section >
564
577
< section >
@@ -989,7 +1002,7 @@ <h3>Ancestors</h3>
989
1002
for family_member in family.get_child_elements():
990
1003
991
1004
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():
993
1006
994
1007
for child in family_member.get_child_elements():
995
1008
if child.get_value() == "Natural":
@@ -1071,19 +1084,32 @@ <h3>Ancestors</h3>
1071
1084
1072
1085
# Other methods
1073
1086
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
+
1074
1102
def print_gedcom(self):
1075
1103
"""Write GEDCOM data to stdout"""
1076
1104
from sys import stdout
1077
1105
self.save_gedcom(stdout)
1078
1106
1079
- def save_gedcom(self, open_file):
1107
+ def save_gedcom(self, open_file, recursive=True ):
1080
1108
"""Save GEDCOM data to a file
1081
1109
:type open_file: file
1110
+ :type recursive: bool
1082
1111
"""
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 >
1087
1113
</ details >
1088
1114
< h3 > Methods</ h3 >
1089
1115
< dl >
@@ -1450,7 +1476,7 @@ <h3>Methods</h3>
1450
1476
for family_member in family.get_child_elements():
1451
1477
1452
1478
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():
1454
1480
1455
1481
for child in family_member.get_child_elements():
1456
1482
if child.get_value() == "Natural":
@@ -1649,23 +1675,48 @@ <h3>Methods</h3>
1649
1675
</ details >
1650
1676
</ dd >
1651
1677
< 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 >
1653
1679
</ code > </ dt >
1654
1680
< dd >
1655
1681
< 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 >
1657
1684
< details class ="source ">
1658
1685
< summary >
1659
1686
< span > Expand source code</ span >
1660
1687
</ 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 ):
1662
1689
"""Save GEDCOM data to a file
1663
1690
:type open_file: file
1691
+ :type recursive: bool
1664
1692
"""
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 >
1669
1720
</ details >
1670
1721
</ dd >
1671
1722
</ dl >
@@ -1710,6 +1761,7 @@ <h4><code><a title="gedcom.parser.Parser" href="#gedcom.parser.Parser">Parser</a
1710
1761
< li > < code > < a title ="gedcom.parser.Parser.parse_file " href ="#gedcom.parser.Parser.parse_file "> parse_file</ a > </ code > </ li >
1711
1762
< li > < code > < a title ="gedcom.parser.Parser.print_gedcom " href ="#gedcom.parser.Parser.print_gedcom "> print_gedcom</ a > </ code > </ li >
1712
1763
< 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 >
1713
1765
</ ul >
1714
1766
</ li >
1715
1767
</ ul >
0 commit comments