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.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/project1/proj1_s4498062/webhttp/resource.py b/project1/proj1_s4498062/webhttp/resource.py
index 8fefc9c..9dd948c 100644
--- a/project1/proj1_s4498062/webhttp/resource.py
+++ b/project1/proj1_s4498062/webhttp/resource.py
@@ -4,15 +4,19 @@ This module contains a handler class for resources.
"""
import binascii
+import gzip
import hashlib
import mimetypes
import os
import re
+import StringIO
import urlparse
from config import config
+import encodings
import regexes as r
+
class FileExistError(Exception):
"""Exception which is raised when file does not exist"""
pass
@@ -36,6 +40,8 @@ class Resource:
Args:
uri (str): Uniform Resource Identifier
"""
+ if uri == None:
+ raise FileExistError
self.uri = uri
out = urlparse.urlparse(uri)
self.path = os.path.join("content", out.path.lstrip("/"))
@@ -69,13 +75,14 @@ class Resource:
return etag == '*' or \
any([tag == my_etag for tag in re.split(r.ETagSplit, etag)])
- def get_content(self):
+ def get_content(self, encoding=encodings.IDENTITY):
"""Get the contents of the resource
Returns:
str: Contents of the resource
"""
- return open(self.path).read()
+ content = open(self.path).read()
+ return encodings.encode(encoding, content)
def get_content_type(self):
"""Get the content type, i.e "text/html"