Skip to content
Snippets Groups Projects
Commit 6d7f18cd authored by Matt Harbison's avatar Matt Harbison
Browse files

py3: raw stringify various things in the LFS server module

Some of this is based on code written by Augie.  I'm slightly unsure if these
are the correct pycompat bytes <-> str conversion methods.
parent 7a11e4e5
No related merge requests found
......@@ -133,8 +133,8 @@
lfsreq = json.loads(req.bodyfh.read())
# If no transfer handlers are explicitly requested, 'basic' is assumed.
if 'basic' not in lfsreq.get('transfers', ['basic']):
if r'basic' not in lfsreq.get(r'transfers', [r'basic']):
_sethttperror(res, HTTP_BAD_REQUEST,
b'Only the basic LFS transfer handler is supported')
return True
......@@ -137,12 +137,14 @@
_sethttperror(res, HTTP_BAD_REQUEST,
b'Only the basic LFS transfer handler is supported')
return True
operation = lfsreq.get('operation')
if operation not in ('upload', 'download'):
operation = lfsreq.get(r'operation')
operation = pycompat.bytestr(operation)
if operation not in (b'upload', b'download'):
_sethttperror(res, HTTP_BAD_REQUEST,
b'Unsupported LFS transfer operation: %s' % operation)
return True
localstore = repo.svfs.lfslocalblobstore
......@@ -143,10 +145,10 @@
_sethttperror(res, HTTP_BAD_REQUEST,
b'Unsupported LFS transfer operation: %s' % operation)
return True
localstore = repo.svfs.lfslocalblobstore
objects = [p for p in _batchresponseobjects(req, lfsreq.get('objects', []),
objects = [p for p in _batchresponseobjects(req, lfsreq.get(r'objects', []),
operation, localstore)]
rsp = {
......@@ -150,8 +152,8 @@
operation, localstore)]
rsp = {
'transfer': 'basic',
'objects': objects,
r'transfer': r'basic',
r'objects': objects,
}
res.status = hgwebcommon.statusmessage(HTTP_OK)
......@@ -190,5 +192,6 @@
for obj in objects:
# Convert unicode to ASCII to create a filesystem path
oid = obj.get('oid').encode('ascii')
soid = obj.get(r'oid')
oid = soid.encode(r'ascii')
rsp = {
......@@ -194,7 +197,7 @@
rsp = {
'oid': oid,
'size': obj.get('size'), # XXX: should this check the local size?
#'authenticated': True,
r'oid': soid,
r'size': obj.get(r'size'), # XXX: should this check the local size?
#r'authenticated': True,
}
exists = True
......@@ -217,9 +220,9 @@
if inst.errno != errno.ENOENT:
_logexception(req)
rsp['error'] = {
'code': 500,
'message': inst.strerror or 'Internal Server Server'
rsp[r'error'] = {
r'code': 500,
r'message': inst.strerror or r'Internal Server Server'
}
yield rsp
continue
......@@ -230,11 +233,11 @@
# IFF they already exist locally.
if action == b'download':
if not exists:
rsp['error'] = {
'code': 404,
'message': "The object does not exist"
rsp[r'error'] = {
r'code': 404,
r'message': r"The object does not exist"
}
yield rsp
continue
elif not verifies:
......@@ -236,11 +239,11 @@
}
yield rsp
continue
elif not verifies:
rsp['error'] = {
'code': 422, # XXX: is this the right code?
'message': "The object is corrupt"
rsp[r'error'] = {
r'code': 422, # XXX: is this the right code?
r'message': r"The object is corrupt"
}
yield rsp
continue
......@@ -256,8 +259,8 @@
# a gratuitous deviation from lfs-test-server in the test
# output.
hdr = {
'Accept': 'application/vnd.git-lfs'
r'Accept': r'application/vnd.git-lfs'
}
auth = req.headers.get(b'Authorization', b'')
if auth.startswith(b'Basic '):
......@@ -260,8 +263,8 @@
}
auth = req.headers.get(b'Authorization', b'')
if auth.startswith(b'Basic '):
hdr['Authorization'] = auth
hdr[r'Authorization'] = pycompat.strurl(auth)
return hdr
......@@ -265,8 +268,8 @@
return hdr
rsp['actions'] = {
'%s' % action: {
'href': '%s%s/.hg/lfs/objects/%s'
% (req.baseurl, req.apppath, oid),
rsp[r'actions'] = {
r'%s' % pycompat.strurl(action): {
r'href': pycompat.strurl(b'%s%s/.hg/lfs/objects/%s'
% (req.baseurl, req.apppath, oid)),
# datetime.isoformat() doesn't include the 'Z' suffix
......@@ -272,6 +275,6 @@
# datetime.isoformat() doesn't include the 'Z' suffix
"expires_at": expiresat.strftime('%Y-%m-%dT%H:%M:%SZ'),
'header': _buildheader(),
r"expires_at": expiresat.strftime(r'%Y-%m-%dT%H:%M:%SZ'),
r'header': _buildheader(),
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment