Python 3.2 port
This commit is contained in:
@@ -6,6 +6,5 @@ tag_date = true
|
||||
release = egg_info -RDb ''
|
||||
|
||||
[nosetests]
|
||||
with-xunit = true
|
||||
with-coverage = true
|
||||
cover-package = wsme
|
||||
|
||||
2
tox.ini
2
tox.ini
@@ -15,7 +15,7 @@ deps =
|
||||
coverage
|
||||
transaction
|
||||
|
||||
commands=nosetests []
|
||||
commands=nosetests --verbose []
|
||||
downloadcache=.tox/cache
|
||||
|
||||
[testenv:py25simplejson]
|
||||
|
||||
20
wsme/root.py
20
wsme/root.py
@@ -3,6 +3,7 @@ import sys
|
||||
import traceback
|
||||
import weakref
|
||||
import six
|
||||
from six import u, b
|
||||
|
||||
import webob
|
||||
|
||||
@@ -12,7 +13,7 @@ from wsme.api import scan_api
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
html_body = """
|
||||
html_body = u("""
|
||||
<html>
|
||||
<head>
|
||||
<style type='text/css'>
|
||||
@@ -23,7 +24,7 @@ html_body = """
|
||||
%(content)s
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
""")
|
||||
|
||||
|
||||
class DummyTransaction:
|
||||
@@ -128,7 +129,7 @@ class WSRoot(object):
|
||||
context.path = protocol.extract_path(context)
|
||||
|
||||
if context.path is None:
|
||||
raise exc.ClientSideError(six.u(
|
||||
raise exc.ClientSideError(u(
|
||||
'The %s protocol was unable to extract a function '
|
||||
'path from the request') % protocol.name)
|
||||
|
||||
@@ -186,7 +187,7 @@ class WSRoot(object):
|
||||
(p.name for p in self.protocols)))
|
||||
res.status = 500
|
||||
res.content_type = 'text/plain'
|
||||
res.body = msg
|
||||
res.text = u(msg)
|
||||
log.error(msg)
|
||||
return res
|
||||
|
||||
@@ -206,7 +207,7 @@ class WSRoot(object):
|
||||
body = prepare_response_body(request, (
|
||||
self._do_call(protocol, context)
|
||||
for context in protocol.iter_calls(request)))
|
||||
if isinstance(body, unicode):
|
||||
if isinstance(body, six.text_type):
|
||||
res.unicode_body = body
|
||||
else:
|
||||
res.body = body
|
||||
@@ -229,7 +230,7 @@ class WSRoot(object):
|
||||
except Exception:
|
||||
infos = self._format_exception(sys.exc_info())
|
||||
request.server_errorcount += 1
|
||||
res.body = protocol.encode_error(context, infos)
|
||||
res.text = protocol.encode_error(context, infos)
|
||||
res.status = 500
|
||||
|
||||
if res_content_type is None:
|
||||
@@ -242,7 +243,7 @@ class WSRoot(object):
|
||||
# output format.
|
||||
if res_content_type is None:
|
||||
if "text/html" in request.accept:
|
||||
res.body = self._html_format(res.body, protocol.content_types)
|
||||
res.text = self._html_format(res.body, protocol.content_types)
|
||||
res_content_type = "text/html"
|
||||
|
||||
# TODO should we consider the encoding asked by
|
||||
@@ -322,5 +323,6 @@ class WSRoot(object):
|
||||
"error :\n%s" % e)
|
||||
return html_body % dict(
|
||||
css='',
|
||||
content='<pre>%s</pre>' %
|
||||
content.replace('>', '>').replace('<', '<'))
|
||||
content=u('<pre>%s</pre>') %
|
||||
content.replace(b('>'), b('>'))
|
||||
.replace(b('<'), b('<')))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# encoding=utf8
|
||||
|
||||
import six
|
||||
from six import u, b
|
||||
import sys
|
||||
|
||||
import unittest
|
||||
@@ -29,7 +29,7 @@ def test_pexpose():
|
||||
|
||||
@pexpose(None, "text/xml")
|
||||
def ufunc(self):
|
||||
return six.u("<p>\xc3\xa9</p>")
|
||||
return u("<p>\xc3\xa9</p>")
|
||||
|
||||
func, fd = FunctionDefinition.get(Proto.func)
|
||||
assert fd.return_type is None
|
||||
@@ -41,11 +41,13 @@ def test_pexpose():
|
||||
r.addprotocol(p)
|
||||
|
||||
app = webtest.TestApp(wsme.wsgi.adapt(r))
|
||||
|
||||
res = app.get('/func')
|
||||
|
||||
assert res.status_int == 200
|
||||
assert res.body == "<p></p>", res.body
|
||||
assert res.body == b("<p></p>"), res.body
|
||||
res = app.get('/ufunc')
|
||||
assert res.unicode_body == six.u("<p>\xc3\xa9</p>"), res.body
|
||||
assert res.unicode_body == u("<p>\xc3\xa9</p>"), res.body
|
||||
|
||||
|
||||
class TestController(unittest.TestCase):
|
||||
@@ -179,7 +181,7 @@ class TestController(unittest.TestCase):
|
||||
assert res.status_int == 500
|
||||
print(res.body)
|
||||
assert res.body.find(
|
||||
"None of the following protocols can handle this request") != -1
|
||||
b("None of the following protocols can handle this request")) != -1
|
||||
|
||||
def test_return_content_type_guess(self):
|
||||
class DummierProto(DummyProtocol):
|
||||
|
||||
Reference in New Issue
Block a user