Skip to content

Commit ba853a4

Browse files
committed
fixes for windows: convert url to file with pathname2url, use 'b' for
reading warcs, don't use %s for timestamp conversion (not portable) (#56)
1 parent 7f52ecd commit ba853a4

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

pywb/warc/cdxindexer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def write_multi_cdx_index(output, inputs, **options):
116116
outpath = os.path.join(output, outpath)
117117

118118
with open(outpath, 'w') as outfile:
119-
with open(fullpath, 'r') as infile:
119+
with open(fullpath, 'rb') as infile:
120120
write_cdx_index(outfile, infile, filename, **options)
121121

122122
# write to one cdx file
@@ -133,7 +133,7 @@ def write_multi_cdx_index(output, inputs, **options):
133133

134134
with writer_cls(outfile, options.get('cdx09')) as writer:
135135
for fullpath, filename in iter_file_or_dir(inputs):
136-
with open(fullpath, 'r') as infile:
136+
with open(fullpath, 'rb') as infile:
137137
entry_iter = create_index_iter(infile, **options)
138138

139139
for entry in entry_iter:

pywb/warc/pathresolvers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pywb.utils.binsearch import iter_exact
44

55
import urlparse
6+
import urllib
67
import os
78
import logging
89

@@ -92,6 +93,7 @@ def make_best_resolver(param):
9293

9394
if url_parts.scheme == 'file':
9495
path = url_parts.path
96+
path = urllib.url2pathname(path)
9597

9698
if os.path.isfile(path):
9799
logging.debug('Adding Path Index: ' + path)

pywb/warc/test/test_pathresolvers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
RedisResolver('redis://myhost.example.com:1234/1')
3434
3535
# a file
36-
>>> r = make_best_resolver('file://' + os.path.realpath(__file__))
36+
>>> r = make_best_resolver(to_local_url(os.path.realpath(__file__)))
3737
>>> r.__class__.__name__
3838
'PathIndexResolver'
3939
4040
# a dir
4141
>>> path = os.path.realpath(__file__)
42-
>>> r = make_best_resolver('file://' + os.path.dirname(path))
42+
>>> r = make_best_resolver(to_local_url(os.path.dirname(path)))
4343
>>> r.__class__.__name__
4444
'PrefixResolver'
4545
@@ -56,6 +56,7 @@
5656
from pywb.warc.pathresolvers import make_best_resolver, make_best_resolvers
5757
import os
5858

59+
from urllib import pathname2url
5960

6061
from fakeredis import FakeStrictRedis
6162
from mock import patch
@@ -68,6 +69,11 @@ def init_redis_resolver():
6869
def hset_path(filename, path):
6970
redis_resolver.redis.hset(redis_resolver.key_prefix + filename, 'path', path)
7071

72+
def to_local_url(filename):
73+
filename = os.path.abspath(filename)
74+
res = 'file:' + pathname2url(filename)
75+
#print(res)
76+
return res
7177

7278
redis_resolver = init_redis_resolver()
7379

pywb/webapp/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import urlparse
66
import logging
7+
import time
78

89
from os import path
910
from itertools import imap
@@ -42,7 +43,10 @@ def __call__(self, func):
4243
@template_filter
4344
def format_ts(value, format_='%a, %b %d %Y %H:%M:%S'):
4445
value = timestamp_to_datetime(value)
45-
return value.strftime(format_)
46+
if format_ == '%s':
47+
return int(time.mktime(value.timetuple()) * 1000)
48+
else:
49+
return value.strftime(format_)
4650

4751

4852
@template_filter('urlsplit')

0 commit comments

Comments
 (0)