~ubuntu-branches/ubuntu/lucid/lastfmsubmitd/lucid

« back to all changes in this revision

Viewing changes to lib/lastfm/marshaller.py

  • Committer: Bazaar Package Importer
  • Author(s): Decklin Foster
  • Date: 2006-09-01 15:26:38 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060901152638-ao5al6ysgs5klzhp
Updated Czech and French translations. (Closes: #382235, #384429)

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    print >>out, '\n'.join([dump(d) for d in docs])
44
44
 
45
45
def load(doc):
46
 
    lines = filter(None, doc.split('\n'))
47
46
    song = {}
48
 
    for line in lines:
49
 
        k, v = line.split(': ', 1)
50
 
        if v.startswith('!timestamp '):
51
 
            v = time.strptime(v[11:], lastfm.TIME_FMT)
52
 
        else:
53
 
            try:
54
 
                v = parse_length(v)
55
 
            except ValueError:
56
 
                v = parse_string(v)
57
 
        song[k] = v
 
47
    for line in doc.split('\n'):
 
48
        if line:
 
49
            k, v = line.split(': ', 1)
 
50
            if v.startswith('!timestamp '):
 
51
                v = time.strptime(v[11:], lastfm.TIME_FMT)
 
52
            else:
 
53
                try:
 
54
                    v = parse_length(v)
 
55
                except ValueError:
 
56
                    v = parse_string(v)
 
57
            song[k] = v
58
58
    return song
59
59
 
60
60
def load_documents(stream):
61
 
    docs = filter(None, [d.strip() for d in stream.split('---\n')])
62
 
    for d in docs:
63
 
        try:
64
 
            yield load(d)
65
 
        except ValueError:
66
 
            pass
 
61
    docs = []
 
62
    for doc in stream.read().split('---\n'):
 
63
        doc = doc.strip()
 
64
        if doc:
 
65
            try:
 
66
                docs.append(load(doc))
 
67
            except ValueError:
 
68
                pass
 
69
    return docs