Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/common.py @ 40158:9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
This function wants a str (which represents a path) and returns a str.
We normalize input to str and output to bytes.
Differential Revision: https://phab.mercurial-scm.org/D4967
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 11 Oct 2018 21:47:39 +0200 |
parents | a1110db1e455 |
children | d216ae4cc3f6 |
comparison
equal
deleted
inserted
replaced
40157:a8be613391d1 | 40158:9310037f0636 |
---|---|
180 path = os.path.join(d, fpath) | 180 path = os.path.join(d, fpath) |
181 if os.path.exists(path): | 181 if os.path.exists(path): |
182 break | 182 break |
183 try: | 183 try: |
184 os.stat(path) | 184 os.stat(path) |
185 ct = mimetypes.guess_type(pycompat.fsdecode(path))[0] or "text/plain" | 185 ct = pycompat.sysbytes( |
186 mimetypes.guess_type(pycompat.fsdecode(path))[0] or "text/plain") | |
186 with open(path, 'rb') as fh: | 187 with open(path, 'rb') as fh: |
187 data = fh.read() | 188 data = fh.read() |
188 | 189 |
189 res.headers['Content-Type'] = ct | 190 res.headers['Content-Type'] = ct |
190 res.setbodybytes(data) | 191 res.setbodybytes(data) |