Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorgan Collett <morgan.collett@gmail.com>2008-09-12 10:29:26 (GMT)
committer Morgan Collett <morgan.collett@gmail.com>2008-09-12 10:33:45 (GMT)
commit263ec89d3caaf6b5f54ca10da2e62b148aa4ae99 (patch)
tree02681d343ef5abf591e0cc14e7acdc588d5b2b32
parenta976aab0860ccdffa6e485cd1b8265321a50c1f4 (diff)
#7017: Detect and handle 404 Error
Subclass network.GlibURLDownloader to get ReadURLDownloader that provides content-type so that text/html can be detected so a 404 error can be handled. The root cause of the 404 was probably addressed by #7948. Added getting the content-length to ReadURLDownloader too.
-rw-r--r--NEWS7
-rw-r--r--readactivity.py43
2 files changed, 42 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index 480245b..ce07c07 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
-* Add COPYING with GPL2
-* Remove parameter from bundlebuilder.start
-* #8411: Add license to activity.info
+* #7017: Detect and handle 404 Error (morgs)
+* Add COPYING with GPL2 (morgs)
+* Remove parameter from bundlebuilder.start (morgs)
+* #8411: Add license to activity.info (morgs)
* #8352 Fix keep error with no document (morgs)
50
diff --git a/readactivity.py b/readactivity.py
index 5cf31ad..95989d1 100644
--- a/readactivity.py
+++ b/readactivity.py
@@ -47,6 +47,7 @@ def _get_screen_dpi():
print 'Setting dpi to %f' % (float(xft_dpi / 1024))
return float(xft_dpi / 1024)
+
class ReadHTTPRequestHandler(network.ChunkedGlibHTTPRequestHandler):
"""HTTP Request Handler for transferring document while collaborating.
@@ -59,6 +60,7 @@ class ReadHTTPRequestHandler(network.ChunkedGlibHTTPRequestHandler):
"""Return the filepath to the shared document."""
return self.server.filepath
+
class ReadHTTPServer(network.GlibTCPServer):
"""HTTP Server for transferring document while collaborating."""
def __init__(self, server_address, filepath):
@@ -70,6 +72,22 @@ class ReadHTTPServer(network.GlibTCPServer):
network.GlibTCPServer.__init__(self, server_address,
ReadHTTPRequestHandler)
+
+class ReadURLDownloader(network.GlibURLDownloader):
+ """URLDownloader that provides content-length and content-type."""
+
+ def get_content_length(self):
+ """Return the content-length of the download."""
+ if self._info is not None:
+ return int(self._info.headers.get('Content-Length'))
+
+ def get_content_type(self):
+ """Return the content-type of the download."""
+ if self._info is not None:
+ return self._info.headers.get('Content-type')
+ return None
+
+
READ_STREAM_SERVICE = 'read-activity-http'
class ReadActivity(activity.Activity):
@@ -140,6 +158,8 @@ class ReadActivity(activity.Activity):
self.unused_download_tubes = set()
self._want_document = True
+ self._download_content_length = 0
+ self._download_content_type = None
# Status of temp file used for write_file:
self._tempfile = None
self._close_requested = False
@@ -294,6 +314,11 @@ class ReadActivity(activity.Activity):
return True
def _download_result_cb(self, getter, tempfile, suggested_name, tube_id):
+ if self._download_content_type == 'text/html':
+ # got an error page instead
+ self._download_error_cb(getter, 'HTTP Error', tube_id)
+ return
+
del self.unused_download_tubes
self._tempfile = tempfile
@@ -310,15 +335,21 @@ class ReadActivity(activity.Activity):
self.save()
def _download_progress_cb(self, getter, bytes_downloaded, tube_id):
- # FIXME: signal the expected size somehow, so we can draw a progress
- # bar
- _logger.debug("Downloaded %u bytes from tube %u...",
- bytes_downloaded, tube_id)
+ # FIXME: Draw a progress bar
+ if self._download_content_length > 0:
+ _logger.debug("Downloaded %u of %u bytes from tube %u...",
+ bytes_downloaded, self._download_content_length,
+ tube_id)
+ else:
+ _logger.debug("Downloaded %u bytes from tube %u...",
+ bytes_downloaded, tube_id)
def _download_error_cb(self, getter, err, tube_id):
_logger.debug("Error getting document from tube %u: %s",
tube_id, err)
self._want_document = True
+ self._download_content_length = 0
+ self._download_content_type = None
gobject.idle_add(self._get_document)
def _download_document(self, tube_id, path):
@@ -339,13 +370,15 @@ class ReadActivity(activity.Activity):
assert addr[1] > 0 and addr[1] < 65536
port = int(addr[1])
- getter = network.GlibURLDownloader("http://%s:%d/document"
+ getter = ReadURLDownloader("http://%s:%d/document"
% (addr[0], port))
getter.connect("finished", self._download_result_cb, tube_id)
getter.connect("progress", self._download_progress_cb, tube_id)
getter.connect("error", self._download_error_cb, tube_id)
_logger.debug("Starting download to %s...", path)
getter.start(path)
+ self._download_content_length = getter.get_content_length()
+ self._download_content_type = getter.get_content_type()
return False
def _get_document(self):