paul@5 | 1 | #!/usr/bin/env python |
paul@5 | 2 | |
paul@10 | 3 | import codecs, vCalendar, os |
paul@5 | 4 | |
paul@10 | 5 | this_dir = os.path.split(__file__)[0] |
paul@10 | 6 | f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8") |
paul@7 | 7 | out = codecs.open("tmp.ics", "w", encoding="utf-8") |
paul@7 | 8 | try: |
paul@7 | 9 | doc = vCalendar.iterparse(f) |
paul@8 | 10 | w = vCalendar.iterwrite(out) |
paul@7 | 11 | for name, parameters, value in doc: |
paul@7 | 12 | print "%r, %r, %r" % (name, parameters, value) |
paul@11 | 13 | w.write(name, parameters, value) |
paul@7 | 14 | finally: |
paul@7 | 15 | out.close() |
paul@7 | 16 | f.close() |
paul@5 | 17 | |
paul@11 | 18 | print "--------" |
paul@11 | 19 | |
paul@11 | 20 | f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8") |
paul@11 | 21 | f2 = codecs.open("tmp.ics", encoding="utf-8") |
paul@11 | 22 | try: |
paul@11 | 23 | doc = vCalendar.iterparse(f) |
paul@11 | 24 | doc2 = vCalendar.iterparse(f2) |
paul@11 | 25 | for (name, parameters, value), (name2, parameters2, value2) in zip(doc, doc2): |
paul@11 | 26 | print "%r, %r, %r" % (name, parameters, value) |
paul@11 | 27 | print "%r, %r, %r" % (name2, parameters2, value2) |
paul@11 | 28 | assert name == name2 |
paul@11 | 29 | assert parameters == parameters2 |
paul@11 | 30 | assert value == value2 |
paul@11 | 31 | finally: |
paul@11 | 32 | f2.close() |
paul@11 | 33 | f.close() |
paul@11 | 34 | |
paul@5 | 35 | # vim: tabstop=4 expandtab shiftwidth=4 |