Make Song.parse() take the file content instead of a file name
This commit is contained in:
parent
61b1cda0f6
commit
80e74a77d4
@ -190,16 +190,16 @@ class Song(object):
|
|||||||
def __init__(self, filename=None):
|
def __init__(self, filename=None):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
if self.filename:
|
if self.filename:
|
||||||
self.parse(self.filename)
|
with open(filename) as song_file:
|
||||||
|
self.parse(song_file.read())
|
||||||
|
|
||||||
def parse(self, filename):
|
def parse(self, text):
|
||||||
self.metadata = Metadata()
|
self.metadata = Metadata()
|
||||||
self.verses = []
|
self.verses = []
|
||||||
self.verse_order = []
|
self.verse_order = []
|
||||||
with open(filename) as song_file:
|
|
||||||
is_verse = False
|
is_verse = False
|
||||||
current_verse = None
|
current_verse = None
|
||||||
for line_number, line in enumerate(song_file):
|
for line_number, line in enumerate(text.splitlines()):
|
||||||
if Directive.is_directive(line):
|
if Directive.is_directive(line):
|
||||||
self.metadata.add(Directive(line))
|
self.metadata.add(Directive(line))
|
||||||
elif Verse.is_start_of_verse(line):
|
elif Verse.is_start_of_verse(line):
|
||||||
|
Loading…
Reference in New Issue
Block a user