summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgoodwillcoding <goodwillcoding@webhippo.net>2013-08-17 12:50:53 -0700
committergoodwillcoding <goodwillcoding@webhippo.net>2013-08-17 12:50:53 -0700
commitb3ed638a1f5e5379e208bd0d5c90a7dac3b18afa (patch)
treea56284d840699b136822106be0153f7c67171f37
parent1ea0fa53d253eae501f0a48611dd01493240b34d (diff)
downloadpygments-b3ed638a1f5e5379e208bd0d5c90a7dac3b18afa.tar.gz
Make pygments.lexers.guess_lexer_for_filename py3 compatible.
Background: In py3 one can longer sort classes by class names the fix addes a custome sorting function that works the same in py2 and py3
-rw-r--r--pygments/lexers/__init__.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py
index dbfe4351..20b484a7 100644
--- a/pygments/lexers/__init__.py
+++ b/pygments/lexers/__init__.py
@@ -188,7 +188,13 @@ def guess_lexer_for_filename(_fn, _text, **options):
if rv == 1.0:
return lexer(**options)
result.append((rv, lexer))
- result.sort()
+
+ # since py3 can no longer sort by class name by default, here is the
+ # sorting function that works in both
+ def type_sort(type_):
+ return (type_[0], type_[1].__name__)
+ result.sort(key=type_sort)
+
if not result[-1][0] and primary is not None:
return primary(**options)
return result[-1][1](**options)