diff gpp/gcalendar/calendar.py @ 68:cce1fc3f8752

#16, GCalendar: clean up exception class. Put a try catch around the ExecuteBatch, as I saw it fail. No need to add any logging.
author Brian Neal <bgneal@gmail.com>
date Sun, 28 Jun 2009 18:48:08 +0000
parents dbd703f7d63a
children 9c18250972d5
line wrap: on
line diff
--- a/gpp/gcalendar/calendar.py	Sat Jun 27 22:22:22 2009 +0000
+++ b/gpp/gcalendar/calendar.py	Sun Jun 28 18:48:08 2009 +0000
@@ -19,11 +19,11 @@
 
 
 class CalendarError(Exception):
-    def __init__(self, errs):
-        self.errs = errs
+    def __init__(self, msg):
+        self.msg = msg
 
     def __str__(self):
-        return repr(self.errs)
+        return repr(self.msg)
 
 
 class Calendar(object):
@@ -41,9 +41,9 @@
         try:
             self.client.ProgrammaticLogin()
         except BadAuthentication:
-            raise CalendarError(['Incorrect password'])
+            raise CalendarError('Incorrect password')
         except Exception, e:
-            raise CalendarError([e])
+            raise CalendarError(str(e))
 
     def sync_events(self, qs):
         request_feed = CalendarEventFeed()
@@ -60,7 +60,11 @@
             else:
                 assert False, 'unexpected status in sync_events'
 
-        response_feed = self.client.ExecuteBatch(request_feed, self.batch_feed)
+        try:
+            response_feed = self.client.ExecuteBatch(request_feed, self.batch_feed)
+        except Exception, e:
+            raise CalendarError('ExecuteBatch exception: %s' % e)
+
         err_msgs = []
         for entry in response_feed.entry:
             i = int(entry.batch_id.text)
@@ -86,13 +90,14 @@
                         (qs[i].title, code, entry.batch_status.reason))
 
         if len(err_msgs) > 0:
-            raise CalendarError(err_msgs)
+            raise CalendarError(', '.join(err_msgs))
 
     def _retrieve_event(self, model):
         try:
             event = self.client.GetCalendarEventEntry(model.google_id)
-        except Exception:
-            raise CalendarError(['Could not retrieve event from Google: %s' % model.what])
+        except Exception, e:
+            raise CalendarError('Could not retrieve event from Google: %s, %s' \
+                    % (model.what, e))
         return event
 
     def _populate_event(self, model, event):
@@ -135,11 +140,10 @@
             try:
                 tz = pytz.timezone(tz_name)
             except pytz.UnknownTimeZoneError:
-                raise CalendarError(['Invalid time zone: %s' (tz_name,)])
+                raise CalendarError('Invalid time zone: %s' (tz_name,))
             local = tz.localize(d)
             zulu = local.astimezone(FixedOffset(0))
             s = zulu.strftime(self.DATE_TIME_TZ_FMT)
 
         return s
 
-# vim: ts=4 sw=4