#!/usr/bin/env python




##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
    import builtins as builtin
except ImportError:
    import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from xpdeint.Segments._Segment import _Segment
from xpdeint.CallOnceGuards import callOncePerInstanceGuard

##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.4.4'
__CHEETAH_versionTuple__ = (2, 4, 4, 'development', 0)
__CHEETAH_genTime__ = 1484975072.521234
__CHEETAH_genTimestamp__ = 'Sat Jan 21 16:04:32 2017'
__CHEETAH_src__ = '/home/mattias/xmds-2.2.3/admin/staging/xmds-2.2.3/xpdeint/Segments/SequenceSegment.tmpl'
__CHEETAH_srcLastModified__ = 'Sat Feb  4 18:39:07 2012'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class SequenceSegment(_Segment):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        super(SequenceSegment, self).__init__(*args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def description(self, **KWS):



        ## Generated from @def description: segment $segmentNumber (Sequence) at line 28, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write(u'''segment ''')
        _v = VFFSL(SL,"segmentNumber",True) # u'$segmentNumber' on line 28, col 27
        if _v is not None: write(_filter(_v, rawExpr=u'$segmentNumber')) # from line 28, col 27.
        write(u''' (Sequence)''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def segmentFunctionBody(self, function, **KWS):



        ## CHEETAH: generated from @def segmentFunctionBody($function) at line 30, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        extraIndent = 0
        if VFFSL(SL,"localCycles",True) > 1: # generated from line 33, col 3
            write(u'''// Initialise child segments
''')
            _v = VFFSL(SL,"allocate",True) # u'${allocate}' on line 35, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'${allocate}')) # from line 35, col 1.
            _v = VFFSL(SL,"initialise",True) # u'${initialise}' on line 36, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'${initialise}')) # from line 36, col 1.
            write(u'''for (unsigned long _cycle = 0; _cycle < ''')
            _v = VFFSL(SL,"localCycles",True) # u'${localCycles}' on line 37, col 41
            if _v is not None: write(_filter(_v, rawExpr=u'${localCycles}')) # from line 37, col 41.
            write(u'''; _cycle++) {
''')
            extraIndent = 2
        # 
        _v = VFFSL(SL,"callChildSegments",False)(function) # u'${callChildSegments(function), extraIndent=extraIndent}' on line 41, col 1
        if _v is not None: write(_filter(_v, extraIndent=extraIndent, rawExpr=u'${callChildSegments(function), extraIndent=extraIndent}')) # from line 41, col 1.
        # 
        if VFFSL(SL,"localCycles",True) > 1: # generated from line 43, col 3
            write(u'''}
''')
            extraIndent = 0
            write(u'''// Finalise child segments
''')
            _v = VFFSL(SL,"finalise",True) # u'${finalise}' on line 47, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'${finalise}')) # from line 47, col 1.
            _v = VFFSL(SL,"free",True) # u'${free}' on line 48, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'${free}')) # from line 48, col 1.
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def callChildSegments(self, function, **KWS):



        ## CHEETAH: generated from @def callChildSegments($function) at line 53, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        for segment in VFFSL(SL,"childSegments",True): # generated from line 55, col 3
            _v = VFN(VFN(VFFSL(SL,"segment",True),"functions",True)['segment'],"call",False)(parentFunction=function) # u"${segment.functions['segment'].call(parentFunction=function)}" on line 56, col 1
            if _v is not None: write(_filter(_v, rawExpr=u"${segment.functions['segment'].call(parentFunction=function)}")) # from line 56, col 1.
            write(u'''
''')
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    @callOncePerInstanceGuard
    def allocate(self, **KWS):



        ## CHEETAH: generated from @def allocate at line 62, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        _v = super(SequenceSegment, self).allocate()
        if _v is not None: write(_filter(_v))
        # 
        for segment in VFFSL(SL,"childSegments",True): # generated from line 66, col 3
            _v = VFFSL(SL,"segment.allocate",True) # u'$segment.allocate' on line 67, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'$segment.allocate')) # from line 67, col 1.
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    @callOncePerInstanceGuard
    def free(self, **KWS):



        ## CHEETAH: generated from @def free at line 73, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        _v = super(SequenceSegment, self).free()
        if _v is not None: write(_filter(_v))
        # 
        for segment in VFFSL(SL,"childSegments",True): # generated from line 77, col 3
            _v = VFFSL(SL,"segment.free",True) # u'$segment.free' on line 78, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'$segment.free')) # from line 78, col 1.
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    @callOncePerInstanceGuard
    def initialise(self, **KWS):



        ## CHEETAH: generated from @def initialise at line 84, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        _v = super(SequenceSegment, self).initialise()
        if _v is not None: write(_filter(_v))
        # 
        for segment in VFFSL(SL,"childSegments",True): # generated from line 88, col 3
            _v = VFFSL(SL,"segment.initialise",True) # u'$segment.initialise' on line 89, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'$segment.initialise')) # from line 89, col 1.
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    @callOncePerInstanceGuard
    def finalise(self, **KWS):



        ## CHEETAH: generated from @def finalise at line 95, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        _v = super(SequenceSegment, self).finalise()
        if _v is not None: write(_filter(_v))
        # 
        for segment in VFFSL(SL,"childSegments",True): # generated from line 99, col 3
            _v = VFFSL(SL,"segment.finalise",True) # u'$segment.finalise' on line 100, col 1
            if _v is not None: write(_filter(_v, rawExpr=u'$segment.finalise')) # from line 100, col 1.
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        # SequenceSegment.tmpl
        # 
        # Created by Graham Dennis on 2008-03-18.
        # 
        # Copyright (c) 2008-2012, Graham Dennis
        # 
        # This program is free software: you can redistribute it and/or modify
        # it under the terms of the GNU General Public License as published by
        # the Free Software Foundation, either version 2 of the License, or
        # (at your option) any later version.
        # 
        # This program is distributed in the hope that it will be useful,
        # but WITHOUT ANY WARRANTY; without even the implied warranty of
        # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        # GNU General Public License for more details.
        # 
        # You should have received a copy of the GNU General Public License
        # along with this program.  If not, see <http://www.gnu.org/licenses/>.
        # 
        write(u'''
''')
        # 
        #   Description of template
        write(u'''






''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    _mainCheetahMethod_for_SequenceSegment= 'writeBody'

## END CLASS DEFINITION

if not hasattr(SequenceSegment, '_initCheetahAttributes'):
    templateAPIClass = getattr(SequenceSegment, '_CHEETAH_templateClass', Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(SequenceSegment)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit http://www.CheetahTemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=SequenceSegment()).run()


