Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGd216ae4cc3f6: py3: r'' prefix default values for mimetypes.guess_mime()
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/hgweb/common.py (2 lines) | |||
M | mercurial/hgweb/webcommands.py (6 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Gregory Szorc | Oct 12 2018, 1:49 PM |
directory = [directory] | directory = [directory] | ||||
for d in directory: | for d in directory: | ||||
path = os.path.join(d, fpath) | path = os.path.join(d, fpath) | ||||
if os.path.exists(path): | if os.path.exists(path): | ||||
break | break | ||||
try: | try: | ||||
os.stat(path) | os.stat(path) | ||||
ct = pycompat.sysbytes( | ct = pycompat.sysbytes( | ||||
mimetypes.guess_type(pycompat.fsdecode(path))[0] or "text/plain") | mimetypes.guess_type(pycompat.fsdecode(path))[0] or r"text/plain") | ||||
with open(path, 'rb') as fh: | with open(path, 'rb') as fh: | ||||
data = fh.read() | data = fh.read() | ||||
res.headers['Content-Type'] = ct | res.headers['Content-Type'] = ct | ||||
res.setbodybytes(data) | res.setbodybytes(data) | ||||
return res | return res | ||||
except TypeError: | except TypeError: | ||||
raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') | raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
f = fctx.path() | f = fctx.path() | ||||
text = fctx.data() | text = fctx.data() | ||||
parity = paritygen(web.stripecount) | parity = paritygen(web.stripecount) | ||||
ishead = fctx.filenode() in fctx.filelog().heads() | ishead = fctx.filenode() in fctx.filelog().heads() | ||||
if stringutil.binary(text): | if stringutil.binary(text): | ||||
mt = pycompat.sysbytes( | mt = pycompat.sysbytes( | ||||
mimetypes.guess_type(pycompat.fsdecode(f))[0] | mimetypes.guess_type(pycompat.fsdecode(f))[0] | ||||
or 'application/octet-stream') | or r'application/octet-stream') | ||||
text = '(binary:%s)' % mt | text = '(binary:%s)' % mt | ||||
def lines(context): | def lines(context): | ||||
for lineno, t in enumerate(text.splitlines(True)): | for lineno, t in enumerate(text.splitlines(True)): | ||||
yield {"line": t, | yield {"line": t, | ||||
"lineid": "l%d" % (lineno + 1), | "lineid": "l%d" % (lineno + 1), | ||||
"linenumber": "% 6d" % (lineno + 1), | "linenumber": "% 6d" % (lineno + 1), | ||||
"parity": next(parity)} | "parity": next(parity)} | ||||
context = parsecontext(web.req.qsparams['context']) | context = parsecontext(web.req.qsparams['context']) | ||||
else: | else: | ||||
context = parsecontext(web.config('web', 'comparisoncontext', '5')) | context = parsecontext(web.config('web', 'comparisoncontext', '5')) | ||||
def filelines(f): | def filelines(f): | ||||
if f.isbinary(): | if f.isbinary(): | ||||
mt = pycompat.sysbytes( | mt = pycompat.sysbytes( | ||||
mimetypes.guess_type(pycompat.fsdecode(f.path()))[0] | mimetypes.guess_type(pycompat.fsdecode(f.path()))[0] | ||||
or 'application/octet-stream') | or r'application/octet-stream') | ||||
return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] | return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] | ||||
return f.data().splitlines() | return f.data().splitlines() | ||||
fctx = None | fctx = None | ||||
parent = ctx.p1() | parent = ctx.p1() | ||||
leftrev = parent.rev() | leftrev = parent.rev() | ||||
leftnode = parent.node() | leftnode = parent.node() | ||||
rightrev = ctx.rev() | rightrev = ctx.rev() | ||||
for p in parentscache[rev]: | for p in parentscache[rev]: | ||||
yield p | yield p | ||||
def annotate(context): | def annotate(context): | ||||
if fctx.isbinary(): | if fctx.isbinary(): | ||||
mt = pycompat.sysbytes( | mt = pycompat.sysbytes( | ||||
mimetypes.guess_type(pycompat.fsdecode(fctx.path()))[0] | mimetypes.guess_type(pycompat.fsdecode(fctx.path()))[0] | ||||
or 'application/octet-stream') | or r'application/octet-stream') | ||||
lines = [dagop.annotateline(fctx=fctx.filectx(fctx.filerev()), | lines = [dagop.annotateline(fctx=fctx.filectx(fctx.filerev()), | ||||
lineno=1, text='(binary:%s)' % mt)] | lineno=1, text='(binary:%s)' % mt)] | ||||
else: | else: | ||||
lines = webutil.annotate(web.req, fctx, web.repo.ui) | lines = webutil.annotate(web.req, fctx, web.repo.ui) | ||||
previousrev = None | previousrev = None | ||||
blockparitygen = paritygen(1) | blockparitygen = paritygen(1) | ||||
for lineno, aline in enumerate(lines): | for lineno, aline in enumerate(lines): |