Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Gedcom constructor with encoding, errors and opener arguments … #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions gedcom/__init__.py
Original file line number Diff line number Diff line change
@@ -41,12 +41,18 @@ class Gedcom:
- a dict (only elements with pointers, which are the keys)
"""

def __init__(self, filepath):
def __init__(self, filepath,
encoding=None,
errors=None,
opener=None):
""" Initialize a GEDCOM data object. You must supply a Gedcom file."""
self.__element_list = []
self.__element_dict = {}
self.__element_top = Element(-1, "", "TOP", "")
self.__parse(filepath)
self.__parse(filepath,
encoding=encoding,
errors=errors,
opener=opener)

def element_list(self):
""" Return a list of all the elements in the Gedcom file.
@@ -64,10 +70,17 @@ def element_dict(self):
return self.__element_dict

# Private methods

def __parse(self, filepath):
def __parse(self, filepath,
encoding='utf-8',
errors=None,
opener=None):
"""Open and parse file path as GEDCOM 5.5 formatted data."""
gedcom_file = open(filepath, 'rU')
gedcom_file = open(filepath,
mode = 'rU',
encoding=encoding,
errors=errors,
newline='\r\n', # this is part of gedcom 5.5 spec
opener=opener)
line_num = 1
last_elem = self.__element_top
for line in gedcom_file: