ComponentTag.py :  » Web-Server » SkunkWEB » skunkweb-3.4.4 » pylibs » AE » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Server » SkunkWEB 
SkunkWEB » skunkweb 3.4.4 » pylibs » AE » ComponentTag.py
#  
#  Copyright (C) 2001 Andrew T. Csillag <drew_csillag@geocities.com>
#  
#      You may distribute under the terms of either the GNU General
#      Public License or the SkunkWeb License, as specified in the
#      README file.
#   
"""
This module implements the component family of tags
"""

import Component
from CommonStuff import *
from DT import DT_REGULAR,DT_INCLUDE,DT_DATA

class ComponentTag(DTTag):
    """
    The component tag is used to render non-cacheable components which 
    inherit the namespace of their parent
    """
    def __init__(self):
        DTTag.__init__ ( self, 'component', isempty = 1, 
                         modules = [Component] )

    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        #args=DTUtil.tagCall(tag, ['name', ('cache', 'no'),
        #                          ('defer', -1), ('__args__', None)],
        #                    kwcol='kw')
        args=DTUtil.tagCall(tag, ['name', ('cache', 'no'),
                                  ('__args__', None)],
                            kwcol='kw')
        kw = DTCompilerUtil.pyifyKWArgs(tag, args['kw'])
        args = DTCompilerUtil.pyifyArgs(tag, args)

        # Create the temp variables
        text = DTCompilerUtil.getTempName()

        if args['__args__']:
            argsarg = DTCompilerUtil.getTempName()
            codeout.write(indent, '%s = %s' % (argsarg, args['__args__']))
            codeout.write(indent, 'if type(%s) != __h.types.DictType:' % argsarg)
            codeout.write(indent+4, 'raise TypeError, "__args__ argument must'
                          ' be a dictionary"')
            codeout.write(indent, '%s.update(%s)' % (argsarg, kw))
            # Render the component
            #codeout.write ( indent, '%s = __h.Component.callComponent ( '
            #            '%s, (%s), cache = __h.Component.strBool(%s)'
            #                ', defer = __h.Component.strBool(%s))' % 
            #            ( text, args['name'], argsarg, args['cache'],
            #              args['defer'] ) )
            codeout.write ( indent, '%s = __h.Component.callComponent ( '
                        '%s, (%s), cache = __h.Component.strCache(%s)'
                            ')' % 
                        ( text, args['name'], argsarg, args['cache'],
                           ) )
                                      
        else:
            # Render the component
            #codeout.write ( indent, '%s = __h.Component.callComponent ( '
            #                '%s, (%s), cache = __h.Component.strBool(%s)'
            #                ', defer = __h.Component.strBool(%s))' % 
            #                ( text, args['name'], kw, args['cache'],
            #                  args['defer'] ) )
            codeout.write ( indent, '%s = __h.Component.callComponent ( '
                            '%s, (%s), cache = __h.Component.strCache(%s)'
                            ')' % 
                            ( text, args['name'], kw, args['cache'],
                              ) )

        # Write the result
        codeout.write ( indent, '__h.OUTPUT.write ( %s )' % text )

        # Delete the temporary variable
        codeout.write ( indent, 'del %s' % text )
        if args['__args__']:
            codeout.write(indent, 'del %s' % argsarg)

class DataComponentTag(DTTag):
    """
    This tag is used to render components which return a pickleable 
    value
    """
    def __init__(self):
        DTTag.__init__ ( self, 'datacomp', isempty=1, 
                         modules = [ Component ] )

    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        #pargs=args=DTUtil.tagCall(tag, [ 'var', 'name', 
        #                                 ( 'cache', 'no'), ('defer', -1),
        #                                 ('__args__', None)],
        #                          kwcol='kw')
        pargs=args=DTUtil.tagCall(tag, [ 'var', 'name', 
                                         ( 'cache', 'no'), 
                                         ('__args__', None)],
                                  kwcol='kw')
        kw=DTCompilerUtil.pyifyKWArgs(tag, args['kw'])
        args=DTCompilerUtil.pyifyArgs(tag, args)

        varname = DTCompilerUtil.checkName(tag, 'var', args['var'],
                                           pargs['var'])
        if args['__args__']:
            argsarg = DTCompilerUtil.getTempName()
            codeout.write(indent, '%s = %s' % (argsarg, args['__args__']))
            codeout.write(indent, 'if type(%s) != __h.types.DictType:' % argsarg)
            codeout.write(indent+4, 'raise TypeError, "__args__ argument must'
                          ' be a dictionary"')
            codeout.write(indent, '%s.update(%s)' % (argsarg, kw))
            # Render the component
            #codeout.write (
            #    indent, '%s = __h.Component.callComponent ( '
            #    '%s, (%s), cache = __h.Component.strBool(%s)'
            #    ', defer = __h.Component.strBool(%s), '
            #    'compType = __h.Component.DT_DATA )' % 
            #    ( varname, args['name'], argsarg,
            #      args['cache'],
            #      args['defer']) )
            codeout.write (
                indent, '%s = __h.Component.callComponent ( '
                '%s, (%s), cache = __h.Component.strCache(%s)'
                ', compType = __h.Component.DT_DATA )' % 
                ( varname, args['name'], argsarg,
                  args['cache'],
                  ) )
            codeout.write( indent, 'del %s' % argsarg)
        else:
            # Render the component
            #codeout.write (
            #    indent, '%s = __h.Component.callComponent ( '
            #    '%s, (%s), cache = __h.Component.strBool(%s)'
            #    ', defer = __h.Component.strBool(%s), '
            #    'compType = __h.Component.DT_DATA )' % 
            #    ( varname, args['name'], kw, args['cache'],
            #      args['defer']) )
            codeout.write (
                indent, '%s = __h.Component.callComponent ( '
                '%s, (%s), cache = __h.Component.strCache(%s)'
                ', compType = __h.Component.DT_DATA )' % 
                ( varname, args['name'], kw, args['cache'] ))#,
            #args['defer']) )

class IncludeTag(DTTag):
    """
    This tag is used to run a component in parent namespace
    """
    def __init__(self):
        DTTag.__init__ ( self, 'include', isempty=1, 
                         modules = [ Component ] )

    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        args=DTUtil.tagCall(tag, [ 'name', ] )

        args=DTCompilerUtil.pyifyArgs(tag, args)

        text = DTCompilerUtil.getTempName()
        
        codeout.write(indent, '%s = __h.Component.callComponent ('
                              '%s, {}, '
                              'compType = __h.Component.DT_INCLUDE )' % 
                                            (text, args['name']) )

        codeout.write(indent, '__h.OUTPUT.write(%s)' % text)

        codeout.write(indent, 'del %s' % (text))
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.