##// END OF EJS Templates
py3: pass str and return bytes from mimetypes.guess_type()...
Gregory Szorc -
r40513:9310037f default
parent child Browse files
Show More
@@ -182,7 +182,8 b' def staticfile(directory, fname, res):'
182 182 break
183 183 try:
184 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 187 with open(path, 'rb') as fh:
187 188 data = fh.read()
188 189
@@ -123,12 +123,15 b' def rawfile(web):'
123 123 text = fctx.data()
124 124 mt = 'application/binary'
125 125 if guessmime:
126 mt = mimetypes.guess_type(path)[0]
126 mt = mimetypes.guess_type(pycompat.fsdecode(path))[0]
127 127 if mt is None:
128 128 if stringutil.binary(text):
129 129 mt = 'application/binary'
130 130 else:
131 131 mt = 'text/plain'
132 else:
133 mt = pycompat.sysbytes(mt)
134
132 135 if mt.startswith('text/'):
133 136 mt += '; charset="%s"' % encoding.encoding
134 137
@@ -146,7 +149,9 b' def _filerevision(web, fctx):'
146 149 ishead = fctx.filenode() in fctx.filelog().heads()
147 150
148 151 if stringutil.binary(text):
149 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
152 mt = pycompat.sysbytes(
153 mimetypes.guess_type(pycompat.fsdecode(f))[0]
154 or 'application/octet-stream')
150 155 text = '(binary:%s)' % mt
151 156
152 157 def lines(context):
@@ -857,9 +862,9 b' def comparison(web):'
857 862
858 863 def filelines(f):
859 864 if f.isbinary():
860 mt = mimetypes.guess_type(f.path())[0]
861 if not mt:
862 mt = 'application/octet-stream'
865 mt = pycompat.sysbytes(
866 mimetypes.guess_type(pycompat.fsdecode(f.path()))[0]
867 or 'application/octet-stream')
863 868 return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))]
864 869 return f.data().splitlines()
865 870
@@ -945,8 +950,9 b' def annotate(web):'
945 950
946 951 def annotate(context):
947 952 if fctx.isbinary():
948 mt = (mimetypes.guess_type(fctx.path())[0]
949 or 'application/octet-stream')
953 mt = pycompat.sysbytes(
954 mimetypes.guess_type(pycompat.fsdecode(fctx.path()))[0]
955 or 'application/octet-stream')
950 956 lines = [dagop.annotateline(fctx=fctx.filectx(fctx.filerev()),
951 957 lineno=1, text='(binary:%s)' % mt)]
952 958 else:
General Comments 0
You need to be logged in to leave comments. Login now