summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2020-01-01 16:53:44 +0100
committerMarcel Hellkamp <marc@gsites.de>2020-01-01 16:55:29 +0100
commit556ec241464397117af67394a367bf6c0b994547 (patch)
tree8eec4f5a11a537d5cf2bf4c6eeb3e843b354d458
parent30775d00d046c3a92214b1b9b0e31a573075d7cb (diff)
downloadbottle-556ec241464397117af67394a367bf6c0b994547.tar.gz
Deprecated tonat() helper
-rwxr-xr-xbottle.py15
-rwxr-xr-xtest/test_environ.py12
-rwxr-xr-xtest/tools.py2
3 files changed, 15 insertions, 14 deletions
diff --git a/bottle.py b/bottle.py
index 17e7f7c..b7d3f55 100755
--- a/bottle.py
+++ b/bottle.py
@@ -145,8 +145,9 @@ def touni(s, enc='utf8', err='strict'):
return unicode("" if s is None else s)
-tonat = touni
-
+def tonat(s, enc='utf8', err='strict'):
+ dept(0, 13, "tonat() no longer needed", "Use touni()")
+ return touni(s, enc, err)
# A bug in functools causes it to break if the wrapper is an instance method
@@ -1298,7 +1299,7 @@ class BaseRequest(object):
if len(header) > bufsize: raise err
size, _, _ = header.partition(sem)
try:
- maxread = int(tonat(size.strip()), 16)
+ maxread = int(touni(size.strip()), 16)
except ValueError:
raise err
if maxread == 0: break
@@ -1335,8 +1336,8 @@ class BaseRequest(object):
return body
def _get_body_string(self, maxread):
- """ Read body into a string. Raise HTTPError(413) on requests that are
- to large. """
+ """ Read body into a byte string. Raise HTTPError(413) on requests that
+ are to large. """
if self.content_length > maxread:
raise HTTPError(413, 'Request entity too large')
data = self.body.read(maxread + 1)
@@ -1373,7 +1374,7 @@ class BaseRequest(object):
# We default to application/x-www-form-urlencoded for everything that
# is not multipart and take the fast path (also: 3.1 workaround)
if not self.content_type.startswith('multipart/'):
- body = tonat(self._get_body_string(self.MEMFILE_MAX), 'latin1')
+ body = self._get_body_string(self.MEMFILE_MAX).decode('latin1')
for key, value in _parse_qsl(body):
post[key] = value
return post
@@ -1584,7 +1585,7 @@ def _hkey(key):
def _hval(value):
- value = tonat(value)
+ value = touni(value)
if '\n' in value or '\r' in value or '\0' in value:
raise ValueError("Header value must not contain control characters: %r" % value)
return value
diff --git a/test/test_environ.py b/test/test_environ.py
index 598e4e0..b51eccf 100755
--- a/test/test_environ.py
+++ b/test/test_environ.py
@@ -7,7 +7,7 @@ import sys
import itertools
import bottle
-from bottle import request, tob, touni, tonat, json_dumps, HTTPError, parse_date, CookieError
+from bottle import request, tob, touni, json_dumps, HTTPError, parse_date, CookieError
from . import tools
import wsgiref.util
import base64
@@ -160,7 +160,7 @@ class TestRequest(unittest.TestCase):
def test_get(self):
""" Environ: GET data """
- qs = tonat(tob('a=a&a=1&b=b&c=c&cn=%e7%93%b6'), 'latin1')
+ qs = touni(tob('a=a&a=1&b=b&c=c&cn=%e7%93%b6'), 'latin1')
request = BaseRequest({'QUERY_STRING':qs})
self.assertTrue('a' in request.query)
self.assertTrue('b' in request.query)
@@ -168,7 +168,7 @@ class TestRequest(unittest.TestCase):
self.assertEqual(['b'], request.query.getall('b'))
self.assertEqual('1', request.query['a'])
self.assertEqual('b', request.query['b'])
- self.assertEqual(tonat(tob('瓶'), 'latin1'), request.query['cn'])
+ self.assertEqual(touni(tob('瓶'), 'latin1'), request.query['cn'])
self.assertEqual(touni('瓶'), request.query.cn)
def test_post(self):
@@ -189,7 +189,7 @@ class TestRequest(unittest.TestCase):
self.assertEqual('b', request.POST['b'])
self.assertEqual('', request.POST['c'])
self.assertEqual('', request.POST['d'])
- self.assertEqual(tonat(tob('瓶'), 'latin1'), request.POST['cn'])
+ self.assertEqual(touni(tob('瓶'), 'latin1'), request.POST['cn'])
self.assertEqual(touni('瓶'), request.POST.cn)
def test_bodypost(self):
@@ -501,7 +501,7 @@ class TestResponse(unittest.TestCase):
result = [v for (h, v) in rs.headerlist if h.lower()=='x-test'][0]
self.assertEqual(wire, result)
- cmp(1, tonat('1', 'latin1'))
+ cmp(1, touni('1', 'latin1'))
cmp('öäü', 'öäü'.encode('utf8').decode('latin1'))
def test_set_status(self):
@@ -725,7 +725,7 @@ class TestResponse(unittest.TestCase):
response['x-test'] = None
self.assertEqual('', response['x-test'])
response['x-test'] = touni('瓶')
- self.assertEqual(tonat(touni('瓶')), response['x-test'])
+ self.assertEqual(touni('瓶'), response['x-test'])
def test_prevent_control_characters_in_headers(self):
masks = '{}test', 'test{}', 'te{}st'
diff --git a/test/tools.py b/test/tools.py
index 8f15133..d590cf0 100755
--- a/test/tools.py
+++ b/test/tools.py
@@ -12,7 +12,7 @@ import wsgiref.validate
import mimetypes
import uuid
-from bottle import tob, tonat, BytesIO, unicode
+from bottle import tob, BytesIO, unicode
def warn(msg):