db_annotate
  • Overview
  • Repository
  • Tickets
  • Statistics
  • Projects

Repository

Add the Sql lexer, escape code otherwise

Parent commits : 7a2f3937fdf1563bf66208b7f5f25f7e67951185,
Children commits : 505d84dd1d045a31204deab9d9302e8626c5b522,

By Laurent Defert on 2015-01-26 20:14:39
Add the Sql lexer, escape code otherwise

Browse content
Difference with parent commit 7a2f3937fdf1563bf66208b7f5f25f7e67951185
Files modified:
dbannotate/db.py
--- 
+++ 
@@ -220,7 +220,7 @@
         if table_size == 0:
             errors += ['empty table']
         elif table_size < MIN_TABLE_SIZE:
-            errors += ['has only %s entries' % table_size]
+            errors += ['has only %s rows' % table_size]
 
         foreign = self.inspector.get_foreign_keys(table)
         primary = self.inspector.get_pk_constraint(table)

dbannotate/html.py
--- 
+++ 
@@ -14,6 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from cgi import escape
 from datetime import datetime
 import os
 import re
@@ -175,16 +176,18 @@
     CSS = ['highlight.css']
     LEXERS = {
         'plpgsql': PlPgsqlLexer(),
+        'sql': SqlLexer(),
     }
 
     def _get_lexer(self, language):
-        if language not in self.LEXERS:
-            raise NotImplemented('Unknown function language "%s"' % language)
-        return self.LEXERS[language]
+        return self.LEXERS.get(language)
 
     def _render(self, function, language, code):
         lexer = self._get_lexer(language)
-        highlighted = highlight(code, lexer, FORMATTER)
+        if lexer is not None:
+            highlighted = highlight(code, lexer, FORMATTER)
+        else:
+            highlighted = '<pre>%s</pre>' % escape(code)
         self.write('<h1>Function %s</h1>' % function)
         self.write('%s language' % language)
         self.write(highlighted)

Generated with KisssPM