changeset 5748:5957c7b5894a

highlight: fix more tracebacks by forcing util._encoding to hgweb.encoding This is needed in case util._encoding and hgweb.encoding conflict. Extreme example: HGENCODING=UTF-8 [web] encoding = ascii Note: display of files whose encoding differs from HGENCODING or hgweb.encoding behaves not exactly the same way as with highlight turned off as replacement chars are either converted or replaced.
author Christian Ebert <blacktrash@gmx.net>
date Wed, 19 Dec 2007 10:11:32 +0100
parents f75ca1b0c81e
children 4fba4fee0718
files hgext/highlight.py
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/highlight.py	Tue Dec 18 12:45:30 2007 -0800
+++ b/hgext/highlight.py	Wed Dec 19 10:11:32 2007 +0100
@@ -66,12 +66,10 @@
         yield 0, "</div>"
 
 
-def pygments_format(filename, rawtext, forcetext, encoding,
-                    stripecount, style):
-    etext = util.tolocal(rawtext)
+def pygments_format(filename, text, forcetext, stripecount, style):
     if not forcetext:
         try:
-            lexer = guess_lexer_for_filename(filename, etext,
+            lexer = guess_lexer_for_filename(filename, text,
                                              encoding=util._encoding)
         except ClassNotFound:
             lexer = TextLexer(encoding=util._encoding)
@@ -79,9 +77,9 @@
         lexer = TextLexer(encoding=util._encoding)
 
     formatter = StripedHtmlFormatter(stripecount, style=style,
-                                     linenos='inline', encoding=encoding)
+                                     linenos='inline', encoding=util._encoding)
 
-    return highlight(etext, lexer, formatter)
+    return highlight(text, lexer, formatter)
 
 
 def filerevision_pygments(self, tmpl, fctx):
@@ -96,6 +94,9 @@
 
     mt = mimetypes.guess_type(f)[0]
 
+    # we always want hgweb.encoding
+    util._encoding = self.encoding
+
     if util.binary(text):
         mt = mt or 'application/octet-stream'
         text = "(binary:%s)" % mt
@@ -104,6 +105,9 @@
         forcetext = True
     else:
         mt = mt or 'text/plain'
+
+        # encode to hgweb.encoding for lexers and formatter
+        text = util.tolocal(text)
         forcetext = False
 
     def lines(text):
@@ -112,7 +116,7 @@
 
     style = self.config("web", "pygments_style", "colorful")
 
-    text_formatted = lines(pygments_format(f, text, forcetext, self.encoding,
+    text_formatted = lines(pygments_format(f, text, forcetext,
                                            self.stripecount, style))
 
     # override per-line template