Python 3: fix parse_requestline().

The parse_requestline() function needs a text string as an input. In Python 3,
it had bytes.
This commit is contained in:
Cyril Roelandt
2014-01-11 00:50:27 +01:00
parent a132fda766
commit a0ed19aa77
2 changed files with 13 additions and 12 deletions

View File

@@ -345,7 +345,7 @@ class fakesock(object):
try:
requestline, _ = data.split(b'\r\n', 1)
method, path, version = parse_requestline(requestline)
method, path, version = parse_requestline(decode_utf8(requestline))
is_parsing_headers = True
except ValueError:
is_parsing_headers = False

View File

@@ -27,6 +27,7 @@ from __future__ import unicode_literals
import re
from .compat import BaseClass
from .utils import decode_utf8
STATUSES = {
@@ -109,14 +110,14 @@ STATUSES = {
class HttpBaseClass(BaseClass):
GET = b'GET'
PUT = b'PUT'
POST = b'POST'
DELETE = b'DELETE'
HEAD = b'HEAD'
PATCH = b'PATCH'
OPTIONS = b'OPTIONS'
CONNECT = b'CONNECT'
GET = 'GET'
PUT = 'PUT'
POST = 'POST'
DELETE = 'DELETE'
HEAD = 'HEAD'
PATCH = 'PATCH'
OPTIONS = 'OPTIONS'
CONNECT = 'CONNECT'
METHODS = (GET, PUT, POST, DELETE, HEAD, PATCH, OPTIONS, CONNECT)
@@ -133,8 +134,8 @@ def parse_requestline(s):
...
ValueError: Not a Request-Line
"""
methods = b'|'.join(HttpBaseClass.METHODS)
m = re.match(br'(' + methods + b')\s+(.*)\s+HTTP/(1.[0|1])', s, re.I)
methods = '|'.join(HttpBaseClass.METHODS)
m = re.match(r'(' + methods + ')\s+(.*)\s+HTTP/(1.[0|1])', s, re.I)
if m:
return m.group(1).upper(), m.group(2), m.group(3)
else:
@@ -147,7 +148,7 @@ def last_requestline(sent_data):
"""
for line in reversed(sent_data):
try:
parse_requestline(line)
parse_requestline(decode_utf8(line))
except ValueError:
pass
else: