|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
import re |
|
|
|
import re |
|
|
|
import os |
|
|
|
import os |
|
|
|
|
|
|
|
import os.path |
|
|
|
import sys |
|
|
|
import sys |
|
|
|
import errno |
|
|
|
import errno |
|
|
|
import time |
|
|
|
import time |
|
|
@ -29,7 +30,7 @@ for source in sources: |
|
|
|
filename = 'hosts.txt.' + source_hostname |
|
|
|
filename = 'hosts.txt.' + source_hostname |
|
|
|
# build last-modified info from file mtime |
|
|
|
# build last-modified info from file mtime |
|
|
|
try: |
|
|
|
try: |
|
|
|
statinfo = os.stat(filename) |
|
|
|
mtime = os.path.getmtime(filename) |
|
|
|
except OSError, e: |
|
|
|
except OSError, e: |
|
|
|
if e.errno == errno.ENOENT: |
|
|
|
if e.errno == errno.ENOENT: |
|
|
|
pass |
|
|
|
pass |
|
|
@ -37,7 +38,7 @@ for source in sources: |
|
|
|
sys.stderr.write('fatal error: %s', e) |
|
|
|
sys.stderr.write('fatal error: %s', e) |
|
|
|
os.exit(1) |
|
|
|
os.exit(1) |
|
|
|
else: |
|
|
|
else: |
|
|
|
last_modified = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.localtime(statinfo.st_mtime)) |
|
|
|
last_modified = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.localtime(mtime)) |
|
|
|
# prevent redownloading of hosts-file by passing If-Modified-Since http header |
|
|
|
# prevent redownloading of hosts-file by passing If-Modified-Since http header |
|
|
|
opener.addheaders = [('If-Modified-Since', last_modified)] |
|
|
|
opener.addheaders = [('If-Modified-Since', last_modified)] |
|
|
|
try: |
|
|
|
try: |
|
|
|