# xmlrep module for VCalendar files

from logilab.vcalsax import vcalsax

try:
    from Ft.Xml import pDomlette
    from Ft.Xml.pDomletteReader import SaxReader #,DomletteGenerator
except:
    from Ft.Lib import pDomlette
    from Ft.Lib.pDomletteReader import SaxReader #,DomletteGenerator

##try :
##    from narval.ext.pDomletteReader import SaxReader
##except :
##    print "pDomletteReader temporary version not found, use the Ft.Lib version"
##    from Ft.Lib.pDomletteReader import SaxReader

from narval.lib import xpath_lock

def read(uri) :
    parser=vcalsax.VcfParser()
    reader = SaxReader(parser=parser)
    return reader.fromUri(uri)

def write(dom, uri) :
    from re import sub
    xpath_lock.acquire()
    vcalsax.write_dom_to_vcal(dom,sub('file://','',uri))
    xpath_lock.release()

if __name__=="__main__":
    print read('/home/adim/ypiou/data/first2.vcs')
