diff options
| author | NCH(OpenERP) <> | 2009-12-15 14:02:18 +0530 |
|---|---|---|
| committer | hda (Tiny) <hda@tinyerp.com> | 2009-12-15 14:02:18 +0530 |
| commit | 3bcfde0b35e95c4cebfca52d5777626fa09b7fe2 (patch) | |
| tree | 598dc3e05e1950f2704267c9ae5c9c8d6b00d471 /bin/mako/ext | |
| parent | 3f33f865f59e7acd09b1b3e3d6b1e5a7c3b47076 (diff) | |
| parent | 99ffac43ea7e7a82adc720bd286321eac26fcdb3 (diff) | |
Removed mako from source and improved printscreen report
bzr revid: hda@tinyerp.com-20091215083218-4pcbwf7vcpi5e90y
Diffstat (limited to 'bin/mako/ext')
| -rwxr-xr-x | bin/mako/ext/__init__.py | 20 | ||||
| -rwxr-xr-x | bin/mako/ext/autohandler.py | 58 | ||||
| -rwxr-xr-x | bin/mako/ext/babelplugin.py | 119 | ||||
| -rwxr-xr-x | bin/mako/ext/preprocessors.py | 21 | ||||
| -rwxr-xr-x | bin/mako/ext/pygmentplugin.py | 102 | ||||
| -rwxr-xr-x | bin/mako/ext/turbogears.py | 51 |
6 files changed, 0 insertions, 371 deletions
diff --git a/bin/mako/ext/__init__.py b/bin/mako/ext/__init__.py deleted file mode 100755 index 22e68000a4b..00000000000 --- a/bin/mako/ext/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -##############################################################################
\ No newline at end of file diff --git a/bin/mako/ext/autohandler.py b/bin/mako/ext/autohandler.py deleted file mode 100755 index e63b005accf..00000000000 --- a/bin/mako/ext/autohandler.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -"""adds autohandler functionality to Mako templates. - -requires that the TemplateLookup class is used with templates. - -usage: - -<%! - from mako.ext.autohandler import autohandler -%> -<%inherit file="${autohandler(template, context)}"/> - - -or with custom autohandler filename: - -<%! - from mako.ext.autohandler import autohandler -%> -<%inherit file="${autohandler(template, context, name='somefilename')}"/> - -""" - -import posixpath, os, re - -def autohandler(template, context, name='autohandler'): - lookup = context.lookup - _template_uri = template.module._template_uri - if not lookup.filesystem_checks: - try: - return lookup._uri_cache[(autohandler, _template_uri, name)] - except KeyError: - pass - - tokens = re.findall(r'([^/]+)', posixpath.dirname(_template_uri)) + [name] - while len(tokens): - path = '/' + '/'.join(tokens) - if path != _template_uri and _file_exists(lookup, path): - if not lookup.filesystem_checks: - return lookup._uri_cache.setdefault((autohandler, _template_uri, name), path) - else: - return path - if len(tokens) == 1: - break - tokens[-2:] = [name] - - if not lookup.filesystem_checks: - return lookup._uri_cache.setdefault((autohandler, _template_uri, name), None) - else: - return None - -def _file_exists(lookup, path): - psub = re.sub(r'^/', '',path) - for d in lookup.directories: - if os.path.exists(d + '/' + psub): - return True - else: - return False - diff --git a/bin/mako/ext/babelplugin.py b/bin/mako/ext/babelplugin.py deleted file mode 100755 index 54d266877ba..00000000000 --- a/bin/mako/ext/babelplugin.py +++ /dev/null @@ -1,119 +0,0 @@ -# -*- coding: utf-8 -*- -"""gettext message extraction via Babel: http://babel.edgewall.org/""" -from StringIO import StringIO - -from babel.messages.extract import extract_python - -from mako import lexer, parsetree - -def extract(fileobj, keywords, comment_tags, options): - """Extract messages from Mako templates. - - :param fileobj: the file-like object the messages should be extracted from - :param keywords: a list of keywords (i.e. function names) that should be - recognized as translation functions - :param comment_tags: a list of translator tags to search for and include - in the results - :param options: a dictionary of additional options (optional) - :return: an iterator over ``(lineno, funcname, message, comments)`` tuples - :rtype: ``iterator`` - """ - encoding = options.get('input_encoding', options.get('encoding', None)) - - template_node = lexer.Lexer(fileobj.read(), - input_encoding=encoding).parse() - for extracted in extract_nodes(template_node.get_children(), - keywords, comment_tags, options): - yield extracted - -def extract_nodes(nodes, keywords, comment_tags, options): - """Extract messages from Mako's lexer node objects - - :param nodes: an iterable of Mako parsetree.Node objects to extract from - :param keywords: a list of keywords (i.e. function names) that should be - recognized as translation functions - :param comment_tags: a list of translator tags to search for and include - in the results - :param options: a dictionary of additional options (optional) - :return: an iterator over ``(lineno, funcname, message, comments)`` tuples - :rtype: ``iterator`` - """ - translator_comments = [] - in_translator_comments = False - - for node in nodes: - child_nodes = None - if in_translator_comments and isinstance(node, parsetree.Text) and \ - not node.content.strip(): - # Ignore whitespace within translator comments - continue - - if isinstance(node, parsetree.Comment): - value = node.text.strip() - if in_translator_comments: - translator_comments.extend(_split_comment(node.lineno, value)) - continue - for comment_tag in comment_tags: - if value.startswith(comment_tag): - in_translator_comments = True - translator_comments.extend(_split_comment(node.lineno, - value)) - continue - - if isinstance(node, parsetree.DefTag): - code = node.function_decl.code - child_nodes = node.nodes - elif isinstance(node, parsetree.CallTag): - code = node.code.code - child_nodes = node.nodes - elif isinstance(node, parsetree.PageTag): - code = node.body_decl.code - elif isinstance(node, parsetree.ControlLine): - if node.isend: - translator_comments = [] - in_translator_comments = False - continue - code = node.text - elif isinstance(node, parsetree.Code): - # <% and <%! blocks would provide their own translator comments - translator_comments = [] - in_translator_comments = False - - code = node.code.code - elif isinstance(node, parsetree.Expression): - code = node.code.code - else: - translator_comments = [] - in_translator_comments = False - continue - - # Comments don't apply unless they immediately preceed the message - if translator_comments and \ - translator_comments[-1][0] < node.lineno - 1: - translator_comments = [] - else: - translator_comments = \ - [comment[1] for comment in translator_comments] - - if isinstance(code, unicode): - code = code.encode('ascii', 'backslashreplace') - code = StringIO(code) - for lineno, funcname, messages, python_translator_comments \ - in extract_python(code, keywords, comment_tags, options): - yield (node.lineno + (lineno - 1), funcname, messages, - translator_comments + python_translator_comments) - - translator_comments = [] - in_translator_comments = False - - if child_nodes: - for extracted in extract_nodes(child_nodes, keywords, comment_tags, - options): - yield extracted - - -def _split_comment(lineno, comment): - """Return the multiline comment at lineno split into a list of comment line - numbers and the accompanying comment line""" - return [(lineno + index, line) for index, line in - enumerate(comment.splitlines())] diff --git a/bin/mako/ext/preprocessors.py b/bin/mako/ext/preprocessors.py deleted file mode 100755 index ac7618b979e..00000000000 --- a/bin/mako/ext/preprocessors.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -"""preprocessing functions, used with the 'preprocessor' argument on Template, TemplateLookup""" - -import re - -def convert_comments(text): - """preprocess old style comments. - - example: - - from mako.ext.preprocessors import convert_comments - t = Template(..., preprocessor=preprocess_comments)""" - return re.sub(r'(?<=\n)\s*#[^#]', "##", text) - -# TODO -def create_tag(callable): - """given a callable, extract the *args and **kwargs, and produce a preprocessor - that will parse for <%<funcname> <args>> and convert to an appropriate <%call> statement. - - this allows any custom tag to be created which looks like a pure Mako-style tag.""" - raise NotImplementedError("Future functionality....")
\ No newline at end of file diff --git a/bin/mako/ext/pygmentplugin.py b/bin/mako/ext/pygmentplugin.py deleted file mode 100755 index aa61d75678e..00000000000 --- a/bin/mako/ext/pygmentplugin.py +++ /dev/null @@ -1,102 +0,0 @@ -# -*- coding: utf-8 -*- -import re -try: - set -except NameError: - from sets import Set as set - -from pygments.lexers.web import \ - HtmlLexer, XmlLexer, JavascriptLexer, CssLexer -from pygments.lexers.agile import PythonLexer -from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \ - include, using, this -from pygments.token import Error, Punctuation, \ - Text, Comment, Operator, Keyword, Name, String, Number, Other, Literal -from pygments.util import html_doctype_matches, looks_like_xml - -class MakoLexer(RegexLexer): - name = 'Mako' - aliases = ['mako'] - filenames = ['*.mao'] - - tokens = { - 'root': [ - (r'(\s*)(\%)(\s*end(?:\w+))(\n|\Z)', - bygroups(Text, Comment.Preproc, Keyword, Other)), - (r'(\s*)(\%)([^\n]*)(\n|\Z)', - bygroups(Text, Comment.Preproc, using(PythonLexer), Other)), - (r'(\s*)(##[^\n]*)(\n|\Z)', - bygroups(Text, Comment.Preproc, Other)), - (r'''(?s)<%doc>.*?</%doc>''', Comment.Preproc), - (r'(<%)([\w\.\:]+)', bygroups(Comment.Preproc, Name.Builtin), 'tag'), - (r'(</%)([\w\.\:]+)(>)', bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)), - (r'<%(?=([\w\.\:]+))', Comment.Preproc, 'ondeftags'), - (r'(<%(?:!?))(.*?)(%>)(?s)', bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)), - (r'(\$\{)(.*?)(\})', - bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)), - (r'''(?sx) - (.+?) # anything, followed by: - (?: - (?<=\n)(?=%|\#\#) | # an eval or comment line - (?=\#\*) | # multiline comment - (?=</?%) | # a python block - # call start or end - (?=\$\{) | # a substitution - (?<=\n)(?=\s*%) | - # - don't consume - (\\\n) | # an escaped newline - \Z # end of string - ) - ''', bygroups(Other, Operator)), - (r'\s+', Text), - ], - 'ondeftags': [ - (r'<%', Comment.Preproc), - (r'(?<=<%)(include|inherit|namespace|page)', Name.Builtin), - include('tag'), - ], - 'tag': [ - (r'((?:\w+)\s*=)\s*(".*?")', - bygroups(Name.Attribute, String)), - (r'/?\s*>', Comment.Preproc, '#pop'), - (r'\s+', Text), - ], - 'attr': [ - ('".*?"', String, '#pop'), - ("'.*?'", String, '#pop'), - (r'[^\s>]+', String, '#pop'), - ], - } - - -class MakoHtmlLexer(DelegatingLexer): - name = 'HTML+Mako' - aliases = ['html+mako'] - - def __init__(self, **options): - super(MakoHtmlLexer, self).__init__(HtmlLexer, MakoLexer, - **options) - -class MakoXmlLexer(DelegatingLexer): - name = 'XML+Mako' - aliases = ['xml+mako'] - - def __init__(self, **options): - super(MakoXmlLexer, self).__init__(XmlLexer, MakoLexer, - **options) - -class MakoJavascriptLexer(DelegatingLexer): - name = 'JavaScript+Mako' - aliases = ['js+mako', 'javascript+mako'] - - def __init__(self, **options): - super(MakoJavascriptLexer, self).__init__(JavascriptLexer, - MakoLexer, **options) - -class MakoCssLexer(DelegatingLexer): - name = 'CSS+Mako' - aliases = ['css+mako'] - - def __init__(self, **options): - super(MakoCssLexer, self).__init__(CssLexer, MakoLexer, - **options) diff --git a/bin/mako/ext/turbogears.py b/bin/mako/ext/turbogears.py deleted file mode 100755 index c86f8d534df..00000000000 --- a/bin/mako/ext/turbogears.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -import re, inspect -from mako.lookup import TemplateLookup -from mako.template import Template - -class TGPlugin(object): - """TurboGears compatible Template Plugin.""" - - def __init__(self, extra_vars_func=None, options=None, extension='mak'): - self.extra_vars_func = extra_vars_func - self.extension = extension - if not options: - options = {} - - # Pull the options out and initialize the lookup - lookup_options = {} - for k, v in options.iteritems(): - if k.startswith('mako.'): - lookup_options[k[5:]] = v - elif k in ['directories', 'filesystem_checks', 'module_directory']: - lookup_options[k] = v - self.lookup = TemplateLookup(**lookup_options) - - self.tmpl_options = {} - # transfer lookup args to template args, based on those available - # in getargspec - for kw in inspect.getargspec(Template.__init__)[0]: - if kw in lookup_options: - self.tmpl_options[kw] = lookup_options[kw] - - def load_template(self, templatename, template_string=None): - """Loads a template from a file or a string""" - if template_string is not None: - return Template(template_string, **self.tmpl_options) - # Translate TG dot notation to normal / template path - if '/' not in templatename: - templatename = '/' + templatename.replace('.', '/') + '.' + self.extension - - # Lookup template - return self.lookup.get_template(templatename) - - def render(self, info, format="html", fragment=False, template=None): - if isinstance(template, basestring): - template = self.load_template(template) - - # Load extra vars func if provided - if self.extra_vars_func: - info.update(self.extra_vars_func()) - - return template.render(**info) - |
