summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>2009-04-27 17:49:20 (GMT)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>2009-04-27 17:49:20 (GMT)
commitd469bdc62cf64f0d586d7846ab3706d730a132b1 (patch)
tree961c1f2ffd31dee656e3b2eb2d54968915466b5a
parent227c1f468b6591906fc2543bda25856f25e5db57 (diff)
downloadgtimelog-d469bdc62cf64f0d586d7846ab3706d730a132b1.tar.gz
gtimelog-d469bdc62cf64f0d586d7846ab3706d730a132b1.tar.xz
Reindent and add a verification for redirected when downloading task list
-rwxr-xr-xsrc/gtimelog/gtimelog.py48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/gtimelog/gtimelog.py b/src/gtimelog/gtimelog.py
index 0fb853b..69098f8 100755
--- a/src/gtimelog/gtimelog.py
+++ b/src/gtimelog/gtimelog.py
@@ -883,30 +883,34 @@ class RemoteTaskList(TaskList):
if self.loading_callback:
self.loading_callback()
- passmgr = GtkPasswordRequest ()
- auth_handler = urllib2.HTTPBasicAuthHandler (passmgr)
+ passmgr = GtkPasswordRequest ()
+ auth_handler = urllib2.HTTPBasicAuthHandler (passmgr)
- opener = urllib2.build_opener (auth_handler)
- urllib2.install_opener (opener)
+ opener = urllib2.build_opener (auth_handler)
+ urllib2.install_opener (opener)
- try:
- fp = urllib2.urlopen (self.url)
- except urllib2.URLError:
- if self.error_callback:
- self.error_callback ()
- else:
- # FIXME - is there a better way to do this?
- try:
- out = open (self.filename, 'w')
-
- out.write (fp.read ())
- except IOError:
- if self.error_callback:
- self.error_callback ()
- finally:
- out.close ()
-
- fp.close ()
+ try:
+ fp = urllib2.urlopen (self.url)
+ except urllib2.URLError:
+ if self.error_callback:
+ self.error_callback ()
+ else:
+ # check if we were redirected, if so, drop the information
+ if fp.geturl() != self.url and self.error_callback:
+ self.error_callback ()
+ return
+
+ # FIXME - is there a better way to do this?
+ try:
+ out = open (self.filename, 'w')
+ out.write (fp.read ())
+ except IOError:
+ if self.error_callback:
+ self.error_callback ()
+ finally:
+ out.close ()
+
+ fp.close ()
self.load()
if self.loaded_callback: