summaryrefslogtreecommitdiff
path: root/project1/proj1_s4498062/webhttp/resource.py
diff options
context:
space:
mode:
Diffstat (limited to 'project1/proj1_s4498062/webhttp/resource.py')
-rw-r--r--project1/proj1_s4498062/webhttp/resource.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/project1/proj1_s4498062/webhttp/resource.py b/project1/proj1_s4498062/webhttp/resource.py
index cf2b725..8fefc9c 100644
--- a/project1/proj1_s4498062/webhttp/resource.py
+++ b/project1/proj1_s4498062/webhttp/resource.py
@@ -3,10 +3,15 @@
This module contains a handler class for resources.
"""
-import os
+import binascii
+import hashlib
import mimetypes
+import os
+import re
import urlparse
+from config import config
+import regexes as r
class FileExistError(Exception):
"""Exception which is raised when file does not exist"""
@@ -37,7 +42,7 @@ class Resource:
if not os.path.exists(self.path):
raise FileExistError
if os.path.isdir(self.path):
- self.path = os.path.join(self.path, "index.html")
+ self.path = os.path.join(self.path, config('index'))
if not os.path.exists(self.path):
raise FileAccessError
if not os.path.isfile(self.path):
@@ -52,9 +57,18 @@ class Resource:
str: ETag for the resource
"""
stat = os.stat(self.path)
- etag = ""
+ m = hashlib.md5()
+ m.update(str(stat))
+ etag = binascii.hexlify(m.digest())
return etag
+ def etag_match(self, etag):
+ if etag == None:
+ return False
+ my_etag = self.generate_etag()
+ return etag == '*' or \
+ any([tag == my_etag for tag in re.split(r.ETagSplit, etag)])
+
def get_content(self):
"""Get the contents of the resource