File tree 1 file changed +18
-5
lines changed
1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 9
9
# see also: https://pymotw.com/2/BaseHTTPServer/
10
10
11
11
import BaseHTTPServer
12
- import hashlib
12
+ # import hashlib
13
13
import os
14
14
import urllib2
15
15
@@ -21,11 +21,24 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
21
21
22
22
class CacheHandler (BaseHTTPServer .BaseHTTPRequestHandler ):
23
23
def do_GET (self ):
24
- m = hashlib .md5 ()
25
- m .update (self .path )
26
- cache_filename = ".tiles/" + m .hexdigest ()
24
+
25
+ dirname = ".tiles/" + os .path .dirname (self .path )[1 :]
26
+ filename = os .path .basename (self .path )
27
+
28
+ while not os .path .exists (dirname ):
29
+ # might be a race here
30
+ try :
31
+ os .makedirs (dirname )
32
+ except :
33
+ None
34
+
35
+ # m = hashlib.md5()
36
+ # m.update(self.path)
37
+ # cache_filename = ".tiles/" + m.hexdigest()
38
+ cache_filename = dirname + "/" + filename
39
+
27
40
if os .path .exists (cache_filename ):
28
- print "Cache hit"
41
+ # print "Cache hit"
29
42
data = open (cache_filename ).readlines ()
30
43
else :
31
44
print "Cache miss"
You can’t perform that action at this time.
0 commit comments