Example #1
0
def _render(request, content, path_or_url, markup, highlight, strip_html):
    markup_no = None
    if markup:
        if markup not in MARKUPS:
            return _error(request, "Include error.",
                "Can't include: Unknown markup %r (Available: %s)" % (markup, ", ".join(MARKUPS.keys()))
            )
        markup_no = MARKUPS[markup]

    if markup_no:
        content = apply_markup(content, markup_no, request, escape_django_tags=False) # xxx: escape_django_tags
        if highlight == True:
            highlight = "html"

    if highlight == True:
        highlight = os.path.splitext(path_or_url)[1]

    if highlight is not None:
        content = make_html(content, highlight)

    if not (markup_no or highlight):
        if strip_html:
            content = strip_tags(content)
        content = escape(content)

    return content
Example #2
0
def _error(request, msg, staff_msg):
    etype, value, tb = sys.exc_info()
    if tb is not None:
        #        if settings.DEBUG and settings.RUN_WITH_DEV_SERVER:
        #            raise
        if request.user.is_superuser:
            # put the full traceback into page_msg, but only for superusers
            messages.debug(
                request,
                mark_safe("%s:<pre>%s</pre>" %
                          (escape(staff_msg), escape(traceback.format_exc()))))
        return "[%s]" % msg

    if request.user.is_staff:
        messages.error(request, staff_msg)

    return "[%s]" % msg
Example #3
0
def _error(request, msg, staff_msg):
    etype, value, tb = sys.exc_info()
    if tb is not None:
#        if settings.DEBUG and settings.RUN_WITH_DEV_SERVER:
#            raise
        if request.user.is_superuser:
            # put the full traceback into page_msg, but only for superusers
            messages.debug(request,
                mark_safe(
                    "%s:<pre>%s</pre>" % (escape(staff_msg), escape(traceback.format_exc()))
                )
            )
        return "[%s]" % msg

    if request.user.is_staff:
        messages.error(request, staff_msg)

    return "[%s]" % msg
Example #4
0
    def _setattr_debug(self, name, value):
        """
        debug __setattr__ to see if new attributes would be defined or existing changed.
        
        HowTo: http://www.pylucid.org/permalink/133/pylucid-objects#DEBUG
        """
        if self._check_setattr:
            if hasattr(self, name):
                action = "changed"
            else:
                action = "set"

            value_preview = repr(value)
            if len(value_preview) > MAX_VALUE_LENGTH - 3:
                value_preview = value_preview[:MAX_VALUE_LENGTH] + "..."
            value_preview = escape(value_preview)
            msg = "request.PYLUCID.<strong>%s</strong> %s to: <i>%s</i> (type: %s)" % (
                name, action, value_preview, escape(repr(type(value))))
            messages.info(self.request, mark_safe(msg))

        super(PyLucidRequestObjects, self).__setattr__(name, value)
Example #5
0
    def _setattr_debug(self, name, value):
        """
        debug __setattr__ to see if new attributes would be defined or existing changed.
        
        HowTo: http://www.pylucid.org/permalink/133/pylucid-objects#DEBUG
        """
        if self._check_setattr:
            if hasattr(self, name):
                action = "changed"
            else:
                action = "set"

            value_preview = repr(value)
            if len(value_preview) > MAX_VALUE_LENGTH - 3:
                value_preview = value_preview[:MAX_VALUE_LENGTH] + "..."
            value_preview = escape(value_preview)
            msg = "request.PYLUCID.<strong>%s</strong> %s to: <i>%s</i> (type: %s)" % (
                name, action, value_preview, escape(repr(type(value)))
            )
            messages.info(self.request, mark_safe(msg))

        super(PyLucidRequestObjects, self).__setattr__(name, value)
Example #6
0
def pygmentize(sourcecode, source_type):
    """
    returned html-code and the lexer_name
    """
    if not PYGMENTS_AVAILABLE:
        lexer_name = escape(source_type)
        html = no_hightlight(sourcecode)
        return html, lexer_name

    source_type = source_type.lower().strip("'\" ").lstrip(".")

    try:
        lexer = get_lexer(source_type, sourcecode)
    except lexers.ClassNotFound, err:
        info = _("unknown type")
        lexer_name = u'<small title="%s">%s</small>' % (err, info)
        html = no_hightlight(sourcecode)
        return html, lexer_name
Example #7
0
def pygmentize(sourcecode, source_type):
    """
    returned html-code and the lexer_name
    """
    if not PYGMENTS_AVAILABLE:
        lexer_name = escape(source_type)
        html = no_hightlight(sourcecode)
        return html, lexer_name

    source_type = source_type.lower().strip("'\" ").lstrip(".")

    try:
        lexer = get_lexer(source_type, sourcecode)
    except lexers.ClassNotFound, err:
        info = _("unknown type")
        lexer_name = u'<small title="%s">%s</small>' % (err, info)
        html = no_hightlight(sourcecode)
        return html, lexer_name
Example #8
0
def no_hightlight(code):
    html = u'\n<pre><code>%s</code></pre>\n' % escape(code)
    return html
Example #9
0
 def render(self, name, value, attrs=None):
     if value:
         value = escape(value)
     return super(PageContentTextarea, self).render(name, value, attrs)
Example #10
0
                assembler = DjangoTagAssembler()
                cut_data = assembler.cut_out(lucidtag_doc)[1]
                examples = cut_data

                for example in examples:
                    if not (
                        example.startswith("{%% lucidTag %s " % plugin_name) or \
                        example.startswith("{%% lucidTag %s." % plugin_name)
                        ):
                        messages.info(request,
                            _("Info: lucidTag %(plugin_name)s has wrong tag example: %(example)r") % {
                                "plugin_name": plugin_name, "example": example
                            }
                        )

                examples = [escape(example) for example in examples]

                lucidtag_doc = lucidtag_doc.split("example:", 1)[0].strip()

            lucidtag_doc = unicode(lucidtag_doc)
            doc = apply_markup(lucidtag_doc,
                markup_no=MARKUP_CREOLE, request=request,
                escape_django_tags=True
            )

        if not examples:
            # No DocString or it contains no examples -> generate a example
            fallback_example = escape("{%% lucidTag %s %%}" % plugin_name)

        lucid_tags.append({
            "plugin_name": plugin_name.replace("_", " "),
Example #11
0
def no_hightlight(code):
    html = u'\n<pre><code>%s</code></pre>\n' % escape(code)
    return html
Example #12
0
 def render(self, name, value, attrs=None):
     if value:
         value = escape(value)
     return super(PageContentTextarea, self).render(name, value, attrs)