예제 #1
0
 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))
예제 #2
0
 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")
예제 #3
0
 def test_epoch2str(self):
     string = Date.epoch2str(1323691200)
     self.assertEqual(string, "Mon, 12 Dec 2011 12:00:00 GMT")
예제 #4
0
 def test_epoch2time(self):
     time = Date.epoch2time(1323720000)
     self.assertEqual(time.year, 2011)
     pass
예제 #5
0
 def test_str2epoch(self):
     epoch = Date.str2epoch("Mon, 12 Dec 2011 12:00:00 GMT")
     self.assertEqual(epoch, 1323691200)
예제 #6
0
 def test_str2time(self):
     time = Date.str2time("Mon, 12 Dec 2011 12:00:00 GMT")
     self.assertEqual(time.year, 2011)
예제 #7
0
 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')
예제 #8
0
 def test_epoch2str(self):
     string = Date.epoch2str(1323691200)
     self.assertEqual(string, 'Mon, 12 Dec 2011 12:00:00 GMT')
예제 #9
0
 def test_epoch2time(self):
     time = Date.epoch2time(1323720000)
     self.assertEqual(time.year, 2011)
     pass
예제 #10
0
 def test_str2epoch(self):
     epoch = Date.str2epoch('Mon, 12 Dec 2011 12:00:00 GMT')
     self.assertEqual(epoch, 1323691200)
예제 #11
0
 def test_str2time(self):
     time = Date.str2time('Mon, 12 Dec 2011 12:00:00 GMT')
     self.assertEqual(time.year, 2011)
예제 #12
0
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)
예제 #13
0
파일: simple.py 프로젝트: franckcuny/http
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)