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