################################################## # SPYCE - Python-based HTML Scripting # Copyright (c) 2002 Rimon Barr. # # Refer to spyce.py # CVS: $Id: core.py 1172 2006-08-29 16:59:46Z ellisj $ ################################################## __doc__ = '''Core Spyce tags.''' import os.path from spyceTag import spyceTagLibrary, spyceTagPlus, spyceTag, invokeSingleton from spyceException import spyceDone import spyce, spyceUtil from _formhelper import formatArgs _parent_files = {} class tag_parent(spyceTagPlus): name = 'parent' def syntax(self): self.syntaxSingleOnly() def filename(self, uri): return spyceUtil.url2file(uri, self.getModule('request').filename()) def find_parent(self, src): if not src: # check for parent file in current directory # (we don't climb further up the path tree, though; that doesn't make # sense for CGI-based installations) immediateparent = self.filename('parent.spi') if os.path.exists(immediateparent) \ and immediateparent != self.getModule('request').filename(): src = 'parent.spi' else: src = spyce.getServer().config.defaultparent if not src: raise 'src not specified, no parent.spi found in current directory, and defaultparent not configured' return src def begin(self, src=None, **kwargs): key = (self.getModule('request').filename(), src) try: pfile = _parent_files[key] except KeyError: pfile = _parent_files[key] = self.filename(self.find_parent(src)) if self._api._parent: spyce.DEBUG('warning: replacing old parent %s with %s' % (self._api._parent, src)) self._api._parent = (pfile, kwargs) # most of the work here is special-cased by spyceCompile class tag_login_required(spyceTagPlus): name = 'login_required' def syntax(self): self.syntaxSingleOnly() def begin(self, validator=None): import spyceConfig invokeSingleton(self._api, spyceConfig.loginrequired_render) raise spyceDone() # most of the work here is special-cased by spyceCompile class tag_login(spyceTagPlus): name = 'login' def syntax(self): self.syntaxSingleOnly() def begin(self, validator=None): self.parentRequired('form') import spyceConfig invokeSingleton(self._api, spyceConfig.login_render) # modified from code generated by spyceCompile from the following: # [[.begin name=logout singleton=True]] # # [[.end]] class tag_logout(spyceTagPlus): name='logout' def syntax(self): self.syntaxSingleOnly() def begin(self): self.parentRequired('form') request = self._api.getModule('request') taglib = self._api.getModules()['taglib'] taglib.load('form','form.py','f') taglib.tagPush('f','submit','_spy_logout',locals(),{'handler':'_coreutil.logout','value':'Log out'},False) try: taglib.tagBegin() taglib.tagBody() taglib.tagEnd() finally:taglib.tagPop() # TODO spoof line numbers in classcode better handlers = {'_spy_logout': ['_coreutil.logout']} class tag_list(spyceTagPlus): def begin(self, data, **kwargs): self.getOut().write('<%s%s>' % (self.name, formatArgs(kwargs))) for item in self.eval(data): self.getOut().write('
  • %s
  • ' % item) def end(self): self.getOut().write('' % self.name) class tag_ul(tag_list): name = 'ul' class tag_ol(tag_list): name = 'ol' class tag_dl(spyceTagPlus): name = 'dl' def begin(self, data, **kwargs): self.getOut().write('' % formatArgs(kwargs)) for term, desc in self.eval(data): self.getOut().write('
    %s
    %s
    ' % (term, desc)) def end(self): self.getOut().write('') class tag_table(spyceTagPlus): name = 'table' def begin(self, data, **kwargs): self.getOut().write('' % formatArgs(kwargs)) for row in self.eval(data): self.getOut().write('') for item in row: self.getOut().write('%s' % item) self.getOut().write('') def end(self): self.getOut().write('') class core(spyceTagLibrary): tags = [ tag_parent, tag_login_required, tag_login, tag_logout, tag_ul, tag_ol, tag_dl, tag_table, ]