summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Smith <code@term.ie>2010-10-25 19:21:09 +0900
committerAndy Smith <code@term.ie>2010-10-25 19:21:09 +0900
commit2e67031ffb981ae1a47043cd48d50470eb6dc0b6 (patch)
treebdf1eaa0b63faa22380a4f2c8818ccecb483d918
parent81e8c5256c1e52326b6b64cf237128364d1bcb22 (diff)
downloadnova-2e67031ffb981ae1a47043cd48d50470eb6dc0b6.tar.gz
nova-2e67031ffb981ae1a47043cd48d50470eb6dc0b6.tar.xz
nova-2e67031ffb981ae1a47043cd48d50470eb6dc0b6.zip
Duplicate the two trivial escaping functions remaining from tornado's code and remove the dependency.
-rw-r--r--nova/objectstore/handler.py12
-rw-r--r--nova/utils.py25
-rw-r--r--tools/pip-requires1
3 files changed, 31 insertions, 7 deletions
diff --git a/nova/objectstore/handler.py b/nova/objectstore/handler.py
index 074eea601..b26906001 100644
--- a/nova/objectstore/handler.py
+++ b/nova/objectstore/handler.py
@@ -44,7 +44,6 @@ import multiprocessing
import os
import urllib
-from tornado import escape
from twisted.application import internet
from twisted.application import service
from twisted.web import error
@@ -55,6 +54,7 @@ from twisted.web import static
from nova import context
from nova import exception
from nova import flags
+from nova import utils
from nova.auth import manager
from nova.objectstore import bucket
from nova.objectstore import image
@@ -70,10 +70,10 @@ def render_xml(request, value):
name = value.keys()[0]
request.write('<?xml version="1.0" encoding="UTF-8"?>\n')
- request.write('<' + escape.utf8(name) +
+ request.write('<' + utils.utf8(name) +
' xmlns="http://doc.s3.amazonaws.com/2006-03-01">')
_render_parts(value.values()[0], request.write)
- request.write('</' + escape.utf8(name) + '>')
+ request.write('</' + utils.utf8(name) + '>')
request.finish()
@@ -87,7 +87,7 @@ def finish(request, content=None):
def _render_parts(value, write_cb):
"""Helper method to render different Python objects to XML"""
if isinstance(value, basestring):
- write_cb(escape.xhtml_escape(value))
+ write_cb(utils.xhtml_escape(value))
elif isinstance(value, int) or isinstance(value, long):
write_cb(str(value))
elif isinstance(value, datetime.datetime):
@@ -97,9 +97,9 @@ def _render_parts(value, write_cb):
if not isinstance(subvalue, list):
subvalue = [subvalue]
for subsubvalue in subvalue:
- write_cb('<' + escape.utf8(name) + '>')
+ write_cb('<' + utils.utf8(name) + '>')
_render_parts(subsubvalue, write_cb)
- write_cb('</' + escape.utf8(name) + '>')
+ write_cb('</' + utils.utf8(name) + '>')
else:
raise Exception("Unknown S3 value type %r", value)
diff --git a/nova/utils.py b/nova/utils.py
index 7683fc9f4..e58302c11 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -28,6 +28,7 @@ import random
import subprocess
import socket
import sys
+from xml.sax import saxutils
from twisted.internet.threads import deferToThread
@@ -212,3 +213,27 @@ def deferredToThread(f):
def g(*args, **kwargs):
return deferToThread(f, *args, **kwargs)
return g
+
+
+def xhtml_escape(value):
+ """Escapes a string so it is valid within XML or XHTML.
+
+ Code is directly from the utf8 function in
+ http://github.com/facebook/tornado/blob/master/tornado/escape.py
+
+ """
+ return saxutils.escape(value, {'"': "&quot;"})
+
+
+def utf8(value):
+ """Try to turn a string into utf-8 if possible.
+
+ Code is directly from the utf8 function in
+ http://github.com/facebook/tornado/blob/master/tornado/escape.py
+
+ """
+ if isinstance(value, unicode):
+ return value.encode("utf-8")
+ assert isinstance(value, str)
+ return value
+
diff --git a/tools/pip-requires b/tools/pip-requires
index c76fad86f..548073326 100644
--- a/tools/pip-requires
+++ b/tools/pip-requires
@@ -13,7 +13,6 @@ python-daemon==1.5.5
python-gflags==1.3
redis==2.0.0
routes==1.12.3
-tornado==1.0
WebOb==0.9.8
wsgiref==0.1.2
zope.interface==3.6.1