To whom it may concern:
The attempted port of google-cal-helper.py to use 4Suite did not go
far enough. It was attempting to use 4Suite XPath evaluation on
minidom objects, but 4Suite XPath evaluation will only work on 4Suite
Domlette objects. It was easy enough to augment the port to use the
appropriate 4Suite API where necessary. The patch also makes a few
other minor adjustments; you may want to back them out manually if
they are not welcome.
Take care,
John L. Clark
--- google-cal-helper.py 2007-07-21 05:21:17.000000000 -0400
+++ google-cal-helper.new.py 2008-04-11 21:26:42.000000000 -0400
@@ -31,7 +31,8 @@
print "httplib2 not found!\n You need httplib2 which could be found http://bitworking.org/projects/httplib2/"
sys.exit(1)
from xml.dom import minidom as md
-from xml import xpath
+#from xml import xpath
+from Ft.Xml import XPath, Parse
# XML namespaces:
NS_GD = u'http://schemas.google.com/g/2005'
@@ -115,7 +116,7 @@
#TODO: handle timezone properly
m = XSDATE_RE.match(s)
if not m:
- raise DateConversionError("Invalid date/time: %s" % (s))
+ raise DateConversionError("Invalid date/time: %s" % (s,))
year,month,day = [int(m.group(g)) for g in 1,2,3]
time = m.group(4)
tzone = m.group(5)
@@ -125,7 +126,7 @@
if time:
m = XSTIME_RE.match(time)
if not m:
- raise DateConversionError("Invalid time: %s" % (time))
+ raise DateConversionError("Invalid time: %s" % (time,))
h,min,sec = [int(m.group(g)) for g in 1,2,3]
r += 'T%02d%02d%02d' % (h,min,sec)
@@ -133,7 +134,7 @@
if tzone == 'Z':
r += 'Z'
else:
- sys.stderr.write("Warning: Not handling timezone: %s\n" % (tzone))
+ sys.stderr.write("Warning: Not handling timezone: %s\n" % (tzone,))
sys.stderr.write("xs to osync: %s => %s\n" % (s, r))
return r
@@ -239,8 +240,9 @@
if self.content:
self.addElementContent(doc, event, 'Description', self.content)
- self.addElementContent(doc, event, 'DateStarted', xsdateToOsync(self.dtstart))
- self.addElementContent(doc, event, 'DateEnd', xsdateToOsync(self.dtend))
+ if self.dtstart and self.dtend:
+ self.addElementContent(doc, event, 'DateStarted', xsdateToOsync(self.dtstart))
+ self.addElementContent(doc, event, 'DateEnd', xsdateToOsync(self.dtend))
if self.dtrecur:
self.addElementContent(doc, event, 'RecurrenceRule',
self.dtrecur)
@@ -297,8 +299,8 @@
def query(self, expr):
"""XPath query"""
- ctx = xpath.Context.Context(self.element, processorNss=NS_DICT)
- return xpath.Evaluate(expr, context=ctx)
+ ctx = XPath.Context.Context(self.element, processorNss=NS_DICT)
+ return XPath.Evaluate(expr, context=ctx)
class GCalHelper:
def __init__(self, url, user, pwd):
@@ -322,8 +324,10 @@
def oper_get_all(self, argv):
r,c = self.h.request(self.url)
self.check_response_success(r)
- doc = md.parseString(c)
- entries = doc.getElementsByTagNameNS(NS_ATOM, 'entry')
+ #doc = md.parseString(c)
+ doc = Parse(c)
+ #entries = doc.getElementsByTagNameNS(NS_ATOM, 'entry')
+ entries = doc.xpath('.//atom:entry', {'atom': NS_ATOM})
for xe in entries:
e = GCalEntry(atom=xe)
if e.eventStatus == EVSTATUS_CANCELLED:
@@ -338,8 +342,10 @@
sys.stdout.write(hash)
def oper_test(self, argv):
- doc = md.parseString(sys.stdin.read())
- entries = doc.getElementsByTagNameNS(NS_ATOM, 'entry')
+ #doc = md.parseString(sys.stdin.read())
+ doc = Parse(sys.stdin.read())
+ #entries = doc.getElementsByTagNameNS(NS_ATOM, 'entry')
+ entries = doc.xpath('.//atom:entry', {'atom': NS_ATOM})
for xe in entries:
e = GCalEntry(atom=xe)
print e.dumpOsync()