changeset 6114:27e6594645f1

pygmentsutils: separate from util2 __get_lem and __get_index_filenames has nothing in common with the rest of util2, neither with respects to implementation nor usage, and belongs in a dedicated module. Also, they are clearly not actually private, so shouldn't be named with leading underscores.
author Søren Løvborg <sorenl@unity3d.com>
date Tue, 02 Aug 2016 17:24:25 +0200
parents 7ea933acdb8b
children f4c712ab3e40
files kallithea/config/conf.py kallithea/lib/pygmentsutils.py kallithea/lib/utils2.py
diffstat 3 files changed, 83 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/config/conf.py	Fri Jun 24 20:12:05 2016 +0200
+++ b/kallithea/config/conf.py	Tue Aug 02 17:24:25 2016 +0200
@@ -25,12 +25,12 @@
 :license: GPLv3, see LICENSE.md for more details.
 """
 
-from kallithea.lib.utils2 import __get_lem, __get_index_filenames
+from kallithea.lib import pygmentsutils
 
 
 # language map is also used by whoosh indexer, which for those specified
 # extensions will index it's content
-LANGUAGES_EXTENSIONS_MAP = __get_lem()
+LANGUAGES_EXTENSIONS_MAP = pygmentsutils.get_lem()
 
 # Whoosh index targets
 
@@ -38,7 +38,7 @@
 INDEX_EXTENSIONS = LANGUAGES_EXTENSIONS_MAP.keys()
 
 # Filenames we want to index content of using whoosh
-INDEX_FILENAMES = __get_index_filenames()
+INDEX_FILENAMES = pygmentsutils.get_index_filenames()
 
 # list of readme files to search in file tree and display in summary
 # attached weights defines the search  order lower is first
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kallithea/lib/pygmentsutils.py	Tue Aug 02 17:24:25 2016 +0200
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+kallithea.lib.pygmentsutils
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Functions for extracting internal Pygments data.
+
+This file was forked by the Kallithea project in July 2014.
+Original author and date, and relevant copyright and licensing information is below:
+:created_on: Jan 5, 2011
+:author: marcink
+:copyright: (c) 2013 RhodeCode GmbH, and others.
+:license: GPLv3, see LICENSE.md for more details.
+"""
+
+from collections import defaultdict
+from itertools import ifilter
+from string import lower
+
+from pygments import lexers
+
+
+def get_lem():
+    """
+    Get language extension map based on what's inside pygments lexers
+    """
+    d = defaultdict(lambda: [])
+
+    def __clean(s):
+        s = s.lstrip('*')
+        s = s.lstrip('.')
+
+        if s.find('[') != -1:
+            exts = []
+            start, stop = s.find('['), s.find(']')
+
+            for suffix in s[start + 1:stop]:
+                exts.append(s[:s.find('[')] + suffix)
+            return map(lower, exts)
+        else:
+            return map(lower, [s])
+
+    for lx, t in sorted(lexers.LEXERS.items()):
+        m = map(__clean, t[-2])
+        if m:
+            m = reduce(lambda x, y: x + y, m)
+            for ext in m:
+                desc = lx.replace('Lexer', '')
+                d[ext].append(desc)
+
+    return dict(d)
+
+
+def get_index_filenames():
+    """
+    Get list of known indexable filenames from pygment lexer internals
+    """
+
+    filenames = []
+
+    def likely_filename(s):
+        return s.find('*') == -1 and s.find('[') == -1
+
+    for lx, t in sorted(lexers.LEXERS.items()):
+        for f in ifilter(likely_filename, t[-2]):
+            filenames.append(f)
+
+    return filenames
--- a/kallithea/lib/utils2.py	Fri Jun 24 20:12:05 2016 +0200
+++ b/kallithea/lib/utils2.py	Tue Aug 02 17:24:25 2016 +0200
@@ -43,60 +43,6 @@
 from kallithea.lib.compat import json
 
 
-def __get_lem():
-    """
-    Get language extension map based on what's inside pygments lexers
-    """
-    from pygments import lexers
-    from string import lower
-    from collections import defaultdict
-
-    d = defaultdict(lambda: [])
-
-    def __clean(s):
-        s = s.lstrip('*')
-        s = s.lstrip('.')
-
-        if s.find('[') != -1:
-            exts = []
-            start, stop = s.find('['), s.find(']')
-
-            for suffix in s[start + 1:stop]:
-                exts.append(s[:s.find('[')] + suffix)
-            return map(lower, exts)
-        else:
-            return map(lower, [s])
-
-    for lx, t in sorted(lexers.LEXERS.items()):
-        m = map(__clean, t[-2])
-        if m:
-            m = reduce(lambda x, y: x + y, m)
-            for ext in m:
-                desc = lx.replace('Lexer', '')
-                d[ext].append(desc)
-
-    return dict(d)
-
-
-def __get_index_filenames():
-    """
-    Get list of known indexable filenames from pygment lexer internals
-    """
-    from pygments import lexers
-    from itertools import ifilter
-
-    filenames = []
-
-    def likely_filename(s):
-        return s.find('*') == -1 and s.find('[') == -1
-
-    for lx, t in sorted(lexers.LEXERS.items()):
-        for f in ifilter(likely_filename, t[-2]):
-            filenames.append(f)
-
-    return filenames
-
-
 def str2bool(_str):
     """
     returns True/False value from given string, it tries to translate the