############################################################################## # Copyright Sean Treadway 2001 (c) seant@superchannel.org # Licensed under the Zope public license # http://www.zope.org/Resources/License # import re import string from urllib import * import Acquisition re_format = re.compile('|<|>| |\t', re.I) def abs_val(ob): if callable(ob): return ob() return ob class Formatter(Acquisition.Implicit): tab_stop = 4 def __call__(self, match): m = match.group(0) if m == '<': return '<' elif m == '>': return '>' elif m == ' ': return ' ' elif m == '\t': return ' ' * self.tab_stop else: id = match.group(1) if hasattr(self, id): ob = getattr(self, id) url = '..' if hasattr(ob, 'absolute_url'): url = ob.absolute_url(1) return '<%s>' % (quote(url), m[1:-1]) return '<%s>' % m[1:-1] def view_source(self, REQUEST=None): "Render the document_src with links to included variables" # TODO make sure we don't get crawled res = [] a = res.append a(self.standard_html_header(self, REQUEST=REQUEST)) # Little secret for my site if hasattr(self, 'menu_top'): a(self.menu_top(self, REQUEST=REQUEST)) path = self.absolute_url(1) a('

%s

' % (path, path)) a('Up (..)') a('Back...') a('
') a('
')
    try:
        if self.isPrincipiaFolderish:
            # Display a link to our contents instead
            for ob in self.objectValues():
                a('%s' % (quote(abs_val(ob.id)), abs_val(ob.icon), abs_val(ob.id)))
        else:
            try:
                # Create a linker and have it aquire us
                formatter = Formatter()
                formatter = formatter.__of__(self.aq_parent)

                # Highlight the links
                src = self.document_src(REQUEST, REQUEST.RESPONSE)
                src = re_format.sub(formatter, src)
                a(src)
            except:
                a('Cannot render the source for this ' + self.meta_type)
    except IOError:
        if hasattr(self, 'index.html') and REQUEST:
            REQUEST.RESPONSE.redirect('index.html/view_source')
        else:
            a('Cannot render the source for this ' + self.meta_type)

    a('
') a(self.standard_html_footer(self, REQUEST)) if REQUEST: REQUEST.RESPONSE.setHeader('Content-Type', 'text/html') return string.join(res, '\n')