MsgCatalogTags.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 » MsgCatalogTags.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.
#   
"""
Here the message catalog tags are implemented
"""

import string

from CommonStuff import *
import MsgCatalog, Cache
from SkunkExcept import *
import SkunkExcept
from Logs import DEBUG,WEIRD

class CatalogTag ( DTTag ):
    """
    General purpose catalog tag - supports both multi-language and basic 
    catalogs
    """

    def __init__ ( self ):
        DTTag.__init__ ( self, 'catalog', isempty = 1,
                         modules = [ MsgCatalog, Cache ])

    def checkCatName(self, catname):
        DEBUG(WEIRD, "in checkCatName, stub version")
        return catname

    def genCode ( self, indent, codeout, tagreg, tag ):
        """
        Generate our code
        """

        DTCompilerUtil.tagDebug ( indent, codeout, tag )

        pargs = args = DTUtil.tagCall ( tag, [ 'catname', 'name' ] )

        args = DTCompilerUtil.pyifyArgs ( tag, args )

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])

        # this hook is to accomodate the aed-compat module
        catname=self.checkCatName(args['catname'])
        
        # Call the create catalog function and assign the result to variable
        codeout.write ( indent, '%s = __h.Cache.getMessageCatalog '
                        '( %s )' % ( name, catname ))

        # All done

class MessageTag ( DTTag ):

    def __init__ ( self ):
        DTTag.__init__ ( self, 'msg', isempty = 1, 
                         modules = ( MsgCatalog, SkunkExcept, string ) )

    def genCode ( self, indent, codeout, tagreg, tag ):
        """
        Generate our code
        """
        DTCompilerUtil.tagDebug ( indent, codeout, tag )

        # Message name is in msgObject.msgName format
        args = DTUtil.tagCall ( tag, [ 'catname', 'msgname', 
                                     ( 'lang', 'None' ), 
             ('fmt', 'None') ],
                                 kwcol = 'kw' )

        pargs = DTCompilerUtil.pyifyArgs ( tag, args )
        kw = DTCompilerUtil.pyifyKWArgs ( tag, pargs['kw'] )

        # Cool, now let's check if the message catalog exists
        text = DTCompilerUtil.getTempName()
        fmt = DTCompilerUtil.getTempName()
        catname = args['catname']

        codeout.write ( indent, 'try:' )
        codeout.write ( indent+4, 'if %s:' % pargs['fmt'] )
        codeout.write ( indent+8, '%s = __h.VALFMTRGY[%s]' % ( fmt, 
                                                               pargs['fmt'] ))
        codeout.write ( indent+4, 'else:' )
        codeout.write ( indent+8, '%s = lambda x:x' % fmt )
        codeout.write ( indent, 'except:' )
        codeout.write ( indent+4, 'raise __h.SkunkExcept.SkunkStandardError, '
              '"unknown formatting: %s, use one of (%%s)" %% '
              '__h.string.join ( __h.VALFMTRGY.keys(), "," )' % pargs['fmt'] )

        codeout.write ( indent, '%s = __h.MsgCatalog.getMessage ( %s, %s, '
                        'default="", lang = %s, fmt = %s, bindvars = %s) ' % 
                        ( text, catname, pargs['msgname'], 
                          pargs['lang'], fmt, kw ) )
                                            
        codeout.write ( indent, '__h.OUTPUT.write ( %s )' % text )

        codeout.write ( indent, 'del %s, %s' % (text, fmt))

#
# Create the tag list
#
CatalogTags = [ CatalogTag(), MessageTag() ]
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.