8
8
from pypi_server import PY2
9
9
from pypi_server .db import DB
10
10
from pypi_server .handlers .pypi .proxy .client import PYPIClient
11
+ from six import b
11
12
from tornado .gen import coroutine , Task , maybe_future , Return
12
13
from tornado .web import asynchronous , HTTPError
13
14
from tornado .httpclient import AsyncHTTPClient
@@ -136,7 +137,7 @@ def wrap(self, *args, **kwargs):
136
137
if auth_type .lower () != 'basic' :
137
138
raise Return (self .send_error (400 ))
138
139
139
- username , password = map (unquote_plus , base64 .b64decode (data ).split (":" ))
140
+ username , password = map (lambda x : unquote_plus ( x . decode ( "utf-8" )) , base64 .b64decode (b ( data )) .split (b ( ":" ) ))
140
141
try :
141
142
self .current_user = yield check_password (username , password )
142
143
except LookupError :
@@ -179,7 +180,7 @@ class XmlRPC(BaseHandler):
179
180
180
181
@coroutine
181
182
def prepare (self ):
182
- if self .request .method .upper () == 'POST' and not self .request .body .startswith ("\r \n " ):
183
+ if self .request .method .upper () == 'POST' and not self .request .body .startswith (b ( "\r \n " ) ):
183
184
boundary = dict (
184
185
filter (
185
186
lambda x : x [0 ] == 'boundary' ,
@@ -194,19 +195,19 @@ def prepare(self):
194
195
raise HTTPError (400 )
195
196
196
197
def normalize (chunk ):
197
- if '\n \n ' not in chunk :
198
- return '\r \n ' + chunk [1 :]
198
+ if b ( '\n \n ' ) not in chunk :
199
+ return b ( '\r \n ' ) + chunk [1 :]
199
200
200
- ret = ''
201
- ret += '\r \n '
202
- data , content = chunk .split ('\n \n ' , 1 )
201
+ ret = b ( '' )
202
+ ret += b ( '\r \n ' )
203
+ data , content = chunk .split (b ( '\n \n ' ) , 1 )
203
204
ret += data [1 :]
204
- ret += '\r \n \r \n '
205
+ ret += b ( '\r \n \r \n ' )
205
206
ret += content [:- 1 ]
206
- ret += '\r \n '
207
+ ret += b ( '\r \n ' )
207
208
return ret
208
209
209
- boundary = "--{0}" .format (boundary )
210
+ boundary = b ( "--{0}" .format (boundary ) )
210
211
211
212
new_body = boundary .join (
212
213
map (
@@ -216,7 +217,7 @@ def normalize(chunk):
216
217
)
217
218
218
219
new_body = new_body [:- 4 ]
219
- new_body += '--\r \n '
220
+ new_body += b ( '--\r \n ' )
220
221
221
222
self .request .body = new_body
222
223
self .request ._parse_body ()
0 commit comments