conduit r1699 - in trunk: . conduit/utils test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1699 - in trunk: . conduit/utils test/python-tests
- Date: Fri, 29 Aug 2008 23:39:51 +0000 (UTC)
Author: jstowers
Date: Fri Aug 29 23:39:50 2008
New Revision: 1699
URL: http://svn.gnome.org/viewvc/conduit?rev=1699&view=rev
Log:
* conduit/utils/__init__.py:
* test/python-tests/TestCoreUtil.py: More util functions using urllib to
work around gvfs bugs.
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/conduit/utils/__init__.py
trunk/test/python-tests/TestCoreUtil.py
Modified: trunk/conduit/utils/__init__.py
==============================================================================
--- trunk/conduit/utils/__init__.py (original)
+++ trunk/conduit/utils/__init__.py Fri Aug 29 23:39:50 2008
@@ -17,14 +17,10 @@
import logging
log = logging.getLogger("Utils")
-def get_http_resource_last_modified(url):
- """
- Returns the last modified date of the http resource at the given URL.
- @returns: A Float timestamp or None
- """
+def _get_http_resource(url):
try:
request = urllib2.Request(url)
- a = urllib2.build_opener().open(request)
+ return urllib2.build_opener().open(request)
except urllib2.HTTPError:
log.info("URL does not exist: %s" % url)
return None
@@ -32,9 +28,35 @@
log.warn("Error getting url last modified: %s" % e)
return None
- date = a.headers.getdate('Last-Modified')
- if date:
- date = time.mktime(date)
+def get_http_resource_mimetype(url):
+ """
+ Returns the mimetype of the http resource at the given URL.
+ """
+ a = _get_http_resource(url)
+ if a:
+ return a.headers.getheader('content-type')
+ return None
+
+def get_http_resource_size(url):
+ """
+ Returns the mimetype of the http resource at the given URL.
+ """
+ a = _get_http_resource(url)
+ if a:
+ return int(a.headers.getheader('content-length'))
+ return None
+
+def get_http_resource_last_modified(url):
+ """
+ Returns the last modified date of the http resource at the given URL.
+ @returns: A Float timestamp or None
+ """
+ date = None
+ a = _get_http_resource(url)
+ if a:
+ date = a.headers.getdate('Last-Modified')
+ if date:
+ date = time.mktime(date)
return date
def get_proportional_resize(desiredW, desiredH, currentW, currentH):
Modified: trunk/test/python-tests/TestCoreUtil.py
==============================================================================
--- trunk/test/python-tests/TestCoreUtil.py (original)
+++ trunk/test/python-tests/TestCoreUtil.py Fri Aug 29 23:39:50 2008
@@ -11,8 +11,14 @@
import sys
if is_online():
- date = Utils.get_http_resource_last_modified("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg")
- ok("Got mtime of http resource", date == datetime.datetime(2007,5,6,14,47,36))
+ ts = Utils.get_http_resource_last_modified("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg")
+ ok("Got mtime (timestamp) of http resource", ts == 1178419656.0)
+
+ mimetype = Utils.get_http_resource_mimetype("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg")
+ ok("Got mimetype of http resource", mimetype == 'video/mpeg')
+
+ size = Utils.get_http_resource_size("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg")
+ ok("Got size of http resource", size == 4792300)
date1 = Utils.get_http_resource_last_modified("http://foo.com/1/2/3")
ok("Got no mtime from missing http resource", date1 == None)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]