def mirror(self, url, filename): req = Request('GET', url) res = self.request(req) if res.is_success: f = open(filename, 'w') f.write(res.content) f.close() last_modified = Date.time2epoch(res.last_modified) if last_modified: os.utime(file, (last_modified, last_modified))
def test_time2str(self): string = Date.time2str(datetime(2011, 12, 12, 12, 0, 0)) self.assertEqual(string, "Mon, 12 Dec 2011 12:00:00 GMT") string = Date.time2str(datetime(2012, 2, 9, 12, 0, 0)) self.assertEqual(string, "Thu, 09 Feb 2012 12:00:00 GMT")
def test_epoch2str(self): string = Date.epoch2str(1323691200) self.assertEqual(string, "Mon, 12 Dec 2011 12:00:00 GMT")
def test_epoch2time(self): time = Date.epoch2time(1323720000) self.assertEqual(time.year, 2011) pass
def test_str2epoch(self): epoch = Date.str2epoch("Mon, 12 Dec 2011 12:00:00 GMT") self.assertEqual(epoch, 1323691200)
def test_str2time(self): time = Date.str2time("Mon, 12 Dec 2011 12:00:00 GMT") self.assertEqual(time.year, 2011)
def test_time2str(self): string = Date.time2str(datetime(2011, 12, 12, 12, 0, 0)) self.assertEqual(string, 'Mon, 12 Dec 2011 12:00:00 GMT') string = Date.time2str(datetime(2012, 2, 9, 12, 0, 0)) self.assertEqual(string, 'Thu, 09 Feb 2012 12:00:00 GMT')
def test_epoch2str(self): string = Date.epoch2str(1323691200) self.assertEqual(string, 'Mon, 12 Dec 2011 12:00:00 GMT')
def test_str2epoch(self): epoch = Date.str2epoch('Mon, 12 Dec 2011 12:00:00 GMT') self.assertEqual(epoch, 1323691200)
def test_str2time(self): time = Date.str2time('Mon, 12 Dec 2011 12:00:00 GMT') self.assertEqual(time.year, 2011)
import sys sys.path.append('.') from datetime import datetime from http import Client, Request, Date client = Client(agent='my uber agent') request = Request('HEAD', 'http://lumberjaph.net') request.if_modified_since = datetime(2011, 12, 1, 0, 0) response = client.request(request) if response.is_success: print "yeah, success!" print "status: {status}".format(status=response.status) print "message: {message}".format(message=response.message) print "content length: {length}".format(length=response.content_length) print "last modified in epoch: {last_modified}".format(last_modified=Date.time2epoch(response.last_modified)) print "last modified in string: {last_modified}".format(last_modified=response.header('Last-Modified')) if response.content_is_text: print response.content else: print "oups! {status_line}".format(status_line=response.status_line)
import sys sys.path.append('.') from datetime import datetime from http import Client, Request, Date client = Client(agent='my uber agent') request = Request('HEAD', 'http://lumberjaph.net') request.if_modified_since = datetime(2011, 12, 1, 0, 0) response = client.request(request) if response.is_success: print "yeah, success!" print "status: {status}".format(status=response.status) print "message: {message}".format(message=response.message) print "content length: {length}".format(length=response.content_length) print "last modified in epoch: {last_modified}".format( last_modified=Date.time2epoch(response.last_modified)) print "last modified in string: {last_modified}".format( last_modified=response.header('Last-Modified')) if response.content_is_text: print response.content else: print "oups! {status_line}".format(status_line=response.status_line)