예제 #1
0
 def gen_html(self, data):
     "Interpret DTML and convert to HTML"
     if callable(data):
         data = data.__of__(self)()
     try:
         if 'dtml' in data:
             return Globals.HTML(data, globals())(self, self.REQUEST)
     except TypeError:
         pass
     return data
예제 #2
0
파일: FSObject.py 프로젝트: bendavis78/zope
class BadFile(FSObject):
    """
        Represent a file which was not readable or parseable
        as its intended type.
    """
    meta_type = 'Bad File'
    icon = 'p_/broken'

    BAD_FILE_VIEW = """\
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<h2> Bad Filesystem Object: &dtml-getId; </h2>

<h3> File Contents </h3>
<pre>
<dtml-var getFileContents>
</pre>

<h3> Exception </h3>
<pre>
<dtml-var getExceptionText>
</pre>
<dtml-var manage_page_footer>
"""

    manage_options = ({'label': 'Error', 'action': 'manage_showError'}, )

    def __init__(self,
                 id,
                 filepath,
                 exc_str='',
                 fullname=None,
                 properties=None):
        id = fullname or id  # Use the whole filename.
        self.exc_str = exc_str
        self.file_contents = ''
        FSObject.__init__(self, id, filepath, fullname, properties)

    security = ClassSecurityInfo()

    showError = Globals.HTML(BAD_FILE_VIEW)
    security.declareProtected(CMFCorePermissions.ManagePortal,
                              'manage_showError')

    def manage_showError(self, REQUEST):
        """
        """
        return self.showError(self, REQUEST)

    security.declarePrivate('_readFile')

    def _readFile(self, reparse):
        """Read the data from the filesystem.
        
        Read the file indicated by exandpath(self._filepath), and parse the
        data if necessary.  'reparse' is set when reading the second
        time and beyond.
        """
        try:
            fp = expandpath(self._filepath)
            file = open(fp, 'rb')
            try:
                data = self.file_contents = file.read()
            finally:
                file.close()
        except:
            data = self.file_contents = None  #give up
        return data

    security.declarePublic('getFileContents')

    def getFileContents(self):
        """
            Return the contents of the file, if we could read it.
        """
        return self.file_contents

    security.declarePublic('getExceptionText')

    def getExceptionText(self):
        """
            Return the exception thrown while reading or parsing
            the file.
        """
        return self.exc_str
예제 #3
0
class FSSTXMethod( FSObject ):
    """
        A chunk of StructuredText, rendered as a skin method of a
        CMFSite.
    """

    meta_type = 'Filesystem STX Method'

    manage_options=( { 'label'      : 'Customize'
                     , 'action'     : 'manage_main'
                     }
                   , { 'label'      : 'View'
                     , 'action'     : ''
                     , 'help'       : ('OFSP'
                                      ,'DTML-DocumentOrMethod_View.stx'
                                      )
                     }
                   )

    security = ClassSecurityInfo()
    security.declareObjectProtected( View )

    security.declareProtected( ViewManagementScreens, 'manage_main')
    manage_main = Globals.DTMLFile( 'custstx', _dtmldir )

    #
    #   FSObject interface
    #
    def _createZODBClone(self):
        """
            Create a ZODB (editable) equivalent of this object.
        """
        # XXX:  do this soon
        raise NotImplemented, "See next week's model."

    def _readFile( self, reparse ):

        fp = expandpath( self._filepath )
        file = open( fp, 'r' )  # not binary, we want CRLF munging here.

        try:
            data = file.read()
        finally:
            file.close()

        self.raw = data

        if reparse:
            self.cook()

    #
    #   "Wesleyan" interface (we need to be "methodish").
    #
    class func_code:
        pass

    func_code=func_code()
    func_code.co_varnames= ()
    func_code.co_argcount=0
    func_code.__roles__=()
    
    func_defaults__roles__=()
    func_defaults=()

    index_html = None   # No accidental acquisition

    default_content_type = 'text/html'

    def cook( self ):
        if not hasattr( self, '_v_cooked' ):
            self._v_cooked = format_stx( text=self.raw )
        return self._v_cooked

    _default_template = Globals.HTML( """\
<dtml-var standard_html_header>
<div class="Desktop">
<dtml-var cooked>
</div>
<dtml-var standard_html_footer>""" )

    def __call__( self, REQUEST={}, RESPONSE=None, **kw ):
        """
            Return our rendered StructuredText.
        """
        self._updateFromFS()

        if RESPONSE is not None:
            RESPONSE.setHeader( 'Content-Type', 'text/html' )
        return apply( self._render, ( REQUEST, RESPONSE ), kw )

    security.declarePrivate( '_render' )
    def _render( self, REQUEST={}, RESPONSE=None, **kw ):
        """
            Find the appropriate rendering template and use it to
            render us.
        """
        template = getattr( self, 'stxmethod_view', self._default_template )

        if getattr( template, 'isDocTemp', 0 ):
            posargs = ( self, REQUEST )
        else:
            posargs = ()
        
        return apply( template, posargs, { 'cooked' : self.cook() } )

    security.declareProtected( FTPAccess, 'manage_FTPget' )
    def manage_FTPget( self ):
        """
            Fetch our source for delivery via FTP.
        """
        return self.raw

    security.declareProtected( ViewManagementScreens
                             , 'PrincipiaSearchSource' )
    def PrincipiaSearchSource( self ):
        """
            Fetch our source for indexing in a catalog.
        """
        return self.raw

    security.declareProtected( ViewManagementScreens
                             , 'document_src' )
    def document_src( self ):
        """
            Fetch our source for indexing in a catalog.
        """
        return self.raw
예제 #4
0
def run_dtml(data, context, REQUEST):
    "run this dtml fragement and return it"
    return Globals.HTML(data, globals())(context, REQUEST)
예제 #5
0
fMessageDialog=Globals.HTML("""
<HTML>
<HEAD>
<TITLE>&dtml-title;</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM ACTION="&dtml-action;" METHOD="GET" <dtml-if
 target>TARGET="&dtml-target;"</dtml-if>>
<TABLE BORDER="0" WIDTH="100%%" CELLPADDING="10">
<TR>
  <TD VALIGN="TOP">
  <BR>
  <CENTER><B><FONT SIZE="+6" COLOR="#77003B">!</FONT></B></CENTER>
  </TD>
  <TD VALIGN="TOP">
  <BR><BR>
  <CENTER>
  <dtml-var message>
  </CENTER>
  </TD>
</TR>
<TR>
  <TD VALIGN="TOP">
  </TD>
  <TD VALIGN="TOP">
  <CENTER>
  <INPUT TYPE="SUBMIT" VALUE="   Ok   ">
  </CENTER>
  </TD>
</TR>
</TABLE>
</FORM>
</BODY></HTML>""", target='', action='manage_main', title='Changed')
예제 #6
0
파일: FSObject.py 프로젝트: bendavis78/zope
class BadFile(FSObject):
    """
        Represent a file which was not readable or parseable
        as its intended type.
    """
    meta_type = 'Bad File'
    icon = 'p_/broken'

    BAD_FILE_VIEW = """\
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<h2> Bad Filesystem Object: &dtml-getId; </h2>

<h3> File Path </h3>
<pre>
<dtml-var getFilePath>
</pre>

<h3> File Contents </h3>
<pre>
<dtml-var getFileContents>
</pre>

<h3> Exception </h3>
<pre>
<dtml-var getExceptionText>
</pre>
<dtml-var manage_page_footer>
"""

    manage_options = ({'label': 'Error', 'action': 'manage_showError'}, )

    def __init__(self,
                 id,
                 package=None,
                 entry_subpath=None,
                 filepath=None,
                 fullname=None,
                 properties=None,
                 exc_str=''):
        id = fullname or id  # Use the whole filename.
        self.exc_str = exc_str
        self.file_contents = ''
        FSObject.__init__(self, id, package, entry_subpath, filepath, fullname,
                          properties)

    security = ClassSecurityInfo()

    security.declarePrivate('showError')
    showError = Globals.HTML(BAD_FILE_VIEW)

    security.declarePrivate('_readFile')

    def _readFile(self, reparse):
        """ Stub this out.
        """
        pass

    security.declareProtected(ManagePortal, 'manage_showError')

    def manage_showError(self, REQUEST):
        """ Render the error page.
        """
        return self.showError(self, REQUEST)

    security.declarePublic('getFilePath')

    def getFilePath(self):
        """
            Return the path to the file.
        """
        if self._filepath:
            return self._filepath
        else:
            return 'package: %s, subpath: %s' % (self._package,
                                                 self._entry_subpath)

    security.declarePublic('getFileContents')

    def getFileContents(self):
        """
            Return the contents of the file, if we could read it.
        """
        return self.file_contents

    security.declarePublic('getExceptionText')

    def getExceptionText(self):
        """
            Return the exception thrown while reading or parsing
            the file.
        """
        return self.exc_str